@kerebron/tree-sitter 0.4.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.
Files changed (70) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +4 -0
  3. package/esm/_dnt.polyfills.d.ts +101 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +127 -0
  6. package/esm/deno-tree-sitter/main/extended/base_node.d.ts +48 -0
  7. package/esm/deno-tree-sitter/main/extended/base_node.d.ts.map +1 -0
  8. package/esm/deno-tree-sitter/main/extended/base_node.js +154 -0
  9. package/esm/deno-tree-sitter/main/extended/node_extended.d.ts +237 -0
  10. package/esm/deno-tree-sitter/main/extended/node_extended.d.ts.map +1 -0
  11. package/esm/deno-tree-sitter/main/extended/node_extended.js +665 -0
  12. package/esm/deno-tree-sitter/main/extended/parser.d.ts +37 -0
  13. package/esm/deno-tree-sitter/main/extended/parser.d.ts.map +1 -0
  14. package/esm/deno-tree-sitter/main/extended/parser.js +86 -0
  15. package/esm/deno-tree-sitter/main/extended/soft_node.d.ts +15 -0
  16. package/esm/deno-tree-sitter/main/extended/soft_node.d.ts.map +1 -0
  17. package/esm/deno-tree-sitter/main/extended/soft_node.js +32 -0
  18. package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts +10 -0
  19. package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts.map +1 -0
  20. package/esm/deno-tree-sitter/main/extended/soft_text_node.js +10 -0
  21. package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts +10 -0
  22. package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts.map +1 -0
  23. package/esm/deno-tree-sitter/main/extended/whitespace_node.js +10 -0
  24. package/esm/deno-tree-sitter/main/extras/misc.d.ts +2 -0
  25. package/esm/deno-tree-sitter/main/extras/misc.d.ts.map +1 -0
  26. package/esm/deno-tree-sitter/main/extras/misc.js +13 -0
  27. package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts +14 -0
  28. package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts.map +1 -0
  29. package/esm/deno-tree-sitter/main/tree_sitter/bindings.js +21 -0
  30. package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts +60 -0
  31. package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts.map +1 -0
  32. package/esm/deno-tree-sitter/main/tree_sitter/constants.js +66 -0
  33. package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts +137 -0
  34. package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts.map +1 -0
  35. package/esm/deno-tree-sitter/main/tree_sitter/language.js +296 -0
  36. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts +41 -0
  37. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts.map +1 -0
  38. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +75 -0
  39. package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts +85 -0
  40. package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts.map +1 -0
  41. package/esm/deno-tree-sitter/main/tree_sitter/marshal.js +173 -0
  42. package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts +260 -0
  43. package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts.map +1 -0
  44. package/esm/deno-tree-sitter/main/tree_sitter/node.js +592 -0
  45. package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts +124 -0
  46. package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts.map +1 -0
  47. package/esm/deno-tree-sitter/main/tree_sitter/parser.js +272 -0
  48. package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts +134 -0
  49. package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts.map +1 -0
  50. package/esm/deno-tree-sitter/main/tree_sitter/query.js +670 -0
  51. package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts +49 -0
  52. package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts.map +1 -0
  53. package/esm/deno-tree-sitter/main/tree_sitter/tree.js +145 -0
  54. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts +165 -0
  55. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts.map +1 -0
  56. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js +305 -0
  57. package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts +3 -0
  58. package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts.map +1 -0
  59. package/esm/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
  60. package/esm/deno-tree-sitter/main/wasm_loader.d.ts +29 -0
  61. package/esm/deno-tree-sitter/main/wasm_loader.d.ts.map +1 -0
  62. package/esm/deno-tree-sitter/main/wasm_loader.js +1709 -0
  63. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts +3 -0
  64. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts.map +1 -0
  65. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js +8 -0
  66. package/esm/mod.d.ts +8 -0
  67. package/esm/mod.d.ts.map +1 -0
  68. package/esm/mod.js +8 -0
  69. package/esm/package.json +3 -0
  70. package/package.json +16 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Permission is hereby granted, free of charge, to any
