-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
Bug Report
Input Code
Repro available: https://github.com/jeysal/babel-scope-filename-typescript-repro
const { transform } = require("@babel/core");
const plugin = ({ types: t }) => ({
visitor: {
CallExpression(path) {
if (path.node.callee.name === "a") {
path.scope
.getProgramParent()
.path.unshiftContainer(
"body",
t.importDeclaration(
[t.importDefaultSpecifier(t.identifier("local"))],
t.stringLiteral("source")
)
);
path.scope.crawl();
path.node.callee = t.identifier("local");
}
}
}
});
console.log(
transform(`a();`, {
presets: ["@babel/preset-typescript"],
plugins: [plugin]
}).code
);Babel/Babylon Configuration (.babelrc, package.json, cli command)
{
"devDependencies": {
"@babel/core": "^7.0.0-beta.46",
"@babel/preset-typescript": "^7.0.0-beta.46"
}
}Expected Behavior
Generated code has import local from "source";
Current Behavior
local();Context
Generated code misses the import.
Ways to fix this (ONE of the following is sufficient):
- disable
@babel/preset-typescript crawlone line later (after adding a reference to the import)
Your Environment
| software | version(s) |
|---|---|
| Babel | 7.0.0-beta.46 |
| Babylon | |
| node | 8.11.1 |
| yarn | 1.6.0 |
| Operating System | Linux version 4.16.4-1-ARCH |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue