@babel/helper-module-imports
Advanced tools
Comparing version 7.12.5 to 7.12.13
@@ -30,3 +30,4 @@ "use strict"; | ||
ensureLiveReference: false, | ||
ensureNoContext: false | ||
ensureNoContext: false, | ||
importPosition: "before" | ||
}; | ||
@@ -99,2 +100,3 @@ const programPath = path.find(p => p.isProgram()); | ||
nameHint, | ||
importPosition, | ||
blockHoist | ||
@@ -106,2 +108,7 @@ } = opts; | ||
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); | ||
@@ -246,3 +253,3 @@ | ||
this._insertStatements(statements, blockHoist); | ||
this._insertStatements(statements, importPosition, blockHoist); | ||
@@ -256,17 +263,28 @@ if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") { | ||
_insertStatements(statements, blockHoist = 3) { | ||
statements.forEach(node => { | ||
node._blockHoist = blockHoist; | ||
}); | ||
_insertStatements(statements, importPosition = "before", blockHoist = 3) { | ||
const body = this._programPath.get("body"); | ||
const targetPath = this._programPath.get("body").find(p => { | ||
const val = p.node._blockHoist; | ||
return Number.isFinite(val) && val < 4; | ||
}); | ||
if (importPosition === "after") { | ||
for (let i = body.length - 1; i >= 0; i--) { | ||
if (body[i].isImportDeclaration()) { | ||
body[i].insertAfter(statements); | ||
return; | ||
} | ||
} | ||
} else { | ||
statements.forEach(node => { | ||
node._blockHoist = blockHoist; | ||
}); | ||
const targetPath = body.find(p => { | ||
const val = p.node._blockHoist; | ||
return Number.isFinite(val) && val < 4; | ||
}); | ||
if (targetPath) { | ||
targetPath.insertBefore(statements); | ||
} else { | ||
this._programPath.unshiftContainer("body", statements); | ||
if (targetPath) { | ||
targetPath.insertBefore(statements); | ||
return; | ||
} | ||
} | ||
this._programPath.unshiftContainer("body", statements); | ||
} | ||
@@ -273,0 +291,0 @@ |
{ | ||
"name": "@babel/helper-module-imports", | ||
"version": "7.12.5", | ||
"version": "7.12.13", | ||
"description": "Babel helper functions for inserting module loads", | ||
"author": "Logan Smyth <loganfsmyth@gmail.com>", | ||
"homepage": "https://babeljs.io/", | ||
"homepage": "https://babel.dev/docs/en/next/babel-helper-module-imports", | ||
"license": "MIT", | ||
@@ -18,7 +18,7 @@ "publishConfig": { | ||
"dependencies": { | ||
"@babel/types": "^7.12.5" | ||
"@babel/types": "^7.12.13" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.12.3" | ||
"@babel/core": "7.12.13" | ||
} | ||
} |
18412
402
Updated@babel/types@^7.12.13