@babel/helper-module-imports
Advanced tools
Comparing version 7.18.6 to 7.21.4-esm
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = void 0; | ||
var _assert = require("assert"); | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -27,3 +24,2 @@ callExpression, | ||
} = _t; | ||
class ImportBuilder { | ||
@@ -38,3 +34,2 @@ constructor(importedSource, scope, hub) { | ||
} | ||
done() { | ||
@@ -46,24 +41,15 @@ return { | ||
} | ||
import() { | ||
this._statements.push(importDeclaration([], stringLiteral(this._importedSource))); | ||
return this; | ||
} | ||
require() { | ||
this._statements.push(expressionStatement(callExpression(identifier("require"), [stringLiteral(this._importedSource)]))); | ||
return this; | ||
} | ||
namespace(name = "namespace") { | ||
const local = this._scope.generateUidIdentifier(name); | ||
const statement = this._statements[this._statements.length - 1]; | ||
_assert(statement.type === "ImportDeclaration"); | ||
_assert(statement.specifiers.length === 0); | ||
statement.specifiers = [importNamespaceSpecifier(local)]; | ||
@@ -73,12 +59,7 @@ this._resultName = cloneNode(local); | ||
} | ||
default(name) { | ||
const id = this._scope.generateUidIdentifier(name); | ||
const statement = this._statements[this._statements.length - 1]; | ||
_assert(statement.type === "ImportDeclaration"); | ||
_assert(statement.specifiers.length === 0); | ||
statement.specifiers = [importDefaultSpecifier(id)]; | ||
@@ -88,14 +69,8 @@ this._resultName = cloneNode(id); | ||
} | ||
named(name, importName) { | ||
if (importName === "default") return this.default(name); | ||
const id = this._scope.generateUidIdentifier(name); | ||
const statement = this._statements[this._statements.length - 1]; | ||
_assert(statement.type === "ImportDeclaration"); | ||
_assert(statement.specifiers.length === 0); | ||
statement.specifiers = [importSpecifier(id, identifier(importName))]; | ||
@@ -105,16 +80,10 @@ this._resultName = cloneNode(id); | ||
} | ||
var(name) { | ||
const id = this._scope.generateUidIdentifier(name); | ||
let statement = this._statements[this._statements.length - 1]; | ||
if (statement.type !== "ExpressionStatement") { | ||
_assert(this._resultName); | ||
statement = expressionStatement(this._resultName); | ||
this._statements.push(statement); | ||
} | ||
this._statements[this._statements.length - 1] = variableDeclaration("var", [variableDeclarator(id, statement.expression)]); | ||
@@ -124,14 +93,10 @@ this._resultName = cloneNode(id); | ||
} | ||
defaultInterop() { | ||
return this._interop(this._hub.addHelper("interopRequireDefault")); | ||
} | ||
wildcardInterop() { | ||
return this._interop(this._hub.addHelper("interopRequireWildcard")); | ||
} | ||
_interop(callee) { | ||
const statement = this._statements[this._statements.length - 1]; | ||
if (statement.type === "ExpressionStatement") { | ||
@@ -141,3 +106,2 @@ statement.expression = callExpression(callee, [statement.expression]); | ||
_assert(statement.declarations.length === 1); | ||
statement.declarations[0].init = callExpression(callee, [statement.declarations[0].init]); | ||
@@ -147,9 +111,6 @@ } else { | ||
} | ||
return this; | ||
} | ||
prop(name) { | ||
const statement = this._statements[this._statements.length - 1]; | ||
if (statement.type === "ExpressionStatement") { | ||
@@ -159,3 +120,2 @@ statement.expression = memberExpression(statement.expression, identifier(name)); | ||
_assert(statement.declarations.length === 1); | ||
statement.declarations[0].init = memberExpression(statement.declarations[0].init, identifier(name)); | ||
@@ -165,12 +125,10 @@ } else { | ||
} | ||
return this; | ||
} | ||
read(name) { | ||
this._resultName = memberExpression(this._resultName, identifier(name)); | ||
} | ||
} | ||
exports.default = ImportBuilder; | ||
exports.default = ImportBuilder; | ||
//# sourceMappingURL=import-builder.js.map |
@@ -7,11 +7,6 @@ "use strict"; | ||
exports.default = void 0; | ||
var _assert = require("assert"); | ||
var _t = require("@babel/types"); | ||
var _importBuilder = require("./import-builder"); | ||
var _isModule = require("./is-module"); | ||
const { | ||
@@ -21,3 +16,2 @@ numericLiteral, | ||
} = _t; | ||
class ImportInjector { | ||
@@ -40,24 +34,17 @@ constructor(path, importedSource, opts) { | ||
} | ||
addDefault(importedSourceIn, opts) { | ||
return this.addNamed("default", importedSourceIn, opts); | ||
} | ||
addNamed(importName, importedSourceIn, opts) { | ||
_assert(typeof importName === "string"); | ||
return this._generateImport(this._applyDefaults(importedSourceIn, opts), importName); | ||
} | ||
addNamespace(importedSourceIn, opts) { | ||
return this._generateImport(this._applyDefaults(importedSourceIn, opts), null); | ||
} | ||
addSideEffect(importedSourceIn, opts) { | ||
return this._generateImport(this._applyDefaults(importedSourceIn, opts), void 0); | ||
} | ||
_applyDefaults(importedSource, opts, isInit = false) { | ||
let newOpts; | ||
if (typeof importedSource === "string") { | ||
@@ -69,6 +56,4 @@ newOpts = Object.assign({}, this._defaultOpts, { | ||
_assert(!opts, "Unexpected secondary arguments."); | ||
newOpts = Object.assign({}, this._defaultOpts, importedSource); | ||
} | ||
if (!isInit && opts) { | ||
@@ -78,6 +63,4 @@ if (opts.nameHint !== undefined) newOpts.nameHint = opts.nameHint; | ||
} | ||
return newOpts; | ||
} | ||
_generateImport(opts, importName) { | ||
@@ -102,9 +85,6 @@ const isDefault = importName === "default"; | ||
const isModuleForBabel = isMod && importingInterop === "babel"; | ||
if (importPosition === "after" && !isMod) { | ||
throw new Error(`"importPosition": "after" is only supported in modules`); | ||
} | ||
const builder = new _importBuilder.default(importedSource, this._programScope, this._hub); | ||
if (importedType === "es6") { | ||
@@ -114,5 +94,3 @@ if (!isModuleForNode && !isModuleForBabel) { | ||
} | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -130,3 +108,2 @@ builder.namespace(nameHint || importedSource); | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -145,3 +122,2 @@ builder.default(es6Default).var(name || importedSource).wildcardInterop(); | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -154,3 +130,2 @@ builder.namespace(name || importedSource); | ||
builder.require(); | ||
if (isNamespace) { | ||
@@ -175,3 +150,2 @@ builder.var(name || importedSource).wildcardInterop(); | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -184,3 +158,2 @@ builder.default(name || importedSource); | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -193,3 +166,2 @@ builder.namespace(name || importedSource); | ||
builder.require(); | ||
if (isNamespace) { | ||
@@ -209,6 +181,4 @@ builder.var(name || importedSource); | ||
} | ||
if (isModuleForNode) { | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -223,3 +193,2 @@ builder.default(name || importedSource); | ||
builder.import(); | ||
if (isNamespace) { | ||
@@ -234,3 +203,2 @@ builder.default(name || importedSource); | ||
builder.require(); | ||
if (isNamespace) { | ||
@@ -251,3 +219,2 @@ builder.var(name || importedSource); | ||
} | ||
const { | ||
@@ -257,15 +224,10 @@ statements, | ||
} = builder.done(); | ||
this._insertStatements(statements, importPosition, blockHoist); | ||
if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") { | ||
return sequenceExpression([numericLiteral(0), resultName]); | ||
} | ||
return resultName; | ||
} | ||
_insertStatements(statements, importPosition = "before", blockHoist = 3) { | ||
const body = this._programPath.get("body"); | ||
if (importPosition === "after") { | ||
@@ -286,3 +248,2 @@ for (let i = body.length - 1; i >= 0; i--) { | ||
}); | ||
if (targetPath) { | ||
@@ -293,8 +254,7 @@ targetPath.insertBefore(statements); | ||
} | ||
this._programPath.unshiftContainer("body", statements); | ||
} | ||
} | ||
exports.default = ImportInjector; | ||
exports.default = ImportInjector; | ||
//# sourceMappingURL=import-injector.js.map |
@@ -22,21 +22,17 @@ "use strict"; | ||
}); | ||
var _importInjector = require("./import-injector"); | ||
var _isModule = require("./is-module"); | ||
function addDefault(path, importedSource, opts) { | ||
return new _importInjector.default(path).addDefault(importedSource, opts); | ||
} | ||
function addNamed(path, name, importedSource, opts) { | ||
return new _importInjector.default(path).addNamed(name, importedSource, opts); | ||
} | ||
function addNamespace(path, importedSource, opts) { | ||
return new _importInjector.default(path).addNamespace(importedSource, opts); | ||
} | ||
function addSideEffect(path, importedSource, opts) { | ||
return new _importInjector.default(path).addSideEffect(importedSource, opts); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -7,13 +7,6 @@ "use strict"; | ||
exports.default = isModule; | ||
function isModule(path) { | ||
const { | ||
sourceType | ||
} = path.node; | ||
return path.node.sourceType === "module"; | ||
} | ||
if (sourceType !== "module" && sourceType !== "script") { | ||
throw path.buildCodeFrameError(`Unknown sourceType "${sourceType}", cannot transform.`); | ||
} | ||
return path.node.sourceType === "module"; | ||
} | ||
//# sourceMappingURL=is-module.js.map |
{ | ||
"name": "@babel/helper-module-imports", | ||
"version": "7.18.6", | ||
"version": "7.21.4-esm", | ||
"description": "Babel helper functions for inserting module loads", | ||
@@ -18,7 +18,7 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/types": "^7.18.6" | ||
"@babel/types": "^7.21.4-esm" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.18.6", | ||
"@babel/traverse": "^7.18.6" | ||
"@babel/core": "^7.21.4-esm", | ||
"@babel/traverse": "^7.21.4-esm" | ||
}, | ||
@@ -25,0 +25,0 @@ "engines": { |
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
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
54269
12
402
1
Updated@babel/types@^7.21.4-esm