Huge News!Announcing our $40M Series B led by Abstract Ventures.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.92 to 2.0.0-nightly.97

lib/formats/index.js

8

lib/concat.js

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

enter(asset, context) {
if (shouldExcludeAsset(asset, usedExports)) {
if (shouldExcludeAsset(asset, usedExports, bundleGraph)) {
return context;

@@ -85,3 +85,3 @@ }

exit(asset, context) {
if (!context || shouldExcludeAsset(asset, usedExports)) {
if (!context || shouldExcludeAsset(asset, usedExports, bundleGraph)) {
return;

@@ -217,4 +217,4 @@ }

function shouldExcludeAsset(asset, usedExports) {
return asset.sideEffects === false && !asset.meta.isCommonJS && (!usedExports.has(asset.id) || (0, _nullthrows.default)(usedExports.get(asset.id)).size === 0);
function shouldExcludeAsset(asset, usedExports, bundleGraph) {
return asset.sideEffects === false && !asset.meta.isCommonJS && !bundleGraph.isAssetReferencedByAssetType(asset, 'js') && (!usedExports.has(asset.id) || (0, _nullthrows.default)(usedExports.get(asset.id)).size === 0);
}

@@ -221,0 +221,0 @@

@@ -16,4 +16,8 @@ "use strict";

var _path = require("path");
var _utils = require("@parcel/utils");
var _diagnostic = _interopRequireDefault(require("@parcel/diagnostic"));
var _renamer = _interopRequireDefault(require("../renamer"));

@@ -193,3 +197,3 @@

function generateExports(bundleGraph, bundle, referencedAssets, path, replacements) {
function generateExports(bundleGraph, bundle, referencedAssets, path, replacements, options) {
let exported = new Set();

@@ -239,10 +243,19 @@ let statements = [];

exportSymbol,
symbol
symbol,
asset
} of bundleGraph.getExportedSymbols(entry)) {
if (symbol) {
symbol = replacements.get(symbol) || symbol;
} // If there is an existing binding with the exported name (e.g. an import),
if (!symbol) {
let relativePath = (0, _path.relative)(options.inputFS.cwd(), asset.filePath);
throw new _diagnostic.default({
diagnostic: {
message: `${relativePath} does not export '${exportSymbol}'`,
filePath: entry.filePath // TODO: add codeFrames (actual and reexporting asset) when AST from transformers is reused
}
});
}
symbol = replacements.get(symbol) || symbol; // If there is an existing binding with the exported name (e.g. an import),
// rename it so we can use the name for the export instead.
if (path.scope.hasBinding(exportSymbol) && exportSymbol !== symbol) {

@@ -249,0 +262,0 @@ (0, _renamer.default)(path.scope, exportSymbol, path.scope.generateUid(exportSymbol));

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

var _path = require("path");
var _diagnostic = _interopRequireDefault(require("@parcel/diagnostic"));
var _renamer = _interopRequireDefault(require("../renamer"));

@@ -76,3 +80,3 @@

function generateExports(bundleGraph, bundle, referencedAssets, path, replacements) {
function generateExports(bundleGraph, bundle, referencedAssets, path, replacements, options) {
let exportedIdentifiers = new Map();

@@ -84,9 +88,18 @@ let entry = bundle.getMainEntry();

exportSymbol,
symbol
symbol,
asset
} of bundleGraph.getExportedSymbols(entry)) {
if (symbol) {
symbol = replacements.get(symbol) || symbol;
} // Map CommonJS module.exports assignments to default ESM exports for interop
if (!symbol) {
let relativePath = (0, _path.relative)(options.inputFS.cwd(), asset.filePath);
throw new _diagnostic.default({
diagnostic: {
message: `${relativePath} does not export '${exportSymbol}'`,
filePath: entry.filePath // TODO: add codeFrame when AST from transformers is reused
}
});
}
symbol = replacements.get(symbol) || symbol; // Map CommonJS module.exports assignments to default ESM exports for interop
if (exportSymbol === '*') {

@@ -93,0 +106,0 @@ exportSymbol = 'default';

@@ -22,12 +22,6 @@ "use strict";

var _mangler = _interopRequireDefault(require("./mangler"));
var _utils = require("./utils");
var esmodule = _interopRequireWildcard(require("./formats/esmodule"));
var _index = _interopRequireDefault(require("./formats/index.js"));
var global = _interopRequireWildcard(require("./formats/global"));
var commonjs = _interopRequireWildcard(require("./formats/commonjs"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

@@ -42,7 +36,2 @@

const THROW_TEMPLATE = (0, _template.default)('$parcel$missingModule(MODULE)');
const FORMATS = {
esmodule,
global,
commonjs
};

@@ -60,3 +49,3 @@ function assertString(v) {

}) {
let format = FORMATS[bundle.env.outputFormat];
let format = _index.default[bundle.env.outputFormat];
let replacements = new Map();

@@ -578,8 +567,4 @@ let imports = new Map();

let exported = format.generateExports(bundleGraph, bundle, referencedAssets, path, replacements);
let exported = format.generateExports(bundleGraph, bundle, referencedAssets, path, replacements, options);
(0, _shake.default)(path.scope, exported);
if (options.minify) {
(0, _mangler.default)(path.scope, exported);
}
}

@@ -586,0 +571,0 @@

{
"name": "@parcel/scope-hoisting",
"version": "2.0.0-nightly.92+c0655c56",
"version": "2.0.0-nightly.97+a63f3fc9",
"description": "Blazing fast, zero configuration web application bundler",

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

"@babel/types": "^7.3.3",
"@parcel/utils": "2.0.0-nightly.92+c0655c56",
"@parcel/utils": "2.0.0-nightly.97+a63f3fc9",
"babylon-walk": "^1.0.2",
"nullthrows": "^1.1.1"
},
"gitHead": "c0655c56f7973492fdb28671029ddd923f17a244"
"gitHead": "a63f3fc9726483219412920faeb255e035f90747"
}

@@ -56,3 +56,3 @@ // @flow

enter(asset, context) {
if (shouldExcludeAsset(asset, usedExports)) {
if (shouldExcludeAsset(asset, usedExports, bundleGraph)) {
return context;

@@ -67,3 +67,3 @@ }

exit(asset, context) {
if (!context || shouldExcludeAsset(asset, usedExports)) {
if (!context || shouldExcludeAsset(asset, usedExports, bundleGraph)) {
return;

@@ -201,2 +201,3 @@ }

usedExports: Map<string, Set<Symbol>>,
bundleGraph: BundleGraph,
) {

@@ -206,2 +207,3 @@ return (

!asset.meta.isCommonJS &&
!bundleGraph.isAssetReferencedByAssetType(asset, 'js') &&
(!usedExports.has(asset.id) ||

@@ -208,0 +210,0 @@ nullthrows(usedExports.get(asset.id)).size === 0)

// @flow
import type {Asset, Bundle, BundleGraph, Symbol} from '@parcel/types';
import type {
Asset,
Bundle,
BundleGraph,
PluginOptions,
Symbol,
} from '@parcel/types';
import type {ExternalModule} from '../types';

@@ -8,3 +14,5 @@ import * as t from '@babel/types';

import invariant from 'assert';
import {relative} from 'path';
import {relativeBundlePath} from '@parcel/utils';
import ThrowableDiagnostic from '@parcel/diagnostic';
import rename from '../renamer';

@@ -234,2 +242,3 @@

replacements: Map<Symbol, Symbol>,
options: PluginOptions,
) {

@@ -282,9 +291,18 @@ let exported = new Set<Symbol>();

} else {
for (let {exportSymbol, symbol} of bundleGraph.getExportedSymbols(
for (let {exportSymbol, symbol, asset} of bundleGraph.getExportedSymbols(
entry,
)) {
if (symbol) {
symbol = replacements.get(symbol) || symbol;
if (!symbol) {
let relativePath = relative(options.inputFS.cwd(), asset.filePath);
throw new ThrowableDiagnostic({
diagnostic: {
message: `${relativePath} does not export '${exportSymbol}'`,
filePath: entry.filePath,
// TODO: add codeFrames (actual and reexporting asset) when AST from transformers is reused
},
});
}
symbol = replacements.get(symbol) || symbol;
// If there is an existing binding with the exported name (e.g. an import),

@@ -291,0 +309,0 @@ // rename it so we can use the name for the export instead.

// @flow
import type {Asset, Bundle, BundleGraph, Symbol} from '@parcel/types';
import type {
Asset,
Bundle,
BundleGraph,
PluginOptions,
Symbol,
} from '@parcel/types';
import type {ExternalModule} from '../types';

@@ -9,2 +15,4 @@ import * as t from '@babel/types';

import invariant from 'assert';
import {relative} from 'path';
import ThrowableDiagnostic from '@parcel/diagnostic';
import rename from '../renamer';

@@ -79,2 +87,3 @@

replacements: Map<Symbol, Symbol>,
options: PluginOptions,
) {

@@ -84,7 +93,18 @@ let exportedIdentifiers = new Map();

if (entry) {
for (let {exportSymbol, symbol} of bundleGraph.getExportedSymbols(entry)) {
if (symbol) {
symbol = replacements.get(symbol) || symbol;
for (let {exportSymbol, symbol, asset} of bundleGraph.getExportedSymbols(
entry,
)) {
if (!symbol) {
let relativePath = relative(options.inputFS.cwd(), asset.filePath);
throw new ThrowableDiagnostic({
diagnostic: {
message: `${relativePath} does not export '${exportSymbol}'`,
filePath: entry.filePath,
// TODO: add codeFrame when AST from transformers is reused
},
});
}
symbol = replacements.get(symbol) || symbol;
// Map CommonJS module.exports assignments to default ESM exports for interop

@@ -91,0 +111,0 @@ if (exportSymbol === '*') {

@@ -20,7 +20,4 @@ // @flow

import treeShake from './shake';
import mangleScope from './mangler';
import {getName, getIdentifier} from './utils';
import * as esmodule from './formats/esmodule';
import * as global from './formats/global';
import * as commonjs from './formats/commonjs';
import OutputFormats from './formats/index.js';

@@ -33,8 +30,2 @@ const ESMODULE_TEMPLATE = template(`$parcel$defineInteropFlag(EXPORTS);`);

const FORMATS = {
esmodule,
global,
commonjs,
};
function assertString(v): string {

@@ -56,3 +47,3 @@ invariant(typeof v === 'string');

|}) {
let format = FORMATS[bundle.env.outputFormat];
let format = OutputFormats[bundle.env.outputFormat];
let replacements: Map<Symbol, Symbol> = new Map();

@@ -585,8 +576,6 @@ let imports: Map<Symbol, ?[Asset, Symbol]> = new Map();

replacements,
options,
);
treeShake(path.scope, exported);
if (options.minify) {
mangleScope(path.scope, exported);
}
},

@@ -593,0 +582,0 @@ },

@@ -0,4 +1,5 @@

// @flow
import * as t from '@babel/types';
export default function rename(scope, oldName, newName) {
export default function rename(scope: any, oldName: string, newName: string) {
if (oldName === newName) {

@@ -5,0 +6,0 @@ return;

// @flow
import type {ModuleSpecifier, Symbol, Bundle, Asset} from '@parcel/types';
import type {
Asset,
Bundle,
BundleGraph,
ModuleSpecifier,
PluginOptions,
Symbol,
} from '@parcel/types';

@@ -14,1 +21,22 @@ export type ExternalModule = {|

|};
export type OutputFormat = {|
generateBundleImports(
from: Bundle,
bundle: Bundle,
assets: Set<Asset>,
): Array<any>,
generateExternalImport(
bundle: Bundle,
external: ExternalModule,
scope: any,
): any,
generateExports(
bundleGraph: BundleGraph,
bundle: Bundle,
referencedAssets: Set<Asset>,
path: any,
replacements: Map<Symbol, Symbol>,
options: PluginOptions,
): any,
|};
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