@babel/traverse 8.0.0-alpha.2 → 8.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/lib/index.js +136 -131
  2. package/lib/index.js.map +1 -1
  3. package/package.json +11 -11
  4. package/lib/cache.js +0 -28
  5. package/lib/cache.js.map +0 -1
  6. package/lib/context.js +0 -108
  7. package/lib/context.js.map +0 -1
  8. package/lib/hub.js +0 -12
  9. package/lib/hub.js.map +0 -1
  10. package/lib/path/ancestry.js +0 -126
  11. package/lib/path/ancestry.js.map +0 -1
  12. package/lib/path/comments.js +0 -46
  13. package/lib/path/comments.js.map +0 -1
  14. package/lib/path/context.js +0 -194
  15. package/lib/path/context.js.map +0 -1
  16. package/lib/path/conversion.js +0 -453
  17. package/lib/path/conversion.js.map +0 -1
  18. package/lib/path/evaluation.js +0 -333
  19. package/lib/path/evaluation.js.map +0 -1
  20. package/lib/path/family.js +0 -322
  21. package/lib/path/family.js.map +0 -1
  22. package/lib/path/index.js +0 -181
  23. package/lib/path/index.js.map +0 -1
  24. package/lib/path/inference/index.js +0 -137
  25. package/lib/path/inference/index.js.map +0 -1
  26. package/lib/path/inference/inferer-reference.js +0 -145
  27. package/lib/path/inference/inferer-reference.js.map +0 -1
  28. package/lib/path/inference/inferers.js +0 -172
  29. package/lib/path/inference/inferers.js.map +0 -1
  30. package/lib/path/inference/util.js +0 -20
  31. package/lib/path/inference/util.js.map +0 -1
  32. package/lib/path/introspection.js +0 -360
  33. package/lib/path/introspection.js.map +0 -1
  34. package/lib/path/lib/hoister.js +0 -164
  35. package/lib/path/lib/hoister.js.map +0 -1
  36. package/lib/path/lib/removal-hooks.js +0 -31
  37. package/lib/path/lib/removal-hooks.js.map +0 -1
  38. package/lib/path/lib/virtual-types-validator.js +0 -133
  39. package/lib/path/lib/virtual-types-validator.js.map +0 -1
  40. package/lib/path/lib/virtual-types.js +0 -20
  41. package/lib/path/lib/virtual-types.js.map +0 -1
  42. package/lib/path/modification.js +0 -209
  43. package/lib/path/modification.js.map +0 -1
  44. package/lib/path/removal.js +0 -48
  45. package/lib/path/removal.js.map +0 -1
  46. package/lib/path/replacement.js +0 -192
  47. package/lib/path/replacement.js.map +0 -1
  48. package/lib/scope/binding.js +0 -78
  49. package/lib/scope/binding.js.map +0 -1
  50. package/lib/scope/index.js +0 -870
  51. package/lib/scope/index.js.map +0 -1
  52. package/lib/scope/lib/renamer.js +0 -105
  53. package/lib/scope/lib/renamer.js.map +0 -1
  54. package/lib/traverse-node.js +0 -23
  55. package/lib/traverse-node.js.map +0 -1
  56. package/lib/types.js +0 -3
  57. package/lib/types.js.map +0 -1
  58. package/lib/visitors.js +0 -210
  59. package/lib/visitors.js.map +0 -1
