Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@parcel/core

Package Overview
Dependencies
Maintainers
1
Versions
889
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/core - npm Package Compare versions

Comparing version 2.0.0-nightly.251 to 2.0.0-nightly.255

4

lib/assetUtils.js

@@ -33,3 +33,3 @@ "use strict";

function createAsset(options) {
var _options$committed, _options$isIsolated, _options$isInline, _options$sideEffects;
var _options$committed, _options$isIsolated, _options$isInline, _options$symbols, _options$sideEffects;

@@ -59,3 +59,3 @@ let idBase = options.idBase != null ? options.idBase : options.filePath;

stats: options.stats,
symbols: options.symbols || new Map(),
symbols: (_options$symbols = options.symbols) !== null && _options$symbols !== void 0 ? _options$symbols : options.symbols === null ? null : new Map(),
sideEffects: (_options$sideEffects = options.sideEffects) !== null && _options$sideEffects !== void 0 ? _options$sideEffects : true,

@@ -62,0 +62,0 @@ uniqueKey: uniqueKey,

@@ -556,14 +556,12 @@ "use strict";

return this._graph.filteredTraverse(filter, visit, (0, _nullthrows.default)(this._graph.getNode(bundle.id)));
} // Resolve the export `symbol` of `asset` to the source,
// stopping at the first asset after leaving `bundle` (symbol is nullish in that case)
}
resolveSymbol(asset, symbol, boundary) {
var _asset$symbols$get, _asset$symbols$get4;
var _asset$symbols, _asset$symbols$get, _asset$symbols4, _asset$symbols4$get;
let assetOutside = boundary && !this.bundleHasAsset(boundary, asset);
let identifier = (_asset$symbols$get = asset.symbols.get(symbol)) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local;
let identifier = (_asset$symbols = asset.symbols) === null || _asset$symbols === void 0 ? void 0 : (_asset$symbols$get = _asset$symbols.get(symbol)) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local;
if (symbol === '*') {
var _asset$symbols$get2;
var _asset$symbols2, _asset$symbols2$get;

@@ -573,7 +571,8 @@ return {

exportSymbol: '*',
symbol: identifier,
loc: (_asset$symbols$get2 = asset.symbols.get(symbol)) === null || _asset$symbols$get2 === void 0 ? void 0 : _asset$symbols$get2.loc
symbol: identifier !== null && identifier !== void 0 ? identifier : null,
loc: (_asset$symbols2 = asset.symbols) === null || _asset$symbols2 === void 0 ? void 0 : (_asset$symbols2$get = _asset$symbols2.get(symbol)) === null || _asset$symbols2$get === void 0 ? void 0 : _asset$symbols2$get.loc
};
}
let maybeFoundInDependencies = !asset.symbols;
let deps = this.getDependencies(asset).reverse();

@@ -592,3 +591,4 @@

if (!resolved) {
// External module.
// External module
maybeFoundInDependencies = true;
break;

@@ -599,2 +599,3 @@ }

// We found the symbol, but `asset` is outside, return `asset` and the original symbol
maybeFoundInDependencies = true;
break;

@@ -611,23 +612,12 @@ }

if (!loc) {
var _asset$symbols$get3;
var _asset$symbols3, _asset$symbols3$get;
// the recursive call didn't actually do anything
loc = (_asset$symbols$get3 = asset.symbols.get(symbol)) === null || _asset$symbols$get3 === void 0 ? void 0 : _asset$symbols$get3.loc;
} // If it didn't resolve to anything (likely CommonJS), pass through where we got to
// Remember how we got there
loc = (_asset$symbols3 = asset.symbols) === null || _asset$symbols3 === void 0 ? void 0 : (_asset$symbols3$get = _asset$symbols3.get(symbol)) === null || _asset$symbols3$get === void 0 ? void 0 : _asset$symbols3$get.loc;
}
if (resolvedSymbol == null) {
return {
asset: resolvedAsset,
symbol: resolvedSymbol,
exportSymbol,
loc
};
} // Otherwise, keep the original symbol name along with the resolved symbol
return {
asset: resolvedAsset,
symbol: resolvedSymbol,
exportSymbol: symbol,
exportSymbol,
loc

@@ -645,6 +635,7 @@ };

