@parcel/scope-hoisting
Advanced tools
Comparing version 2.0.0-nightly.581 to 2.0.0-nightly.587
100
lib/link.js
@@ -400,3 +400,3 @@ "use strict"; | ||
function maybeReplaceIdentifier(node, ancestors) { | ||
function maybeReplaceIdentifier(node) { | ||
let { | ||
@@ -425,3 +425,3 @@ name | ||
let [asset, symbol] = imported; | ||
res = replaceImportNode(asset, symbol, node, ancestors); // If the export does not exist, replace with an empty object. | ||
res = replaceImportNode(asset, symbol, node); // If the export does not exist, replace with an empty object. | ||
@@ -438,3 +438,3 @@ if (!res) { | ||
function replaceImportNode(originalModule, originalName, node, ancestors) { | ||
function replaceImportNode(originalModule, originalName, node) { | ||
let { | ||
@@ -466,3 +466,3 @@ asset: mod, | ||
res = addBundleImport(mod, node, ancestors); | ||
res = addBundleImport(mod, node); | ||
return res ? interop(mod, symbol, node, res) : null; | ||
@@ -595,3 +595,3 @@ } // The ESM 'does not export' case was already handled by core's symbol proapgation. | ||
function addBundleImport(mod, node, ancestors) { | ||
function addBundleImport(mod, node) { | ||
// Find a bundle that's reachable from the current bundle (sibling or ancestor) | ||
@@ -615,11 +615,8 @@ // containing this asset, and create an import for it if needed. | ||
importedFiles.set(filePath, imported); | ||
} // If not unused, add the asset to the list of specifiers to import. | ||
} | ||
if (!isUnusedValue(ancestors) && mod.meta.exportsIdentifier) { | ||
(0, _assert().default)(imported.assets != null); | ||
imported.assets.add(mod); | ||
let initIdentifier = (0, _utils().getIdentifier)(mod, 'init'); | ||
return t().callExpression(initIdentifier, []); | ||
} | ||
(0, _assert().default)(imported.assets != null); | ||
imported.assets.add(mod); | ||
let initIdentifier = (0, _utils().getIdentifier)(mod, 'init'); | ||
return t().callExpression(initIdentifier, []); | ||
} | ||
@@ -672,3 +669,3 @@ | ||
if (args.length > 2 && (0, t().isIdentifier)(args[2])) { | ||
newNode = maybeReplaceIdentifier(args[2], ancestors); | ||
newNode = maybeReplaceIdentifier(args[2]); | ||
} else { | ||
@@ -687,3 +684,3 @@ if (mod.meta.id && assets.has((0, _utils().assertString)(mod.meta.id))) { | ||
} else if (mod.type === 'js') { | ||
newNode = addBundleImport(mod, node, ancestors); | ||
newNode = addBundleImport(mod, node); | ||
} | ||
@@ -839,49 +836,52 @@ } // async dependency that was internalized | ||
AssignmentExpression(node, state, ancestors) { | ||
if ((0, t().isIdentifier)(node.left)) { | ||
let res = maybeReplaceIdentifier(node.left, ancestors); | ||
AssignmentExpression(node) { | ||
let { | ||
left, | ||
right | ||
} = node; | ||
if ((0, t().isIdentifier)(res) || (0, t().isMemberExpression)(res)) { | ||
node.left = res; | ||
} | ||
return; | ||
} | ||
if (!(0, t().isMemberExpression)(node.left)) { | ||
return; | ||
} | ||
let { | ||
left: { | ||
if ((0, t().isMemberExpression)(left)) { | ||
let { | ||
object, | ||
property, | ||
computed | ||
}, | ||
right | ||
} = node; | ||
} = left; | ||
if (!((0, t().isIdentifier)(object) && ((0, t().isIdentifier)(property) && !computed || (0, t().isStringLiteral)(property)))) { | ||
return; | ||
} // Rename references to exported symbols to the exported name. | ||
if (!((0, t().isIdentifier)(object) && ((0, t().isIdentifier)(property) && !computed || (0, t().isStringLiteral)(property)))) { | ||
return; | ||
} // Rename references to exported symbols to the exported name. | ||
let exp = exportedSymbols.get(object.name); | ||
let exp = exportedSymbols.get(object.name); | ||
if (exp) { | ||
object.name = exp[0].local; | ||
} | ||
if (exp) { | ||
object.name = exp[0].local; | ||
} | ||
let asset = exportsMap.get(object.name); | ||
let asset = exportsMap.get(object.name); | ||
if (!asset) { | ||
return; | ||
} | ||
if (!asset) { | ||
return; | ||
} | ||
if (!needsExportsIdentifier(object.name)) { | ||
return _babylonWalk().REMOVE; | ||
if (!needsExportsIdentifier(object.name)) { | ||
return _babylonWalk().REMOVE; | ||
} | ||
if ((0, t().isIdentifier)(right) && !needsDeclaration(right.name)) { | ||
return _babylonWalk().REMOVE; | ||
} | ||
} | ||
if ((0, t().isIdentifier)(right) && !needsDeclaration(right.name)) { | ||
return _babylonWalk().REMOVE; | ||
if ((0, t().isIdentifier)(node.left)) { | ||
let res = maybeReplaceIdentifier(node.left); | ||
if ((0, t().isIdentifier)(res) || (0, t().isMemberExpression)(res)) { | ||
node.left = res; | ||
} // remove unused CommonJS `$id$export$foo = $id$var$foo;` | ||
if ((0, t().isIdentifier)(left) && !needsDeclaration(left.name)) { | ||
return _babylonWalk().REMOVE; | ||
} | ||
} | ||
@@ -905,3 +905,3 @@ }, | ||
return maybeReplaceIdentifier(node, ancestors); | ||
return maybeReplaceIdentifier(node); | ||
} | ||
@@ -908,0 +908,0 @@ }, |
{ | ||
"name": "@parcel/scope-hoisting", | ||
"version": "2.0.0-nightly.581+0d3abd6f", | ||
"version": "2.0.0-nightly.587+a26f6397", | ||
"description": "Blazing fast, zero configuration web application bundler", | ||
@@ -27,11 +27,11 @@ "license": "MIT", | ||
"@babel/types": "^7.12.13", | ||
"@parcel/babel-ast-utils": "2.0.0-nightly.2203+0d3abd6f", | ||
"@parcel/babylon-walk": "2.0.0-nightly.2203+0d3abd6f", | ||
"@parcel/diagnostic": "2.0.0-nightly.581+0d3abd6f", | ||
"@parcel/babel-ast-utils": "2.0.0-nightly.2209+a26f6397", | ||
"@parcel/babylon-walk": "2.0.0-nightly.2209+a26f6397", | ||
"@parcel/diagnostic": "2.0.0-nightly.587+a26f6397", | ||
"@parcel/source-map": "2.0.0-alpha.4.21", | ||
"@parcel/utils": "2.0.0-nightly.581+0d3abd6f", | ||
"@parcel/utils": "2.0.0-nightly.587+a26f6397", | ||
"globals": "^13.2.0", | ||
"nullthrows": "^1.1.1" | ||
}, | ||
"gitHead": "0d3abd6ffa8fc21bbefe6f48bd6edb9713512edc" | ||
"gitHead": "a26f6397c42370799391511361e4074a0df2d62a" | ||
} |
100
src/link.js
@@ -392,3 +392,3 @@ // @flow | ||
function maybeReplaceIdentifier(node: Identifier, ancestors) { | ||
function maybeReplaceIdentifier(node: Identifier) { | ||
let {name} = node; | ||
@@ -412,3 +412,3 @@ if (typeof name !== 'string') { | ||
let [asset, symbol] = imported; | ||
res = replaceImportNode(asset, symbol, node, ancestors); | ||
res = replaceImportNode(asset, symbol, node); | ||
@@ -425,3 +425,3 @@ // If the export does not exist, replace with an empty object. | ||
// node is an Identifier like $id$import$foo that directly imports originalName from originalModule | ||
function replaceImportNode(originalModule, originalName, node, ancestors) { | ||
function replaceImportNode(originalModule, originalName, node) { | ||
let {asset: mod, symbol, identifier} = resolveSymbol( | ||
@@ -452,3 +452,3 @@ originalModule, | ||
res = addBundleImport(mod, node, ancestors); | ||
res = addBundleImport(mod, node); | ||
return res ? interop(mod, symbol, node, res) : null; | ||
@@ -578,3 +578,3 @@ } | ||
function addBundleImport(mod, node, ancestors) { | ||
function addBundleImport(mod, node) { | ||
// Find a bundle that's reachable from the current bundle (sibling or ancestor) | ||
@@ -603,10 +603,7 @@ // containing this asset, and create an import for it if needed. | ||
// If not unused, add the asset to the list of specifiers to import. | ||
if (!isUnusedValue(ancestors) && mod.meta.exportsIdentifier) { | ||
invariant(imported.assets != null); | ||
imported.assets.add(mod); | ||
invariant(imported.assets != null); | ||
imported.assets.add(mod); | ||
let initIdentifier = getIdentifier(mod, 'init'); | ||
return t.callExpression(initIdentifier, []); | ||
} | ||
let initIdentifier = getIdentifier(mod, 'init'); | ||
return t.callExpression(initIdentifier, []); | ||
} | ||
@@ -665,3 +662,3 @@ | ||
if (args.length > 2 && isIdentifier(args[2])) { | ||
newNode = maybeReplaceIdentifier(args[2], ancestors); | ||
newNode = maybeReplaceIdentifier(args[2]); | ||
} else { | ||
@@ -684,3 +681,3 @@ if (mod.meta.id && assets.has(assertString(mod.meta.id))) { | ||
} else if (mod.type === 'js') { | ||
newNode = addBundleImport(mod, node, ancestors); | ||
newNode = addBundleImport(mod, node); | ||
} | ||
@@ -850,47 +847,46 @@ } | ||
}, | ||
AssignmentExpression(node, state, ancestors) { | ||
if (isIdentifier(node.left)) { | ||
let res = maybeReplaceIdentifier(node.left, ancestors); | ||
if (isIdentifier(res) || isMemberExpression(res)) { | ||
node.left = res; | ||
AssignmentExpression(node) { | ||
let {left, right} = node; | ||
if (isMemberExpression(left)) { | ||
let {object, property, computed} = left; | ||
if ( | ||
!( | ||
isIdentifier(object) && | ||
((isIdentifier(property) && !computed) || isStringLiteral(property)) | ||
) | ||
) { | ||
return; | ||
} | ||
return; | ||
} | ||
// Rename references to exported symbols to the exported name. | ||
let exp = exportedSymbols.get(object.name); | ||
if (exp) { | ||
object.name = exp[0].local; | ||
} | ||
if (!isMemberExpression(node.left)) { | ||
return; | ||
} | ||
let asset = exportsMap.get(object.name); | ||
if (!asset) { | ||
return; | ||
} | ||
let { | ||
left: {object, property, computed}, | ||
right, | ||
} = node; | ||
if ( | ||
!( | ||
isIdentifier(object) && | ||
((isIdentifier(property) && !computed) || isStringLiteral(property)) | ||
) | ||
) { | ||
return; | ||
} | ||
if (!needsExportsIdentifier(object.name)) { | ||
return REMOVE; | ||
} | ||
// Rename references to exported symbols to the exported name. | ||
let exp = exportedSymbols.get(object.name); | ||
if (exp) { | ||
object.name = exp[0].local; | ||
if (isIdentifier(right) && !needsDeclaration(right.name)) { | ||
return REMOVE; | ||
} | ||
} | ||
if (isIdentifier(node.left)) { | ||
let res = maybeReplaceIdentifier(node.left); | ||
if (isIdentifier(res) || isMemberExpression(res)) { | ||
node.left = res; | ||
} | ||
let asset = exportsMap.get(object.name); | ||
if (!asset) { | ||
return; | ||
// remove unused CommonJS `$id$export$foo = $id$var$foo;` | ||
if (isIdentifier(left) && !needsDeclaration(left.name)) { | ||
return REMOVE; | ||
} | ||
} | ||
if (!needsExportsIdentifier(object.name)) { | ||
return REMOVE; | ||
} | ||
if (isIdentifier(right) && !needsDeclaration(right.name)) { | ||
return REMOVE; | ||
} | ||
}, | ||
@@ -917,3 +913,3 @@ Identifier(node, state, ancestors) { | ||
return maybeReplaceIdentifier(node, ancestors); | ||
return maybeReplaceIdentifier(node); | ||
} | ||
@@ -920,0 +916,0 @@ }, |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
253073
6929