@@ -1,31 +0,0 @@
1
- export const hooks = [function (self, parent) {
2
- const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
3
- if (removeParent) {
4
- parent.remove();
5
- return true;
6
- }
7
- }, function (self, parent) {
8
- if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
9
- parent.replaceWith(parent.node.expressions[0]);
10
- return true;
11
- }
12
- }, function (self, parent) {
13
- if (parent.isBinary()) {
14
- if (self.key === "left") {
15
- parent.replaceWith(parent.node.right);
16
- } else {
17
- parent.replaceWith(parent.node.left);
18
- }
19
- return true;
20
- }
21
- }, function (self, parent) {
22
- if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
23
- self.replaceWith({
24
- type: "BlockStatement",
25
- body: []
26
- });
27
- return true;
28
- }
29
- }];
30
-
31
- //# sourceMappingURL=removal-hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["hooks","self","parent","removeParent","key","isWhile","isSwitchCase","isExportDeclaration","isLabeledStatement","listKey","isVariableDeclaration","node","declarations","length","isExpressionStatement","remove","isSequenceExpression","expressions","replaceWith","isBinary","right","left","isIfStatement","isLoop","isArrowFunctionExpression","type","body"],"sources":["../../../src/path/lib/removal-hooks.ts"],"sourcesContent":["// this file contains hooks that handle ancestry cleanup of parent nodes when removing children\n\nimport type NodePath from \"..\";\nimport type * as t from \"@babel/types\";\n/**\n * Pre hooks should be used for either rejecting removal or delegating removal\n */\n\nexport const hooks = [\n function (self: NodePath, parent: NodePath) {\n const removeParent =\n // while (NODE);\n // removing the test of a while/switch, we can either just remove it entirely *or* turn the\n // `test` into `true` unlikely that the latter will ever be what's wanted so we just remove\n // the loop to avoid infinite recursion\n (self.key === \"test\" && (parent.isWhile() || parent.isSwitchCase())) ||\n // export NODE;\n // just remove a declaration for an export as this is no longer valid\n (self.key === \"declaration\" && parent.isExportDeclaration()) ||\n // label: NODE\n // stray labeled statement with no body\n (self.key === \"body\" && parent.isLabeledStatement()) ||\n // let NODE;\n // remove an entire declaration if there are no declarators left\n (self.listKey === \"declarations\" &&\n parent.isVariableDeclaration() &&\n parent.node.declarations.length === 1) ||\n // NODE;\n // remove the entire expression statement if there's no expression\n (self.key === \"expression\" && parent.isExpressionStatement());\n\n if (removeParent) {\n parent.remove();\n return true;\n }\n },\n\n function (self: NodePath, parent: NodePath) {\n if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {\n // (node, NODE);\n // we've just removed the second element of a sequence expression so let's turn that sequence\n // expression into a regular expression\n parent.replaceWith(parent.node.expressions[0]);\n return true;\n }\n },\n\n function (self: NodePath, parent: NodePath) {\n if (parent.isBinary()) {\n // left + NODE;\n // NODE + right;\n // we're in a binary expression, better remove it and replace it with the last expression\n if (self.key === \"left\") {\n parent.replaceWith(parent.node.right);\n } else {\n // key === \"right\"\n parent.replaceWith(parent.node.left);\n }\n return true;\n }\n },\n\n function (self: NodePath, parent: NodePath) {\n if (\n (parent.isIfStatement() && self.key === \"consequent\") ||\n (self.key === \"body\" &&\n (parent.isLoop() || parent.isArrowFunctionExpression()))\n ) {\n self.replaceWith({\n type: \"BlockStatement\",\n body: [],\n } as t.BlockStatement);\n return true;\n }\n },\n];\n"],"mappings":"AAQA,OAAO,MAAMA,KAAK,GAAG,CACnB,UAAUC,IAAc,EAAEC,MAAgB,EAAE;EAC1C,MAAMC,YAAY,GAKfF,IAAI,CAACG,GAAG,KAAK,MAAM,KAAKF,MAAM,CAACG,OAAO,CAAC,CAAC,IAAIH,MAAM,CAACI,YAAY,CAAC,CAAC,CAAC,IAGlEL,IAAI,CAACG,GAAG,KAAK,aAAa,IAAIF,MAAM,CAACK,mBAAmB,CAAC,CAAE,IAG3DN,IAAI,CAACG,GAAG,KAAK,MAAM,IAAIF,MAAM,CAACM,kBAAkB,CAAC,CAAE,IAGnDP,IAAI,CAACQ,OAAO,KAAK,cAAc,IAC9BP,MAAM,CAACQ,qBAAqB,CAAC,CAAC,IAC9BR,MAAM,CAACS,IAAI,CAACC,YAAY,CAACC,MAAM,KAAK,CAAE,IAGvCZ,IAAI,CAACG,GAAG,KAAK,YAAY,IAAIF,MAAM,CAACY,qBAAqB,CAAC,CAAE;EAE/D,IAAIX,YAAY,EAAE;IAChBD,MAAM,CAACa,MAAM,CAAC,CAAC;IACf,OAAO,IAAI;EACb;AACF,CAAC,EAED,UAAUd,IAAc,EAAEC,MAAgB,EAAE;EAC1C,IAAIA,MAAM,CAACc,oBAAoB,CAAC,CAAC,IAAId,MAAM,CAACS,IAAI,CAACM,WAAW,CAACJ,MAAM,KAAK,CAAC,EAAE;IAIzEX,MAAM,CAACgB,WAAW,CAAChB,MAAM,CAACS,IAAI,CAACM,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,IAAI;EACb;AACF,CAAC,EAED,UAAUhB,IAAc,EAAEC,MAAgB,EAAE;EAC1C,IAAIA,MAAM,CAACiB,QAAQ,CAAC,CAAC,EAAE;IAIrB,IAAIlB,IAAI,CAACG,GAAG,KAAK,MAAM,EAAE;MACvBF,MAAM,CAACgB,WAAW,CAAChB,MAAM,CAACS,IAAI,CAACS,KAAK,CAAC;IACvC,CAAC,MAAM;MAELlB,MAAM,CAACgB,WAAW,CAAChB,MAAM,CAACS,IAAI,CAACU,IAAI,CAAC;IACtC;IACA,OAAO,IAAI;EACb;AACF,CAAC,EAED,UAAUpB,IAAc,EAAEC,MAAgB,EAAE;EAC1C,IACGA,MAAM,CAACoB,aAAa,CAAC,CAAC,IAAIrB,IAAI,CAACG,GAAG,KAAK,YAAY,IACnDH,IAAI,CAACG,GAAG,KAAK,MAAM,KACjBF,MAAM,CAACqB,MAAM,CAAC,CAAC,IAAIrB,MAAM,CAACsB,yBAAyB,CAAC,CAAC,CAAE,EAC1D;IACAvB,IAAI,CAACiB,WAAW,CAAC;MACfO,IAAI,EAAE,gBAAgB;MACtBC,IAAI,EAAE;IACR,CAAqB,CAAC;IACtB,OAAO,IAAI;EACb;AACF,CAAC,CACF"}
@@ -1,133 +0,0 @@
1
- import * as _t from "@babel/types";
2
- const {
3
- isBinding,
4
- isBlockScoped: nodeIsBlockScoped,
5
- isExportDeclaration,
6
- isExpression: nodeIsExpression,
7
- isFlow: nodeIsFlow,
8
- isForStatement,
9
- isForXStatement,
10
- isIdentifier,
11
- isImportDeclaration,
12
- isImportSpecifier,
13
- isJSXIdentifier,
14
- isJSXMemberExpression,
15
- isMemberExpression,
16
- isRestElement: nodeIsRestElement,
17
- isReferenced: nodeIsReferenced,
18
- isScope: nodeIsScope,
19
- isStatement: nodeIsStatement,
20
- isVar: nodeIsVar,
21
- isVariableDeclaration,
22
- react,
23
- isForOfStatement
24
- } = _t;
25
- const {
26
- isCompatTag
27
- } = react;
28
- export function isReferencedIdentifier(opts) {
29
- const {
30
- node,
31
- parent
32
- } = this;
33
- if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
34
- if (isJSXIdentifier(node, opts)) {
35
- if (isCompatTag(node.name)) return false;
36
- } else {
37
- return false;
38
- }
39
- }
40
- return nodeIsReferenced(node, parent, this.parentPath.parent);
41
- }
42
- export function isReferencedMemberExpression() {
43
- const {
44
- node,
45
- parent
46
- } = this;
47
- return isMemberExpression(node) && nodeIsReferenced(node, parent);
48
- }
49
- export function isBindingIdentifier() {
50
- const {
51
- node,
52
- parent
53
- } = this;
54
- const grandparent = this.parentPath.parent;
55
- return isIdentifier(node) && isBinding(node, parent, grandparent);
56
- }
57
- export function isStatement() {
58
- const {
59
- node,
60
- parent
61
- } = this;
62
- if (nodeIsStatement(node)) {
63
- if (isVariableDeclaration(node)) {
64
- if (isForXStatement(parent, {
65
- left: node
66
- })) return false;
67
- if (isForStatement(parent, {
68
- init: node
69
- })) return false;
70
- }
71
- return true;
72
- } else {
73
- return false;
74
- }
75
- }
76
- export function isExpression() {
77
- if (this.isIdentifier()) {
78
- return this.isReferencedIdentifier();
79
- } else {
80
- return nodeIsExpression(this.node);
81
- }
82
- }
83
- export function isScope() {
84
- return nodeIsScope(this.node, this.parent);
85
- }
86
- export function isReferenced() {
87
- return nodeIsReferenced(this.node, this.parent);
88
- }
89
- export function isBlockScoped() {
90
- return nodeIsBlockScoped(this.node);
91
- }
92
- export function isVar() {
93
- return nodeIsVar(this.node);
94
- }
95
- export function isUser() {
96
- return this.node && !!this.node.loc;
97
- }
98
- export function isGenerated() {
99
- return !this.isUser();
100
- }
101
- export function isPure(constantsOnly) {
102
- return this.scope.isPure(this.node, constantsOnly);
103
- }
104
- export function isFlow() {
105
- const {
106
- node
107
- } = this;
108
- if (nodeIsFlow(node)) {
109
- return true;
110
- } else if (isImportDeclaration(node)) {
111
- return node.importKind === "type" || node.importKind === "typeof";
112
- } else if (isExportDeclaration(node)) {
113
- return node.exportKind === "type";
114
- } else if (isImportSpecifier(node)) {
115
- return node.importKind === "type" || node.importKind === "typeof";
116
- } else {
117
- return false;
118
- }
119
- }
120
- export function isRestProperty() {
121
- return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
122
- }
123
- export function isSpreadProperty() {
124
- return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
125
- }
126
- export function isForAwaitStatement() {
127
- return isForOfStatement(this.node, {
128
- await: true
129
- });
130
- }
131
- ;
132
-
133
- //# sourceMappingURL=virtual-types-validator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_t","isBinding","isBlockScoped","nodeIsBlockScoped","isExportDeclaration","isExpression","nodeIsExpression","isFlow","nodeIsFlow","isForStatement","isForXStatement","isIdentifier","isImportDeclaration","isImportSpecifier","isJSXIdentifier","isJSXMemberExpression","isMemberExpression","isRestElement","nodeIsRestElement","isReferenced","nodeIsReferenced","isScope","nodeIsScope","isStatement","nodeIsStatement","isVar","nodeIsVar","isVariableDeclaration","react","isForOfStatement","isCompatTag","isReferencedIdentifier","opts","node","parent","name","parentPath","isReferencedMemberExpression","isBindingIdentifier","grandparent","left","init","isUser","loc","isGenerated","isPure","constantsOnly","scope","importKind","exportKind","isRestProperty","isObjectPattern","isSpreadProperty","isObjectExpression","isForAwaitStatement","await"],"sources":["../../../src/path/lib/virtual-types-validator.ts"],"sourcesContent":["import type NodePath from \"../index\";\nimport {\n isBinding,\n isBlockScoped as nodeIsBlockScoped,\n isExportDeclaration,\n isExpression as nodeIsExpression,\n isFlow as nodeIsFlow,\n isForStatement,\n isForXStatement,\n isIdentifier,\n isImportDeclaration,\n isImportSpecifier,\n isJSXIdentifier,\n isJSXMemberExpression,\n isMemberExpression,\n isRestElement as nodeIsRestElement,\n isReferenced as nodeIsReferenced,\n isScope as nodeIsScope,\n isStatement as nodeIsStatement,\n isVar as nodeIsVar,\n isVariableDeclaration,\n react,\n isForOfStatement,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nconst { isCompatTag } = react;\nimport type { VirtualTypeAliases } from \"./virtual-types\";\n\ntype Opts<Obj> = Partial<{\n [Prop in keyof Obj]: Obj[Prop] extends t.Node\n ? t.Node\n : Obj[Prop] extends t.Node[]\n ? t.Node[]\n : Obj[Prop];\n}>;\n\nexport interface VirtualTypeNodePathValidators {\n isBindingIdentifier<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"BindingIdentifier\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"BindingIdentifier\"]>;\n isBlockScoped(opts?: Opts<VirtualTypeAliases[\"BlockScoped\"]>): boolean;\n /**\n * @deprecated\n */\n isExistentialTypeParam<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"ExistentialTypeParam\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"ExistentialTypeParam\"]>;\n isExpression<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"Expression\"]>,\n ): this is NodePath<T & t.Expression>;\n isFlow<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"Flow\"]>,\n ): this is NodePath<T & t.Flow>;\n isForAwaitStatement<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"ForAwaitStatement\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"ForAwaitStatement\"]>;\n isGenerated(opts?: VirtualTypeAliases[\"Generated\"]): boolean;\n /**\n * @deprecated\n */\n isNumericLiteralTypeAnnotation(\n opts?: VirtualTypeAliases[\"NumericLiteralTypeAnnotation\"],\n ): void;\n isPure(opts?: VirtualTypeAliases[\"Pure\"]): boolean;\n isReferenced(opts?: VirtualTypeAliases[\"Referenced\"]): boolean;\n isReferencedIdentifier<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"ReferencedIdentifier\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"ReferencedIdentifier\"]>;\n isReferencedMemberExpression<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"ReferencedMemberExpression\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"ReferencedMemberExpression\"]>;\n isRestProperty<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"RestProperty\"]>,\n ): this is NodePath<T & t.RestProperty>;\n isScope<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"Scope\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"Scope\"]>;\n isSpreadProperty<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"SpreadProperty\"]>,\n ): this is NodePath<T & t.SpreadProperty>;\n isStatement<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"Statement\"]>,\n ): this is NodePath<T & t.Statement>;\n isUser(opts?: VirtualTypeAliases[\"User\"]): boolean;\n isVar<T extends t.Node>(\n this: NodePath<T>,\n opts?: Opts<VirtualTypeAliases[\"Var\"]>,\n ): this is NodePath<T & VirtualTypeAliases[\"Var\"]>;\n}\n\nexport function isReferencedIdentifier(this: NodePath, opts?: any): boolean {\n const { node, parent } = this;\n if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {\n if (isJSXIdentifier(node, opts)) {\n if (isCompatTag(node.name)) return false;\n } else {\n // not a JSXIdentifier or an Identifier\n return false;\n }\n }\n\n // check if node is referenced\n return nodeIsReferenced(node, parent, this.parentPath.parent);\n}\n\nexport function isReferencedMemberExpression(this: NodePath): boolean {\n const { node, parent } = this;\n return isMemberExpression(node) && nodeIsReferenced(node, parent);\n}\n\nexport function isBindingIdentifier(this: NodePath): boolean {\n const { node, parent } = this;\n const grandparent = this.parentPath.parent;\n return isIdentifier(node) && isBinding(node, parent, grandparent);\n}\n\nexport function isStatement(this: NodePath): boolean {\n const { node, parent } = this;\n if (nodeIsStatement(node)) {\n if (isVariableDeclaration(node)) {\n if (isForXStatement(parent, { left: node })) return false;\n if (isForStatement(parent, { init: node })) return false;\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nexport function isExpression(this: NodePath): boolean {\n if (this.isIdentifier()) {\n return this.isReferencedIdentifier();\n } else {\n return nodeIsExpression(this.node);\n }\n}\n\nexport function isScope(this: NodePath): boolean {\n return nodeIsScope(this.node, this.parent);\n}\n\nexport function isReferenced(this: NodePath): boolean {\n return nodeIsReferenced(this.node, this.parent);\n}\n\nexport function isBlockScoped(this: NodePath): boolean {\n return nodeIsBlockScoped(this.node);\n}\n\nexport function isVar(this: NodePath): boolean {\n return nodeIsVar(this.node);\n}\n\nexport function isUser(this: NodePath): boolean {\n return this.node && !!this.node.loc;\n}\n\nexport function isGenerated(this: NodePath): boolean {\n return !this.isUser();\n}\n\nexport function isPure(this: NodePath, constantsOnly?: boolean): boolean {\n return this.scope.isPure(this.node, constantsOnly);\n}\n\nexport function isFlow(this: NodePath): boolean {\n const { node } = this;\n if (nodeIsFlow(node)) {\n return true;\n } else if (isImportDeclaration(node)) {\n return node.importKind === \"type\" || node.importKind === \"typeof\";\n } else if (isExportDeclaration(node)) {\n return node.exportKind === \"type\";\n } else if (isImportSpecifier(node)) {\n return node.importKind === \"type\" || node.importKind === \"typeof\";\n } else {\n return false;\n }\n}\n\n// TODO: 7.0 Backwards Compat\nexport function isRestProperty(this: NodePath): boolean {\n return (\n nodeIsRestElement(this.node) &&\n this.parentPath &&\n this.parentPath.isObjectPattern()\n );\n}\n\nexport function isSpreadProperty(this: NodePath): boolean {\n return (\n nodeIsRestElement(this.node) &&\n this.parentPath &&\n this.parentPath.isObjectExpression()\n );\n}\n\nexport function isForAwaitStatement(this: NodePath): boolean {\n return isForOfStatement(this.node, { await: true });\n}\n\nif (!process.env.BABEL_8_BREAKING) {\n if (!USE_ESM) {\n // eslint-disable-next-line no-restricted-globals\n exports.isExistentialTypeParam = function isExistentialTypeParam(\n this: NodePath,\n ): void {\n throw new Error(\n \"`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.\",\n );\n };\n\n // eslint-disable-next-line no-restricted-globals\n exports.isNumericLiteralTypeAnnotation =\n function isNumericLiteralTypeAnnotation(this: NodePath): void {\n throw new Error(\n \"`path.isNumericLiteralTypeAnnotation()`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ACA,UAAU,CAACe,eAAe,CAAC,CAAC;AAErC;AAEA,OAAO,SAASC,gBAAgBA,CAAA,EAA0B;EACxD,OACElC,iBAAiB,CAAC,IAAI,CAACe,IAAI,CAAC,IAC5B,IAAI,CAACG,UAAU,IACf,IAAI,CAACA,UAAU,CAACiB,kBAAkB,CAAC,CAAC;AAExC;AAEA,OAAO,SAASC,mBAAmBA,CAAA,EAA0B;EAC3D,OAAOzB,gBAAgB,CAAC,IAAI,CAACI,IAAI,EAAE;IAAEsB,KAAK,EAAE;EAAK,CAAC,CAAC;AACrD;AAAC"}
@@ -1,20 +0,0 @@
1
- export const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
2
- export const ReferencedMemberExpression = ["MemberExpression"];
3
- export const BindingIdentifier = ["Identifier"];
4
- export const Statement = ["Statement"];
5
- export const Expression = ["Expression"];
6
- export const Scope = ["Scopable", "Pattern"];
7
- export const Referenced = null;
8
- export const BlockScoped = null;
9
- export const Var = ["VariableDeclaration"];
10
- export const User = null;
11
- export const Generated = null;
12
- export const Pure = null;
13
- export const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
14
- export const RestProperty = ["RestElement"];
15
- export const SpreadProperty = ["RestElement"];
16
- export const ExistentialTypeParam = ["ExistsTypeAnnotation"];
17
- export const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
18
- export const ForAwaitStatement = ["ForOfStatement"];
19
-
20
- //# sourceMappingURL=virtual-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ReferencedIdentifier","ReferencedMemberExpression","BindingIdentifier","Statement","Expression","Scope","Referenced","BlockScoped","Var","User","Generated","Pure","Flow","RestProperty","SpreadProperty","ExistentialTypeParam","NumericLiteralTypeAnnotation","ForAwaitStatement"],"sources":["../../../src/path/lib/virtual-types.ts"],"sourcesContent":["import type * as t from \"@babel/types\";\n\nexport interface VirtualTypeAliases {\n BindingIdentifier: t.Identifier;\n BlockScoped: t.Node;\n ExistentialTypeParam: t.ExistsTypeAnnotation;\n Expression: t.Expression;\n Flow: t.Flow | t.ImportDeclaration | t.ExportDeclaration | t.ImportSpecifier;\n ForAwaitStatement: t.ForOfStatement;\n Generated: t.Node;\n NumericLiteralTypeAnnotation: t.NumberLiteralTypeAnnotation;\n Pure: t.Node;\n Referenced: t.Node;\n ReferencedIdentifier: t.Identifier | t.JSXIdentifier;\n ReferencedMemberExpression: t.MemberExpression;\n RestProperty: t.RestElement;\n Scope: t.Scopable | t.Pattern;\n SpreadProperty: t.RestElement;\n Statement: t.Statement;\n User: t.Node;\n Var: t.VariableDeclaration;\n}\n\ntype VirtualTypeMapping = readonly (t.Node[\"type\"] | keyof t.Aliases)[] | null;\n\nexport const ReferencedIdentifier: VirtualTypeMapping = [\n \"Identifier\",\n \"JSXIdentifier\",\n] as const;\n\nexport const ReferencedMemberExpression: VirtualTypeMapping = [\n \"MemberExpression\",\n] as const;\n\nexport const BindingIdentifier: VirtualTypeMapping = [\"Identifier\"] as const;\n\nexport const Statement: VirtualTypeMapping = [\"Statement\"] as const;\n\nexport const Expression: VirtualTypeMapping = [\"Expression\"] as const;\n\nexport const Scope: VirtualTypeMapping = [\"Scopable\", \"Pattern\"] as const;\n\nexport const Referenced: VirtualTypeMapping = null;\n\nexport const BlockScoped: VirtualTypeMapping = null;\n\nexport const Var: VirtualTypeMapping = [\"VariableDeclaration\"];\n\nexport const User: VirtualTypeMapping = null;\n\nexport const Generated: VirtualTypeMapping = null;\n\nexport const Pure: VirtualTypeMapping = null;\n\nexport const Flow: VirtualTypeMapping = [\n \"Flow\",\n \"ImportDeclaration\",\n \"ExportDeclaration\",\n \"ImportSpecifier\",\n] as const;\n\n// TODO: 7.0 Backwards Compat\nexport const RestProperty: VirtualTypeMapping = [\"RestElement\"] as const;\n\nexport const SpreadProperty: VirtualTypeMapping = [\"RestElement\"] as const;\n\nexport const ExistentialTypeParam: VirtualTypeMapping = [\n \"ExistsTypeAnnotation\",\n] as const;\n\nexport const NumericLiteralTypeAnnotation: VirtualTypeMapping = [\n \"NumberLiteralTypeAnnotation\",\n] as const;\n\nexport const ForAwaitStatement: VirtualTypeMapping = [\n \"ForOfStatement\",\n] as const;\n"],"mappings":"AAyBA,OAAO,MAAMA,oBAAwC,GAAG,CACtD,YAAY,EACZ,eAAe,CACP;AAEV,OAAO,MAAMC,0BAA8C,GAAG,CAC5D,kBAAkB,CACV;AAEV,OAAO,MAAMC,iBAAqC,GAAG,CAAC,YAAY,CAAU;AAE5E,OAAO,MAAMC,SAA6B,GAAG,CAAC,WAAW,CAAU;AAEnE,OAAO,MAAMC,UAA8B,GAAG,CAAC,YAAY,CAAU;AAErE,OAAO,MAAMC,KAAyB,GAAG,CAAC,UAAU,EAAE,SAAS,CAAU;AAEzE,OAAO,MAAMC,UAA8B,GAAG,IAAI;AAElD,OAAO,MAAMC,WAA+B,GAAG,IAAI;AAEnD,OAAO,MAAMC,GAAuB,GAAG,CAAC,qBAAqB,CAAC;AAE9D,OAAO,MAAMC,IAAwB,GAAG,IAAI;AAE5C,OAAO,MAAMC,SAA6B,GAAG,IAAI;AAEjD,OAAO,MAAMC,IAAwB,GAAG,IAAI;AAE5C,OAAO,MAAMC,IAAwB,GAAG,CACtC,MAAM,EACN,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,CACT;AAGV,OAAO,MAAMC,YAAgC,GAAG,CAAC,aAAa,CAAU;AAExE,OAAO,MAAMC,cAAkC,GAAG,CAAC,aAAa,CAAU;AAE1E,OAAO,MAAMC,oBAAwC,GAAG,CACtD,sBAAsB,CACd;AAEV,OAAO,MAAMC,4BAAgD,GAAG,CAC9D,6BAA6B,CACrB;AAEV,OAAO,MAAMC,iBAAqC,GAAG,CACnD,gBAAgB,CACR"}
@@ -1,209 +0,0 @@
1
- import { getCachedPaths } from "../cache.js";
2
- import PathHoister from "./lib/hoister.js";
3
- import NodePath from "./index.js";
4
- import * as _t from "@babel/types";
5
- const {
6
- arrowFunctionExpression,
7
- assertExpression,
8
- assignmentExpression,
9
- blockStatement,
10
- callExpression,
11
- cloneNode,
12
- expressionStatement,
13
- isAssignmentExpression,
14
- isCallExpression,
15
- isExportNamedDeclaration,
16
- isExpression,
17
- isIdentifier,
18
- isSequenceExpression,
19
- isSuper,
20
- thisExpression
21
- } = _t;
22
- export function insertBefore(nodes_) {
23
- this._assertUnremoved();
24
- const nodes = this._verifyNodeList(nodes_);
25
- const {
26
- parentPath,
27
- parent
28
- } = this;
29
- if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
30
- return parentPath.insertBefore(nodes);
31
- } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
32
- if (this.node) nodes.push(this.node);
33
- return this.replaceExpressionWithStatements(nodes);
34
- } else if (Array.isArray(this.container)) {
35
- return this._containerInsertBefore(nodes);
36
- } else if (this.isStatementOrBlock()) {
37
- const node = this.node;
38
- const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
39
- this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
40
- return this.unshiftContainer("body", nodes);
41
- } else {
42
- throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
43
- }
44
- }
45
- export function _containerInsert(from, nodes) {
46
- this.updateSiblingKeys(from, nodes.length);
47
- const paths = [];
48
- this.container.splice(from, 0, ...nodes);
49
- for (let i = 0; i < nodes.length; i++) {
50
- const to = from + i;
51
- const path = this.getSibling(to);
52
- paths.push(path);
53
- if (this.context?.queue) {
54
- path.pushContext(this.context);
55
- }
56
- }
57
- const contexts = this._getQueueContexts();
58
- for (const path of paths) {
59
- path.setScope();
60
- path.debug("Inserted.");
61
- for (const context of contexts) {
62
- context.maybeQueue(path, true);
63
- }
64
- }
65
- return paths;
66
- }
67
- export function _containerInsertBefore(nodes) {
68
- return this._containerInsert(this.key, nodes);
69
- }
70
- export function _containerInsertAfter(nodes) {
71
- return this._containerInsert(this.key + 1, nodes);
72
- }
73
- const last = arr => arr[arr.length - 1];
74
- function isHiddenInSequenceExpression(path) {
75
- return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
76
- }
77
- function isAlmostConstantAssignment(node, scope) {
78
- if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
79
- return false;
80
- }
81
- const blockScope = scope.getBlockParent();
82
- return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
83
- }
84
- export function insertAfter(nodes_) {
85
- this._assertUnremoved();
86
- if (this.isSequenceExpression()) {
87
- return last(this.get("expressions")).insertAfter(nodes_);
88
- }
89
- const nodes = this._verifyNodeList(nodes_);
90
- const {
91
- parentPath,
92
- parent
93
- } = this;
94
- if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
95
- return parentPath.insertAfter(nodes.map(node => {
96
- return isExpression(node) ? expressionStatement(node) : node;
97
- }));
98
- } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
99
- if (this.node) {
100
- const node = this.node;
101
- let {
102
- scope
103
- } = this;
104
- if (scope.path.isPattern()) {
105
- assertExpression(node);
106
- this.replaceWith(callExpression(arrowFunctionExpression([], node), []));
107
- this.get("callee.body").insertAfter(nodes);
108
- return [this];
109
- }
110
- if (isHiddenInSequenceExpression(this)) {
111
- nodes.unshift(node);
112
- } else if (isCallExpression(node) && isSuper(node.callee)) {
113
- nodes.unshift(node);
114
- nodes.push(thisExpression());
115
- } else if (isAlmostConstantAssignment(node, scope)) {
116
- nodes.unshift(node);
117
- nodes.push(cloneNode(node.left));
118
- } else if (scope.isPure(node, true)) {
119
- nodes.push(node);
120
- } else {
121
- if (parentPath.isMethod({
122
- computed: true,
123
- key: node
124
- })) {
125
- scope = scope.parent;
126
- }
127
- const temp = scope.generateDeclaredUidIdentifier();
128
- nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
129
- nodes.push(expressionStatement(cloneNode(temp)));
130
- }
131
- }
132
- return this.replaceExpressionWithStatements(nodes);
133
- } else if (Array.isArray(this.container)) {
134
- return this._containerInsertAfter(nodes);
135
- } else if (this.isStatementOrBlock()) {
136
- const node = this.node;
137
- const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
138
- this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
139
- return this.pushContainer("body", nodes);
140
- } else {
141
- throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
142
- }
143
- }
144
- export function updateSiblingKeys(fromIndex, incrementBy) {
145
- if (!this.parent) return;
146
- const paths = getCachedPaths(this.hub, this.parent) || [];
147
- for (const [, path] of paths) {
148
- if (typeof path.key === "number" && path.key >= fromIndex) {
149
- path.key += incrementBy;
150
- }
151
- }
152
- }
153
- export function _verifyNodeList(nodes) {
154
- if (!nodes) {
155
- return [];
156
- }
157
- if (!Array.isArray(nodes)) {
158
- nodes = [nodes];
159
- }
160
- for (let i = 0; i < nodes.length; i++) {
161
- const node = nodes[i];
162
- let msg;
163
- if (!node) {
164
- msg = "has falsy node";
165
- } else if (typeof node !== "object") {
166
- msg = "contains a non-object node";
167
- } else if (!node.type) {
168
- msg = "without a type";
169
- } else if (node instanceof NodePath) {
170
- msg = "has a NodePath when it expected a raw object";
171
- }
172
- if (msg) {
173
- const type = Array.isArray(node) ? "array" : typeof node;
174
- throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
175
- }
176
- }
177
- return nodes;
178
- }
179
- export function unshiftContainer(listKey, nodes) {
180
- this._assertUnremoved();
181
- nodes = this._verifyNodeList(nodes);
182
- const path = NodePath.get({
183
- parentPath: this,
184
- parent: this.node,
185
- container: this.node[listKey],
186
- listKey,
187
- key: 0
188
- }).setContext(this.context);
189
- return path._containerInsertBefore(nodes);
190
- }
191
- export function pushContainer(listKey, nodes) {
192
- this._assertUnremoved();
193
- const verifiedNodes = this._verifyNodeList(nodes);
194
- const container = this.node[listKey];
195
- const path = NodePath.get({
196
- parentPath: this,
197
- parent: this.node,
198
- container: container,
199
- listKey,
200
- key: container.length
201
- }).setContext(this.context);
202
- return path.replaceWithMultiple(verifiedNodes);
203
- }
204
- export function hoist(scope = this.scope) {
205
- const hoister = new PathHoister(this, scope);
206
- return hoister.run();
207
- }
208
-
209
- //# sourceMappingURL=modification.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["getCachedPaths","PathHoister","NodePath","_t","arrowFunctionExpression","assertExpression","assignmentExpression","blockStatement","callExpression","cloneNode","expressionStatement","isAssignmentExpression","isCallExpression","isExportNamedDeclaration","isExpression","isIdentifier","isSequenceExpression","isSuper","thisExpression","insertBefore","nodes_","_assertUnremoved","nodes","_verifyNodeList","parentPath","parent","isExpressionStatement","isLabeledStatement","isExportDefaultDeclaration","isDeclaration","isNodeType","isJSXElement","isForStatement","key","node","push","replaceExpressionWithStatements","Array","isArray","container","_containerInsertBefore","isStatementOrBlock","shouldInsertCurrentNode","expression","replaceWith","unshiftContainer","Error","_containerInsert","from","updateSiblingKeys","length","paths","splice","i","to","path","getSibling","context","queue","pushContext","contexts","_getQueueContexts","setScope","debug","maybeQueue","_containerInsertAfter","last","arr","isHiddenInSequenceExpression","expressions","isAlmostConstantAssignment","scope","left","blockScope","getBlockParent","hasOwnBinding","name","getOwnBinding","constantViolations","insertAfter","get","map","isPattern","unshift","callee","isPure","isMethod","computed","temp","generateDeclaredUidIdentifier","pushContainer","fromIndex","incrementBy","hub","msg","type","listKey","setContext","verifiedNodes","replaceWithMultiple","hoist","hoister","run"],"sources":["../../src/path/modification.ts"],"sourcesContent":["// This file contains methods that modify the path/node in some ways.\n\nimport { getCachedPaths } from \"../cache\";\nimport PathHoister from \"./lib/hoister\";\nimport NodePath from \"./index\";\nimport {\n arrowFunctionExpression,\n assertExpression,\n assignmentExpression,\n blockStatement,\n callExpression,\n cloneNode,\n expressionStatement,\n isAssignmentExpression,\n isCallExpression,\n isExportNamedDeclaration,\n isExpression,\n isIdentifier,\n isSequenceExpression,\n isSuper,\n thisExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"../scope\";\n\n/**\n * Insert the provided nodes before the current one.\n */\n\nexport function insertBefore(\n this: NodePath,\n nodes_: t.Node | t.Node[],\n): NodePath[] {\n this._assertUnremoved();\n\n const nodes = this._verifyNodeList(nodes_);\n\n const { parentPath, parent } = this;\n\n if (\n parentPath.isExpressionStatement() ||\n parentPath.isLabeledStatement() ||\n // https://github.com/babel/babel/issues/15293\n // When Babel transforms `export class String { field }`, the class properties plugin will inject the defineProperty\n // helper, which depends on the builtins e.g. String, Number, Symbol, etc. To prevent them from being shadowed by local\n // exports, the helper injector replaces the named export into `class _String { field }; export { _String as String }`,\n // with `parentPath` here changed to the moved ClassDeclaration, causing rare inconsistency between `parent` and `parentPath`.\n // Here we retrieve the parent type from the `parent` property. This is a temporary fix and we should revisit when\n // helpers should get injected.\n isExportNamedDeclaration(parent) ||\n (parentPath.isExportDefaultDeclaration() && this.isDeclaration())\n ) {\n return parentPath.insertBefore(nodes);\n } else if (\n (this.isNodeType(\"Expression\") && !this.isJSXElement()) ||\n (parentPath.isForStatement() && this.key === \"init\")\n ) {\n if (this.node) nodes.push(this.node);\n // @ts-expect-error todo(flow->ts): check that nodes is an array of statements\n return this.replaceExpressionWithStatements(nodes);\n } else if (Array.isArray(this.container)) {\n return this._containerInsertBefore(nodes);\n } else if (this.isStatementOrBlock()) {\n const node = this.node as t.Statement;\n const shouldInsertCurrentNode =\n node &&\n (!this.isExpressionStatement() ||\n (node as t.ExpressionStatement).expression != null);\n\n this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));\n return (this as NodePath<t.BlockStatement>).unshiftContainer(\n \"body\",\n // @ts-expect-error Fixme: refine nodes to t.BlockStatement[\"body\"] when this is a BlockStatement path\n nodes,\n );\n } else {\n throw new Error(\n \"We don't know what to do with this node type. \" +\n \"We were previously a Statement but we can't fit in here?\",\n );\n }\n}\n\nexport function _containerInsert<N extends t.Node>(\n this: NodePath,\n from: number,\n nodes: N[],\n): NodePath<N>[] {\n this.updateSiblingKeys(from, nodes.length);\n\n const paths: NodePath<N>[] = [];\n\n // @ts-expect-error todo(flow->ts): this.container could be a NodePath\n this.container.splice(from, 0, ...nodes);\n for (let i = 0; i < nodes.length; i++) {\n const to = from + i;\n const path = this.getSibling(to) as NodePath<N>;\n paths.push(path);\n\n if (this.context?.queue) {\n path.pushContext(this.context);\n }\n }\n\n const contexts = this._getQueueContexts();\n\n for (const path of paths) {\n path.setScope();\n path.debug(\"Inserted.\");\n\n for (const context of contexts) {\n context.maybeQueue(path, true);\n }\n }\n\n return paths;\n}\n\nexport function _containerInsertBefore<N extends t.Node>(\n this: NodePath,\n nodes: N[],\n) {\n return this._containerInsert(this.key as number, nodes);\n}\n\nexport function _containerInsertAfter<N extends t.Node>(\n this: NodePath,\n nodes: N[],\n) {\n return this._containerInsert((this.key as number) + 1, nodes);\n}\n\nconst last = <T>(arr: T[]) => arr[arr.length - 1];\n\nfunction isHiddenInSequenceExpression(path: NodePath): boolean {\n return (\n isSequenceExpression(path.parent) &&\n (last(path.parent.expressions) !== path.node ||\n isHiddenInSequenceExpression(path.parentPath))\n );\n}\n\nfunction isAlmostConstantAssignment(\n node: t.Node,\n scope: Scope,\n): node is t.AssignmentExpression & { left: t.Identifier } {\n if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {\n return false;\n }\n\n // Not every scope can contain variables. For example, we might be in\n // a ClassScope either in the ClassHeritage or in a computed key.\n const blockScope = scope.getBlockParent();\n\n // If the variable is defined in the current scope and only assigned here,\n // we can be sure that its value won't change.\n return (\n blockScope.hasOwnBinding(node.left.name) &&\n blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1\n );\n}\n\n/**\n * Insert the provided nodes after the current one. When inserting nodes after an\n * expression, ensure that the completion record is correct by pushing the current node.\n */\n\nexport function insertAfter(\n this: NodePath,\n nodes_: t.Node | t.Node[],\n): NodePath[] {\n this._assertUnremoved();\n\n if (this.isSequenceExpression()) {\n return last(this.get(\"expressions\")).insertAfter(nodes_);\n }\n\n const nodes = this._verifyNodeList(nodes_);\n\n const { parentPath, parent } = this;\n if (\n parentPath.isExpressionStatement() ||\n parentPath.isLabeledStatement() ||\n // see insertBefore\n isExportNamedDeclaration(parent) ||\n (parentPath.isExportDefaultDeclaration() && this.isDeclaration())\n ) {\n return parentPath.insertAfter(\n nodes.map(node => {\n // Usually after an expression we can safely insert another expression:\n // A.insertAfter(B)\n // foo = A; -> foo = (A, B);\n // If A is an expression statement, it isn't safe anymore so we need to\n // convert B to an expression statement\n // A; -> A; B // No semicolon! It could break if followed by [!\n return isExpression(node) ? expressionStatement(node) : node;\n }),\n );\n } else if (\n (this.isNodeType(\"Expression\") &&\n !this.isJSXElement() &&\n !parentPath.isJSXElement()) ||\n (parentPath.isForStatement() && this.key === \"init\")\n ) {\n if (this.node) {\n const node = this.node as t.Expression | t.VariableDeclaration;\n let { scope } = this;\n\n if (scope.path.isPattern()) {\n assertExpression(node);\n\n this.replaceWith(callExpression(arrowFunctionExpression([], node), []));\n (this.get(\"callee.body\") as NodePath<t.Expression>).insertAfter(nodes);\n return [this];\n }\n\n if (isHiddenInSequenceExpression(this)) {\n nodes.unshift(node);\n }\n // We need to preserve the value of this expression.\n else if (isCallExpression(node) && isSuper(node.callee)) {\n nodes.unshift(node);\n // `super(...)` always evaluates to `this`.\n nodes.push(thisExpression());\n } else if (isAlmostConstantAssignment(node, scope)) {\n nodes.unshift(node);\n nodes.push(cloneNode(node.left));\n } else if (scope.isPure(node, true)) {\n // Insert the nodes before rather than after; it's not observable.\n nodes.push(node);\n } else {\n // Inserting after the computed key of a method should insert the\n // temporary binding in the method's parent's scope.\n if (parentPath.isMethod({ computed: true, key: node })) {\n scope = scope.parent;\n }\n const temp = scope.generateDeclaredUidIdentifier();\n nodes.unshift(\n expressionStatement(\n // @ts-expect-error todo(flow->ts): This can be a variable\n // declaration in the \"init\" of a for statement, but that's\n // invalid here.\n assignmentExpression(\"=\", cloneNode(temp), node),\n ),\n );\n nodes.push(expressionStatement(cloneNode(temp)));\n }\n }\n // @ts-expect-error todo(flow->ts): check that nodes is an array of statements\n return this.replaceExpressionWithStatements(nodes);\n } else if (Array.isArray(this.container)) {\n return this._containerInsertAfter(nodes);\n } else if (this.isStatementOrBlock()) {\n const node = this.node as t.Statement;\n const shouldInsertCurrentNode =\n node &&\n (!this.isExpressionStatement() ||\n (node as t.ExpressionStatement).expression != null);\n\n this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));\n // @ts-expect-error Fixme: refine nodes to t.BlockStatement[\"body\"] when this is a BlockStatement path\n return this.pushContainer(\"body\", nodes);\n } else {\n throw new Error(\n \"We don't know what to do with this node type. \" +\n \"We were previously a Statement but we can't fit in here?\",\n );\n }\n}\n\n/**\n * Update all sibling node paths after `fromIndex` by `incrementBy`.\n */\n\nexport function updateSiblingKeys(\n this: NodePath,\n fromIndex: number,\n incrementBy: number,\n) {\n if (!this.parent) return;\n\n const paths = getCachedPaths(this.hub, this.parent) || ([] as never[]);\n\n for (const [, path] of paths) {\n if (typeof path.key === \"number\" && path.key >= fromIndex) {\n path.key += incrementBy;\n }\n }\n}\n\nexport function _verifyNodeList<N extends t.Node>(\n this: NodePath,\n nodes: N | N[],\n): N[] {\n if (!nodes) {\n return [];\n }\n\n if (!Array.isArray(nodes)) {\n nodes = [nodes];\n }\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n let msg;\n\n if (!node) {\n msg = \"has falsy node\";\n } else if (typeof node !== \"object\") {\n msg = \"contains a non-object node\";\n } else if (!node.type) {\n msg = \"without a type\";\n } else if (node instanceof NodePath) {\n msg = \"has a NodePath when it expected a raw object\";\n }\n\n if (msg) {\n const type = Array.isArray(node) ? \"array\" : typeof node;\n throw new Error(\n `Node list ${msg} with the index of ${i} and type of ${type}`,\n );\n }\n }\n\n return nodes;\n}\n\nexport function unshiftContainer<N extends t.Node, K extends keyof N & string>(\n this: NodePath<N>,\n listKey: K,\n nodes: N[K] extends (infer E)[]\n ? E | E[]\n : // todo: refine to t.Node[]\n // ? E extends t.Node\n // ? E | E[]\n // : never\n never,\n) {\n // todo: NodePaths<Nodes>\n this._assertUnremoved();\n\n // @ts-expect-error fixme\n nodes = this._verifyNodeList(nodes);\n\n // get the first path and insert our nodes before it, if it doesn't exist then it\n // doesn't matter, our nodes will be inserted anyway\n const path = NodePath.get({\n parentPath: this,\n parent: this.node,\n container: this.node[listKey] as unknown as t.Node | t.Node[],\n listKey,\n key: 0,\n }).setContext(this.context);\n\n return path._containerInsertBefore(\n // @ts-expect-error typings needed to narrow down nodes as t.Node[]\n nodes,\n );\n}\n\nexport function pushContainer<N extends t.Node, K extends keyof N & string>(\n this: NodePath<N>,\n listKey: K,\n nodes: N[K] extends (infer E)[]\n ? E | E[]\n : // todo: refine to t.Node[]\n // ? E extends t.Node\n // ? E | E[]\n // : never\n never,\n) {\n this._assertUnremoved();\n\n const verifiedNodes = this._verifyNodeList(\n // @ts-expect-error refine typings\n nodes,\n );\n\n // get an invisible path that represents the last node + 1 and replace it with our\n // nodes, effectively inlining it\n\n const container = this.node[listKey];\n const path = NodePath.get({\n parentPath: this,\n parent: this.node,\n container: container as unknown as t.Node | t.Node[],\n listKey,\n // @ts-expect-error TS cannot infer that container is t.Node[]\n key: container.length,\n }).setContext(this.context);\n\n return path.replaceWithMultiple(verifiedNodes);\n}\n\n/**\n * Hoist the current node to the highest scope possible and return a UID\n * referencing it.\n */\nexport function hoist<T extends t.Node>(\n this: NodePath<T>,\n scope: Scope = this.scope,\n) {\n const hoister = new PathHoister<T>(this, scope);\n return hoister.run();\n}\n"],"mappings":"AAEA,SAASA,cAAc,QAAQ,aAAU;AACzC,OAAOC,WAAW,MAAM,kBAAe;AACvC,OAAOC,QAAQ,MAAM,YAAS;AAC9B,YAAAC,EAAA,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IAC7DA,OAAO;IACP/D,GAAG,EAAE;EACP,CAAC,CAAC,CAACgE,UAAU,CAAC,IAAI,CAACxC,OAAO,CAAC;EAE3B,OAAOF,IAAI,CAACf,sBAAsB,CAEhClB,KACF,CAAC;AACH;AAEA,OAAO,SAASoE,aAAaA,CAE3BM,OAAU,EACV1E,KAMS,EACT;EACA,IAAI,CAACD,gBAAgB,CAAC,CAAC;EAEvB,MAAM6E,aAAa,GAAG,IAAI,CAAC3E,eAAe,CAExCD,KACF,CAAC;EAKD,MAAMiB,SAAS,GAAG,IAAI,CAACL,IAAI,CAAC8D,OAAO,CAAC;EACpC,MAAMzC,IAAI,GAAGrD,QAAQ,CAAC8E,GAAG,CAAC;IACxBxD,UAAU,EAAE,IAAI;IAChBC,MAAM,EAAE,IAAI,CAACS,IAAI;IACjBK,SAAS,EAAEA,SAAyC;IACpDyD,OAAO;IAEP/D,GAAG,EAAEM,SAAS,CAACW;EACjB,CAAC,CAAC,CAAC+C,UAAU,CAAC,IAAI,CAACxC,OAAO,CAAC;EAE3B,OAAOF,IAAI,CAAC4C,mBAAmB,CAACD,aAAa,CAAC;AAChD;AAMA,OAAO,SAASE,KAAKA,CAEnB7B,KAAY,GAAG,IAAI,CAACA,KAAK,EACzB;EACA,MAAM8B,OAAO,GAAG,IAAIpG,WAAW,CAAI,IAAI,EAAEsE,KAAK,CAAC;EAC/C,OAAO8B,OAAO,CAACC,GAAG,CAAC,CAAC;AACtB"}
@@ -1,48 +0,0 @@
1
- import { hooks } from "./lib/removal-hooks.js";
2
- import { getCachedPaths } from "../cache.js";
3
- import { REMOVED, SHOULD_SKIP } from "./index.js";
4
- export function remove() {
5
- this._assertUnremoved();
6
- this.resync();
7
- if (!this.opts?.noScope) {
8
- this._removeFromScope();
9
- }
10
- if (this._callRemovalHooks()) {
11
- this._markRemoved();
12
- return;
13
- }
14
- this.shareCommentsWithSiblings();
15
- this._remove();
16
- this._markRemoved();
17
- }
18
- export function _removeFromScope() {
19
- const bindings = this.getBindingIdentifiers();
20
- Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
21
- }
22
- export function _callRemovalHooks() {
23
- for (const fn of hooks) {
24
- if (fn(this, this.parentPath)) return true;
25
- }
26
- }
27
- export function _remove() {
28
- if (Array.isArray(this.container)) {
29
- this.container.splice(this.key, 1);
30
- this.updateSiblingKeys(this.key, -1);
31
- } else {
32
- this._replaceWith(null);
33
- }
34
- }
35
- export function _markRemoved() {
36
- this._traverseFlags |= SHOULD_SKIP | REMOVED;
37
- if (this.parent) {
38
- getCachedPaths(this.hub, this.parent).delete(this.node);
39
- }
40
- this.node = null;
41
- }
42
- export function _assertUnremoved() {
43
- if (this.removed) {
44
- throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
45
- }
46
- }
47
-
48
- //# sourceMappingURL=removal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["hooks","getCachedPaths","REMOVED","SHOULD_SKIP","remove","_assertUnremoved","resync","opts","noScope","_removeFromScope","_callRemovalHooks","_markRemoved","shareCommentsWithSiblings","_remove","bindings","getBindingIdentifiers","Object","keys","forEach","name","scope","removeBinding","fn","parentPath","Array","isArray","container","splice","key","updateSiblingKeys","_replaceWith","_traverseFlags","parent","hub","delete","node","removed","buildCodeFrameError"],"sources":["../../src/path/removal.ts"],"sourcesContent":["// This file contains methods responsible for removing a node.\n\nimport { hooks } from \"./lib/removal-hooks\";\nimport { getCachedPaths } from \"../cache\";\nimport type NodePath from \"./index\";\nimport { REMOVED, SHOULD_SKIP } from \"./index\";\n\nexport function remove(this: NodePath) {\n this._assertUnremoved();\n\n this.resync();\n if (!this.opts?.noScope) {\n this._removeFromScope();\n }\n\n if (this._callRemovalHooks()) {\n this._markRemoved();\n return;\n }\n\n this.shareCommentsWithSiblings();\n this._remove();\n this._markRemoved();\n}\n\nexport function _removeFromScope(this: NodePath) {\n const bindings = this.getBindingIdentifiers();\n Object.keys(bindings).forEach(name => this.scope.removeBinding(name));\n}\n\nexport function _callRemovalHooks(this: NodePath) {\n for (const fn of hooks) {\n if (fn(this, this.parentPath)) return true;\n }\n}\n\nexport function _remove(this: NodePath) {\n if (Array.isArray(this.container)) {\n this.container.splice(this.key as number, 1);\n this.updateSiblingKeys(this.key as number, -1);\n } else {\n this._replaceWith(null);\n }\n}\n\nexport function _markRemoved(this: NodePath) {\n // this.shouldSkip = true; this.removed = true;\n this._traverseFlags |= SHOULD_SKIP | REMOVED;\n if (this.parent) {\n getCachedPaths(this.hub, this.parent).delete(this.node);\n }\n this.node = null;\n}\n\nexport function _assertUnremoved(this: NodePath) {\n if (this.removed) {\n throw this.buildCodeFrameError(\n \"NodePath has been removed so is read-only.\",\n );\n }\n}\n"],"mappings":"AAEA,SAASA,KAAK,QAAQ,wBAAqB;AAC3C,SAASC,cAAc,QAAQ,aAAU;AAEzC,SAASC,OAAO,EAAEC,WAAW,QAAQ,YAAS;AAE9C,OAAO,SAASC,MAAMA,CAAA,EAAiB;EACrC,IAAI,CAACC,gBAAgB,CAAC,CAAC;EAEvB,IAAI,CAACC,MAAM,CAAC,CAAC;EACb,IAAI,CAAC,IAAI,CAACC,IAAI,EAAEC,OAAO,EAAE;IACvB,IAAI,CAACC,gBAAgB,CAAC,CAAC;EACzB;EAEA,IAAI,IAAI,CAACC,iBAAiB,CAAC,CAAC,EAAE;IAC5B,IAAI,CAACC,YAAY,CAAC,CAAC;IACnB;EACF;EAEA,IAAI,CAACC,yBAAyB,CAAC,CAAC;EAChC,IAAI,CAACC,OAAO,CAAC,CAAC;EACd,IAAI,CAACF,YAAY,CAAC,CAAC;AACrB;AAEA,OAAO,SAASF,gBAAgBA,CAAA,EAAiB;EAC/C,MAAMK,QAAQ,GAAG,IAAI,CAACC,qBAAqB,CAAC,CAAC;EAC7CC,MAAM,CAACC,IAAI,CAACH,QAAQ,CAAC,CAACI,OAAO,CAACC,IAAI,IAAI,IAAI,CAACC,KAAK,CAACC,aAAa,CAACF,IAAI,CAAC,CAAC;AACvE;AAEA,OAAO,SAAST,iBAAiBA,CAA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