@babel/helper-module-transforms
Advanced tools
Comparing version 7.21.4-esm.4 to 7.21.5
@@ -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, |
122
lib/index.js
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
148558
1192
0
15
No
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-environment-visitor@7.24.7(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-simple-access@7.25.9(transitive)
+ Added@babel/helper-split-export-declaration@7.24.7(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedpicocolors@1.1.1(transitive)
- Removed@babel/code-frame@7.21.4-esm.4(transitive)
- Removed@babel/generator@7.21.4-esm.4(transitive)
- Removed@babel/helper-environment-visitor@7.21.4-esm.4(transitive)
- Removed@babel/helper-function-name@7.21.4-esm.4(transitive)
- Removed@babel/helper-hoist-variables@7.21.4-esm.4(transitive)
- Removed@babel/helper-module-imports@7.21.4-esm.4(transitive)
- Removed@babel/helper-simple-access@7.21.4-esm.4(transitive)
- Removed@babel/helper-split-export-declaration@7.21.4-esm.4(transitive)
- Removed@babel/helper-string-parser@7.21.4-esm.4(transitive)
- Removed@babel/helper-validator-identifier@7.21.4-esm.4(transitive)
- Removed@babel/highlight@7.21.4-esm.4(transitive)
- Removed@babel/parser@7.21.4-esm.4(transitive)
- Removed@babel/template@7.21.4-esm.4(transitive)
- Removed@babel/traverse@7.21.4-esm.4(transitive)
- Removed@babel/types@7.21.4-esm.4(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedjsesc@2.5.2(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedto-fast-properties@2.0.0(transitive)
Updated@babel/template@^7.20.7
Updated@babel/traverse@^7.21.5
Updated@babel/types@^7.21.5