yuku-parser 0.4.6 → 0.5.0-beta.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.
Files changed (4) hide show
  1. package/index.d.ts +1139 -93
  2. package/index.js +20 -1
  3. package/package.json +20 -21
  4. package/decode.js +0 -237
package/index.js CHANGED
@@ -3,5 +3,24 @@ import { decode } from "./decode.js";
3
3
 
4
4
  export function parse(source, options) {
5
5
  const buffer = binding.parse(source, options ?? {});
6
- return decode(buffer, source);
6
+ let decoded = null;
7
+
8
+ const getDecoded = () => {
9
+ if (decoded === null) {
10
+ decoded = decode(buffer, source);
11
+ }
12
+ return decoded;
13
+ };
14
+
15
+ return {
16
+ get program() {
17
+ return getDecoded().program;
18
+ },
19
+ get comments() {
20
+ return getDecoded().comments;
21
+ },
22
+ get diagnostics() {
23
+ return getDecoded().diagnostics;
24
+ },
25
+ };
7
26
  }
package/package.json CHANGED
@@ -1,32 +1,31 @@
1
1
  {
2
2
  "name": "yuku-parser",
3
- "version": "0.4.6",
3
+ "version": "0.5.0-beta.2",
4
4
  "description": "High-performance JavaScript/TypeScript parser",
5
5
  "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/yuku-toolchain/yuku.git"
9
- },
6
+ "type": "module",
7
+ "main": "index.js",
8
+ "types": "index.d.ts",
10
9
  "files": [
11
10
  "index.js",
12
11
  "index.d.ts",
13
- "binding.js",
14
- "decode.js"
12
+ "binding.js"
15
13
  ],
16
- "type": "module",
17
- "main": "index.js",
18
- "types": "index.d.ts",
19
14
  "optionalDependencies": {
20
- "@yuku-parser/binding-darwin-arm64": "0.4.6",
21
- "@yuku-parser/binding-darwin-x64": "0.4.6",
22
- "@yuku-parser/binding-freebsd-x64": "0.4.6",
23
- "@yuku-parser/binding-linux-arm-gnu": "0.4.6",
24
- "@yuku-parser/binding-linux-arm-musl": "0.4.6",
25
- "@yuku-parser/binding-linux-arm64-gnu": "0.4.6",
26
- "@yuku-parser/binding-linux-arm64-musl": "0.4.6",
27
- "@yuku-parser/binding-linux-x64-gnu": "0.4.6",
28
- "@yuku-parser/binding-linux-x64-musl": "0.4.6",
29
- "@yuku-parser/binding-win32-arm64": "0.4.6",
30
- "@yuku-parser/binding-win32-x64": "0.4.6"
15
+ "@yuku-parser/binding-linux-x64-gnu": "0.5.0-beta.2",
16
+ "@yuku-parser/binding-linux-arm64-gnu": "0.5.0-beta.2",
17
+ "@yuku-parser/binding-linux-arm-gnu": "0.5.0-beta.2",
18
+ "@yuku-parser/binding-linux-x64-musl": "0.5.0-beta.2",
19
+ "@yuku-parser/binding-linux-arm64-musl": "0.5.0-beta.2",
20
+ "@yuku-parser/binding-linux-arm-musl": "0.5.0-beta.2",
21
+ "@yuku-parser/binding-darwin-x64": "0.5.0-beta.2",
22
+ "@yuku-parser/binding-darwin-arm64": "0.5.0-beta.2",
23
+ "@yuku-parser/binding-win32-x64": "0.5.0-beta.2",
24
+ "@yuku-parser/binding-win32-arm64": "0.5.0-beta.2",
25
+ "@yuku-parser/binding-freebsd-x64": "0.5.0-beta.2"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/yuku-toolchain/yuku.git"
31
30
  }
32
31
  }
