Socket
Socket
Sign inDemoInstall

@babel/helper-module-transforms

Package Overview
Dependencies
Maintainers
4
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-module-transforms - npm Package Compare versions

Comparing version 8.0.0-alpha.11 to 8.0.0-alpha.12

7

lib/index.d.ts

@@ -1,3 +0,4 @@

import { NodePath, types } from '@babel/core';
import { types, NodePath as NodePath$1 } from '@babel/core';
export { isModule } from '@babel/helper-module-imports';
import { NodePath } from '@babel/traverse';

@@ -83,3 +84,3 @@ declare function rewriteThis(programPath: NodePath): void;

*/
declare function rewriteModuleStatementsAndPrepareHeader(path: NodePath<types.Program>, { exportName, strict, allowTopLevelThis, strictMode, noInterop, importInterop, lazy, getWrapperPayload, wrapReference, esNamespaceOnly, filename, constantReexports, enumerableModuleMeta, noIncompleteNsImportDetection, }: RewriteModuleStatementsAndPrepareHeaderOptions): {
declare function rewriteModuleStatementsAndPrepareHeader(path: NodePath$1<types.Program>, { exportName, strict, allowTopLevelThis, strictMode, noInterop, importInterop, lazy, getWrapperPayload, wrapReference, esNamespaceOnly, filename, constantReexports, enumerableModuleMeta, noIncompleteNsImportDetection, }: RewriteModuleStatementsAndPrepareHeaderOptions): {
meta: ModuleMetadata;

@@ -97,3 +98,3 @@ headers: (types.BlockStatement | types.BreakStatement | types.ClassDeclaration | types.ContinueStatement | types.DebuggerStatement | types.DeclareClass | types.DeclareExportAllDeclaration | types.DeclareExportDeclaration | types.DeclareFunction | types.DeclareInterface | types.DeclareModule | types.DeclareModuleExports | types.DeclareOpaqueType | types.DeclareTypeAlias | types.DeclareVariable | types.DoWhileStatement | types.EmptyStatement | types.EnumDeclaration | types.ExportAllDeclaration | types.ExportDefaultDeclaration | types.ExportNamedDeclaration | types.ExpressionStatement | types.ForInStatement | types.ForOfStatement | types.ForStatement | types.FunctionDeclaration | types.IfStatement | types.ImportDeclaration | types.InterfaceDeclaration | types.LabeledStatement | types.OpaqueType | types.ReturnStatement | types.SwitchStatement | types.TSDeclareFunction | types.TSEnumDeclaration | types.TSExportAssignment | types.TSImportEqualsDeclaration | types.TSInterfaceDeclaration | types.TSModuleDeclaration | types.TSNamespaceExportDeclaration | types.TSTypeAliasDeclaration | types.ThrowStatement | types.TryStatement | types.TypeAlias | types.VariableDeclaration | types.WhileStatement | types.WithStatement)[];

*/
declare function wrapInterop(programPath: NodePath<types.Program>, expr: types.Expression, type: InteropType): types.CallExpression;
declare function wrapInterop(programPath: NodePath$1<types.Program>, expr: types.Expression, type: InteropType): types.CallExpression;
/**

@@ -100,0 +101,0 @@ * Create the runtime initialization statements for a given requested source.

import assert from 'assert';
import { traverse, types, template } from '@babel/core';
import { types, template } from '@babel/core';
import { isModule } from '@babel/helper-module-imports';
export { isModule } from '@babel/helper-module-imports';
import environmentVisitor from '@babel/helper-environment-visitor';
import traverse, { visitors } from '@babel/traverse';
import simplifyAccess from '@babel/helper-simple-access';
import { basename, extname } from 'path';
import { isIdentifierName } from '@babel/helper-validator-identifier';
import splitExportDeclaration from '@babel/helper-split-export-declaration';
const {
numericLiteral: numericLiteral$1,
unaryExpression
} = types;
const rewriteThisVisitor = traverse.visitors.merge([environmentVisitor, {
ThisExpression(path) {
path.replaceWith(unaryExpression("void", numericLiteral$1(0), true));
let rewriteThisVisitor;
function rewriteThis(programPath) {
if (!rewriteThisVisitor) {
rewriteThisVisitor = visitors.environmentVisitor({
ThisExpression(path) {
path.replaceWith(types.unaryExpression("void", types.numericLiteral(0), true));
}
});
rewriteThisVisitor.noScope = true;
}
}]);
function rewriteThis(programPath) {
traverse(programPath.node, Object.assign({}, rewriteThisVisitor, {
noScope: true
}));
traverse(programPath.node, rewriteThisVisitor);
}
const {
assignmentExpression,
cloneNode: cloneNode$1,
expressionStatement: expressionStatement$1,
getOuterBindingIdentifiers,
identifier: identifier$1,
isArrowFunctionExpression,
isClassExpression,
isFunctionExpression,
isIdentifier: isIdentifier$1,
isMemberExpression,
isVariableDeclaration,
jsxIdentifier,
jsxMemberExpression,
memberExpression: memberExpression$1,
numericLiteral,
sequenceExpression,
stringLiteral: stringLiteral$1,
variableDeclaration: variableDeclaration$1,
variableDeclarator: variableDeclarator$1
} = types;
function isInType(path) {

@@ -114,3 +90,3 @@ do {

}
let namespace = identifier$1(meta.name);
let namespace = types.identifier(meta.name);
if (meta.wrap) {

@@ -123,3 +99,3 @@ namespace = wrapReference(namespace, meta.wrap) ?? namespace;

const computed = metadata.stringSpecifiers.has(importName);
return memberExpression$1(namespace, computed ? stringLiteral$1(importName) : identifier$1(importName), computed);
return types.memberExpression(namespace, computed ? types.stringLiteral(importName) : types.identifier(importName), computed);
}

@@ -146,3 +122,3 @@ };

if (exportNames.length > 0) {
const statement = expressionStatement$1(buildBindingExportAssignmentExpression(metadata, exportNames, identifier$1(localName), path.scope));
const statement = types.expressionStatement(buildBindingExportAssignmentExpression(metadata, exportNames, types.identifier(localName), path.scope));
statement._blockHoist = path.node._blockHoist;

@@ -166,3 +142,3 @@ requeueInParent(path.insertAfter(statement)[0]);

} = decl.node;
if (isIdentifier$1(id) && exported.has(id.name) && !isArrowFunctionExpression(init) && (!isFunctionExpression(init) || init.id) && (!isClassExpression(init) || init.id)) {
if (types.isIdentifier(id) && exported.has(id.name) && !types.isArrowFunctionExpression(init) && (!types.isFunctionExpression(init) || init.id) && (!types.isClassExpression(init) || init.id)) {
if (!init) {

@@ -180,3 +156,3 @@ if (isVar) {

if (exported.has(localName)) {
const statement = expressionStatement$1(buildBindingExportAssignmentExpression(metadata, exported.get(localName), identifier$1(localName), path.scope));
const statement = types.expressionStatement(buildBindingExportAssignmentExpression(metadata, exported.get(localName), types.identifier(localName), path.scope));
statement._blockHoist = path.node._blockHoist;

@@ -202,3 +178,3 @@ requeueInParent(path.insertAfter(statement)[0]);

const computed = stringSpecifiers.has(exportName);
return assignmentExpression("=", memberExpression$1(identifier$1(exportsObjectName), computed ? stringLiteral$1(exportName) : identifier$1(exportName), computed), expr);
return types.assignmentExpression("=", types.memberExpression(types.identifier(exportsObjectName), computed ? types.stringLiteral(exportName) : types.identifier(exportName), computed), expr);
}, localExpr);

@@ -241,5 +217,5 @@ };

tag: path.node
})) && isMemberExpression(ref)) {
path.replaceWith(sequenceExpression([numericLiteral(0), ref]));
} else if (path.isJSXIdentifier() && isMemberExpression(ref)) {
})) && types.isMemberExpression(ref)) {
path.replaceWith(types.sequenceExpression([types.numericLiteral(0), ref]));
} else if (path.isJSXIdentifier() && types.isMemberExpression(ref)) {
const {

@@ -249,3 +225,3 @@ object,

} = ref;
path.replaceWith(jsxMemberExpression(jsxIdentifier(object.name), jsxIdentifier(property.name)));
path.replaceWith(types.jsxMemberExpression(types.jsxIdentifier(object.name), types.jsxIdentifier(property.name)));
} else {

@@ -281,8 +257,8 @@ path.replaceWith(ref);

if (importData) {
path.replaceWith(assignmentExpression(update.operator[0] + "=", buildImportReference(importData, arg.node), buildImportThrow(localName)));
path.replaceWith(types.assignmentExpression(update.operator[0] + "=", buildImportReference(importData, arg.node), buildImportThrow(localName)));
} else if (update.prefix) {
path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, cloneNode$1(update), path.scope));
path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, types.cloneNode(update), path.scope));
} else {
const ref = scope.generateDeclaredUidIdentifier(localName);
path.replaceWith(sequenceExpression([assignmentExpression("=", cloneNode$1(ref), cloneNode$1(update)), buildBindingExportAssignmentExpression(this.metadata, exportedNames, identifier$1(localName), path.scope), cloneNode$1(ref)]));
path.replaceWith(types.sequenceExpression([types.assignmentExpression("=", types.cloneNode(ref), types.cloneNode(update)), buildBindingExportAssignmentExpression(this.metadata, exportedNames, types.identifier(localName), path.scope), types.cloneNode(ref)]));
}

@@ -320,3 +296,3 @@ }

assignment.left = buildImportReference(importData, left.node);
assignment.right = sequenceExpression([assignment.right, buildImportThrow(localName)]);
assignment.right = types.sequenceExpression([assignment.right, buildImportThrow(localName)]);
}

@@ -331,3 +307,3 @@ path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, assignment, path.scope));

if (id) {
path.node.right = sequenceExpression([path.node.right, buildImportThrow(id)]);
path.node.right = types.sequenceExpression([path.node.right, buildImportThrow(id)]);
}

@@ -338,9 +314,9 @@ const items = [];

if (exportedNames.length > 0) {
items.push(buildBindingExportAssignmentExpression(this.metadata, exportedNames, identifier$1(localName), path.scope));
items.push(buildBindingExportAssignmentExpression(this.metadata, exportedNames, types.identifier(localName), path.scope));
}
});
if (items.length > 0) {
let node = sequenceExpression(items);
let node = types.sequenceExpression(items);
if (path.parentPath.isExpressionStatement()) {
node = expressionStatement$1(node);
node = types.expressionStatement(node);
node._blockHoist = path.parentPath.node._blockHoist;

@@ -367,7 +343,7 @@ }

} = this;
if (!isVariableDeclaration(left)) {
if (!types.isVariableDeclaration(left)) {
let didTransformExport = false,
importConstViolationName;
const loopBodyScope = path.get("body").scope;
for (const name of Object.keys(getOuterBindingIdentifiers(left))) {
for (const name of Object.keys(types.getOuterBindingIdentifiers(left))) {
if (programScope.getBinding(name) === scope.getBinding(name)) {

@@ -391,9 +367,9 @@ if (exported.has(name)) {

const newLoopId = scope.generateUidIdentifierBasedOnNode(left);
path.get("left").replaceWith(variableDeclaration$1("let", [variableDeclarator$1(cloneNode$1(newLoopId))]));
path.get("left").replaceWith(types.variableDeclaration("let", [types.variableDeclarator(types.cloneNode(newLoopId))]));
scope.registerDeclaration(path.get("left"));
if (didTransformExport) {
bodyPath.unshiftContainer("body", expressionStatement$1(assignmentExpression("=", left, newLoopId)));
bodyPath.unshiftContainer("body", types.expressionStatement(types.assignmentExpression("=", left, newLoopId)));
}
if (importConstViolationName) {
bodyPath.unshiftContainer("body", expressionStatement$1(buildImportThrow(importConstViolationName)));
bodyPath.unshiftContainer("body", types.expressionStatement(buildImportThrow(importConstViolationName)));
}

@@ -721,3 +697,3 @@ }

if (!child.isExportDefaultDeclaration()) return;
splitExportDeclaration(child);
child.splitExportDeclaration();
});

@@ -755,6 +731,6 @@ }

if (lazy === true) {
return /\./.test(source) ? null : "lazy";
return source.includes(".") ? null : "lazy";
}
if (Array.isArray(lazy)) {
return lazy.indexOf(source) === -1 ? null : "lazy";
return !lazy.includes(source) ? null : "lazy";
}

@@ -835,17 +811,2 @@ if (typeof lazy === "function") {

const {
booleanLiteral,
callExpression,
cloneNode,
directive,
directiveLiteral,
expressionStatement,
identifier,
isIdentifier,
memberExpression,
stringLiteral,
valueToNode,
variableDeclaration,
variableDeclarator
} = types;
function rewriteModuleStatementsAndPrepareHeader(path, {

@@ -886,3 +847,3 @@ exportName,

if (!hasStrict) {
path.unshiftContainer("directives", directive(directiveLiteral("use strict")));
path.unshiftContainer("directives", types.directive(types.directiveLiteral("use strict")));
}

@@ -915,3 +876,3 @@ }

if (type === "node-namespace") {
return callExpression(programPath.hub.addHelper("interopRequireWildcard"), [expr, booleanLiteral(true)]);
return types.callExpression(programPath.hub.addHelper("interopRequireWildcard"), [expr, types.booleanLiteral(true)]);
} else if (type === "node-default") {

@@ -928,7 +889,7 @@ return null;

}
return callExpression(programPath.hub.addHelper(helper), [expr]);
return types.callExpression(programPath.hub.addHelper(helper), [expr]);
}
function buildNamespaceInitStatements(metadata, sourceMetadata, constantReexports = false, wrapReference$1 = wrapReference) {
const statements = [];
const srcNamespaceId = identifier(sourceMetadata.name);
const srcNamespaceId = types.identifier(sourceMetadata.name);
for (const localName of sourceMetadata.importsNamespace) {

@@ -938,3 +899,3 @@ if (localName === sourceMetadata.name) continue;

NAME: localName,
SOURCE: cloneNode(srcNamespaceId)
SOURCE: types.cloneNode(srcNamespaceId)
}));

@@ -957,7 +918,7 @@ }

NAME: exportName,
NAMESPACE: cloneNode(srcNamespace)
NAMESPACE: types.cloneNode(srcNamespace)
}));
}
if (sourceMetadata.reexportAll) {
const statement = buildNamespaceReexport(metadata, cloneNode(srcNamespace), constantReexports);
const statement = buildNamespaceReexport(metadata, types.cloneNode(srcNamespace), constantReexports);
statement.loc = sourceMetadata.reexportAll.loc;

@@ -969,15 +930,31 @@ statements.push(statement);

const ReexportTemplate = {
constant: template.statement`EXPORTS.EXPORT_NAME = NAMESPACE_IMPORT;`,
constantComputed: template.statement`EXPORTS["EXPORT_NAME"] = NAMESPACE_IMPORT;`,
spec: template.statement`
Object.defineProperty(EXPORTS, "EXPORT_NAME", {
enumerable: true,
get: function() {
return NAMESPACE_IMPORT;
},
});
constant: ({
exports,
exportName,
namespaceImport
}) => template.statement.ast`
${exports}.${exportName} = ${namespaceImport};
`,
constantComputed: ({
exports,
exportName,
namespaceImport
}) => template.statement.ast`
${exports}["${exportName}"] = ${namespaceImport};
`,
spec: ({
exports,
exportName,
namespaceImport
}) => template.statement.ast`
Object.defineProperty(${exports}, "${exportName}", {
enumerable: true,
get: function() {
return ${namespaceImport};
},
});
`
};
function buildReexportsFromMeta(meta, metadata, constantReexports, wrapReference) {
let namespace = identifier(metadata.name);
let namespace = types.identifier(metadata.name);
namespace = wrapReference(namespace, metadata.wrap) ?? namespace;

@@ -988,14 +965,14 @@ const {

return Array.from(metadata.reexports, ([exportName, importName]) => {
let NAMESPACE_IMPORT = cloneNode(namespace);
let namespaceImport = types.cloneNode(namespace);
if (importName === "default" && metadata.interop === "node-default") ; else if (stringSpecifiers.has(importName)) {
NAMESPACE_IMPORT = memberExpression(NAMESPACE_IMPORT, stringLiteral(importName), true);
namespaceImport = types.memberExpression(namespaceImport, types.stringLiteral(importName), true);
} else {
NAMESPACE_IMPORT = memberExpression(NAMESPACE_IMPORT, identifier(importName));
namespaceImport = types.memberExpression(namespaceImport, types.identifier(importName));
}
const astNodes = {
EXPORTS: meta.exportName,
EXPORT_NAME: exportName,
NAMESPACE_IMPORT
exports: meta.exportName,
exportName,
namespaceImport
};
if (constantReexports || isIdentifier(NAMESPACE_IMPORT)) {
if (constantReexports || types.isIdentifier(namespaceImport)) {
if (stringSpecifiers.has(exportName)) {

@@ -1076,3 +1053,3 @@ return ReexportTemplate.constantComputed(astNodes);

name: name.name,
statement: variableDeclaration("var", [variableDeclarator(name, valueToNode(exportedVars))])
statement: types.variableDeclaration("var", [types.variableDeclarator(name, types.valueToNode(exportedVars))])
};

@@ -1084,3 +1061,3 @@ }

if (data.kind === "import") ; else if (data.kind === "hoisted") {
initStatements.push([data.names[0], buildInitStatement(metadata, data.names, identifier(localName))]);
initStatements.push([data.names[0], buildInitStatement(metadata, data.names, types.identifier(localName))]);
} else if (!noIncompleteNsImportDetection) {

@@ -1140,5 +1117,22 @@ for (const exportName of data.names) {

const InitTemplate = {
computed: template.expression`EXPORTS["NAME"] = VALUE`,
default: template.expression`EXPORTS.NAME = VALUE`,
define: template.expression`Object.defineProperty(EXPORTS, "NAME", { enumerable:true, value: void 0, writable: true })["NAME"] = VALUE`
computed: ({
exports,
name,
value
}) => template.expression.ast`${exports}["${name}"] = ${value}`,
default: ({
exports,
name,
value
}) => template.expression.ast`${exports}.${name} = ${value}`,
define: ({
exports,
name,
value
}) => template.expression.ast`
Object.defineProperty(${exports}, "${name}", {
enumerable: true,
value: void 0,
writable: true
})["${name}"] = ${value}`
};

@@ -1148,14 +1142,14 @@ function buildInitStatement(metadata, exportNames, initExpr) {

stringSpecifiers,
exportName: EXPORTS
exportName: exports
} = metadata;
return expressionStatement(exportNames.reduce((acc, exportName) => {
return types.expressionStatement(exportNames.reduce((value, name) => {
const params = {
EXPORTS,
NAME: exportName,
VALUE: acc
exports,
name,
value
};
if (exportName === "__proto__") {
if (name === "__proto__") {
return InitTemplate.define(params);
}
if (stringSpecifiers.has(exportName)) {
if (stringSpecifiers.has(name)) {
return InitTemplate.computed(params);

@@ -1162,0 +1156,0 @@ }

{
"name": "@babel/helper-module-transforms",
"version": "8.0.0-alpha.11",
"version": "8.0.0-alpha.12",
"description": "Babel helper functions for implementing ES6 module transformations",

@@ -18,13 +18,12 @@ "author": "The Babel Team (https://babel.dev/team)",

"dependencies": {
"@babel/helper-environment-visitor": "^8.0.0-alpha.11",
"@babel/helper-module-imports": "^8.0.0-alpha.11",
"@babel/helper-simple-access": "^8.0.0-alpha.11",
"@babel/helper-split-export-declaration": "^8.0.0-alpha.11",
"@babel/helper-validator-identifier": "^8.0.0-alpha.11"
"@babel/helper-module-imports": "^8.0.0-alpha.12",
"@babel/helper-simple-access": "^8.0.0-alpha.12",
"@babel/helper-validator-identifier": "^8.0.0-alpha.12",
"@babel/traverse": "^8.0.0-alpha.12"
},
"devDependencies": {
"@babel/core": "^8.0.0-alpha.11"
"@babel/core": "^8.0.0-alpha.12"
},
"peerDependencies": {
"@babel/core": "^8.0.0-alpha.11"
"@babel/core": "^8.0.0-alpha.12"
},

@@ -31,0 +30,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

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