@babel/traverse 7.23.4 → 7.23.6
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.
package/lib/path/comments.js
CHANGED
@@ -36,12 +36,10 @@ function shareCommentsWithSiblings() {
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
function removeIfExisting(list, toRemove) {
|
39
|
-
if (!toRemove) return list;
|
40
|
-
|
39
|
+
if (!(toRemove != null && toRemove.length)) return list;
|
40
|
+
const set = new Set(toRemove);
|
41
41
|
return list.filter(el => {
|
42
|
-
|
43
|
-
if (i === -1) return true;
|
44
|
-
lastFoundIndex = i;
|
42
|
+
return !set.has(el);
|
45
43
|
});
|
46
44
|
}
|
47
45
|
function addComment(type, content, line) {
|
package/lib/path/comments.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_t","require","addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","removeIfExisting","list","toRemove","
|
1
|
+
{"version":3,"names":["_t","require","addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","removeIfExisting","list","toRemove","length","set","Set","filter","el","has","type","content","line","comments"],"sources":["../../src/path/comments.ts"],"sourcesContent":["// This file contains methods responsible for dealing with comments.\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index.ts\";\nimport {\n addComment as _addComment,\n addComments as _addComments,\n} from \"@babel/types\";\n\n/**\n * Share comments amongst siblings.\n */\n\nexport function shareCommentsWithSiblings(this: NodePath) {\n // NOTE: this assumes numbered keys\n if (typeof this.key === \"string\") return;\n\n const node = this.node;\n if (!node) return;\n\n const trailing = node.trailingComments;\n const leading = node.leadingComments;\n if (!trailing && !leading) return;\n\n const prev = this.getSibling(this.key - 1);\n const next = this.getSibling(this.key + 1);\n const hasPrev = Boolean(prev.node);\n const hasNext = Boolean(next.node);\n\n if (hasPrev) {\n if (leading) {\n prev.addComments(\n \"trailing\",\n removeIfExisting(leading, prev.node.trailingComments),\n );\n }\n if (trailing && !hasNext) prev.addComments(\"trailing\", trailing);\n }\n if (hasNext) {\n if (trailing) {\n next.addComments(\n \"leading\",\n removeIfExisting(trailing, next.node.leadingComments),\n );\n }\n if (leading && !hasPrev) next.addComments(\"leading\", leading);\n }\n}\n\nfunction removeIfExisting<T>(list: T[], toRemove?: T[]): T[] {\n if (!toRemove?.length) return list;\n const set = new Set(toRemove);\n return list.filter(el => {\n return !set.has(el);\n });\n}\n\nexport function addComment(\n this: NodePath,\n type: t.CommentTypeShorthand,\n content: string,\n line?: boolean,\n) {\n _addComment(this.node, type, content, line);\n}\n\n/**\n * Give node `comments` of the specified `type`.\n */\n\nexport function addComments(\n this: NodePath,\n type: t.CommentTypeShorthand,\n comments: t.Comment[],\n) {\n _addComments(this.node, type, comments);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,EAAA,GAAAC,OAAA;AAGsB;EAFpBC,UAAU,EAAIC,WAAW;EACzBC,WAAW,EAAIC;AAAY,IAAAL,EAAA;AAOtB,SAASM,yBAAyBA,CAAA,EAAiB;EAExD,IAAI,OAAO,IAAI,CAACC,GAAG,KAAK,QAAQ,EAAE;EAElC,MAAMC,IAAI,GAAG,IAAI,CAACA,IAAI;EACtB,IAAI,CAACA,IAAI,EAAE;EAEX,MAAMC,QAAQ,GAAGD,IAAI,CAACE,gBAAgB;EACtC,MAAMC,OAAO,GAAGH,IAAI,CAACI,eAAe;EACpC,IAAI,CAACH,QAAQ,IAAI,CAACE,OAAO,EAAE;EAE3B,MAAME,IAAI,GAAG,IAAI,CAACC,UAAU,CAAC,IAAI,CAACP,GAAG,GAAG,CAAC,CAAC;EAC1C,MAAMQ,IAAI,GAAG,IAAI,CAACD,UAAU,CAAC,IAAI,CAACP,GAAG,GAAG,CAAC,CAAC;EAC1C,MAAMS,OAAO,GAAGC,OAAO,CA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;AACzC"}
|
package/lib/path/removal.js
CHANGED
@@ -12,6 +12,10 @@ exports.remove = remove;
|
|
12
12
|
var _removalHooks = require("./lib/removal-hooks.js");
|
13
13
|
var _cache = require("../cache.js");
|
14
14
|
var _index = require("./index.js");
|
15
|
+
var _t = require("@babel/types");
|
16
|
+
const {
|
17
|
+
getBindingIdentifiers
|
18
|
+
} = _t;
|
15
19
|
function remove() {
|
16
20
|
var _this$opts;
|
17
21
|
this._assertUnremoved();
|
@@ -28,7 +32,7 @@ function remove() {
|
|
28
32
|
this._markRemoved();
|
29
33
|
}
|
30
34
|
function _removeFromScope() {
|
31
|
-
const bindings = this.
|
35
|
+
const bindings = getBindingIdentifiers(this.node, false, false, true);
|
32
36
|
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
33
37
|
}
|
34
38
|
function _callRemovalHooks() {
|
package/lib/path/removal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_removalHooks","require","_cache","_index","remove","_this$opts","_assertUnremoved","resync","opts","noScope","_removeFromScope","_callRemovalHooks","_markRemoved","shareCommentsWithSiblings","_remove","bindings","
|
1
|
+
{"version":3,"names":["_removalHooks","require","_cache","_index","_t","getBindingIdentifiers","remove","_this$opts","_assertUnremoved","resync","opts","noScope","_removeFromScope","_callRemovalHooks","_markRemoved","shareCommentsWithSiblings","_remove","bindings","node","Object","keys","forEach","name","scope","removeBinding","fn","hooks","parentPath","Array","isArray","container","splice","key","updateSiblingKeys","_replaceWith","_traverseFlags","SHOULD_SKIP","REMOVED","parent","getCachedPaths","hub","delete","removed","buildCodeFrameError"],"sources":["../../src/path/removal.ts"],"sourcesContent":["// This file contains methods responsible for removing a node.\n\nimport { hooks } from \"./lib/removal-hooks.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport type NodePath from \"./index.ts\";\nimport { REMOVED, SHOULD_SKIP } from \"./index.ts\";\nimport { getBindingIdentifiers } from \"@babel/types\";\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 = getBindingIdentifiers(this.node, false, false, true);\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,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,EAAA,GAAAH,OAAA;AAAqD;EAA5CI;AAAqB,IAAAD,EAAA;AAEvB,SAASE,MAAMA,CAAA,EAAiB;EAAA,IAAAC,UAAA;EACrC,IAAI,CAACC,gBAAgB,CAAC,CAAC;EAEvB,IAAI,CAACC,MAAM,CAAC,CAAC;EACb,IAAI,GAAAF,UAAA,GAAC,IAAI,CAACG,IAAI,aAATH,UAAA,CAAWI,OAAO,GAAE;IACvB,IAAI,CAACC,gBAAgB,CAAC,CAAC;EACzB;EAEA,IAAI,IAAI,CAACC,iBAAiB,CAAC,CAAC,EAAE;IAC5B,IAAI,CAACC,YAAY,CAAC,CAAC;IACnB;EACF;EAEA,IA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EAAE;IAChB,MAAM,IAAI,CAACC,mBAAmB,CAC5B,4CACF,CAAC;EACH;AACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.23.
|
3
|
+
"version": "7.23.6",
|
4
4
|
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
|
5
5
|
"author": "The Babel Team (https://babel.dev/team)",
|
6
6
|
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
|
@@ -16,19 +16,19 @@
|
|
16
16
|
},
|
17
17
|
"main": "./lib/index.js",
|
18
18
|
"dependencies": {
|
19
|
-
"@babel/code-frame": "^7.23.
|
20
|
-
"@babel/generator": "^7.23.
|
19
|
+
"@babel/code-frame": "^7.23.5",
|
20
|
+
"@babel/generator": "^7.23.6",
|
21
21
|
"@babel/helper-environment-visitor": "^7.22.20",
|
22
22
|
"@babel/helper-function-name": "^7.23.0",
|
23
23
|
"@babel/helper-hoist-variables": "^7.22.5",
|
24
24
|
"@babel/helper-split-export-declaration": "^7.22.6",
|
25
|
-
"@babel/parser": "^7.23.
|
26
|
-
"@babel/types": "^7.23.
|
27
|
-
"debug": "^4.1
|
25
|
+
"@babel/parser": "^7.23.6",
|
26
|
+
"@babel/types": "^7.23.6",
|
27
|
+
"debug": "^4.3.1",
|
28
28
|
"globals": "^11.1.0"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
-
"@babel/core": "^7.23.
|
31
|
+
"@babel/core": "^7.23.6",
|
32
32
|
"@babel/helper-plugin-test-runner": "^7.22.5"
|
33
33
|
},
|
34
34
|
"engines": {
|