1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.buildScopeIIFE = buildScopeIIFE;
|
---|
7 | exports.collectShadowedParamsNames = collectShadowedParamsNames;
|
---|
8 | exports.iifeVisitor = void 0;
|
---|
9 | var _core = require("@babel/core");
|
---|
10 | const iifeVisitor = exports.iifeVisitor = {
|
---|
11 | "ReferencedIdentifier|BindingIdentifier"(path, state) {
|
---|
12 | const {
|
---|
13 | scope,
|
---|
14 | node
|
---|
15 | } = path;
|
---|
16 | const {
|
---|
17 | name
|
---|
18 | } = node;
|
---|
19 | if (name === "eval" || scope.getBinding(name) === state.scope.parent.getBinding(name) && state.scope.hasOwnBinding(name)) {
|
---|
20 | state.needsOuterBinding = true;
|
---|
21 | path.stop();
|
---|
22 | }
|
---|
23 | },
|
---|
24 | "TypeAnnotation|TSTypeAnnotation|TypeParameterDeclaration|TSTypeParameterDeclaration": path => path.skip()
|
---|
25 | };
|
---|
26 | function collectShadowedParamsNames(param, functionScope, shadowedParams) {
|
---|
27 | for (const name of Object.keys(param.getBindingIdentifiers())) {
|
---|
28 | var _functionScope$bindin;
|
---|
29 | const constantViolations = (_functionScope$bindin = functionScope.bindings[name]) == null ? void 0 : _functionScope$bindin.constantViolations;
|
---|
30 | if (constantViolations) {
|
---|
31 | for (const redeclarator of constantViolations) {
|
---|
32 | const node = redeclarator.node;
|
---|
33 | switch (node.type) {
|
---|
34 | case "VariableDeclarator":
|
---|
35 | {
|
---|
36 | if (node.init === null) {
|
---|
37 | const declaration = redeclarator.parentPath;
|
---|
38 | if (!declaration.parentPath.isFor() || declaration.parentPath.get("body") === declaration) {
|
---|
39 | redeclarator.remove();
|
---|
40 | break;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | shadowedParams.add(name);
|
---|
44 | break;
|
---|
45 | }
|
---|
46 | case "FunctionDeclaration":
|
---|
47 | shadowedParams.add(name);
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | function buildScopeIIFE(shadowedParams, body) {
|
---|
55 | const args = [];
|
---|
56 | const params = [];
|
---|
57 | for (const name of shadowedParams) {
|
---|
58 | args.push(_core.types.identifier(name));
|
---|
59 | params.push(_core.types.identifier(name));
|
---|
60 | }
|
---|
61 | return _core.types.returnStatement(_core.types.callExpression(_core.types.arrowFunctionExpression(params, body), args));
|
---|
62 | }
|
---|
63 |
|
---|
64 | //# sourceMappingURL=shadow-utils.js.map
|
---|