if (result.symbol != undefined) {
var _resolved$symbols$get;
var _resolved$symbols, _resolved$symbols$get;
if (assetOutside) {
// We found the symbol, but `asset` is outside, return `asset` and the original symbol
maybeFoundInDependencies = true;
break;

@@ -657,5 +648,11 @@ }

exportSymbol: symbol,
loc: (_resolved$symbols$get = resolved.symbols.get(symbol)) === null || _resolved$symbols$get === void 0 ? void 0 : _resolved$symbols$get.loc
loc: (_resolved$symbols = resolved.symbols) === null || _resolved$symbols === void 0 ? void 0 : (_resolved$symbols$get = _resolved$symbols.get(symbol)) === null || _resolved$symbols$get === void 0 ? void 0 : _resolved$symbols$get.loc
};
}
if (!result.asset.symbols) {
// We didn't find it in this dependency, but it might still be there: bailout.
maybeFoundInDependencies = true;
break;
}
}

@@ -667,4 +664,4 @@ }

exportSymbol: symbol,
symbol: identifier,
loc: (_asset$symbols$get4 = asset.symbols.get(symbol)) === null || _asset$symbols$get4 === void 0 ? void 0 : _asset$symbols$get4.loc
symbol: identifier !== null && identifier !== void 0 ? identifier : maybeFoundInDependencies ? null : undefined,
loc: (_asset$symbols4 = asset.symbols) === null || _asset$symbols4 === void 0 ? void 0 : (_asset$symbols4$get = _asset$symbols4.get(symbol)) === null || _asset$symbols4$get === void 0 ? void 0 : _asset$symbols4$get.loc
};

@@ -674,6 +671,12 @@ }

getExportedSymbols(asset) {
if (!asset.symbols) {
return [];
}
let symbols = [];
for (let symbol of asset.symbols.keys()) {
symbols.push(this.resolveSymbol(asset, symbol));
symbols.push({ ...this.resolveSymbol(asset, symbol),
exportAs: symbol
});
}

@@ -689,3 +692,5 @@

if (!resolved) continue;
let exported = this.getExportedSymbols(resolved).filter(s => s.exportSymbol !== 'default');
let exported = this.getExportedSymbols(resolved).filter(s => s.exportSymbol !== 'default').map(s => ({ ...s,
exportAs: s.exportSymbol
}));
symbols.push(...exported);

@@ -692,0 +697,0 @@ }

@@ -117,3 +117,3 @@ "use strict";

get symbols() {
return new _Symbols.Symbols(_classPrivateFieldGet(this, _asset).value.symbols);
return new _Symbols.Symbols(_classPrivateFieldGet(this, _asset).value);
}

@@ -264,3 +264,3 @@

get symbols() {
return new _Symbols.MutableSymbols(_classPrivateFieldGet(this, _asset3).value.symbols);
return new _Symbols.MutableAssetSymbols(_classPrivateFieldGet(this, _asset3).value);
}

@@ -267,0 +267,0 @@

@@ -172,3 +172,4 @@ "use strict";

symbol: e.symbol,
loc: e.loc
loc: e.loc,
exportAs: e.exportAs
}));

@@ -175,0 +176,0 @@ }

@@ -103,3 +103,3 @@ "use strict";

get symbols() {
return new _Symbols.MutableSymbols(_classPrivateFieldGet(this, _dep).symbols);
return new _Symbols.MutableDependencySymbols(_classPrivateFieldGet(this, _dep));
}

@@ -106,0 +106,0 @@

