yuku-parser 0.4.6 → 0.5.0

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 (4) hide show
  1. package/decode.js +202 -134
  2. package/index.d.ts +1139 -93
  3. package/index.js +20 -1
  4. package/package.json +19 -19
package/decode.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // generated by tools/gen_estree_decoder.zig, do not edit
2
2
  const NULL = 0xFFFFFFFF;
3
+ const _td = new TextDecoder("utf-8", { ignoreBOM: true });
3
4
  const BINARY_OPS = ["==", "!=", "===", "!==", "<", "<=", ">", ">=", "+", "-", "*", "/", "%", "**", "|", "^", "&", "<<", ">>", ">>>", "in", "instanceof"];
4
5
  const LOGICAL_OPS = ["&&", "||", "??"];
5
6
  const UNARY_OPS = ["-", "+", "!", "~", "typeof", "void", "delete"];
@@ -12,36 +13,96 @@ const FUNCTION_TYPES = ["FunctionDeclaration", "FunctionExpression", "TSDeclareF
12
13
  const CLASS_TYPES = ["ClassDeclaration", "ClassExpression"];
13
14
  const COMMENT_TYPES = ["Line", "Block"];
14
15
  const SEVERITY = ["error", "warning", "hint", "info"];
15
- const _td = new TextDecoder("utf-8", { ignoreBOM: true });
16
- let _u8, _u32, _src, _srcLen, _nodesOff, _extraBase, _spOff, _p, str;
17
- function _poolDecode(s, e) {
18
- const a = _spOff + s - _srcLen, b = _spOff + e - _srcLen;
19
- let hasEd = false;
20
- for (let i = a; i < b; i++) if (_u8[i] === 0xED) { hasEd = true; break; }
21
- if (!hasEd) return _td.decode(_u8.subarray(a, b));
22
- let r = "";
23
- for (let i = a; i < b; ) {
24
- const c = _u8[i];
25
- if (c < 0x80) { r += String.fromCharCode(c); i++; }
26
- else if (c < 0xE0) { r += String.fromCharCode(((c & 0x1F) << 6) | (_u8[i+1] & 0x3F)); i += 2; }
27
- else if (c < 0xF0) { r += String.fromCharCode(((c & 0x0F) << 12) | ((_u8[i+1] & 0x3F) << 6) | (_u8[i+2] & 0x3F)); i += 3; }
28
- else { r += String.fromCodePoint(((c & 0x07) << 18) | ((_u8[i+1] & 0x3F) << 12) | ((_u8[i+2] & 0x3F) << 6) | (_u8[i+3] & 0x3F)); i += 4; }
16
+ const IMPORT_EXPORT_KINDS = ["value", "type"];
17
+ const ACCESSIBILITY = [null, "public", "private", "protected"];
18
+ const TS_TYPE_OPERATORS = ["keyof", "unique", "readonly"];
19
+ const TS_METHOD_SIGNATURE_KINDS = ["method", "get", "set"];
20
+ const TS_MODULE_KINDS = ["namespace", "module"];
21
+ const TS_MAPPED_OPTIONAL = [false, true, "+", "-"];
22
+ const TS_MAPPED_READONLY = [null, true, "+", "-"];
23
+ function buildPosMap(src, byteLen) {
24
+ const m = new Uint32Array(byteLen + 1);
25
+ let bp = 0, u16p = 0;
26
+ for (let i = 0; i < src.length; i++) {
27
+ m[bp] = u16p;
28
+ const cp = src.codePointAt(i);
29
+ let bytes = 1;
30
+ if (cp > 0x7F) { if (cp > 0x7FF) { bytes = cp > 0xFFFF ? 4 : 3; } else { bytes = 2; } }
31
+ const units = bytes === 4 ? 2 : 1;
32
+ u16p += units;
33
+ for (let k = 1; k < bytes; k++) m[bp + k] = u16p;
34
+ bp += bytes;
35
+ if (bytes === 4) i++;
29
36
  }
30
- return r;
37
+ m[byteLen] = u16p;
38
+ return m;
31
39
  }
32
- function node(i) {
33
- const o = _nodesOff + i * 32;
34
- const tag = _u8[o];
35
- const flags = _u8[o + 1];
36
- const f0 = _u8[o + 2] | (_u8[o + 3] << 8);
37
- const b = o >> 2;
38
- const f1 = _u32[b + 1], f2 = _u32[b + 2], f3 = _u32[b + 3], f4 = _u32[b + 4], f5 = _u32[b + 5];
39
- const start = _p(_u32[b + 6]), end = _p(_u32[b + 7]);
40
- switch (tag) {
40
+ function decode(buffer, source) {
41
+ const _u8 = new Uint8Array(buffer);
42
+ const aLen = (buffer.byteLength >> 2) << 2;
43
+ const _u32 = new Uint32Array(buffer, 0, aLen >> 2);
44
+ const _src = source;
45
+ const _srcLen = _u32[3];
46
+ const nodeCount = _u32[0], extraCount = _u32[1], spLen = _u32[2];
47
+ const commentCount = _u32[4], diagCount = _u32[5], progIdx = _u32[6];
48
+ const _isTs = !!(_u32[7] & 2);
49
+ const pm = (_u32[7] & 1) ? null : buildPosMap(source, _srcLen);
50
+ const _p = pm ? (v => pm[v]) : (v => v);
51
+ const _nodesOff = 32;
52
+ const eOff = _nodesOff + nodeCount * 48;
53
+ const _extraBase = eOff >> 2;
54
+ const _spOff = eOff + extraCount * 4;
55
+ function _poolDecode(s, e) {
56
+ const a = _spOff + s - _srcLen, b = _spOff + e - _srcLen;
57
+ let hasEd = false;
58
+ for (let i = a; i < b; i++) if (_u8[i] === 0xED) { hasEd = true; break; }
59
+ if (!hasEd) return _td.decode(_u8.subarray(a, b));
60
+ let r = "";
61
+ for (let i = a; i < b; ) {
62
+ const c = _u8[i];
63
+ if (c < 0x80) { r += String.fromCharCode(c); i++; }
64
+ else if (c < 0xE0) { r += String.fromCharCode(((c & 0x1F) << 6) | (_u8[i+1] & 0x3F)); i += 2; }
65
+ else if (c < 0xF0) { r += String.fromCharCode(((c & 0x0F) << 12) | ((_u8[i+1] & 0x3F) << 6) | (_u8[i+2] & 0x3F)); i += 3; }
66
+ else { r += String.fromCodePoint(((c & 0x07) << 18) | ((_u8[i+1] & 0x3F) << 12) | ((_u8[i+2] & 0x3F) << 6) | (_u8[i+3] & 0x3F)); i += 4; }
67
+ }
68
+ return r;
69
+ }
70
+ const str = pm
71
+ ? ((s, e) => s === e ? "" : s < _srcLen ? _src.slice(pm[s], pm[e]) : _poolDecode(s, e))
72
+ : ((s, e) => s === e ? "" : s < _srcLen ? _src.slice(s, e) : _poolDecode(s, e));
73
+ function nodeArr(s, len) {
74
+ const r = new Array(len);
75
+ for (let j = 0; j < len; j++) r[j] = node(_u32[_extraBase + s + j]);
76
+ return r;
77
+ }
78
+ function nodeArrHoles(s, len) {
79
+ const r = new Array(len);
80
+ for (let j = 0; j < len; j++) { const x = _u32[_extraBase + s + j]; r[j] = x !== NULL ? node(x) : null; }
81
+ return r;
82
+ }
83
+ function fnParams(idx) {
84
+ const po = _nodesOff + idx * 48;
85
+ const len = _u8[po + 4] | (_u8[po + 5] << 8);
86
+ const pb = po >> 2;
87
+ const iStart = _u32[pb + 2], rest = _u32[pb + 3];
88
+ const p = [];
89
+ for (let j = 0; j < len; j++) p.push(node(_u32[_extraBase + iStart + j]));
90
+ if (rest !== NULL) p.push(node(rest));
91
+ return p;
92
+ }
93
+ function node(i) {
94
+ const o = _nodesOff + i * 48;
95
+ const tag = _u8[o];
96
+ const flags = _u8[o + 2] | (_u8[o + 3] << 8);
97
+ const f0 = _u8[o + 4] | (_u8[o + 5] << 8);
98
+ const b = o >> 2;
99
+ const f1 = _u32[b + 2], f2 = _u32[b + 3], f3 = _u32[b + 4], f4 = _u32[b + 5], f5 = _u32[b + 6], f6 = _u32[b + 7], f7 = _u32[b + 8], f8 = _u32[b + 9];
100
+ const start = _p(_u32[b + 10]), end = _p(_u32[b + 11]);
101
+ switch (tag) {
41
102
  case 0: return { type: "SequenceExpression", start, end, expressions: nodeArr(f1, f0) };
42
103
  case 1: return { type: "ParenthesizedExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
43
- case 2: return { type: "ArrowFunctionExpression", start, end, id: null, generator: false, async: !!(flags & 2), params: f1 !== NULL ? fnParams(f1) : [], body: node(f2), expression: !!(flags & 1) };
44
- case 3: { const ft = flags & 3; const r = { type: FUNCTION_TYPES[ft], start, end, id: f1 !== NULL ? node(f1) : null, generator: !!(flags & 4), async: !!(flags & 8), params: f2 !== NULL ? fnParams(f2) : [], body: f3 !== NULL ? node(f3) : null, expression: false }; if (ft === 2) r.declare = true; return r; }
104
+ case 2: { const r = { type: "ArrowFunctionExpression", start, end, id: null, generator: false, async: !!(flags & 2), params: f1 !== NULL ? fnParams(f1) : [], body: node(f2), expression: !!(flags & 1) }; if (_isTs) { r.typeParameters = f3 !== NULL ? node(f3) : null; r.returnType = f4 !== NULL ? node(f4) : null; } return r; }
105
+ case 3: { const ft = flags & 3; const r = { type: FUNCTION_TYPES[ft], start, end, id: f1 !== NULL ? node(f1) : null, generator: !!(flags & 4), async: !!(flags & 8), params: f2 !== NULL ? fnParams(f2) : [], body: f3 !== NULL ? node(f3) : null, expression: false }; if (_isTs) { r.typeParameters = f4 !== NULL ? node(f4) : null; r.returnType = f5 !== NULL ? node(f5) : null; r.declare = !!(flags & 16); } return r; }
45
106
  case 4: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
46
107
  case 5: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
47
108
  case 6: return { params: fnParams(i) };
@@ -55,20 +116,20 @@ function node(i) {
55
116
  case 14: return { type: "ArrayExpression", start, end, elements: nodeArrHoles(f1, f0) };
56
117
  case 15: return { type: "ObjectExpression", start, end, properties: nodeArr(f1, f0) };
57
118
  case 16: return { type: "SpreadElement", start, end, argument: f1 !== NULL ? node(f1) : null };
58
- case 17: return { type: "Property", start, end, key: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null, kind: PROPERTY_KINDS[flags & 3], method: !!(flags & 4), shorthand: !!(flags & 8), computed: !!(flags & 16) };
119
+ case 17: { const r = { type: "Property", start, end, key: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null, kind: PROPERTY_KINDS[flags & 3], method: !!(flags & 4), shorthand: !!(flags & 8), computed: !!(flags & 16) }; if (_isTs) { r.optional = false; } return r; }
59
120
  case 18: return { type: "MemberExpression", start, end, object: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null, computed: !!(flags & 1), optional: !!(flags & 2) };
60
- case 19: return { type: "CallExpression", start, end, callee: f1 !== NULL ? node(f1) : null, arguments: nodeArr(f2, f0), optional: !!(flags & 1) };
121
+ case 19: { const r = { type: "CallExpression", start, end, callee: f1 !== NULL ? node(f1) : null, arguments: nodeArr(f2, f0), optional: !!(flags & 1) }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
61
122
  case 20: return { type: "ChainExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
62
- case 21: return { type: "TaggedTemplateExpression", start, end, tag: f1 !== NULL ? node(f1) : null, quasi: f2 !== NULL ? node(f2) : null };
63
- case 22: return { type: "NewExpression", start, end, callee: f1 !== NULL ? node(f1) : null, arguments: nodeArr(f2, f0) };
123
+ case 21: { const r = { type: "TaggedTemplateExpression", start, end, tag: f1 !== NULL ? node(f1) : null, quasi: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
124
+ case 22: { const r = { type: "NewExpression", start, end, callee: f1 !== NULL ? node(f1) : null, arguments: nodeArr(f2, f0) }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
64
125
  case 23: return { type: "AwaitExpression", start, end, argument: f1 !== NULL ? node(f1) : null };
65
126
  case 24: return { type: "YieldExpression", start, end, argument: f1 !== NULL ? node(f1) : null, delegate: !!(flags & 1) };
66
127
  case 25: return { type: "MetaProperty", start, end, meta: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
67
128
  case 26: return { type: "Decorator", start, end, expression: f1 !== NULL ? node(f1) : null };
68
- case 27: return { type: CLASS_TYPES[flags & 1], start, end, decorators: nodeArr(f1, f0), id: f2 !== NULL ? node(f2) : null, superClass: f3 !== NULL ? node(f3) : null, body: node(f4) };
129
+ case 27: { const r = { type: CLASS_TYPES[flags & 1], start, end, decorators: nodeArr(f1, f0), id: f2 !== NULL ? node(f2) : null, superClass: f3 !== NULL ? node(f3) : null, body: node(f4) }; if (_isTs) { r.typeParameters = f5 !== NULL ? node(f5) : null; r.superTypeArguments = f6 !== NULL ? node(f6) : null; r.implements = nodeArr(f7, f8); r.abstract = !!(flags & 2); r.declare = !!(flags & 4); } return r; }
69
130
  case 28: return { type: "ClassBody", start, end, body: nodeArr(f1, f0) };
70
- case 29: return { type: "MethodDefinition", start, end, decorators: nodeArr(f1, f0), key: f2 !== NULL ? node(f2) : null, value: f3 !== NULL ? node(f3) : null, kind: METHOD_KINDS[flags & 3], computed: !!(flags & 4), static: !!(flags & 8) };
71
- case 30: return { type: (flags & 4) ? "AccessorProperty" : "PropertyDefinition", start, end, decorators: nodeArr(f1, f0), key: node(f2), value: f3 !== NULL ? node(f3) : null, computed: !!(flags & 1), static: !!(flags & 2) };
131
+ case 29: { const r = { type: "MethodDefinition", start, end, decorators: nodeArr(f1, f0), key: node(f2), value: node(f3), kind: METHOD_KINDS[flags & 3], computed: !!(flags & 4), static: !!(flags & 8) }; if (_isTs) { r.override = !!(flags & 16); r.optional = !!(flags & 32); const _abs = !!(flags & 64); r.accessibility = ACCESSIBILITY[(flags >> 7) & 3]; if (_abs) r.type = "TSAbstractMethodDefinition"; } return r; }
132
+ case 30: { const _acc = !!(flags & 4); const r = { type: _acc ? "AccessorProperty" : "PropertyDefinition", start, end, decorators: nodeArr(f1, f0), key: node(f2), value: f3 !== NULL ? node(f3) : null, computed: !!(flags & 1), static: !!(flags & 2) }; if (_isTs) { r.typeAnnotation = f4 !== NULL ? node(f4) : null; r.declare = !!(flags & 8); r.override = !!(flags & 16); r.optional = !!(flags & 32); r.definite = !!(flags & 64); r.readonly = !!(flags & 128); const _abs = !!(flags & 256); r.accessibility = ACCESSIBILITY[(flags >> 9) & 3]; if (_abs) r.type = _acc ? "TSAbstractAccessorProperty" : "TSAbstractPropertyDefinition"; } return r; }
72
133
  case 31: return { type: "StaticBlock", start, end, body: nodeArr(f1, f0) };
73
134
  case 32: return { type: "Super", start, end };
74
135
  case 33: return { type: "Literal", start, end, value: str(f1, f2), raw: _src.slice(start, end) };
@@ -79,13 +140,13 @@ function node(i) {
79
140
  case 38: return { type: "ThisExpression", start, end };
80
141
  case 39: { const p = str(f1, f2), fl = str(f3, f4); let v = null; try { v = new RegExp(p, fl); } catch {} return { type: "Literal", start, end, value: v, raw: "/" + p + "/" + fl, regex: { pattern: p, flags: fl.split("").sort().join("") } }; }
81
142
  case 40: return { type: "TemplateLiteral", start, end, quasis: nodeArr(f1, f0), expressions: nodeArr(f2, f3) };
82
- case 41: { const r = _src.slice(start, end).replace(/\r\n?/g, "\n"); return { type: "TemplateElement", start, end, value: { raw: r, cooked: (flags & 2) ? null : str(f1, f2) }, tail: !!(flags & 1) }; }
83
- case 42: return { type: "Identifier", start, end, name: str(f1, f2) };
143
+ case 41: { const raw = _src.slice(start, end).replace(/\r\n?/g, "\n"); const tl = !!(flags & 1); const s = _isTs ? start - 1 : start; const e = _isTs ? (tl ? end + 1 : end + 2) : end; return { type: "TemplateElement", start: s, end: e, value: { raw, cooked: (flags & 2) ? null : str(f1, f2) }, tail: tl }; }
144
+ case 42: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
84
145
  case 43: return { type: "PrivateIdentifier", start, end, name: str(f1, f2) };
85
- case 44: return { type: "Identifier", start, end, name: str(f1, f2) };
86
- case 45: return { type: "Identifier", start, end, name: str(f1, f2) };
87
- case 46: return { type: "Identifier", start, end, name: str(f1, f2) };
88
- case 47: return { type: "ExpressionStatement", start, end, expression: f1 !== NULL ? node(f1) : null };
146
+ case 44: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = nodeArr(f3, f0); r.typeAnnotation = f4 !== NULL ? node(f4) : null; r.optional = !!(flags & 1); } return r; }
147
+ case 45: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
148
+ case 46: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
149
+ case 47: { const r = { type: "ExpressionStatement", start, end, expression: f1 !== NULL ? node(f1) : null }; if (_isTs) { r.directive = null; } return r; }
89
150
  case 48: return { type: "IfStatement", start, end, test: f1 !== NULL ? node(f1) : null, consequent: f2 !== NULL ? node(f2) : null, alternate: f3 !== NULL ? node(f3) : null };
90
151
  case 49: return { type: "SwitchStatement", start, end, discriminant: f1 !== NULL ? node(f1) : null, cases: nodeArr(f2, f0) };
91
152
  case 50: return { type: "SwitchCase", start, end, test: f1 !== NULL ? node(f1) : null, consequent: nodeArr(f2, f0) };
@@ -104,104 +165,113 @@ function node(i) {
104
165
  case 63: return { type: "CatchClause", start, end, param: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
105
166
  case 64: return { type: "DebuggerStatement", start, end };
106
167
  case 65: return { type: "EmptyStatement", start, end };
107
- case 66: return { type: "VariableDeclaration", start, end, kind: VAR_KINDS[flags & 7], declarations: nodeArr(f1, f0) };
108
- case 67: return { type: "VariableDeclarator", start, end, id: f1 !== NULL ? node(f1) : null, init: f2 !== NULL ? node(f2) : null };
168
+ case 66: { const r = { type: "VariableDeclaration", start, end, kind: VAR_KINDS[flags & 7], declarations: nodeArr(f1, f0) }; if (_isTs) { r.declare = !!(flags & 8); } return r; }
169
+ case 67: { const r = { type: "VariableDeclarator", start, end, id: f1 !== NULL ? node(f1) : null, init: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.definite = !!(flags & 1); } return r; }
109
170
  case 68: return { type: "ExpressionStatement", start, end, expression: node(f1), directive: str(f2, f3) };
110
- case 69: return { type: "AssignmentPattern", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null };
111
- case 70: return { type: "RestElement", start, end, argument: f1 !== NULL ? node(f1) : null };
112
- case 71: { const el = nodeArrHoles(f1, f0); if (f2 !== NULL) el.push(node(f2)); return { type: "ArrayPattern", start, end, elements: el }; }
113
- case 72: { const pr = nodeArr(f1, f0); if (f2 !== NULL) pr.push(node(f2)); return { type: "ObjectPattern", start, end, properties: pr }; }
114
- case 73: return { type: "Property", start, end, kind: "init", key: node(f1), value: node(f2), method: false, shorthand: !!(flags & 1), computed: !!(flags & 2) };
115
- case 74: return { type: "Program", start, end, sourceType: (flags & 1) ? "module" : "script", hashbang: (flags & 2) ? str(f2, f3) : null, body: nodeArr(f1, f0) };
171
+ case 69: { const r = { type: "AssignmentPattern", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.decorators = nodeArr(f3, f0); r.typeAnnotation = f4 !== NULL ? node(f4) : null; r.optional = !!(flags & 1); } return r; }
172
+ case 70: { const r = { type: "RestElement", start, end, argument: f1 !== NULL ? node(f1) : null }; if (_isTs) { r.decorators = nodeArr(f2, f0); r.typeAnnotation = f3 !== NULL ? node(f3) : null; r.optional = !!(flags & 1); r.value = null; } return r; }
173
+ case 71: { const el = nodeArrHoles(f1, f0); if (f2 !== NULL) el.push(node(f2)); const r = { type: "ArrayPattern", start, end, elements: el }; if (_isTs) { r.decorators = nodeArr(f3, f4); r.optional = !!(flags & 1); r.typeAnnotation = f5 !== NULL ? node(f5) : null; } return r; }
174
+ case 72: { const pr = nodeArr(f1, f0); if (f2 !== NULL) pr.push(node(f2)); const r = { type: "ObjectPattern", start, end, properties: pr }; if (_isTs) { r.decorators = nodeArr(f3, f4); r.optional = !!(flags & 1); r.typeAnnotation = f5 !== NULL ? node(f5) : null; } return r; }
175
+ case 73: { const r = { type: "Property", start, end, kind: "init", key: node(f1), value: node(f2), method: false, shorthand: !!(flags & 1), computed: !!(flags & 2) }; if (_isTs) { r.optional = false; } return r; }
176
+ case 74: return { type: "Program", start, end, sourceType: (flags & 1) ? "module" : "script", hashbang: (flags & 2) ? { type: "Hashbang", start: _p(f2 - 2), end: _p(f3), value: str(f2, f3) } : null, body: nodeArr(f1, f0) };
116
177
  case 75: return { type: "ImportExpression", start, end, source: f1 !== NULL ? node(f1) : null, options: f2 !== NULL ? node(f2) : null, phase: (flags & 1) ? ["source", "defer"][(flags >> 1) & 1] : null };
117
- case 76: return { type: "ImportDeclaration", start, end, specifiers: nodeArr(f1, f0), source: f2 !== NULL ? node(f2) : null, attributes: nodeArr(f3, f4), phase: (flags & 1) ? ["source", "defer"][(flags >> 1) & 1] : null };
118
- case 77: return { type: "ImportSpecifier", start, end, imported: f1 !== NULL ? node(f1) : null, local: f2 !== NULL ? node(f2) : null };
178
+ case 76: { const r = { type: "ImportDeclaration", start, end, specifiers: nodeArr(f1, f0), source: f2 !== NULL ? node(f2) : null, attributes: nodeArr(f3, f4), phase: (flags & 1) ? ["source", "defer"][(flags >> 1) & 1] : null }; if (_isTs) { r.importKind = IMPORT_EXPORT_KINDS[(flags >> 2) & 1]; } return r; }
179
+ case 77: { const r = { type: "ImportSpecifier", start, end, imported: f1 !== NULL ? node(f1) : null, local: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.importKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
119
180
  case 78: return { type: "ImportDefaultSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
120
181
  case 79: return { type: "ImportNamespaceSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
121
182
  case 80: return { type: "ImportAttribute", start, end, key: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null };
122
- case 81: return { type: "ExportNamedDeclaration", start, end, declaration: f1 !== NULL ? node(f1) : null, specifiers: nodeArr(f2, f0), source: f3 !== NULL ? node(f3) : null, attributes: nodeArr(f4, f5) };
123
- case 82: return { type: "ExportDefaultDeclaration", start, end, declaration: f1 !== NULL ? node(f1) : null };
124
- case 83: return { type: "ExportAllDeclaration", start, end, exported: f1 !== NULL ? node(f1) : null, source: f2 !== NULL ? node(f2) : null, attributes: nodeArr(f3, f0) };
125
- case 84: return { type: "ExportSpecifier", start, end, local: f1 !== NULL ? node(f1) : null, exported: f2 !== NULL ? node(f2) : null };
126
- case 85: return { type: "TSExportAssignment", start, end, expression: f1 !== NULL ? node(f1) : null };
127
- case 86: return { type: "TSNamespaceExportDeclaration", start, end, id: f1 !== NULL ? node(f1) : null };
128
- case 87: return { type: "JSXElement", start, end, openingElement: f1 !== NULL ? node(f1) : null, children: nodeArr(f2, f0), closingElement: f3 !== NULL ? node(f3) : null };
129
- case 88: return { type: "JSXOpeningElement", start, end, name: f1 !== NULL ? node(f1) : null, attributes: nodeArr(f2, f0), selfClosing: !!(flags & 1) };
130
- case 89: return { type: "JSXClosingElement", start, end, name: f1 !== NULL ? node(f1) : null };
131
- case 90: return { type: "JSXFragment", start, end, openingFragment: f1 !== NULL ? node(f1) : null, children: nodeArr(f2, f0), closingFragment: f3 !== NULL ? node(f3) : null };
132
- case 91: return { type: "JSXOpeningFragment", start, end, attributes: [], selfClosing: false };
133
- case 92: return { type: "JSXClosingFragment", start, end };
134
- case 93: return { type: "JSXIdentifier", start, end, name: str(f1, f2) };
135
- case 94: return { type: "JSXNamespacedName", start, end, namespace: f1 !== NULL ? node(f1) : null, name: f2 !== NULL ? node(f2) : null };
136
- case 95: return { type: "JSXMemberExpression", start, end, object: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
137
- case 96: return { type: "JSXAttribute", start, end, name: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null };
138
- case 97: return { type: "JSXSpreadAttribute", start, end, argument: f1 !== NULL ? node(f1) : null };
139
- case 98: return { type: "JSXExpressionContainer", start, end, expression: f1 !== NULL ? node(f1) : null };
140
- case 99: return { type: "JSXEmptyExpression", start, end };
141
- case 100: { const t = str(f1, f2); return { type: "JSXText", start, end, value: t, raw: t }; }
142
- case 101: return { type: "JSXSpreadChild", start, end, expression: f1 !== NULL ? node(f1) : null };
143
- }
144
- }
145
- function nodeArr(s, len) {
146
- const r = new Array(len);
147
- for (let j = 0; j < len; j++) r[j] = node(_u32[_extraBase + s + j]);
148
- return r;
149
- }
150
- function nodeArrHoles(s, len) {
151
- const r = new Array(len);
152
- for (let j = 0; j < len; j++) { const x = _u32[_extraBase + s + j]; r[j] = x !== NULL ? node(x) : null; }
153
- return r;
154
- }
155
- function fnParams(idx) {
156
- const po = _nodesOff + idx * 32;
157
- const len = _u8[po + 2] | (_u8[po + 3] << 8);
158
- const pb = po >> 2;
159
- const iStart = _u32[pb + 1], rest = _u32[pb + 2];
160
- const p = [];
161
- for (let j = 0; j < len; j++) {
162
- const fi = _u32[_extraBase + iStart + j];
163
- p.push(node(_u32[(_nodesOff + fi * 32 >> 2) + 1]));
164
- }
165
- if (rest !== NULL) p.push(node(rest));
166
- return p;
167
- }
168
- function buildPosMap(src, byteLen) {
169
- const m = new Uint32Array(byteLen + 1);
170
- let bp = 0, u16p = 0;
171
- for (let i = 0; i < src.length; i++) {
172
- m[bp] = u16p;
173
- const cp = src.codePointAt(i);
174
- let bytes = 1;
175
- if (cp > 0x7F) { if (cp > 0x7FF) { bytes = cp > 0xFFFF ? 4 : 3; } else { bytes = 2; } }
176
- const units = bytes === 4 ? 2 : 1;
177
- u16p += units;
178
- for (let k = 1; k < bytes; k++) m[bp + k] = u16p;
179
- bp += bytes;
180
- if (bytes === 4) i++;
181
- }
182
- m[byteLen] = u16p;
183
- return m;
184
- }
185
- function decode(buffer, source) {
186
- _u8 = new Uint8Array(buffer);
187
- const aLen = (buffer.byteLength >> 2) << 2;
188
- _u32 = new Uint32Array(buffer, 0, aLen >> 2);
189
- _src = source;
190
- _srcLen = _u32[5];
191
- const nodeCount = _u32[2], extraCount = _u32[3], spLen = _u32[4];
192
- const commentCount = _u32[6], diagCount = _u32[7], progIdx = _u32[8];
193
- const pm = (_u32[9] & 1) ? null : buildPosMap(source, _srcLen);
194
- if (pm) {
195
- _p = function(v) { return pm[v]; };
196
- str = function(s, e) { if (s === e) return ""; if (s < _srcLen) return _src.slice(pm[s], pm[e]); return _poolDecode(s, e); };
197
- } else {
198
- _p = function(v) { return v; };
199
- str = function(s, e) { if (s === e) return ""; if (s < _srcLen) return _src.slice(s, e); return _poolDecode(s, e); };
183
+ case 81: { const r = { type: "ExportNamedDeclaration", start, end, declaration: f1 !== NULL ? node(f1) : null, specifiers: nodeArr(f2, f0), source: f3 !== NULL ? node(f3) : null, attributes: nodeArr(f4, f5) }; if (_isTs) { r.exportKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
184
+ case 82: { const r = { type: "ExportDefaultDeclaration", start, end, declaration: f1 !== NULL ? node(f1) : null }; if (_isTs) { r.exportKind = "value"; } return r; }
185
+ case 83: { const r = { type: "ExportAllDeclaration", start, end, exported: f1 !== NULL ? node(f1) : null, source: f2 !== NULL ? node(f2) : null, attributes: nodeArr(f3, f0) }; if (_isTs) { r.exportKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
186
+ case 84: { const r = { type: "ExportSpecifier", start, end, local: f1 !== NULL ? node(f1) : null, exported: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.exportKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
187
+ case 85: return { type: "TSTypeAnnotation", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
188
+ case 86: return { type: "TSAnyKeyword", start, end };
189
+ case 87: return { type: "TSUnknownKeyword", start, end };
190
+ case 88: return { type: "TSNeverKeyword", start, end };
191
+ case 89: return { type: "TSVoidKeyword", start, end };
192
+ case 90: return { type: "TSNullKeyword", start, end };
193
+ case 91: return { type: "TSUndefinedKeyword", start, end };
194
+ case 92: return { type: "TSStringKeyword", start, end };
195
+ case 93: return { type: "TSNumberKeyword", start, end };
196
+ case 94: return { type: "TSBigIntKeyword", start, end };
197
+ case 95: return { type: "TSBooleanKeyword", start, end };
198
+ case 96: return { type: "TSSymbolKeyword", start, end };
199
+ case 97: return { type: "TSObjectKeyword", start, end };
200
+ case 98: return { type: "TSIntrinsicKeyword", start, end };
201
+ case 99: return { type: "TSThisType", start, end };
202
+ case 100: return { type: "TSTypeReference", start, end, typeName: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
203
+ case 101: return { type: "TSQualifiedName", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null };
204
+ case 102: return { type: "TSTypeQuery", start, end, exprName: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
205
+ case 103: return { type: "TSImportType", start, end, source: f1 !== NULL ? node(f1) : null, options: f2 !== NULL ? node(f2) : null, qualifier: f3 !== NULL ? node(f3) : null, typeArguments: f4 !== NULL ? node(f4) : null };
206
+ case 104: return { type: "TSTypeParameter", start, end, name: f1 !== NULL ? node(f1) : null, constraint: f2 !== NULL ? node(f2) : null, default: f3 !== NULL ? node(f3) : null, in: !!(flags & 1), out: !!(flags & 2), const: !!(flags & 4) };
207
+ case 105: return { type: "TSTypeParameterDeclaration", start, end, params: nodeArr(f1, f0) };
208
+ case 106: return { type: "TSTypeParameterInstantiation", start, end, params: nodeArr(f1, f0) };
209
+ case 107: return { type: "TSLiteralType", start, end, literal: f1 !== NULL ? node(f1) : null };
210
+ case 108: return { type: "TSTemplateLiteralType", start, end, quasis: nodeArr(f1, f0), types: nodeArr(f2, f3) };
211
+ case 109: return { type: "TSArrayType", start, end, elementType: f1 !== NULL ? node(f1) : null };
212
+ case 110: return { type: "TSIndexedAccessType", start, end, objectType: f1 !== NULL ? node(f1) : null, indexType: f2 !== NULL ? node(f2) : null };
213
+ case 111: return { type: "TSTupleType", start, end, elementTypes: nodeArr(f1, f0) };
214
+ case 112: return { type: "TSNamedTupleMember", start, end, label: f1 !== NULL ? node(f1) : null, elementType: f2 !== NULL ? node(f2) : null, optional: !!(flags & 1) };
215
+ case 113: return { type: "TSOptionalType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
216
+ case 114: return { type: "TSRestType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
217
+ case 115: return { type: "TSJSDocNullableType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null, postfix: !!(flags & 1) };
218
+ case 116: return { type: "TSJSDocNonNullableType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null, postfix: !!(flags & 1) };
219
+ case 117: return { type: "TSJSDocUnknownType", start, end };
220
+ case 118: return { type: "TSUnionType", start, end, types: nodeArr(f1, f0) };
221
+ case 119: return { type: "TSIntersectionType", start, end, types: nodeArr(f1, f0) };
222
+ case 120: return { type: "TSConditionalType", start, end, checkType: f1 !== NULL ? node(f1) : null, extendsType: f2 !== NULL ? node(f2) : null, trueType: f3 !== NULL ? node(f3) : null, falseType: f4 !== NULL ? node(f4) : null };
223
+ case 121: return { type: "TSInferType", start, end, typeParameter: f1 !== NULL ? node(f1) : null };
224
+ case 122: return { type: "TSTypeOperator", start, end, operator: TS_TYPE_OPERATORS[flags & 3], typeAnnotation: f1 !== NULL ? node(f1) : null };
225
+ case 123: return { type: "TSParenthesizedType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
226
+ case 124: return { type: "TSFunctionType", start, end, typeParameters: f1 !== NULL ? node(f1) : null, params: f2 !== NULL ? fnParams(f2) : [], returnType: f3 !== NULL ? node(f3) : null };
227
+ case 125: return { type: "TSConstructorType", start, end, abstract: !!(flags & 1), typeParameters: f1 !== NULL ? node(f1) : null, params: f2 !== NULL ? fnParams(f2) : [], returnType: f3 !== NULL ? node(f3) : null };
228
+ case 126: return { type: "TSTypePredicate", start, end, parameterName: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null, asserts: !!(flags & 1) };
229
+ case 127: return { type: "TSTypeLiteral", start, end, members: nodeArr(f1, f0) };
230
+ case 128: return { type: "TSMappedType", start, end, key: node(f1), constraint: node(f2), nameType: f3 !== NULL ? node(f3) : null, typeAnnotation: f4 !== NULL ? node(f4) : null, optional: TS_MAPPED_OPTIONAL[(flags >> 0) & 3], readonly: TS_MAPPED_READONLY[(flags >> 2) & 3] };
231
+ case 129: { const r = { type: "TSPropertySignature", start, end, key: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null, computed: !!(flags & 1), optional: !!(flags & 2), readonly: !!(flags & 4) }; if (_isTs) { r.accessibility = null; r.static = false; } return r; }
232
+ case 130: return { type: "TSMethodSignature", start, end, key: node(f1), computed: !!(flags & 4), optional: !!(flags & 8), kind: TS_METHOD_SIGNATURE_KINDS[(flags >> 0) & 3], typeParameters: f2 !== NULL ? node(f2) : null, params: f3 !== NULL ? fnParams(f3) : [], returnType: f4 !== NULL ? node(f4) : null, accessibility: null, readonly: false, static: false };
233
+ case 131: return { type: "TSCallSignatureDeclaration", start, end, typeParameters: f1 !== NULL ? node(f1) : null, params: f2 !== NULL ? fnParams(f2) : [], returnType: f3 !== NULL ? node(f3) : null };
234
+ case 132: return { type: "TSConstructSignatureDeclaration", start, end, typeParameters: f1 !== NULL ? node(f1) : null, params: f2 !== NULL ? fnParams(f2) : [], returnType: f3 !== NULL ? node(f3) : null };
235
+ case 133: { const r = { type: "TSIndexSignature", start, end, parameters: nodeArr(f1, f0), typeAnnotation: f2 !== NULL ? node(f2) : null, readonly: !!(flags & 1) }; if (_isTs) { r.static = !!(flags & 2); r.accessibility = null; } return r; }
236
+ case 134: return { type: "TSTypeAliasDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, typeParameters: f2 !== NULL ? node(f2) : null, typeAnnotation: f3 !== NULL ? node(f3) : null, declare: !!(flags & 1) };
237
+ case 135: return { type: "TSInterfaceDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, typeParameters: f2 !== NULL ? node(f2) : null, extends: nodeArr(f3, f0), body: f4 !== NULL ? node(f4) : null, declare: !!(flags & 1) };
238
+ case 136: return { type: "TSInterfaceBody", start, end, body: nodeArr(f1, f0) };
239
+ case 137: return { type: "TSInterfaceHeritage", start, end, expression: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
240
+ case 138: return { type: "TSClassImplements", start, end, expression: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
241
+ case 139: return { type: "TSEnumDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null, const: !!(flags & 1), declare: !!(flags & 2) };
242
+ case 140: return { type: "TSEnumBody", start, end, members: nodeArr(f1, f0) };
243
+ case 141: return { type: "TSEnumMember", start, end, id: f1 !== NULL ? node(f1) : null, initializer: f2 !== NULL ? node(f2) : null, computed: !!(flags & 1) };
244
+ case 142: { const r = { type: "TSModuleDeclaration", start, end, id: node(f1), kind: TS_MODULE_KINDS[(flags >> 0) & 1], declare: !!(flags & 2), global: false }; if (f2 !== NULL) r.body = node(f2); return r; }
245
+ case 143: return { type: "TSModuleBlock", start, end, body: nodeArr(f1, f0) };
246
+ case 144: return { type: "TSModuleDeclaration", start, end, id: node(f1), body: node(f2), kind: "global", declare: !!(flags & 1), global: true };
247
+ case 145: { const r = { type: "TSParameterProperty", start, end, decorators: nodeArr(f1, f0), parameter: f2 !== NULL ? node(f2) : null, override: !!(flags & 1), readonly: !!(flags & 2), accessibility: ACCESSIBILITY[(flags >> 2) & 3] }; if (_isTs) { r.static = false; } return r; }
248
+ case 146: return { type: "Identifier", start, end, decorators: [], name: "this", optional: false, typeAnnotation: f1 !== NULL ? node(f1) : null };
249
+ case 147: return { type: "TSAsExpression", start, end, expression: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null };
250
+ case 148: return { type: "TSSatisfiesExpression", start, end, expression: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null };
251
+ case 149: return { type: "TSTypeAssertion", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null, expression: f2 !== NULL ? node(f2) : null };
252
+ case 150: return { type: "TSNonNullExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
253
+ case 151: return { type: "TSInstantiationExpression", start, end, expression: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
254
+ case 152: return { type: "TSExportAssignment", start, end, expression: f1 !== NULL ? node(f1) : null };
255
+ case 153: return { type: "TSNamespaceExportDeclaration", start, end, id: f1 !== NULL ? node(f1) : null };
256
+ case 154: return { type: "TSImportEqualsDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, moduleReference: f2 !== NULL ? node(f2) : null, importKind: IMPORT_EXPORT_KINDS[flags & 1] };
257
+ case 155: return { type: "TSExternalModuleReference", start, end, expression: f1 !== NULL ? node(f1) : null };
258
+ case 156: return { type: "JSXElement", start, end, openingElement: f1 !== NULL ? node(f1) : null, children: nodeArr(f2, f0), closingElement: f3 !== NULL ? node(f3) : null };
259
+ case 157: { const r = { type: "JSXOpeningElement", start, end, name: f1 !== NULL ? node(f1) : null, attributes: nodeArr(f2, f0), selfClosing: !!(flags & 1) }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
260
+ case 158: return { type: "JSXClosingElement", start, end, name: f1 !== NULL ? node(f1) : null };
261
+ case 159: return { type: "JSXFragment", start, end, openingFragment: f1 !== NULL ? node(f1) : null, children: nodeArr(f2, f0), closingFragment: f3 !== NULL ? node(f3) : null };
262
+ case 160: return { type: "JSXOpeningFragment", start, end };
263
+ case 161: return { type: "JSXClosingFragment", start, end };
264
+ case 162: return { type: "JSXIdentifier", start, end, name: str(f1, f2) };
265
+ case 163: return { type: "JSXNamespacedName", start, end, namespace: f1 !== NULL ? node(f1) : null, name: f2 !== NULL ? node(f2) : null };
266
+ case 164: return { type: "JSXMemberExpression", start, end, object: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
267
+ case 165: return { type: "JSXAttribute", start, end, name: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null };
268
+ case 166: return { type: "JSXSpreadAttribute", start, end, argument: f1 !== NULL ? node(f1) : null };
269
+ case 167: return { type: "JSXExpressionContainer", start, end, expression: f1 !== NULL ? node(f1) : null };
270
+ case 168: return { type: "JSXEmptyExpression", start, end };
271
+ case 169: { const t = str(f1, f2); return { type: "JSXText", start, end, value: t, raw: t }; }
272
+ case 170: return { type: "JSXSpreadChild", start, end, expression: f1 !== NULL ? node(f1) : null };
273
+ }
200
274
  }
201
- _nodesOff = 40;
202
- const eOff = _nodesOff + nodeCount * 32;
203
- _extraBase = eOff >> 2;
204
- _spOff = eOff + extraCount * 4;
205
275
  const cOff = _spOff + spLen, dOff = cOff + commentCount * 20;
206
276
  const dv = new DataView(buffer);
207
277
  const comments = new Array(commentCount);
@@ -230,8 +300,6 @@ function decode(buffer, source) {
230
300
  }
231
301
  diagnostics[j] = { severity: sev, message: msg, start: ds, end: de, help, labels };
232
302
  }
233
- const program = node(progIdx);
234
- _u8 = _u32 = _src = null;
235
- return { program, comments, diagnostics };
303
+ return { program: node(progIdx), comments, diagnostics };
236
304
  }
237
305
  export { decode };