1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/helper-hoist-variables/lib/index.js

51 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
2024-01-16 21:26:16 +08:00
exports.default = hoistVariables;
var _t = require("@babel/types");
const {
assignmentExpression,
expressionStatement,
identifier
} = _t;
2023-12-18 13:12:25 +08:00
const visitor = {
Scope(path, state) {
if (state.kind === "let") path.skip();
},
2024-01-16 21:26:16 +08:00
FunctionParent(path) {
2023-12-18 13:12:25 +08:00
path.skip();
},
VariableDeclaration(path, state) {
if (state.kind && path.node.kind !== state.kind) return;
const nodes = [];
const declarations = path.get("declarations");
let firstId;
for (const declar of declarations) {
firstId = declar.node.id;
if (declar.node.init) {
2024-01-16 21:26:16 +08:00
nodes.push(expressionStatement(assignmentExpression("=", declar.node.id, declar.node.init)));
2023-12-18 13:12:25 +08:00
}
for (const name of Object.keys(declar.getBindingIdentifiers())) {
2024-01-16 21:26:16 +08:00
state.emit(identifier(name), name, declar.node.init !== null);
2023-12-18 13:12:25 +08:00
}
}
if (path.parentPath.isFor({
left: path.node
})) {
path.replaceWith(firstId);
} else {
path.replaceWithMultiple(nodes);
}
}
};
2024-01-16 21:26:16 +08:00
function hoistVariables(path, emit, kind = "var") {
2023-12-18 13:12:25 +08:00
path.traverse(visitor, {
kind,
emit
});
2024-01-16 21:26:16 +08:00
}
//# sourceMappingURL=index.js.map