mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
31 lines
698 B
JavaScript
31 lines
698 B
JavaScript
/**
|
|
* local-exports-inject-var-declarations plugin
|
|
* @param {import("@babel/core").PluginAPI} api
|
|
* @returns
|
|
*/
|
|
module.exports = function(api) {
|
|
const { types: t } = api;
|
|
/**
|
|
* @type {import("@babel/core").PluginObject}
|
|
*/
|
|
const plugin = {
|
|
name: "local-exports-inject-var-declarations",
|
|
visitor: {
|
|
Program(path) {
|
|
path.node.body.push(
|
|
t.exportNamedDeclaration(
|
|
null,
|
|
[t.exportSpecifier(t.identifier("injected"), t.identifier("injected"))]
|
|
),
|
|
t.variableDeclaration(
|
|
"var",
|
|
[t.variableDeclarator(t.identifier("injected"))]
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return plugin;
|
|
}
|