package/decode.js DELETED
@@ -1,237 +0,0 @@
1
- // generated by tools/gen_estree_decoder.zig, do not edit
2
- const NULL = 0xFFFFFFFF;
3
- const BINARY_OPS = ["==", "!=", "===", "!==", "<", "<=", ">", ">=", "+", "-", "*", "/", "%", "**", "|", "^", "&", "<<", ">>", ">>>", "in", "instanceof"];
4
- const LOGICAL_OPS = ["&&", "||", "??"];
5
- const UNARY_OPS = ["-", "+", "!", "~", "typeof", "void", "delete"];
6
- const UPDATE_OPS = ["++", "--"];
7
- const ASSIGNMENT_OPS = ["=", "+=", "-=", "*=", "/=", "%=", "**=", "<<=", ">>=", ">>>=", "|=", "^=", "&=", "||=", "&&=", "??="];
8
- const VAR_KINDS = ["var", "let", "const", "using", "await using"];
9
- const PROPERTY_KINDS = ["init", "get", "set"];
10
- const METHOD_KINDS = ["constructor", "method", "get", "set"];
11
- const FUNCTION_TYPES = ["FunctionDeclaration", "FunctionExpression", "TSDeclareFunction", "TSEmptyBodyFunctionExpression"];
12
- const CLASS_TYPES = ["ClassDeclaration", "ClassExpression"];
13
- const COMMENT_TYPES = ["Line", "Block"];
14
- 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; }
29
- }
30
- return r;
31
- }
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) {
41
- case 0: return { type: "SequenceExpression", start, end, expressions: nodeArr(f1, f0) };
42
- 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; }
45
- case 4: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
46
- case 5: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
47
- case 6: return { params: fnParams(i) };
48
- case 7: return node(f1);
49
- case 8: return { type: "BinaryExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: BINARY_OPS[flags & 31] };
50
- case 9: return { type: "LogicalExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: LOGICAL_OPS[flags & 3] };
51
- 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 };
52
- case 11: return { type: "UnaryExpression", start, end, operator: UNARY_OPS[flags & 7], prefix: true, argument: f1 !== NULL ? node(f1) : null };
53
- case 12: return { type: "UpdateExpression", start, end, argument: f1 !== NULL ? node(f1) : null, operator: UPDATE_OPS[flags & 1], prefix: !!(flags & 2) };
54
- case 13: return { type: "AssignmentExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: ASSIGNMENT_OPS[flags & 15] };
55
- case 14: return { type: "ArrayExpression", start, end, elements: nodeArrHoles(f1, f0) };
56
- case 15: return { type: "ObjectExpression", start, end, properties: nodeArr(f1, f0) };
57
- 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) };
59
- 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) };
61
- 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) };
64
- case 23: return { type: "AwaitExpression", start, end, argument: f1 !== NULL ? node(f1) : null };
65
- case 24: return { type: "YieldExpression", start, end, argument: f1 !== NULL ? node(f1) : null, delegate: !!(flags & 1) };
66
- case 25: return { type: "MetaProperty", start, end, meta: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
67
- 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) };
69
- 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) };
72
- case 31: return { type: "StaticBlock", start, end, body: nodeArr(f1, f0) };
73
- case 32: return { type: "Super", start, end };
74
- case 33: return { type: "Literal", start, end, value: str(f1, f2), raw: _src.slice(start, end) };
75
- 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 }; }
76
- 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() }; }
77
- case 36: { const v = !!(flags & 1); return { type: "Literal", start, end, value: v, raw: v ? "true" : "false" }; }
78
- case 37: return { type: "Literal", start, end, value: null, raw: "null" };
79
- case 38: return { type: "ThisExpression", start, end };
80
- 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
- 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) };
84
- 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 };
89
- 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
- case 49: return { type: "SwitchStatement", start, end, discriminant: f1 !== NULL ? node(f1) : null, cases: nodeArr(f2, f0) };
91
- case 50: return { type: "SwitchCase", start, end, test: f1 !== NULL ? node(f1) : null, consequent: nodeArr(f2, f0) };
92
- 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 };
93
- 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 };
94
- 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) };
95
- case 54: return { type: "WhileStatement", start, end, test: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
96
- case 55: return { type: "DoWhileStatement", start, end, body: f1 !== NULL ? node(f1) : null, test: f2 !== NULL ? node(f2) : null };
97
- case 56: return { type: "BreakStatement", start, end, label: f1 !== NULL ? node(f1) : null };
98
- case 57: return { type: "ContinueStatement", start, end, label: f1 !== NULL ? node(f1) : null };
99
- case 58: return { type: "LabeledStatement", start, end, label: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
100
- case 59: return { type: "WithStatement", start, end, object: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
101
- case 60: return { type: "ReturnStatement", start, end, argument: f1 !== NULL ? node(f1) : null };
102
- case 61: return { type: "ThrowStatement", start, end, argument: f1 !== NULL ? node(f1) : null };
103
- 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 };
104
- case 63: return { type: "CatchClause", start, end, param: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
105
- case 64: return { type: "DebuggerStatement", start, end };
106
- 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 };
109
- 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) };
116
- 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 };
119
- case 78: return { type: "ImportDefaultSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
120
- case 79: return { type: "ImportNamespaceSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
121
- 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); };
200
- }
201
- _nodesOff = 40;
202
- const eOff = _nodesOff + nodeCount * 32;
203
- _extraBase = eOff >> 2;
204
- _spOff = eOff + extraCount * 4;
205
- const cOff = _spOff + spLen, dOff = cOff + commentCount * 20;
206
- const dv = new DataView(buffer);
207
- const comments = new Array(commentCount);
208
- for (let j = 0; j < commentCount; j++) {
209
- const o = cOff + j * 20;
210
- 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)) };
211
- }
212
- const diagnostics = new Array(diagCount);
213
- let dp = dOff;
214
- for (let j = 0; j < diagCount; j++) {
215
- const sev = SEVERITY[_u8[dp]]; dp++;
216
- const ds = _p(dv.getUint32(dp, true)); dp += 4;
217
- const de = _p(dv.getUint32(dp, true)); dp += 4;
218
- const ml = dv.getUint32(dp, true); dp += 4;
219
- const msg = _td.decode(_u8.subarray(dp, dp + ml)); dp += ml;
220
- const hh = _u8[dp]; dp++;
221
- let help = null;
222
- if (hh) { const hl = dv.getUint32(dp, true); dp += 4; help = _td.decode(_u8.subarray(dp, dp + hl)); dp += hl; }
223
- const lc = dv.getUint32(dp, true); dp += 4;
224
- const labels = new Array(lc);
225
- for (let k = 0; k < lc; k++) {
226
- const ls = _p(dv.getUint32(dp, true)); dp += 4;
227
- const le = _p(dv.getUint32(dp, true)); dp += 4;
228
- const lml = dv.getUint32(dp, true); dp += 4;
229
- labels[k] = { start: ls, end: le, message: _td.decode(_u8.subarray(dp, dp + lml)) }; dp += lml;
230
- }
231
- diagnostics[j] = { severity: sev, message: msg, start: ds, end: de, help, labels };
232
- }
233
- const program = node(progIdx);
234
- _u8 = _u32 = _src = null;
235
- return { program, comments, diagnostics };
236
- }
237
- export { decode };