Remove the unused '.addImports' API from 'babel-core'.

This commit is contained in:
Logan Smyth
2017-09-20 00:36:19 -07:00
parent ed3603ef44
commit 5eda451fb8
2 changed files with 7 additions and 73 deletions

View File

@@ -178,49 +178,13 @@ export default class File extends Store {
return source;
}
addImport(
source: string,
imported?: string = "",
name?: string = imported,
): Object | null {
const prependDeclaration = (
specifiers: Array<BabelNodeImportSpecifier>,
): void => {
const declar = t.importDeclaration(specifiers, t.stringLiteral(source));
declar._blockHoist = 3;
this.path.unshiftContainer("body", declar);
};
// import "module-name";
if (!imported) {
prependDeclaration([]);
return null;
}
const alias = `${source}:${imported}`;
let id = this.dynamicImportIds[alias];
if (!id) {
source = this.resolveModuleSource(source);
id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(
name,
);
const specifiers = [];
if (imported === "*") {
specifiers.push(t.importNamespaceSpecifier(id));
} else if (imported === "default") {
specifiers.push(t.importDefaultSpecifier(id));
} else {
specifiers.push(t.importSpecifier(id, t.identifier(imported)));
}
prependDeclaration(specifiers);
}
return t.identifier(id.name);
addImport() {
throw new Error(
"This API has been removed. If you looking for this " +
"functionality in Babel 7, you should import the " +
"'babel-helper-module-imports' module and use the functions exposed " +
" from that module, such as 'addNamed' or 'addDefault'.",
);
}
addHelper(name: string): Object {

View File

@@ -1,30 +0,0 @@
var res = transform("", {
plugins: [
function (b) {
return {
visitor: {
Program: function(path, state) {
var file = state.file;
file.addImport("import-star", "*", "lib");
file.addImport("import-default", "default", "foo");
file.addImport("import-alias", "bar", "baz");
file.addImport("import-default-alias", "quux");
file.addImport("import-empty", "");
file.addImport("import-none");
}
}
};
}
]
});
var expected = multiline([
'import "import-none";',
'import "import-empty";',
'import { quux as _quux } from "import-default-alias";',
'import { bar as _baz } from "import-alias";',
'import _foo from "import-default";',
'import * as _lib from "import-star";',
]);
assert.equal(res.code, expected);