New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@parcel/scope-hoisting

Package Overview
Dependencies
Maintainers
1
Versions
293
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/scope-hoisting - npm Package Compare versions

Comparing version 2.0.0-nightly.167 to 2.0.0-nightly.173

23

lib/formats/commonjs.js

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

let specifiers = [...assets].map(asset => {
let id = asset.meta.shouldWrap ? (0, _utils2.getIdentifier)(asset, 'init') : t.identifier((0, _utils2.assertString)(asset.meta.exportsIdentifier));
let id = (0, _utils2.getIdentifier)(asset, 'init');
return t.objectProperty(id, id, false, true);

@@ -215,17 +215,8 @@ });

for (let asset of referencedAssets) {
if (asset.meta.shouldWrap) {
let id = (0, _utils2.getIdentifier)(asset, 'init');
exported.add(id.name);
statements.push(EXPORT_TEMPLATE({
NAME: id,
IDENTIFIER: id
}));
} else {
let exportsId = (0, _utils2.assertString)(asset.meta.exportsIdentifier);
exported.add(exportsId);
statements.push(EXPORT_TEMPLATE({
NAME: t.identifier(exportsId),
IDENTIFIER: t.identifier(exportsId)
}));
}
let id = (0, _utils2.getIdentifier)(asset, 'init');
exported.add(id.name);
statements.push(EXPORT_TEMPLATE({
NAME: id,
IDENTIFIER: id
}));
}

@@ -232,0 +223,0 @@

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

let specifiers = [...assets].map(asset => {
let id = asset.meta.shouldWrap ? (0, _utils2.getIdentifier)(asset, 'init') : t.identifier((0, _utils2.assertString)(asset.meta.exportsIdentifier));
let id = (0, _utils2.getIdentifier)(asset, 'init');
return t.importSpecifier(id, id);

@@ -119,3 +119,3 @@ });

for (let asset of referencedAssets) {
let exportsId = asset.meta.shouldWrap ? (0, _utils2.getName)(asset, 'init') : (0, _utils2.assertString)(asset.meta.exportsIdentifier);
let exportsId = (0, _utils2.getName)(asset, 'init');
exportedIdentifiers.set(exportsId, exportsId);

@@ -122,0 +122,0 @@ }

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

statements.push(IMPORT_TEMPLATE({
IDENTIFIER: asset.meta.shouldWrap ? (0, _utils2.getIdentifier)(asset, 'init') : t.identifier((0, _utils2.assertString)(asset.meta.exportsIdentifier)),
IDENTIFIER: (0, _utils2.getIdentifier)(asset, 'init'),
ASSET_ID: t.stringLiteral(asset.id)

@@ -59,3 +59,3 @@ }));

