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

@babel/helper-module-transforms

Package Overview
Dependencies
Maintainers
4
Versions
123
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 7.21.4-esm.4 to 7.21.5

32

lib/dynamic-import.js

@@ -1,12 +0,24 @@

import * as t from "@babel/types";
import template from "@babel/template";
export function getDynamicImportSource(node) {
const [source] = node.arguments;
return t.isStringLiteral(source) || t.isTemplateLiteral(source) ? source : template.expression.ast`\`\${${source}}\``;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildDynamicImport = buildDynamicImport;
var t = require("@babel/types");
var _template = require("@babel/template");
{
{
{
exports.getDynamicImportSource = function getDynamicImportSource(node) {
const [source] = node.arguments;
return t.isStringLiteral(source) || t.isTemplateLiteral(source) ? source : _template.default.expression.ast`\`\${${source}}\``;
};
}
}
}
export function buildDynamicImport(node, deferToThen, wrapWithPromise, builder) {
function buildDynamicImport(node, deferToThen, wrapWithPromise, builder) {
const [specifier] = node.arguments;
if (t.isStringLiteral(specifier) || t.isTemplateLiteral(specifier) && specifier.quasis.length === 0) {
if (deferToThen) {
return template.expression.ast`
return _template.default.expression.ast`
Promise.resolve().then(() => ${builder(specifier)})

@@ -22,3 +34,3 @@ `;

if (deferToThen) {
return template.expression.ast`
return _template.default.expression.ast`
(specifier =>

@@ -30,3 +42,3 @@ new Promise(r => r(${specifierToString}))

} else if (wrapWithPromise) {
return template.expression.ast`
return _template.default.expression.ast`
(specifier =>

@@ -37,3 +49,3 @@ new Promise(r => r(${builder(specifierToString)}))

} else {
return template.expression.ast`
return _template.default.expression.ast`
(specifier => ${builder(specifierToString)})(${specifier})

@@ -40,0 +52,0 @@ `;

@@ -0,4 +1,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getModuleName;
{
const originalGetModuleName = getModuleName;
getModuleName = function getModuleName(rootOpts, pluginOpts) {
exports.default = getModuleName = function getModuleName(rootOpts, pluginOpts) {
var _pluginOpts$moduleId, _pluginOpts$moduleIds, _pluginOpts$getModule, _pluginOpts$moduleRoo;

@@ -13,3 +19,3 @@ return originalGetModuleName(rootOpts, {

}
export default function getModuleName(rootOpts, pluginOpts) {
function getModuleName(rootOpts, pluginOpts) {
const {

@@ -16,0 +22,0 @@ filename,

@@ -1,3 +0,55 @@

import assert from "assert";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "buildDynamicImport", {
enumerable: true,
get: function () {
return _dynamicImport.buildDynamicImport;
}
});
exports.buildNamespaceInitStatements = buildNamespaceInitStatements;
exports.ensureStatementsHoisted = ensureStatementsHoisted;
Object.defineProperty(exports, "getModuleName", {
enumerable: true,
get: function () {
return _getModuleName.default;
}
});
Object.defineProperty(exports, "hasExports", {
enumerable: true,
get: function () {
return _normalizeAndLoadMetadata.hasExports;
}
});
Object.defineProperty(exports, "isModule", {
enumerable: true,
get: function () {
return _helperModuleImports.isModule;
}
});
Object.defineProperty(exports, "isSideEffectImport", {
enumerable: true,
get: function () {
return _normalizeAndLoadMetadata.isSideEffectImport;
}
});
exports.rewriteModuleStatementsAndPrepareHeader = rewriteModuleStatementsAndPrepareHeader;
Object.defineProperty(exports, "rewriteThis", {
enumerable: true,
get: function () {
return _rewriteThis.default;
}
});
exports.wrapInterop = wrapInterop;
var _assert = require("assert");
var _t = require("@babel/types");
var _template = require("@babel/template");
var _helperModuleImports = require("@babel/helper-module-imports");
var _rewriteThis = require("./rewrite-this");
var _rewriteLiveReferences = require("./rewrite-live-references");
var _normalizeAndLoadMetadata = require("./normalize-and-load-metadata");
var _dynamicImport = require("./dynamic-import");
var _getModuleName = require("./get-module-name");
const {

@@ -18,12 +70,10 @@ booleanLiteral,

} = _t;
import template from "@babel/template";
import { isModule } from "@babel/helper-module-imports";
import rewriteThis from "./rewrite-this.js";
import rewriteLiveReferences from "./rewrite-live-references.js";
import normalizeModuleAndLoadMetadata, { hasExports, isSideEffectImport, validateImportInteropOption } from "./normalize-and-load-metadata.js";
export { buildDynamicImport, getDynamicImportSource } from "./dynamic-import.js";
export { default as getModuleName } from "./get-module-name.js";
export { hasExports, isSideEffectImport, isModule, rewriteThis };
export function rewriteModuleStatementsAndPrepareHeader(path, {
loose,
{
{
{
exports.getDynamicImportSource = require("./dynamic-import").getDynamicImportSource;
}
}
}
function rewriteModuleStatementsAndPrepareHeader(path, {
exportName,

@@ -38,10 +88,10 @@ strict,

filename,
constantReexports = loose,
enumerableModuleMeta = loose,
constantReexports = arguments[1].loose,
enumerableModuleMeta = arguments[1].loose,
noIncompleteNsImportDetection
}) {
validateImportInteropOption(importInterop);
assert(isModule(path), "Cannot process module statements in a script");
(0, _normalizeAndLoadMetadata.validateImportInteropOption)(importInterop);
_assert((0, _helperModuleImports.isModule)(path), "Cannot process module statements in a script");
path.node.sourceType = "script";
const meta = normalizeModuleAndLoadMetadata(path, exportName, {
const meta = (0, _normalizeAndLoadMetadata.default)(path, exportName, {
importInterop,

@@ -54,5 +104,5 @@ initializeReexports: constantReexports,

if (!allowTopLevelThis) {
rewriteThis(path);
(0, _rewriteThis.default)(path);
}
rewriteLiveReferences(path, meta);
(0, _rewriteLiveReferences.default)(path, meta);
if (strictMode !== false) {

@@ -67,3 +117,3 @@ const hasStrict = path.node.directives.some(directive => {

const headers = [];
if (hasExports(meta) && !strict) {
if ((0, _normalizeAndLoadMetadata.hasExports)(meta) && !strict) {
headers.push(buildESModuleHeader(meta, enumerableModuleMeta));

@@ -82,3 +132,3 @@ }

}
export function ensureStatementsHoisted(statements) {
function ensureStatementsHoisted(statements) {
statements.forEach(header => {

@@ -88,3 +138,3 @@ header._blockHoist = 3;

}
export function wrapInterop(programPath, expr, type) {
function wrapInterop(programPath, expr, type) {
if (type === "none") {

@@ -108,3 +158,3 @@ return null;

}
export function buildNamespaceInitStatements(metadata, sourceMetadata, constantReexports = false) {
function buildNamespaceInitStatements(metadata, sourceMetadata, constantReexports = false) {
const statements = [];

@@ -115,3 +165,3 @@ let srcNamespace = identifier(sourceMetadata.name);

if (localName === sourceMetadata.name) continue;
statements.push(template.statement`var NAME = SOURCE;`({
statements.push(_template.default.statement`var NAME = SOURCE;`({
NAME: localName,

@@ -125,3 +175,3 @@ SOURCE: cloneNode(srcNamespace)

for (const exportName of sourceMetadata.reexportNamespace) {
statements.push((sourceMetadata.lazy ? template.statement`
statements.push((sourceMetadata.lazy ? _template.default.statement`
Object.defineProperty(EXPORTS, "NAME", {

@@ -133,3 +183,3 @@ enumerable: true,

});
` : template.statement`EXPORTS.NAME = NAMESPACE;`)({
` : _template.default.statement`EXPORTS.NAME = NAMESPACE;`)({
EXPORTS: metadata.exportName,

@@ -148,5 +198,5 @@ NAME: exportName,

const ReexportTemplate = {
constant: template.statement`EXPORTS.EXPORT_NAME = NAMESPACE_IMPORT;`,
constantComputed: template.statement`EXPORTS["EXPORT_NAME"] = NAMESPACE_IMPORT;`,
spec: template.statement`
constant: _template.default.statement`EXPORTS.EXPORT_NAME = NAMESPACE_IMPORT;`,
constantComputed: _template.default.statement`EXPORTS["EXPORT_NAME"] = NAMESPACE_IMPORT;`,
spec: _template.default.statement`
Object.defineProperty(EXPORTS, "EXPORT_NAME", {

@@ -189,5 +239,5 @@ enumerable: true,

function buildESModuleHeader(metadata, enumerableModuleMeta = false) {
return (enumerableModuleMeta ? template.statement`
return (enumerableModuleMeta ? _template.default.statement`
EXPORTS.__esModule = true;
` : template.statement`
` : _template.default.statement`
Object.defineProperty(EXPORTS, "__esModule", {

@@ -201,3 +251,3 @@ value: true,

function buildNamespaceReexport(metadata, namespace, constantReexports) {
return (constantReexports ? template.statement`
return (constantReexports ? _template.default.statement`
Object.keys(NAMESPACE).forEach(function(key) {

@@ -210,3 +260,3 @@ if (key === "default" || key === "__esModule") return;

});
` : template.statement`
` : _template.default.statement`
Object.keys(NAMESPACE).forEach(function(key) {

@@ -227,3 +277,3 @@ if (key === "default" || key === "__esModule") return;

EXPORTS: metadata.exportName,
VERIFY_NAME_LIST: metadata.exportNameListName ? template`
VERIFY_NAME_LIST: metadata.exportNameListName ? (0, _template.default)`
if (Object.prototype.hasOwnProperty.call(EXPORTS_LIST, key)) return;

@@ -319,4 +369,4 @@ `({

const InitTemplate = {
computed: template.expression`EXPORTS["NAME"] = VALUE`,
default: template.expression`EXPORTS.NAME = VALUE`
computed: _template.default.expression`EXPORTS["NAME"] = VALUE`,
default: _template.default.expression`EXPORTS.NAME = VALUE`
};

@@ -323,0 +373,0 @@ function buildInitStatement(metadata, exportNames, initExpr) {

@@ -1,11 +0,20 @@

import { basename, extname } from "path";
import { isIdentifierName } from "@babel/helper-validator-identifier";
import splitExportDeclaration from "@babel/helper-split-export-declaration";
export function hasExports(metadata) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = normalizeModuleAndLoadMetadata;
exports.hasExports = hasExports;
exports.isSideEffectImport = isSideEffectImport;
exports.validateImportInteropOption = validateImportInteropOption;
var _path = require("path");
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
function hasExports(metadata) {
return metadata.hasExports;
}
export function isSideEffectImport(source) {
function isSideEffectImport(source) {
return source.imports.size === 0 && source.importsNamespace.size === 0 && source.reexports.size === 0 && source.reexportNamespace.size === 0 && !source.reexportAll;
}
export function validateImportInteropOption(importInterop) {
function validateImportInteropOption(importInterop) {
if (typeof importInterop !== "function" && importInterop !== "none" && importInterop !== "babel" && importInterop !== "node") {

@@ -22,3 +31,3 @@ throw new Error(`.importInterop must be one of "none", "babel", "node", or a function returning one of those values (received ${importInterop}).`);

}
export default function normalizeModuleAndLoadMetadata(programPath, exportName, {
function normalizeModuleAndLoadMetadata(programPath, exportName, {
importInterop,

@@ -73,3 +82,3 @@ initializeReexports = false,

const stringValue = path.node.value;
if (!isIdentifierName(stringValue)) {
if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) {
stringSpecifiers.add(stringValue);

@@ -102,3 +111,3 @@ }

data = {
name: programPath.scope.generateUidIdentifier(basename(source, extname(source))).name,
name: programPath.scope.generateUidIdentifier((0, _path.basename)(source, (0, _path.extname)(source))).name,
interop: "none",

@@ -320,3 +329,3 @@ loc: null,

if (!child.isExportDefaultDeclaration()) return;
splitExportDeclaration(child);
(0, _helperSplitExportDeclaration.default)(child);
});

@@ -323,0 +332,0 @@ }

@@ -1,3 +0,11 @@

import assert from "assert";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = rewriteLiveReferences;
var _assert = require("assert");
var _t = require("@babel/types");
var _template = require("@babel/template");
var _helperSimpleAccess = require("@babel/helper-simple-access");
const {

@@ -21,4 +29,2 @@ assignmentExpression,

} = _t;
import template from "@babel/template";
import simplifyAccess from "@babel/helper-simple-access";
function isInType(path) {

@@ -42,3 +48,3 @@ do {

}
export default function rewriteLiveReferences(programPath, metadata) {
function rewriteLiveReferences(programPath, metadata) {
const imported = new Map();

@@ -72,3 +78,6 @@ const exported = new Map();

programPath.traverse(rewriteBindingInitVisitor, rewriteBindingInitVisitorState);
simplifyAccess(programPath, new Set([...Array.from(imported.keys()), ...Array.from(exported.keys())]), false);
const bindingNames = new Set([...Array.from(imported.keys()), ...Array.from(exported.keys())]);
{
(0, _helperSimpleAccess.default)(programPath, bindingNames, false);
}
const rewriteReferencesVisitorState = {

@@ -155,3 +164,3 @@ seen: new WeakSet(),

const buildImportThrow = localName => {
return template.expression.ast`
return _template.default.expression.ast`
(function() {

@@ -262,3 +271,3 @@ throw new Error('"' + '${localName}' + '" is read-only.');

if ((exportedNames == null ? void 0 : exportedNames.length) > 0 || importData) {
assert(path.node.operator === "=", "Path was not simplified");
_assert(path.node.operator === "=", "Path was not simplified");
const assignment = path.node;

@@ -265,0 +274,0 @@ if (importData) {

@@ -1,4 +0,10 @@

import environmentVisitor from "@babel/helper-environment-visitor";
import traverse from "@babel/traverse";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = rewriteThis;
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
var _traverse = require("@babel/traverse");
var _t = require("@babel/types");
const {

@@ -8,3 +14,3 @@ numericLiteral,

} = _t;
const rewriteThisVisitor = traverse.visitors.merge([environmentVisitor, {
const rewriteThisVisitor = _traverse.default.visitors.merge([_helperEnvironmentVisitor.default, {
ThisExpression(path) {

@@ -14,4 +20,4 @@ path.replaceWith(unaryExpression("void", numericLiteral(0), true));

}]);
export default function rewriteThis(programPath) {
traverse(programPath.node, Object.assign({}, rewriteThisVisitor, {
function rewriteThis(programPath) {
(0, _traverse.default)(programPath.node, Object.assign({}, rewriteThisVisitor, {
noScope: true

@@ -18,0 +24,0 @@ }));

{
"name": "@babel/helper-module-transforms",
"version": "7.21.4-esm.4",
"version": "7.21.5",
"description": "Babel helper functions for implementing ES6 module transformations",

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

"dependencies": {
"@babel/helper-environment-visitor": "7.21.4-esm.4",
"@babel/helper-module-imports": "7.21.4-esm.4",
"@babel/helper-simple-access": "7.21.4-esm.4",
"@babel/helper-split-export-declaration": "7.21.4-esm.4",
"@babel/helper-validator-identifier": "7.21.4-esm.4",
"@babel/template": "7.21.4-esm.4",
"@babel/traverse": "7.21.4-esm.4",
"@babel/types": "7.21.4-esm.4"
"@babel/helper-environment-visitor": "^7.21.5",
"@babel/helper-module-imports": "^7.21.4",
"@babel/helper-simple-access": "^7.21.5",
"@babel/helper-split-export-declaration": "^7.18.6",
"@babel/helper-validator-identifier": "^7.19.1",
"@babel/template": "^7.20.7",
"@babel/traverse": "^7.21.5",
"@babel/types": "^7.21.5"
},

@@ -31,3 +31,3 @@ "engines": {

},
"type": "module"
"type": "commonjs"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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