2
+ person obtaining a copy of this software and associated
3
+ documentation files (the "Software"), to deal in the
4
+ Software without restriction, including without
5
+ limitation the rights to use, copy, modify, merge,
6
+ publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software
8
+ is furnished to do so, subject to the following
9
+ conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ shall be included in all copies or substantial portions
13
+ of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Project [deno-tree-sitter](https://github.com/jeff-hykin/deno-tree-sitter/) contains several patches and extensions over
2
+ web-tree-sitter. Unfortunately deno-tree-sitter is not available as npm package and cannot be used with nodejs.
3
+ Therefor we add it as submodule and package inside @kerebron/tree-sitter
4
+
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
3
+ * but instead of using npm to install additional dependencies,
4
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
5
+ *
6
+ * Note that this code might be imported multiple times
7
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
8
+ * or Node.js might dynamically clear the cache and then force a require).
9
+ * Therefore, it's important to avoid redundant writes to global objects.
10
+ * Additionally, consider that commonjs is used alongside esm,
11
+ * so the two ponyfill functions are stored independently in two separate global objects.
12
+ */
13
+ import { createRequire } from "node:module";
14
+ import { type URL } from "node:url";
15
+ declare global {
16
+ interface ImportMeta {
17
+ /** A string representation of the fully qualified module URL. When the
18
+ * module is loaded locally, the value will be a file URL (e.g.
19
+ * `file:///path/module.ts`).
20
+ *
21
+ * You can also parse the string as a URL to determine more information about
22
+ * how the current module was loaded. For example to determine if a module was
23
+ * local or not:
24
+ *
25
+ * ```ts
26
+ * const url = new URL(import.meta.url);
27
+ * if (url.protocol === "file:") {
28
+ * console.log("this module was loaded locally");
29
+ * }
30
+ * ```
31
+ */
32
+ url: string;
33
+ /**
34
+ * A function that returns resolved specifier as if it would be imported
35
+ * using `import(specifier)`.
36
+ *
37
+ * ```ts
38
+ * console.log(import.meta.resolve("./foo.js"));
39
+ * // file:///dev/foo.js
40
+ * ```
41
+ *
42
+ * @param specifier The module specifier to resolve relative to `parent`.
43
+ * @param parent The absolute parent module URL to resolve from.
44
+ * @returns The absolute (`file:`) URL string for the resolved module.
45
+ */
46
+ resolve(specifier: string, parent?: string | URL | undefined): string;
47
+ /** A flag that indicates if the current module is the main module that was
48
+ * called when starting the program under Deno.
49
+ *
50
+ * ```ts
51
+ * if (import.meta.main) {
52
+ * // this was loaded as the main module, maybe do some bootstrapping
53
+ * }
54
+ * ```
55
+ */
56
+ main: boolean;
57
+ /** The absolute path of the current module.
58
+ *
59
+ * This property is only provided for local modules (ie. using `file://` URLs).
60
+ *
61
+ * Example:
62
+ * ```
63
+ * // Unix
64
+ * console.log(import.meta.filename); // /home/alice/my_module.ts
65
+ *
66
+ * // Windows
67
+ * console.log(import.meta.filename); // C:\alice\my_module.ts
68
+ * ```
69
+ */
70
+ filename: string;
71
+ /** The absolute path of the directory containing the current module.
72
+ *
73
+ * This property is only provided for local modules (ie. using `file://` URLs).
74
+ *
75
+ * * Example:
76
+ * ```
77
+ * // Unix
78
+ * console.log(import.meta.dirname); // /home/alice
79
+ *
80
+ * // Windows
81
+ * console.log(import.meta.dirname); // C:\alice
82
+ * ```
83
+ */
84
+ dirname: string;
85
+ }
86
+ }
87
+ type NodeRequest = ReturnType<typeof createRequire>;
88
+ type NodeModule = NonNullable<NodeRequest["main"]>;
89
+ interface ImportMetaPonyfillCommonjs {
90
+ (require: NodeRequest, module: NodeModule): ImportMeta;
91
+ }
92
+ interface ImportMetaPonyfillEsmodule {
93
+ (importMeta: ImportMeta): ImportMeta;
94
+ }
95
+ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
96
+ }
97
+ export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
98
+ export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
99
+ export declare let import_meta_ponyfill: ImportMetaPonyfill;
100
+ export {};
101
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
3
+ * but instead of using npm to install additional dependencies,
4
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
5
+ *
6
+ * Note that this code might be imported multiple times
7
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
8
+ * or Node.js might dynamically clear the cache and then force a require).
9
+ * Therefore, it's important to avoid redundant writes to global objects.
10
+ * Additionally, consider that commonjs is used alongside esm,
11
+ * so the two ponyfill functions are stored independently in two separate global objects.
12
+ */
13
+ //@ts-ignore
14
+ import { createRequire } from "node:module";
15
+ //@ts-ignore
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+ //@ts-ignore
18
+ import { dirname } from "node:path";
19
+ const defineGlobalPonyfill = (symbolFor, fn) => {
20
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
21
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
22
+ configurable: true,
23
+ get() {
24
+ return fn;
25
+ },
26
+ });
27
+ }
28
+ };
29
+ export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
30
+ (() => {
31
+ const moduleImportMetaWM = new WeakMap();
32
+ return (require, module) => {
33
+ let importMetaCache = moduleImportMetaWM.get(module);
34
+ if (importMetaCache == null) {
35
+ const importMeta = Object.assign(Object.create(null), {
36
+ url: pathToFileURL(module.filename).href,
37
+ main: require.main == module,
38
+ resolve: (specifier, parentURL = importMeta.url) => {
39
+ return pathToFileURL((importMeta.url === parentURL
40
+ ? require
41
+ : createRequire(parentURL))
42
+ .resolve(specifier)).href;
43
+ },
44
+ filename: module.filename,
45
+ dirname: module.path,
46
+ });
47
+ moduleImportMetaWM.set(module, importMeta);
48
+ importMetaCache = importMeta;
49
+ }
50
+ return importMetaCache;
51
+ };
52
+ })());
53
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
54
+ export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
55
+ ((importMeta) => {
56
+ const resolveFunStr = String(importMeta.resolve);
57
+ const shimWs = new WeakSet();
58
+ //@ts-ignore
59
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
60
+ .replace(/\/{3,}/, "///");
61
+ const commonShim = (importMeta) => {
62
+ if (typeof importMeta.main !== "boolean") {
63
+ importMeta.main = importMeta.url === mainUrl;
64
+ }
65
+ if (typeof importMeta.filename !== "string") {
66
+ importMeta.filename = fileURLToPath(importMeta.url);
67
+ importMeta.dirname = dirname(importMeta.filename);
68
+ }
69
+ };
70
+ if (
71
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
72
+ resolveFunStr === "undefined" ||
73
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
74
+ resolveFunStr.startsWith("async")
75
+ // enable by --experimental-import-meta-resolve flag
76
+ ) {
77
+ import_meta_ponyfill_esmodule = (importMeta) => {
78
+ if (!shimWs.has(importMeta)) {
79
+ shimWs.add(importMeta);
80
+ const importMetaUrlRequire = {
81
+ url: importMeta.url,
82
+ require: createRequire(importMeta.url),
83
+ };
84
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
85
+ return pathToFileURL((importMetaUrlRequire.url === parentURL
86
+ ? importMetaUrlRequire.require
87
+ : createRequire(parentURL)).resolve(specifier)).href;
88
+ };
89
+ commonShim(importMeta);
90
+ }
91
+ return importMeta;
92
+ };
93
+ }
94
+ else {
95
+ /// native support
96
+ import_meta_ponyfill_esmodule = (importMeta) => {
97
+ if (!shimWs.has(importMeta)) {
98
+ shimWs.add(importMeta);
99
+ commonShim(importMeta);
100
+ }
101
+ return importMeta;
102
+ };
103
+ }
104
+ return import_meta_ponyfill_esmodule(importMeta);
105
+ }));
106
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
107
+ export let import_meta_ponyfill = ((...args) => {
108
+ const _MODULE = (() => {
109
+ if (typeof require === "function" && typeof module === "object") {
110
+ return "commonjs";
111
+ }
112
+ else {
113
+ // eval("typeof import.meta");
114
+ return "esmodule";
115
+ }
116
+ })();
117
+ if (_MODULE === "commonjs") {
118
+ //@ts-ignore
119
+ import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
120
+ }
121
+ else {
122
+ //@ts-ignore
123
+ import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
124
+ }
125
+ //@ts-ignore
126
+ return import_meta_ponyfill(...args);
127
+ });
@@ -0,0 +1,48 @@
1
+ export const _shadows: {};
2
+ export class BaseNode {
3
+ constructor(data: any);
4
+ /** @type {number} */
5
+ get depth(): number;
6
+ _depth: any;
7
+ /** @type {number} */
8
+ get length(): number;
9
+ get hasChildren(): boolean;
10
+ get hardChildren(): any;
11
+ get fields(): {};
12
+ get fieldNames(): never[];
13
+ /** @type {string} */
14
+ get indent(): string;
15
+ /** @type {Object} */
16
+ toJSON(): {
17
+ children: any;
18
+ type: any;
19
+ typeId: any;
20
+ fieldNames: never[];
21
+ startPosition: any;
22
+ startIndex: any;
23
+ endPosition: any;
24
+ endIndex: any;
25
+ indent: string;
26
+ } | {
27
+ text: any;
28
+ children: never[];
29
+ type: any;
30
+ typeId: any;
31
+ fieldNames: never[];
32
+ startPosition: any;
33
+ startIndex: any;
34
+ endPosition: any;
35
+ endIndex: any;
36
+ indent: string;
37
+ };
38
+ iterFlattened(): Generator<never, void, unknown>;
39
+ flattened(): never[];
40
+ /**
41
+ * Destroy the children of this node and replace the .text of this node with the given string.
42
+ *
43
+ * @param {string} replacement - description
44
+ */
45
+ replaceInnards(replacement: string): void;
46
+ [Symbol.iterator](): Generator<any, void, any>;
47
+ }
48
+ //# sourceMappingURL=base_node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base_node.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/extended/base_node.js"],"names":[],"mappings":"AAEA,0BAA0B;AAC1B;IAUI,uBAEC;IAED,qBAAqB;IACrB,aADW,MAAM,CAUhB;IANW,YAAe;IAQ3B,qBAAqB;IACrB,cADW,MAAM,CAGhB;IAMD,2BAEC;IAED,wBAEC;IAED,iBAEC;IAED,0BAEC;IAED,qBAAqB;IACrB,cADW,MAAM,CAKhB;IAED,qBAAqB;IACrB;;;;;;;;;;;;;;;;;;;;;MAgCC;IAgCD,iDAEC;IACD,qBAEC;IAED;;;;OAIG;IACH,4BAFW,MAAM,QAoChB;IA1ID,+CAEC;CAyIJ"}
@@ -0,0 +1,154 @@
1
+ import { Node } from "../tree_sitter/node.js";
2
+ export const _shadows = {};
3
+ export class BaseNode {
4
+ // type = ""
5
+ // typeId = 0
6
+ // startPosition = 0
7
+ // startIndex = 0
8
+ // endPosition = 0
9
+ // startIndex = 0
10
+ // endIndex = 0
11
+ // indent = ""
12
+ constructor(data) {
13
+ Object.assign(this, data);
14
+ }
15
+ /** @type {number} */
16
+ get depth() {
17
+ if (this._depth == null) {
18
+ if (this.parent == null) {
19
+ this._depth = 0;
20
+ }
21
+ else {
22
+ this._depth = this.parent.depth + 1;
23
+ }
24
+ }
25
+ return this._depth;
26
+ }
27
+ /** @type {number} */
28
+ get length() {
29
+ return this.children?.length || 0;
30
+ }
31
+ *[Symbol.iterator]() {
32
+ yield* this.children || [];
33
+ }
34
+ get hasChildren() {
35
+ return (this.children?.length || 0) > 0;
36
+ }
37
+ get hardChildren() {
38
+ return (this.children || []).filter(each => each instanceof Node);
39
+ }
40
+ get fields() {
41
+ return {};
42
+ }
43
+ get fieldNames() {
44
+ return [];
45
+ }
46
+ /** @type {string} */
47
+ get indent() {
48
+ return this.tree.codeString.match(new RegExp(`^(?:.*\\r?\\n){${this.startPosition.row}}(\\s*)`))[1];
49
+ // equivalent but usually faster than:
50
+ // return this.tree.codeString.split("\n")[this.startPosition.row].match(/^\s*/)[0]
51
+ }
52
+ /** @type {Object} */
53
+ toJSON() {
54
+ const optionalData = {};
55
+ if (this.children?.length) {
56
+ return {
57
+ type: this.type,
58
+ typeId: this.typeId,
59
+ fieldNames: this.fieldNames,
60
+ startPosition: this.startPosition,
61
+ startIndex: this.startIndex,
62
+ endPosition: this.endPosition,
63
+ startIndex: this.startIndex,
64
+ endIndex: this.endIndex,
65
+ indent: this.indent,
66
+ ...optionalData,
67
+ children: this.children.map(each => each.toJSON()),
68
+ };
69
+ }
70
+ else {
71
+ return {
72
+ type: this.type,
73
+ typeId: this.typeId,
74
+ fieldNames: this.fieldNames,
75
+ startPosition: this.startPosition,
76
+ startIndex: this.startIndex,
77
+ endPosition: this.endPosition,
78
+ startIndex: this.startIndex,
79
+ endIndex: this.endIndex,
80
+ indent: this.indent,
81
+ ...optionalData,
82
+ text: this.text,
83
+ children: [],
84
+ };
85
+ }
86
+ }
87
+ [Symbol.for("Deno.customInspect")](inspect, options) {
88
+ const optional = {};
89
+ let text;
90
+ try {
91
+ text = this.text;
92
+ }
93
+ catch (error) {
94
+ text = undefined;
95
+ }
96
+ if (text == undefined) {
97
+ return this;
98
+ }
99
+ return inspect({
100
+ '': text.length < 60 ? text : text.slice(0, 30) + "..." + text.slice(-27),
101
+ type: this.type,
102
+ typeId: this.typeId,
103
+ fieldNames: this.fieldNames,
104
+ startPosition: this.startPosition,
105
+ startIndex: this.startIndex,
106
+ endPosition: this.endPosition,
107
+ startIndex: this.startIndex,
108
+ endIndex: this.endIndex,
109
+ indent: this.indent,
110
+ ...optional,
111
+ hasChildren: this.hasChildren,
112
+ children: [...(this.children || [])],
113
+ }, options);
114
+ }
115
+ *iterFlattened() {
116
+ }
117
+ flattened() {
118
+ return [];
119
+ }
120
+ /**
121
+ * Destroy the children of this node and replace the .text of this node with the given string.
122
+ *
123
+ * @param {string} replacement - description
124
+ */
125
+ replaceInnards(replacement) {
126
+ const tree = this.tree;
127
+ const sourceCode = this.tree.codeString;
128
+ const node = _shadows[this.id] || this;
129
+ // clear out children (innards) because of replacement
130
+ node._children = [];
131
+ node._fields = {};
132
+ // get the node position info
133
+ const { startPosition: originalStart, endPosition: originalEnd, startIndex: originalStartIndex, endIndex: originalEndIndex, } = node;
134
+ // compute what the new row-column will be
135
+ const newNumberOfLines = replacement.match(/\n/g)?.length || 0;
136
+ let newEndCol = originalStart.column;
137
+ if (newNumberOfLines == 0) {
138
+ newEndCol = originalStart.column + replacement.length;
139
+ }
140
+ else {
141
+ newEndCol = replacement.split("\n").slice(-1)[0].length;
142
+ }
143
+ // updates all the indices of all the nodes
144
+ tree.edit({
145
+ startIndex: originalStartIndex,
146
+ oldEndIndex: originalEndIndex,
147
+ newEndIndex: originalStartIndex + replacement.length,
148
+ startPosition: originalStart,
149
+ oldEndPosition: originalEnd,
150
+ newEndPosition: { row: originalStart.row + newNumberOfLines, column: newEndCol },
151
+ });
152
+ this.tree.codeString = sourceCode.slice(0, originalStartIndex) + replacement + sourceCode.slice(originalEndIndex);
153
+ }
154
+ }