@@ -6,6 +6,10 @@ "use strict";

});
exports.MutableSymbols = exports.Symbols = void 0;
exports.MutableAssetSymbols = exports.MutableDependencySymbols = exports.Symbols = void 0;
var _nullthrows = _interopRequireDefault(require("nullthrows"));
let _Symbol$iterator, _Symbol$iterator2;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = privateMap.get(receiver); if (!descriptor) { throw new TypeError("attempted to get private field on non-instance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }

@@ -15,3 +19,11 @@

let parcelSymbolsToSymbols = new WeakMap();
const EMPTY_ITERATOR = {
next() {
return {
done: true
};
}
};
let valueToSymbols = new WeakMap();
_Symbol$iterator = Symbol.iterator;

@@ -23,5 +35,5 @@

*/
// Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>
constructor(symbols) {
_symbols.set(this, {
// Asset
constructor(asset) {
_value.set(this, {
writable: true,

@@ -31,3 +43,3 @@ value: void 0

let existing = parcelSymbolsToSymbols.get(symbols);
let existing = valueToSymbols.get(asset);

@@ -38,18 +50,24 @@ if (existing != null) {

_classPrivateFieldSet(this, _symbols, symbols);
_classPrivateFieldSet(this, _value, asset);
parcelSymbolsToSymbols.set(symbols, this);
valueToSymbols.set(asset, this);
}
get(exportSymbol) {
return _classPrivateFieldGet(this, _symbols).get(exportSymbol);
var _classPrivateFieldGet2;
return (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _value).symbols) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.get(exportSymbol);
}
hasExportSymbol(exportSymbol) {
return _classPrivateFieldGet(this, _symbols).has(exportSymbol);
var _classPrivateFieldGet3;
return Boolean((_classPrivateFieldGet3 = _classPrivateFieldGet(this, _value).symbols) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.has(exportSymbol));
}
hasLocalSymbol(local) {
for (let s of _classPrivateFieldGet(this, _symbols).values()) {
if (local === s.local) return true;
if (_classPrivateFieldGet(this, _value).symbols) {
for (let s of _classPrivateFieldGet(this, _value).symbols.values()) {
if (local === s.local) return true;
}
}

@@ -62,5 +80,9 @@

[_Symbol$iterator]() {
return _classPrivateFieldGet(this, _symbols)[Symbol.iterator]();
return _classPrivateFieldGet(this, _value).symbols ? _classPrivateFieldGet(this, _value).symbols[Symbol.iterator]() : EMPTY_ITERATOR;
}
get isCleared() {
return _classPrivateFieldGet(this, _value).symbols == null;
}
}

@@ -70,5 +92,5 @@

var _symbols = new WeakMap();
var _value = new WeakMap();
let parcelSymbolsToMutableSymbols = new WeakMap();
let valueToMutableSymbols = new WeakMap();
_Symbol$iterator2 = Symbol.iterator;

@@ -80,5 +102,5 @@

*/
// Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>
constructor(symbols) {
_symbols2.set(this, {
// Asset
constructor(asset) {
_value2.set(this, {
writable: true,

@@ -88,15 +110,7 @@ value: void 0

let existing = parcelSymbolsToMutableSymbols.get(symbols);
if (existing != null) {
return existing;
}
_classPrivateFieldSet(this, _symbols2, symbols);
parcelSymbolsToMutableSymbols.set(symbols, this);
_classPrivateFieldSet(this, _value2, asset);
}
set(exportSymbol, local, loc) {
_classPrivateFieldGet(this, _symbols2).set(exportSymbol, {
(0, _nullthrows.default)(_classPrivateFieldGet(this, _value2).symbols, 'Cannot set symbol on cleared Symbols').set(exportSymbol, {
local,

@@ -107,17 +121,19 @@ loc

clear() {
_classPrivateFieldGet(this, _symbols2).clear();
}
get(exportSymbol) {
var _classPrivateFieldGet4;
get(exportSymbol) {
return _classPrivateFieldGet(this, _symbols2).get(exportSymbol);
return (_classPrivateFieldGet4 = _classPrivateFieldGet(this, _value2).symbols) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.get(exportSymbol);
}
hasExportSymbol(exportSymbol) {
return _classPrivateFieldGet(this, _symbols2).has(exportSymbol);
var _classPrivateFieldGet5;
return Boolean((_classPrivateFieldGet5 = _classPrivateFieldGet(this, _value2).symbols) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.has(exportSymbol));
}
hasLocalSymbol(local) {
for (let s of _classPrivateFieldGet(this, _symbols2).values()) {
if (local === s.local) return true;
if (_classPrivateFieldGet(this, _value2).symbols) {
for (let s of _classPrivateFieldGet(this, _value2).symbols.values()) {
if (local === s.local) return true;
}
}

@@ -130,9 +146,69 @@

[_Symbol$iterator2]() {
return _classPrivateFieldGet(this, _symbols2)[Symbol.iterator]();
return _classPrivateFieldGet(this, _value2).symbols ? _classPrivateFieldGet(this, _value2).symbols[Symbol.iterator]() : EMPTY_ITERATOR;
}
get isCleared() {
return _classPrivateFieldGet(this, _value2).symbols == null;
}
}
exports.MutableSymbols = MutableSymbols;
var _value2 = new WeakMap();
var _symbols2 = new WeakMap();
class MutableDependencySymbols extends MutableSymbols {
// Dependency
constructor(dependency) {
let existing = valueToMutableSymbols.get(dependency);
if (existing != null) {
return existing;
}
super(dependency);
_dependency.set(this, {
writable: true,
value: void 0
});
_classPrivateFieldSet(this, _dependency, dependency);
}
clear() {
_classPrivateFieldGet(this, _dependency).symbols.clear();
}
}
exports.MutableDependencySymbols = MutableDependencySymbols;
var _dependency = new WeakMap();
class MutableAssetSymbols extends MutableSymbols {
// Asset
constructor(asset) {
super(asset);
_asset.set(this, {
writable: true,
value: void 0
});
let existing = valueToMutableSymbols.get(asset);
if (existing != null) {
return existing;
}
_classPrivateFieldSet(this, _asset, asset);
}
clear() {
_classPrivateFieldGet(this, _asset).symbols = null;
}
}
exports.MutableAssetSymbols = MutableAssetSymbols;
var _asset = new WeakMap();

@@ -119,5 +119,5 @@ "use strict";

defer = deps.every(d => !(d.env.isLibrary && d.isEntry) && !d.symbols.has('*') && ![...d.symbols.keys()].some(symbol => {
var _resolvedAsset$symbol;
var _resolvedAsset$symbol, _resolvedAsset$symbol2;
let assetSymbol = (_resolvedAsset$symbol = resolvedAsset.symbols.get(symbol)) === null || _resolvedAsset$symbol === void 0 ? void 0 : _resolvedAsset$symbol.local;
let assetSymbol = (_resolvedAsset$symbol = resolvedAsset.symbols) === null || _resolvedAsset$symbol === void 0 ? void 0 : (_resolvedAsset$symbol2 = _resolvedAsset$symbol.get(symbol)) === null || _resolvedAsset$symbol2 === void 0 ? void 0 : _resolvedAsset$symbol2.local;
return assetSymbol != null && symbols.has(assetSymbol);

@@ -124,0 +124,0 @@ }));

@@ -271,3 +271,4 @@ "use strict";

},
symbols: new Map([...this.value.symbols, ...(result.symbols || [])]),
symbols: !result.symbols ? // TODO clone?
this.value.symbols : new Map([...(this.value.symbols || []), ...(result.symbols || [])]),
sideEffects: (_result$sideEffects = result.sideEffects) !== null && _result$sideEffects !== void 0 ? _result$sideEffects : this.value.sideEffects,

@@ -274,0 +275,0 @@ uniqueKey: result.uniqueKey,

{
"name": "@parcel/core",
"version": "2.0.0-nightly.251+44a44081",
"version": "2.0.0-nightly.255+5175a66b",
"license": "MIT",

@@ -19,13 +19,13 @@ "publishConfig": {

"dependencies": {
"@parcel/cache": "2.0.0-nightly.253+44a44081",
"@parcel/diagnostic": "2.0.0-nightly.253+44a44081",
"@parcel/events": "2.0.0-nightly.253+44a44081",
"@parcel/fs": "2.0.0-nightly.253+44a44081",
"@parcel/logger": "2.0.0-nightly.253+44a44081",
"@parcel/package-manager": "2.0.0-nightly.253+44a44081",
"@parcel/plugin": "2.0.0-nightly.253+44a44081",
"@parcel/cache": "2.0.0-nightly.257+5175a66b",
"@parcel/diagnostic": "2.0.0-nightly.257+5175a66b",
"@parcel/events": "2.0.0-nightly.257+5175a66b",
"@parcel/fs": "2.0.0-nightly.257+5175a66b",
"@parcel/logger": "2.0.0-nightly.257+5175a66b",
"@parcel/package-manager": "2.0.0-nightly.257+5175a66b",
"@parcel/plugin": "2.0.0-nightly.257+5175a66b",
"@parcel/source-map": "2.0.0-alpha.4.9",
"@parcel/types": "2.0.0-nightly.253+44a44081",
"@parcel/utils": "2.0.0-nightly.253+44a44081",
"@parcel/workers": "2.0.0-nightly.253+44a44081",
"@parcel/types": "2.0.0-nightly.257+5175a66b",
"@parcel/utils": "2.0.0-nightly.257+5175a66b",
"@parcel/workers": "2.0.0-nightly.257+5175a66b",
"abortcontroller-polyfill": "^1.1.9",

@@ -46,3 +46,3 @@ "browserslist": "^4.6.6",

},
"gitHead": "44a44081bc44503da7233484b318cf5724aa156f"
"gitHead": "5175a66b28cd2a6090b247204e550cc0264aabbe"
}

@@ -51,3 +51,3 @@ // @flow strict-local

stats: Stats,
symbols?: Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
symbols?: ?Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
sideEffects?: boolean,

@@ -88,3 +88,3 @@ uniqueKey?: ?string,

stats: options.stats,
symbols: options.symbols || new Map(),
symbols: options.symbols ?? (options.symbols === null ? null : new Map()),
sideEffects: options.sideEffects ?? true,

@@ -91,0 +91,0 @@ uniqueKey: uniqueKey,

@@ -737,8 +737,6 @@ // @flow strict-local

// Resolve the export `symbol` of `asset` to the source,
// stopping at the first asset after leaving `bundle` (symbol is nullish in that case)
resolveSymbol(asset: Asset, symbol: Symbol, boundary: ?Bundle) {
let assetOutside = boundary && !this.bundleHasAsset(boundary, asset);
let identifier = asset.symbols.get(symbol)?.local;
let identifier = asset.symbols?.get(symbol)?.local;
if (symbol === '*') {

@@ -748,7 +746,8 @@ return {

exportSymbol: '*',
symbol: identifier,
loc: asset.symbols.get(symbol)?.loc,
symbol: identifier ?? null,
loc: asset.symbols?.get(symbol)?.loc,
};
}
let maybeFoundInDependencies = !asset.symbols;
let deps = this.getDependencies(asset).reverse();

@@ -764,3 +763,4 @@ for (let dep of deps) {

if (!resolved) {
// External module.
// External module
maybeFoundInDependencies = true;
break;

@@ -771,2 +771,3 @@ }

// We found the symbol, but `asset` is outside, return `asset` and the original symbol
maybeFoundInDependencies = true;
break;

@@ -783,21 +784,10 @@ }

if (!loc) {
// the recursive call didn't actually do anything
loc = asset.symbols.get(symbol)?.loc;
// Remember how we got there
loc = asset.symbols?.get(symbol)?.loc;
}
// If it didn't resolve to anything (likely CommonJS), pass through where we got to
if (resolvedSymbol == null) {
return {
asset: resolvedAsset,
symbol: resolvedSymbol,
exportSymbol,
loc,
};
}
// Otherwise, keep the original symbol name along with the resolved symbol
return {
asset: resolvedAsset,
symbol: resolvedSymbol,
exportSymbol: symbol,
exportSymbol,
loc,

@@ -816,2 +806,3 @@ };

// We found the symbol, but `asset` is outside, return `asset` and the original symbol
maybeFoundInDependencies = true;
break;

@@ -824,5 +815,10 @@ }

exportSymbol: symbol,
loc: resolved.symbols.get(symbol)?.loc,
loc: resolved.symbols?.get(symbol)?.loc,
};
}
if (!result.asset.symbols) {
// We didn't find it in this dependency, but it might still be there: bailout.
maybeFoundInDependencies = true;
break;
}
}

@@ -834,4 +830,4 @@ }

exportSymbol: symbol,
symbol: identifier,
loc: asset.symbols.get(symbol)?.loc,
symbol: identifier ?? (maybeFoundInDependencies ? null : undefined),
loc: asset.symbols?.get(symbol)?.loc,
};

@@ -841,6 +837,10 @@ }

getExportedSymbols(asset: Asset) {
if (!asset.symbols) {
return [];
}
let symbols = [];
for (let symbol of asset.symbols.keys()) {
symbols.push(this.resolveSymbol(asset, symbol));
symbols.push({...this.resolveSymbol(asset, symbol), exportAs: symbol});
}

@@ -853,5 +853,5 @@

if (!resolved) continue;
let exported = this.getExportedSymbols(resolved).filter(
s => s.exportSymbol !== 'default',
);
let exported = this.getExportedSymbols(resolved)
.filter(s => s.exportSymbol !== 'default')
.map(s => ({...s, exportAs: s.exportSymbol}));
symbols.push(...exported);

@@ -858,0 +858,0 @@ }

@@ -31,3 +31,3 @@ // @flow strict-local

import Dependency from './Dependency';
import {Symbols, MutableSymbols} from './Symbols';
import {Symbols, MutableAssetSymbols} from './Symbols';
import UncommittedAsset from '../UncommittedAsset';

@@ -134,3 +134,3 @@ import CommittedAsset from '../CommittedAsset';

get symbols(): ISymbols {
return new Symbols(this.#asset.value.symbols);
return new Symbols(this.#asset.value);
}

@@ -264,3 +264,3 @@

get symbols(): IMutableSymbols {
return new MutableSymbols(this.#asset.value.symbols);
return new MutableAssetSymbols(this.#asset.value);
}

@@ -267,0 +267,0 @@

@@ -9,2 +9,3 @@ // @flow strict-local

Dependency as IDependency,
ExportSymbolResolution,
GraphVisitor,

@@ -207,3 +208,3 @@ Symbol,

getExportedSymbols(asset: IAsset): Array<SymbolResolution> {
getExportedSymbols(asset: IAsset): Array<ExportSymbolResolution> {
let res = this.#graph.getExportedSymbols(assetToAssetValue(asset));

@@ -215,2 +216,3 @@ return res.map(e => ({

loc: e.loc,
exportAs: e.exportAs,
}));

@@ -217,0 +219,0 @@ }

@@ -13,3 +13,3 @@ // @flow

import Target from './Target';
import {MutableSymbols} from './Symbols';
import {MutableDependencySymbols} from './Symbols';
import nullthrows from 'nullthrows';

@@ -97,3 +97,3 @@

get symbols(): IMutableSymbols {
return new MutableSymbols(this.#dep.symbols);
return new MutableDependencySymbols(this.#dep);
}

@@ -100,0 +100,0 @@

@@ -8,8 +8,14 @@ // @flow

} from '@parcel/types';
import type {Asset, Dependency} from '../types';
let parcelSymbolsToSymbols: WeakMap<
Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
Symbols,
> = new WeakMap();
import nullthrows from 'nullthrows';
const EMPTY_ITERATOR = {
next() {
return {done: true};
},
};
let valueToSymbols: WeakMap<Asset, Symbols> = new WeakMap();
export class Symbols implements ISymbols {

@@ -19,6 +25,6 @@ /*::

*/
#symbols; // Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>
#value; // Asset
constructor(symbols: Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>) {
let existing = parcelSymbolsToSymbols.get(symbols);
constructor(asset: Asset) {
let existing = valueToSymbols.get(asset);
if (existing != null) {

@@ -28,17 +34,19 @@ return existing;

this.#symbols = symbols;
parcelSymbolsToSymbols.set(symbols, this);
this.#value = asset;
valueToSymbols.set(asset, this);
}
get(exportSymbol: Symbol): ?{|local: Symbol, loc: ?SourceLocation|} {
return this.#symbols.get(exportSymbol);
return this.#value.symbols?.get(exportSymbol);
}
hasExportSymbol(exportSymbol: Symbol): boolean {
return this.#symbols.has(exportSymbol);
return Boolean(this.#value.symbols?.has(exportSymbol));
}
hasLocalSymbol(local: Symbol): boolean {
for (let s of this.#symbols.values()) {
if (local === s.local) return true;
if (this.#value.symbols) {
for (let s of this.#value.symbols.values()) {
if (local === s.local) return true;
}
}

@@ -50,46 +58,47 @@ return false;

[Symbol.iterator]() {
return this.#symbols[Symbol.iterator]();
return this.#value.symbols
? this.#value.symbols[Symbol.iterator]()
: EMPTY_ITERATOR;
}
get isCleared() {
return this.#value.symbols == null;
}
}
let parcelSymbolsToMutableSymbols: WeakMap<
Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
let valueToMutableSymbols: WeakMap<
Asset | Dependency,
MutableSymbols,
> = new WeakMap();
export class MutableSymbols implements IMutableSymbols {
class MutableSymbols {
/*::
@@iterator(): Iterator<[Symbol, {|local: Symbol, loc: ?SourceLocation|}]> { return ({}: any); }
*/
#symbols; // Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>
#value; // Asset
constructor(symbols: Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>) {
let existing = parcelSymbolsToMutableSymbols.get(symbols);
if (existing != null) {
return existing;
}
this.#symbols = symbols;
parcelSymbolsToMutableSymbols.set(symbols, this);
constructor(asset: Asset | Dependency) {
this.#value = asset;
}
set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation) {
this.#symbols.set(exportSymbol, {local, loc});
nullthrows(
this.#value.symbols,
'Cannot set symbol on cleared Symbols',
).set(exportSymbol, {local, loc});
}
clear() {
this.#symbols.clear();
}
get(exportSymbol: Symbol): ?{|local: Symbol, loc: ?SourceLocation|} {
return this.#symbols.get(exportSymbol);
return this.#value.symbols?.get(exportSymbol);
}
hasExportSymbol(exportSymbol: Symbol): boolean {
return this.#symbols.has(exportSymbol);
return Boolean(this.#value.symbols?.has(exportSymbol));
}
hasLocalSymbol(local: Symbol): boolean {
for (let s of this.#symbols.values()) {
if (local === s.local) return true;
if (this.#value.symbols) {
for (let s of this.#value.symbols.values()) {
if (local === s.local) return true;
}
}

@@ -101,4 +110,46 @@ return false;

[Symbol.iterator]() {
return this.#symbols[Symbol.iterator]();
return this.#value.symbols
? this.#value.symbols[Symbol.iterator]()
: EMPTY_ITERATOR;
}
get isCleared() {
return this.#value.symbols == null;
}
}
export class MutableDependencySymbols extends MutableSymbols
implements IMutableSymbols {
#dependency; // Dependency
constructor(dependency: Dependency) {
let existing = valueToMutableSymbols.get(dependency);
if (existing != null) {
return ((existing: any): MutableDependencySymbols);
}
super(dependency);
this.#dependency = dependency;
}
clear() {
this.#dependency.symbols.clear();
}
}
export class MutableAssetSymbols extends MutableSymbols
implements IMutableSymbols {
#asset; // Asset
constructor(asset: Asset) {
super(asset);
let existing = valueToMutableSymbols.get(asset);
if (existing != null) {
return ((existing: any): MutableAssetSymbols);
}
this.#asset = asset;
}
clear() {
this.#asset.symbols = null;
}
}

@@ -138,3 +138,3 @@ // @flow strict-local

![...d.symbols.keys()].some(symbol => {
let assetSymbol = resolvedAsset.symbols.get(symbol)?.local;
let assetSymbol = resolvedAsset.symbols?.get(symbol)?.local;
return assetSymbol != null && symbols.has(assetSymbol);

@@ -141,0 +141,0 @@ }),

@@ -123,3 +123,3 @@ // @flow strict-local

astGenerator: ?ASTGenerator,
symbols: Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
symbols: ?Map<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
sideEffects: boolean,

@@ -126,0 +126,0 @@ uniqueKey: ?string,

@@ -298,3 +298,6 @@ // @flow strict-local

},
symbols: new Map([...this.value.symbols, ...(result.symbols || [])]),
symbols: !result.symbols
? // TODO clone?
this.value.symbols
: new Map([...(this.value.symbols || []), ...(result.symbols || [])]),
sideEffects: result.sideEffects ?? this.value.sideEffects,

@@ -301,0 +304,0 @@ uniqueKey: result.uniqueKey,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc