yuku-parser 0.5.0-beta.2 → 0.5.2
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/decode.js +305 -0
- package/package.json +36 -13
package/decode.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// generated by tools/gen_estree_decoder.zig, do not edit
|
|
2
|
+
const NULL = 0xFFFFFFFF;
|
|
3
|
+
const _td = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
4
|
+
const BINARY_OPS = ["==", "!=", "===", "!==", "<", "<=", ">", ">=", "+", "-", "*", "/", "%", "**", "|", "^", "&", "<<", ">>", ">>>", "in", "instanceof"];
|
|
5
|
+
const LOGICAL_OPS = ["&&", "||", "??"];
|
|
6
|
+
const UNARY_OPS = ["-", "+", "!", "~", "typeof", "void", "delete"];
|
|
7
|
+
const UPDATE_OPS = ["++", "--"];
|
|
8
|
+
const ASSIGNMENT_OPS = ["=", "+=", "-=", "*=", "/=", "%=", "**=", "<<=", ">>=", ">>>=", "|=", "^=", "&=", "||=", "&&=", "??="];
|
|
9
|
+
const VAR_KINDS = ["var", "let", "const", "using", "await using"];
|
|
10
|
+
const PROPERTY_KINDS = ["init", "get", "set"];
|
|
11
|
+
const METHOD_KINDS = ["constructor", "method", "get", "set"];
|
|
12
|
+
const FUNCTION_TYPES = ["FunctionDeclaration", "FunctionExpression", "TSDeclareFunction", "TSEmptyBodyFunctionExpression"];
|
|
13
|
+
const CLASS_TYPES = ["ClassDeclaration", "ClassExpression"];
|
|
14
|
+
const COMMENT_TYPES = ["Line", "Block"];
|
|
15
|
+
const SEVERITY = ["error", "warning", "hint", "info"];
|
|
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++;
|
|
36
|
+
}
|
|
37
|
+
m[byteLen] = u16p;
|
|
38
|
+
return m;
|
|
39
|
+
}
|
|
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) {
|
|
102
|
+
case 0: return { type: "SequenceExpression", start, end, expressions: nodeArr(f1, f0) };
|
|
103
|
+
case 1: return { type: "ParenthesizedExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
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; }
|
|
106
|
+
case 4: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
|
|
107
|
+
case 5: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
|
|
108
|
+
case 6: return { params: fnParams(i) };
|
|
109
|
+
case 7: return node(f1);
|
|
110
|
+
case 8: return { type: "BinaryExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: BINARY_OPS[flags & 31] };
|
|
111
|
+
case 9: return { type: "LogicalExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: LOGICAL_OPS[flags & 3] };
|
|
112
|
+
case 10: return { type: "ConditionalExpression", start, end, test: f1 !== NULL ? node(f1) : null, consequent: f2 !== NULL ? node(f2) : null, alternate: f3 !== NULL ? node(f3) : null };
|
|
113
|
+
case 11: return { type: "UnaryExpression", start, end, operator: UNARY_OPS[flags & 7], prefix: true, argument: f1 !== NULL ? node(f1) : null };
|
|
114
|
+
case 12: return { type: "UpdateExpression", start, end, argument: f1 !== NULL ? node(f1) : null, operator: UPDATE_OPS[flags & 1], prefix: !!(flags & 2) };
|
|
115
|
+
case 13: return { type: "AssignmentExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: ASSIGNMENT_OPS[flags & 15] };
|
|
116
|
+
case 14: return { type: "ArrayExpression", start, end, elements: nodeArrHoles(f1, f0) };
|
|
117
|
+
case 15: return { type: "ObjectExpression", start, end, properties: nodeArr(f1, f0) };
|
|
118
|
+
case 16: return { type: "SpreadElement", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
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; }
|
|
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) };
|
|
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; }
|
|
122
|
+
case 20: return { type: "ChainExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
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; }
|
|
125
|
+
case 23: return { type: "AwaitExpression", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
126
|
+
case 24: return { type: "YieldExpression", start, end, argument: f1 !== NULL ? node(f1) : null, delegate: !!(flags & 1) };
|
|
127
|
+
case 25: return { type: "MetaProperty", start, end, meta: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
|
|
128
|
+
case 26: return { type: "Decorator", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
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; }
|
|
130
|
+
case 28: return { type: "ClassBody", start, end, body: nodeArr(f1, f0) };
|
|
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; }
|
|
133
|
+
case 31: return { type: "StaticBlock", start, end, body: nodeArr(f1, f0) };
|
|
134
|
+
case 32: return { type: "Super", start, end };
|
|
135
|
+
case 33: return { type: "Literal", start, end, value: str(f1, f2), raw: _src.slice(start, end) };
|
|
136
|
+
case 34: { const r = _src.slice(start, end); const s = r.indexOf("_") === -1 ? r : r.replace(/_/g, ""); const v = (flags & 3) === 2 && s[1] !== "o" && s[1] !== "O" ? parseInt(s.slice(1), 8) : +s; return { type: "Literal", start, end, value: v === v && isFinite(v) ? v : null, raw: r }; }
|
|
137
|
+
case 35: { const r = _src.slice(start, end); const d = str(f1, f2).replace(/_/g, ""); const v = BigInt(d); return { type: "Literal", start, end, value: v, raw: r, bigint: v.toString() }; }
|
|
138
|
+
case 36: { const v = !!(flags & 1); return { type: "Literal", start, end, value: v, raw: v ? "true" : "false" }; }
|
|
139
|
+
case 37: return { type: "Literal", start, end, value: null, raw: "null" };
|
|
140
|
+
case 38: return { type: "ThisExpression", start, end };
|
|
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("") } }; }
|
|
142
|
+
case 40: return { type: "TemplateLiteral", start, end, quasis: nodeArr(f1, f0), expressions: nodeArr(f2, f3) };
|
|
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; }
|
|
145
|
+
case 43: return { type: "PrivateIdentifier", start, end, name: str(f1, f2) };
|
|
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; }
|
|
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 };
|
|
151
|
+
case 49: return { type: "SwitchStatement", start, end, discriminant: f1 !== NULL ? node(f1) : null, cases: nodeArr(f2, f0) };
|
|
152
|
+
case 50: return { type: "SwitchCase", start, end, test: f1 !== NULL ? node(f1) : null, consequent: nodeArr(f2, f0) };
|
|
153
|
+
case 51: return { type: "ForStatement", start, end, init: f1 !== NULL ? node(f1) : null, test: f2 !== NULL ? node(f2) : null, update: f3 !== NULL ? node(f3) : null, body: f4 !== NULL ? node(f4) : null };
|
|
154
|
+
case 52: return { type: "ForInStatement", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, body: f3 !== NULL ? node(f3) : null };
|
|
155
|
+
case 53: return { type: "ForOfStatement", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, body: f3 !== NULL ? node(f3) : null, await: !!(flags & 1) };
|
|
156
|
+
case 54: return { type: "WhileStatement", start, end, test: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
157
|
+
case 55: return { type: "DoWhileStatement", start, end, body: f1 !== NULL ? node(f1) : null, test: f2 !== NULL ? node(f2) : null };
|
|
158
|
+
case 56: return { type: "BreakStatement", start, end, label: f1 !== NULL ? node(f1) : null };
|
|
159
|
+
case 57: return { type: "ContinueStatement", start, end, label: f1 !== NULL ? node(f1) : null };
|
|
160
|
+
case 58: return { type: "LabeledStatement", start, end, label: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
161
|
+
case 59: return { type: "WithStatement", start, end, object: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
162
|
+
case 60: return { type: "ReturnStatement", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
163
|
+
case 61: return { type: "ThrowStatement", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
164
|
+
case 62: return { type: "TryStatement", start, end, block: f1 !== NULL ? node(f1) : null, handler: f2 !== NULL ? node(f2) : null, finalizer: f3 !== NULL ? node(f3) : null };
|
|
165
|
+
case 63: return { type: "CatchClause", start, end, param: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
166
|
+
case 64: return { type: "DebuggerStatement", start, end };
|
|
167
|
+
case 65: return { type: "EmptyStatement", start, end };
|
|
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; }
|
|
170
|
+
case 68: return { type: "ExpressionStatement", start, end, expression: node(f1), directive: str(f2, f3) };
|
|
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) };
|
|
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 };
|
|
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; }
|
|
180
|
+
case 78: return { type: "ImportDefaultSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
|
|
181
|
+
case 79: return { type: "ImportNamespaceSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
|
|
182
|
+
case 80: return { type: "ImportAttribute", start, end, key: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null };
|
|
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
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const cOff = _spOff + spLen, dOff = cOff + commentCount * 20;
|
|
276
|
+
const dv = new DataView(buffer);
|
|
277
|
+
const comments = new Array(commentCount);
|
|
278
|
+
for (let j = 0; j < commentCount; j++) {
|
|
279
|
+
const o = cOff + j * 20;
|
|
280
|
+
comments[j] = { type: COMMENT_TYPES[_u8[o]], value: str(dv.getUint32(o + 12, true), dv.getUint32(o + 16, true)), start: _p(dv.getUint32(o + 4, true)), end: _p(dv.getUint32(o + 8, true)) };
|
|
281
|
+
}
|
|
282
|
+
const diagnostics = new Array(diagCount);
|
|
283
|
+
let dp = dOff;
|
|
284
|
+
for (let j = 0; j < diagCount; j++) {
|
|
285
|
+
const sev = SEVERITY[_u8[dp]]; dp++;
|
|
286
|
+
const ds = _p(dv.getUint32(dp, true)); dp += 4;
|
|
287
|
+
const de = _p(dv.getUint32(dp, true)); dp += 4;
|
|
288
|
+
const ml = dv.getUint32(dp, true); dp += 4;
|
|
289
|
+
const msg = _td.decode(_u8.subarray(dp, dp + ml)); dp += ml;
|
|
290
|
+
const hh = _u8[dp]; dp++;
|
|
291
|
+
let help = null;
|
|
292
|
+
if (hh) { const hl = dv.getUint32(dp, true); dp += 4; help = _td.decode(_u8.subarray(dp, dp + hl)); dp += hl; }
|
|
293
|
+
const lc = dv.getUint32(dp, true); dp += 4;
|
|
294
|
+
const labels = new Array(lc);
|
|
295
|
+
for (let k = 0; k < lc; k++) {
|
|
296
|
+
const ls = _p(dv.getUint32(dp, true)); dp += 4;
|
|
297
|
+
const le = _p(dv.getUint32(dp, true)); dp += 4;
|
|
298
|
+
const lml = dv.getUint32(dp, true); dp += 4;
|
|
299
|
+
labels[k] = { start: ls, end: le, message: _td.decode(_u8.subarray(dp, dp + lml)) }; dp += lml;
|
|
300
|
+
}
|
|
301
|
+
diagnostics[j] = { severity: sev, message: msg, start: ds, end: de, help, labels };
|
|
302
|
+
}
|
|
303
|
+
return { program: node(progIdx), comments, diagnostics };
|
|
304
|
+
}
|
|
305
|
+
export { decode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuku-parser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "High-performance JavaScript/TypeScript parser",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,21 +9,44 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"index.js",
|
|
11
11
|
"index.d.ts",
|
|
12
|
-
"binding.js"
|
|
12
|
+
"binding.js",
|
|
13
|
+
"decode.js"
|
|
13
14
|
],
|
|
14
15
|
"optionalDependencies": {
|
|
15
|
-
"@yuku-parser/binding-linux-x64-gnu": "0.5.
|
|
16
|
-
"@yuku-parser/binding-linux-arm64-gnu": "0.5.
|
|
17
|
-
"@yuku-parser/binding-linux-arm-gnu": "0.5.
|
|
18
|
-
"@yuku-parser/binding-linux-x64-musl": "0.5.
|
|
19
|
-
"@yuku-parser/binding-linux-arm64-musl": "0.5.
|
|
20
|
-
"@yuku-parser/binding-linux-arm-musl": "0.5.
|
|
21
|
-
"@yuku-parser/binding-darwin-x64": "0.5.
|
|
22
|
-
"@yuku-parser/binding-darwin-arm64": "0.5.
|
|
23
|
-
"@yuku-parser/binding-win32-x64": "0.5.
|
|
24
|
-
"@yuku-parser/binding-win32-arm64": "0.5.
|
|
25
|
-
"@yuku-parser/binding-freebsd-x64": "0.5.
|
|
16
|
+
"@yuku-parser/binding-linux-x64-gnu": "0.5.2",
|
|
17
|
+
"@yuku-parser/binding-linux-arm64-gnu": "0.5.2",
|
|
18
|
+
"@yuku-parser/binding-linux-arm-gnu": "0.5.2",
|
|
19
|
+
"@yuku-parser/binding-linux-x64-musl": "0.5.2",
|
|
20
|
+
"@yuku-parser/binding-linux-arm64-musl": "0.5.2",
|
|
21
|
+
"@yuku-parser/binding-linux-arm-musl": "0.5.2",
|
|
22
|
+
"@yuku-parser/binding-darwin-x64": "0.5.2",
|
|
23
|
+
"@yuku-parser/binding-darwin-arm64": "0.5.2",
|
|
24
|
+
"@yuku-parser/binding-win32-x64": "0.5.2",
|
|
25
|
+
"@yuku-parser/binding-win32-arm64": "0.5.2",
|
|
26
|
+
"@yuku-parser/binding-freebsd-x64": "0.5.2"
|
|
26
27
|
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"parser",
|
|
30
|
+
"javascript",
|
|
31
|
+
"typescript",
|
|
32
|
+
"js",
|
|
33
|
+
"ts",
|
|
34
|
+
"ast",
|
|
35
|
+
"ecmascript",
|
|
36
|
+
"jsx",
|
|
37
|
+
"tsx",
|
|
38
|
+
"tokenizer",
|
|
39
|
+
"lexer",
|
|
40
|
+
"compiler",
|
|
41
|
+
"rust",
|
|
42
|
+
"napi",
|
|
43
|
+
"fast",
|
|
44
|
+
"swc",
|
|
45
|
+
"acorn",
|
|
46
|
+
"babel",
|
|
47
|
+
"oxc",
|
|
48
|
+
"espree"
|
|
49
|
+
],
|
|
27
50
|
"repository": {
|
|
28
51
|
"type": "git",
|
|
29
52
|
"url": "https://github.com/yuku-toolchain/yuku.git"
|