for (let asset of referencedAssets) {
let exportsId = asset.meta.shouldWrap ? (0, _utils2.getName)(asset, 'init') : (0, _utils2.assertString)(asset.meta.exportsIdentifier);
let exportsId = (0, _utils2.getName)(asset, 'init');
exported.add(exportsId);

@@ -62,0 +62,0 @@ statements.push(EXPORT_TEMPLATE({

@@ -38,2 +38,6 @@ "use strict";

const FAKE_INIT_TEMPLATE = _template.default.statement(`function INIT(){
return EXPORTS;
}`);
function link({

@@ -287,8 +291,3 @@ bundle,

imported.assets.add(mod);
if (mod.meta.shouldWrap) {
return t.callExpression((0, _utils.getIdentifier)(mod, 'init'), []);
} else {
return t.identifier((0, _utils.assertString)(mod.meta.exportsIdentifier));
}
return t.callExpression((0, _utils.getIdentifier)(mod, 'init'), []);
}

@@ -339,10 +338,9 @@ }

if (mod.meta.id && assets.get((0, _utils.assertString)(mod.meta.id))) {
// Replace with nothing if the require call's result is not used.
let name = (0, _utils.assertString)(mod.meta.exportsIdentifier);
let isReferenced = bundleGraph.isAssetReferencedByAnotherBundleOfType(mod, 'js');
let isValueUsed = !isUnusedValue(path);
if (!isUnusedValue(path) || isReferenced) {
let name = (0, _utils.assertString)(mod.meta.exportsIdentifier);
node = t.identifier(replacements.get(name) || name); // Insert __esModule interop flag if the required module is an ES6 module with a default export.
if (isValueUsed || isReferenced) {
// Insert __esModule interop flag if the required module is an ES6 module with a default export.
// This ensures that code generated by Babel and other tools works properly.
const hasESModuleDefaultExport = mod.meta.isES6Module && mod.symbols.has('default');

@@ -377,3 +375,6 @@ const isUsed = asset.meta.isCommonJS && hasESModuleDefaultExport; // TODO If referenced it might be used in another bundle, even though we don't know for sure. If not included but required, the code would throw so we insert it always for now. We should find out when it is required and exclude it if now.

node = t.callExpression((0, _utils.getIdentifier)(mod, 'init'), []);
}
} // Replace with nothing if the require call's result is not used.
else if (isValueUsed) {
node = t.identifier(replacements.get(name) || name);
}
} else if (mod.type === 'js') {

@@ -573,5 +574,14 @@ node = addBundleImport(mod, path);

path.scope.crawl();
} // Generate exports
} // Insert fake init functions that will be imported in other bundles,
// because `asset.meta.shouldWrap` isn't set in a packager if `asset` is
// not in the current bundle:
path.pushContainer('body', [...referencedAssets].filter(a => !a.meta.shouldWrap).map(a => {
return FAKE_INIT_TEMPLATE({
INIT: (0, _utils.getIdentifier)(a, 'init'),
EXPORTS: t.identifier((0, _utils.assertString)(a.meta.exportsIdentifier))
});
})); // Generate exports
let exported = format.generateExports(bundleGraph, bundle, referencedAssets, path, replacements, options);

@@ -578,0 +588,0 @@ (0, _shake.default)(path.scope, exported);

{
"name": "@parcel/scope-hoisting",
"version": "2.0.0-nightly.167+b9e4105c",
"version": "2.0.0-nightly.173+bac3f05f",
"description": "Blazing fast, zero configuration web application bundler",

@@ -24,8 +24,8 @@ "license": "MIT",

"@babel/types": "^7.3.3",
"@parcel/babylon-walk": "2.0.0-nightly.1789+b9e4105c",
"@parcel/diagnostic": "2.0.0-nightly.167+b9e4105c",
"@parcel/utils": "2.0.0-nightly.167+b9e4105c",
"@parcel/babylon-walk": "2.0.0-nightly.1795+bac3f05f",
"@parcel/diagnostic": "2.0.0-nightly.173+bac3f05f",
"@parcel/utils": "2.0.0-nightly.173+bac3f05f",
"nullthrows": "^1.1.1"
},
"gitHead": "b9e4105c50576ed22a99860e08e65491d4659a43"
"gitHead": "bac3f05fa31574338f14ab9cd2c9bd78fb1c22ee"
}

@@ -134,6 +134,3 @@ // @flow

let specifiers: Array<ObjectProperty> = [...assets].map(asset => {
let id = asset.meta.shouldWrap
? getIdentifier(asset, 'init')
: t.identifier(assertString(asset.meta.exportsIdentifier));
let id = getIdentifier(asset, 'init');
return t.objectProperty(id, id, false, true);

@@ -306,21 +303,10 @@ });

for (let asset of referencedAssets) {
if (asset.meta.shouldWrap) {
let id = getIdentifier(asset, 'init');
exported.add(id.name);
statements.push(
EXPORT_TEMPLATE({
NAME: id,
IDENTIFIER: id,
}),
);
} else {
let exportsId = assertString(asset.meta.exportsIdentifier);
exported.add(exportsId);
statements.push(
EXPORT_TEMPLATE({
NAME: t.identifier(exportsId),
IDENTIFIER: t.identifier(exportsId),
}),
);
}
let id = getIdentifier(asset, 'init');
exported.add(id.name);
statements.push(
EXPORT_TEMPLATE({
NAME: id,
IDENTIFIER: id,
}),
);
}

@@ -327,0 +313,0 @@

@@ -21,3 +21,3 @@ // @flow

import rename from '../renamer';
import {assertString, getName, getIdentifier} from '../utils';
import {getName, getIdentifier} from '../utils';

@@ -30,6 +30,3 @@ export function generateBundleImports(

let specifiers = [...assets].map(asset => {
let id = asset.meta.shouldWrap
? getIdentifier(asset, 'init')
: t.identifier(assertString(asset.meta.exportsIdentifier));
let id = getIdentifier(asset, 'init');
return t.importSpecifier(id, id);

@@ -133,6 +130,3 @@ });

for (let asset of referencedAssets) {
let exportsId = asset.meta.shouldWrap
? getName(asset, 'init')
: assertString(asset.meta.exportsIdentifier);
let exportsId = getName(asset, 'init');
exportedIdentifiers.set(exportsId, exportsId);

@@ -139,0 +133,0 @@ }

@@ -55,5 +55,3 @@ // @flow

IMPORT_TEMPLATE({
IDENTIFIER: asset.meta.shouldWrap
? getIdentifier(asset, 'init')
: t.identifier(assertString(asset.meta.exportsIdentifier)),
IDENTIFIER: getIdentifier(asset, 'init'),
ASSET_ID: t.stringLiteral(asset.id),

@@ -83,5 +81,3 @@ }),

for (let asset of referencedAssets) {
let exportsId = asset.meta.shouldWrap
? getName(asset, 'init')
: assertString(asset.meta.exportsIdentifier);
let exportsId = getName(asset, 'init');
exported.add(exportsId);

@@ -88,0 +84,0 @@

@@ -54,2 +54,8 @@ // @flow

);
const FAKE_INIT_TEMPLATE = template.statement<
{|INIT: Identifier, EXPORTS: Identifier|},
Statement,
>(`function INIT(){
return EXPORTS;
}`);

@@ -318,7 +324,3 @@ export function link({

if (mod.meta.shouldWrap) {
return t.callExpression(getIdentifier(mod, 'init'), []);
} else {
return t.identifier(assertString(mod.meta.exportsIdentifier));
}
return t.callExpression(getIdentifier(mod, 'init'), []);
}

@@ -374,3 +376,4 @@ }

if (mod.meta.id && assets.get(assertString(mod.meta.id))) {
// Replace with nothing if the require call's result is not used.
let name = assertString(mod.meta.exportsIdentifier);
let isReferenced = bundleGraph.isAssetReferencedByAnotherBundleOfType(

@@ -380,6 +383,4 @@ mod,

);
if (!isUnusedValue(path) || isReferenced) {
let name = assertString(mod.meta.exportsIdentifier);
node = t.identifier(replacements.get(name) || name);
let isValueUsed = !isUnusedValue(path);
if (isValueUsed || isReferenced) {
// Insert __esModule interop flag if the required module is an ES6 module with a default export.

@@ -420,2 +421,6 @@ // This ensures that code generated by Babel and other tools works properly.

}
// Replace with nothing if the require call's result is not used.
else if (isValueUsed) {
node = t.identifier(replacements.get(name) || name);
}
} else if (mod.type === 'js') {

@@ -610,2 +615,17 @@ node = addBundleImport(mod, path);

// Insert fake init functions that will be imported in other bundles,
// because `asset.meta.shouldWrap` isn't set in a packager if `asset` is
// not in the current bundle:
path.pushContainer(
'body',
[...referencedAssets]
.filter(a => !a.meta.shouldWrap)
.map(a => {
return FAKE_INIT_TEMPLATE({
INIT: getIdentifier(a, 'init'),
EXPORTS: t.identifier(assertString(a.meta.exportsIdentifier)),
});
}),
);
// Generate exports

@@ -612,0 +632,0 @@ let exported = format.generateExports(

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