oxc-parser 0.58.0 → 0.60.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.
- package/deserialize-js.js +12 -10
- package/deserialize-ts.js +21 -17
- package/index.js +1 -44
- package/package.json +25 -17
- package/wasm.mjs +11 -0
- package/wrap.cjs +42 -0
- package/wrap.mjs +42 -0
- package/browser.js +0 -1
package/deserialize-js.js
CHANGED
|
@@ -152,8 +152,8 @@ function deserializeTemplateElement(pos) {
|
|
|
152
152
|
type: 'TemplateElement',
|
|
153
153
|
start: deserializeU32(pos),
|
|
154
154
|
end: deserializeU32(pos + 4),
|
|
155
|
-
value: deserializeTemplateElementValue(pos +
|
|
156
|
-
tail: deserializeBool(pos +
|
|
155
|
+
value: deserializeTemplateElementValue(pos + 8),
|
|
156
|
+
tail: deserializeBool(pos + 40),
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -1132,9 +1132,9 @@ function deserializeJSXOpeningElement(pos) {
|
|
|
1132
1132
|
type: 'JSXOpeningElement',
|
|
1133
1133
|
start: deserializeU32(pos),
|
|
1134
1134
|
end: deserializeU32(pos + 4),
|
|
1135
|
-
selfClosing: deserializeBool(pos + 8),
|
|
1136
|
-
name: deserializeJSXElementName(pos + 16),
|
|
1137
1135
|
attributes: deserializeVecJSXAttributeItem(pos + 32),
|
|
1136
|
+
name: deserializeJSXElementName(pos + 16),
|
|
1137
|
+
selfClosing: deserializeBool(pos + 8),
|
|
1138
1138
|
};
|
|
1139
1139
|
}
|
|
1140
1140
|
|
|
@@ -1163,6 +1163,8 @@ function deserializeJSXOpeningFragment(pos) {
|
|
|
1163
1163
|
type: 'JSXOpeningFragment',
|
|
1164
1164
|
start: deserializeU32(pos),
|
|
1165
1165
|
end: deserializeU32(pos + 4),
|
|
1166
|
+
attributes: [],
|
|
1167
|
+
selfClosing: false,
|
|
1166
1168
|
};
|
|
1167
1169
|
}
|
|
1168
1170
|
|
|
@@ -1531,7 +1533,7 @@ function deserializeTSTypeReference(pos) {
|
|
|
1531
1533
|
start: deserializeU32(pos),
|
|
1532
1534
|
end: deserializeU32(pos + 4),
|
|
1533
1535
|
typeName: deserializeTSTypeName(pos + 8),
|
|
1534
|
-
|
|
1536
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1535
1537
|
};
|
|
1536
1538
|
}
|
|
1537
1539
|
|
|
@@ -1595,7 +1597,7 @@ function deserializeTSClassImplements(pos) {
|
|
|
1595
1597
|
start: deserializeU32(pos),
|
|
1596
1598
|
end: deserializeU32(pos + 4),
|
|
1597
1599
|
expression: deserializeTSTypeName(pos + 8),
|
|
1598
|
-
|
|
1600
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1599
1601
|
};
|
|
1600
1602
|
}
|
|
1601
1603
|
|
|
@@ -1701,7 +1703,7 @@ function deserializeTSInterfaceHeritage(pos) {
|
|
|
1701
1703
|
start: deserializeU32(pos),
|
|
1702
1704
|
end: deserializeU32(pos + 4),
|
|
1703
1705
|
expression: deserializeExpression(pos + 8),
|
|
1704
|
-
|
|
1706
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1705
1707
|
};
|
|
1706
1708
|
}
|
|
1707
1709
|
|
|
@@ -1763,7 +1765,7 @@ function deserializeTSTypeQuery(pos) {
|
|
|
1763
1765
|
start: deserializeU32(pos),
|
|
1764
1766
|
end: deserializeU32(pos + 4),
|
|
1765
1767
|
exprName: deserializeTSTypeQueryExprName(pos + 8),
|
|
1766
|
-
|
|
1768
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1767
1769
|
};
|
|
1768
1770
|
}
|
|
1769
1771
|
|
|
@@ -2917,9 +2919,9 @@ function deserializeVariableDeclarationKind(pos) {
|
|
|
2917
2919
|
case 0:
|
|
2918
2920
|
return 'var';
|
|
2919
2921
|
case 1:
|
|
2920
|
-
return 'const';
|
|
2921
|
-
case 2:
|
|
2922
2922
|
return 'let';
|
|
2923
|
+
case 2:
|
|
2924
|
+
return 'const';
|
|
2923
2925
|
case 3:
|
|
2924
2926
|
return 'using';
|
|
2925
2927
|
case 4:
|
package/deserialize-ts.js
CHANGED
|
@@ -144,7 +144,7 @@ function deserializeTaggedTemplateExpression(pos) {
|
|
|
144
144
|
end: deserializeU32(pos + 4),
|
|
145
145
|
tag: deserializeExpression(pos + 8),
|
|
146
146
|
quasi: deserializeTemplateLiteral(pos + 24),
|
|
147
|
-
|
|
147
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 96),
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -153,8 +153,8 @@ function deserializeTemplateElement(pos) {
|
|
|
153
153
|
type: 'TemplateElement',
|
|
154
154
|
start: deserializeU32(pos),
|
|
155
155
|
end: deserializeU32(pos + 4),
|
|
156
|
-
value: deserializeTemplateElementValue(pos +
|
|
157
|
-
tail: deserializeBool(pos +
|
|
156
|
+
value: deserializeTemplateElementValue(pos + 8),
|
|
157
|
+
tail: deserializeBool(pos + 40),
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -207,9 +207,9 @@ function deserializeCallExpression(pos) {
|
|
|
207
207
|
start: deserializeU32(pos),
|
|
208
208
|
end: deserializeU32(pos + 4),
|
|
209
209
|
callee: deserializeExpression(pos + 8),
|
|
210
|
-
typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
211
210
|
arguments: deserializeVecArgument(pos + 32),
|
|
212
211
|
optional: deserializeBool(pos + 64),
|
|
212
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -220,7 +220,7 @@ function deserializeNewExpression(pos) {
|
|
|
220
220
|
end: deserializeU32(pos + 4),
|
|
221
221
|
callee: deserializeExpression(pos + 8),
|
|
222
222
|
arguments: deserializeVecArgument(pos + 24),
|
|
223
|
-
|
|
223
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 56),
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
|
|
@@ -510,6 +510,7 @@ function deserializeExpressionStatement(pos) {
|
|
|
510
510
|
start: deserializeU32(pos),
|
|
511
511
|
end: deserializeU32(pos + 4),
|
|
512
512
|
expression: deserializeExpression(pos + 8),
|
|
513
|
+
directive: null,
|
|
513
514
|
};
|
|
514
515
|
}
|
|
515
516
|
|
|
@@ -844,6 +845,7 @@ function deserializeYieldExpression(pos) {
|
|
|
844
845
|
}
|
|
845
846
|
|
|
846
847
|
function deserializeClass(pos) {
|
|
848
|
+
const classImplements = deserializeOptionVecTSClassImplements(pos + 112);
|
|
847
849
|
return {
|
|
848
850
|
type: deserializeClassType(pos + 8),
|
|
849
851
|
start: deserializeU32(pos),
|
|
@@ -853,8 +855,8 @@ function deserializeClass(pos) {
|
|
|
853
855
|
body: deserializeBoxClassBody(pos + 144),
|
|
854
856
|
decorators: deserializeVecDecorator(pos + 16),
|
|
855
857
|
typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 80),
|
|
856
|
-
|
|
857
|
-
implements:
|
|
858
|
+
superTypeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 104),
|
|
859
|
+
implements: classImplements === null ? [] : classImplements,
|
|
858
860
|
abstract: deserializeBool(pos + 152),
|
|
859
861
|
declare: deserializeBool(pos + 153),
|
|
860
862
|
};
|
|
@@ -1024,8 +1026,8 @@ function deserializeExportNamedDeclaration(pos) {
|
|
|
1024
1026
|
declaration: deserializeOptionDeclaration(pos + 8),
|
|
1025
1027
|
specifiers: deserializeVecExportSpecifier(pos + 24),
|
|
1026
1028
|
source: deserializeOptionStringLiteral(pos + 56),
|
|
1027
|
-
exportKind: deserializeImportOrExportKind(pos + 96),
|
|
1028
1029
|
attributes: withClause === null ? [] : withClause.withEntries,
|
|
1030
|
+
exportKind: deserializeImportOrExportKind(pos + 96),
|
|
1029
1031
|
};
|
|
1030
1032
|
}
|
|
1031
1033
|
|
|
@@ -1184,10 +1186,10 @@ function deserializeJSXOpeningElement(pos) {
|
|
|
1184
1186
|
type: 'JSXOpeningElement',
|
|
1185
1187
|
start: deserializeU32(pos),
|
|
1186
1188
|
end: deserializeU32(pos + 4),
|
|
1187
|
-
selfClosing: deserializeBool(pos + 8),
|
|
1188
|
-
name: deserializeJSXElementName(pos + 16),
|
|
1189
1189
|
attributes: deserializeVecJSXAttributeItem(pos + 32),
|
|
1190
|
-
|
|
1190
|
+
name: deserializeJSXElementName(pos + 16),
|
|
1191
|
+
selfClosing: deserializeBool(pos + 8),
|
|
1192
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 64),
|
|
1191
1193
|
};
|
|
1192
1194
|
}
|
|
1193
1195
|
|
|
@@ -1216,6 +1218,8 @@ function deserializeJSXOpeningFragment(pos) {
|
|
|
1216
1218
|
type: 'JSXOpeningFragment',
|
|
1217
1219
|
start: deserializeU32(pos),
|
|
1218
1220
|
end: deserializeU32(pos + 4),
|
|
1221
|
+
attributes: [],
|
|
1222
|
+
selfClosing: false,
|
|
1219
1223
|
};
|
|
1220
1224
|
}
|
|
1221
1225
|
|
|
@@ -1584,7 +1588,7 @@ function deserializeTSTypeReference(pos) {
|
|
|
1584
1588
|
start: deserializeU32(pos),
|
|
1585
1589
|
end: deserializeU32(pos + 4),
|
|
1586
1590
|
typeName: deserializeTSTypeName(pos + 8),
|
|
1587
|
-
|
|
1591
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1588
1592
|
};
|
|
1589
1593
|
}
|
|
1590
1594
|
|
|
@@ -1648,7 +1652,7 @@ function deserializeTSClassImplements(pos) {
|
|
|
1648
1652
|
start: deserializeU32(pos),
|
|
1649
1653
|
end: deserializeU32(pos + 4),
|
|
1650
1654
|
expression: deserializeTSTypeName(pos + 8),
|
|
1651
|
-
|
|
1655
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1652
1656
|
};
|
|
1653
1657
|
}
|
|
1654
1658
|
|
|
@@ -1754,7 +1758,7 @@ function deserializeTSInterfaceHeritage(pos) {
|
|
|
1754
1758
|
start: deserializeU32(pos),
|
|
1755
1759
|
end: deserializeU32(pos + 4),
|
|
1756
1760
|
expression: deserializeExpression(pos + 8),
|
|
1757
|
-
|
|
1761
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1758
1762
|
};
|
|
1759
1763
|
}
|
|
1760
1764
|
|
|
@@ -1816,7 +1820,7 @@ function deserializeTSTypeQuery(pos) {
|
|
|
1816
1820
|
start: deserializeU32(pos),
|
|
1817
1821
|
end: deserializeU32(pos + 4),
|
|
1818
1822
|
exprName: deserializeTSTypeQueryExprName(pos + 8),
|
|
1819
|
-
|
|
1823
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1820
1824
|
};
|
|
1821
1825
|
}
|
|
1822
1826
|
|
|
@@ -2970,9 +2974,9 @@ function deserializeVariableDeclarationKind(pos) {
|
|
|
2970
2974
|
case 0:
|
|
2971
2975
|
return 'var';
|
|
2972
2976
|
case 1:
|
|
2973
|
-
return 'const';
|
|
2974
|
-
case 2:
|
|
2975
2977
|
return 'let';
|
|
2978
|
+
case 2:
|
|
2979
|
+
return 'const';
|
|
2976
2980
|
case 3:
|
|
2977
2981
|
return 'using';
|
|
2978
2982
|
case 4:
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const bindings = require('./bindings.js');
|
|
2
2
|
const deserializeJS = require('./deserialize-js.js');
|
|
3
3
|
const deserializeTS = require('./deserialize-ts.js');
|
|
4
|
+
const { wrap } = require('./wrap.cjs');
|
|
4
5
|
|
|
5
6
|
module.exports.ParseResult = bindings.ParseResult;
|
|
6
7
|
module.exports.ExportExportNameKind = bindings.ExportExportNameKind;
|
|
@@ -10,49 +11,6 @@ module.exports.ImportNameKind = bindings.ImportNameKind;
|
|
|
10
11
|
module.exports.parseWithoutReturn = bindings.parseWithoutReturn;
|
|
11
12
|
module.exports.Severity = bindings.Severity;
|
|
12
13
|
|
|
13
|
-
function wrap(result) {
|
|
14
|
-
let program, module, comments, errors;
|
|
15
|
-
return {
|
|
16
|
-
get program() {
|
|
17
|
-
if (!program) {
|
|
18
|
-
// Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
|
|
19
|
-
// Any changes should be applied in those 2 scripts too.
|
|
20
|
-
program = JSON.parse(result.program, function(key, value) {
|
|
21
|
-
// Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
|
|
22
|
-
// This is not possible to do on Rust side, as neither can be represented correctly in JSON.
|
|
23
|
-
if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
|
|
24
|
-
if (Object.hasOwn(this, 'bigint')) {
|
|
25
|
-
return BigInt(this.bigint);
|
|
26
|
-
}
|
|
27
|
-
if (Object.hasOwn(this, 'regex')) {
|
|
28
|
-
const { regex } = this;
|
|
29
|
-
try {
|
|
30
|
-
return RegExp(regex.pattern, regex.flags);
|
|
31
|
-
} catch (_err) {
|
|
32
|
-
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return program;
|
|
40
|
-
},
|
|
41
|
-
get module() {
|
|
42
|
-
if (!module) module = result.module;
|
|
43
|
-
return module;
|
|
44
|
-
},
|
|
45
|
-
get comments() {
|
|
46
|
-
if (!comments) comments = result.comments;
|
|
47
|
-
return comments;
|
|
48
|
-
},
|
|
49
|
-
get errors() {
|
|
50
|
-
if (!errors) errors = result.errors;
|
|
51
|
-
return errors;
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
14
|
module.exports.parseAsync = async function parseAsync(...args) {
|
|
57
15
|
return wrap(await bindings.parseAsync(...args));
|
|
58
16
|
};
|
|
@@ -61,7 +19,6 @@ module.exports.parseSync = function parseSync(filename, sourceText, options) {
|
|
|
61
19
|
if (options?.experimentalRawTransfer) {
|
|
62
20
|
return parseSyncRaw(filename, sourceText, options);
|
|
63
21
|
}
|
|
64
|
-
|
|
65
22
|
return wrap(bindings.parseSync(filename, sourceText, options));
|
|
66
23
|
};
|
|
67
24
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"main": "index.js",
|
|
5
|
-
"browser": "
|
|
5
|
+
"browser": "wasm.mjs",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=14.0.0"
|
|
8
8
|
},
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"index.d.ts",
|
|
28
28
|
"index.js",
|
|
29
|
-
"
|
|
29
|
+
"wrap.cjs",
|
|
30
|
+
"wrap.mjs",
|
|
31
|
+
"wasm.mjs",
|
|
30
32
|
"bindings.js",
|
|
31
33
|
"deserialize-js.js",
|
|
32
34
|
"deserialize-ts.js"
|
|
@@ -36,11 +38,14 @@
|
|
|
36
38
|
"access": "public"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@oxc-project/types": "^0.
|
|
41
|
+
"@oxc-project/types": "^0.60.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@codspeed/vitest-plugin": "^4.0.0",
|
|
43
|
-
"
|
|
45
|
+
"@napi-rs/wasm-runtime": "^0.2.7",
|
|
46
|
+
"@vitest/browser": "3.0.7",
|
|
47
|
+
"playwright": "^1.51.0",
|
|
48
|
+
"vitest": "3.0.8"
|
|
44
49
|
},
|
|
45
50
|
"napi": {
|
|
46
51
|
"binaryName": "parser",
|
|
@@ -59,27 +64,30 @@
|
|
|
59
64
|
],
|
|
60
65
|
"wasm": {
|
|
61
66
|
"browser": {
|
|
62
|
-
"fs":
|
|
67
|
+
"fs": false
|
|
63
68
|
}
|
|
64
69
|
},
|
|
65
70
|
"dtsHeaderFile": "header.js"
|
|
66
71
|
},
|
|
67
72
|
"optionalDependencies": {
|
|
68
|
-
"@oxc-parser/binding-win32-x64-msvc": "0.
|
|
69
|
-
"@oxc-parser/binding-win32-arm64-msvc": "0.
|
|
70
|
-
"@oxc-parser/binding-linux-x64-gnu": "0.
|
|
71
|
-
"@oxc-parser/binding-linux-x64-musl": "0.
|
|
72
|
-
"@oxc-parser/binding-linux-arm64-gnu": "0.
|
|
73
|
-
"@oxc-parser/binding-linux-arm64-musl": "0.
|
|
74
|
-
"@oxc-parser/binding-linux-arm-gnueabihf": "0.
|
|
75
|
-
"@oxc-parser/binding-darwin-x64": "0.
|
|
76
|
-
"@oxc-parser/binding-darwin-arm64": "0.
|
|
77
|
-
"@oxc-parser/binding-wasm32-wasi": "0.
|
|
73
|
+
"@oxc-parser/binding-win32-x64-msvc": "0.60.0",
|
|
74
|
+
"@oxc-parser/binding-win32-arm64-msvc": "0.60.0",
|
|
75
|
+
"@oxc-parser/binding-linux-x64-gnu": "0.60.0",
|
|
76
|
+
"@oxc-parser/binding-linux-x64-musl": "0.60.0",
|
|
77
|
+
"@oxc-parser/binding-linux-arm64-gnu": "0.60.0",
|
|
78
|
+
"@oxc-parser/binding-linux-arm64-musl": "0.60.0",
|
|
79
|
+
"@oxc-parser/binding-linux-arm-gnueabihf": "0.60.0",
|
|
80
|
+
"@oxc-parser/binding-darwin-x64": "0.60.0",
|
|
81
|
+
"@oxc-parser/binding-darwin-arm64": "0.60.0",
|
|
82
|
+
"@oxc-parser/binding-wasm32-wasi": "0.60.0"
|
|
78
83
|
},
|
|
79
84
|
"scripts": {
|
|
80
85
|
"build-dev": "napi build --no-dts-cache --platform --js bindings.js",
|
|
81
86
|
"build": "pnpm run build-dev --release",
|
|
82
|
-
"
|
|
87
|
+
"build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
|
|
88
|
+
"build-npm-dir": "rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir .",
|
|
89
|
+
"test": "vitest --typecheck run ./test/ && tsc",
|
|
90
|
+
"test-browser": "vitest -c vitest.config.browser.mts",
|
|
83
91
|
"bench": "vitest bench --run ./bench.bench.mjs"
|
|
84
92
|
}
|
|
85
93
|
}
|
package/wasm.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from '@oxc-parser/binding-wasm32-wasi';
|
|
2
|
+
import * as bindings from '@oxc-parser/binding-wasm32-wasi';
|
|
3
|
+
import { wrap } from './wrap.mjs';
|
|
4
|
+
|
|
5
|
+
export async function parseAsync(...args) {
|
|
6
|
+
return wrap(await bindings.parseAsync(...args));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function parseSync(filename, sourceText, options) {
|
|
10
|
+
return wrap(bindings.parseSync(filename, sourceText, options));
|
|
11
|
+
}
|
package/wrap.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module.exports.wrap = function wrap(result) {
|
|
2
|
+
let program, module, comments, errors;
|
|
3
|
+
return {
|
|
4
|
+
get program() {
|
|
5
|
+
if (!program) {
|
|
6
|
+
// Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
|
|
7
|
+
// Any changes should be applied in those 2 scripts too.
|
|
8
|
+
program = JSON.parse(result.program, function(key, value) {
|
|
9
|
+
// Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
|
|
10
|
+
// This is not possible to do on Rust side, as neither can be represented correctly in JSON.
|
|
11
|
+
if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
|
|
12
|
+
if (Object.hasOwn(this, 'bigint')) {
|
|
13
|
+
return BigInt(this.bigint);
|
|
14
|
+
}
|
|
15
|
+
if (Object.hasOwn(this, 'regex')) {
|
|
16
|
+
const { regex } = this;
|
|
17
|
+
try {
|
|
18
|
+
return RegExp(regex.pattern, regex.flags);
|
|
19
|
+
} catch (_err) {
|
|
20
|
+
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return program;
|
|
28
|
+
},
|
|
29
|
+
get module() {
|
|
30
|
+
if (!module) module = result.module;
|
|
31
|
+
return module;
|
|
32
|
+
},
|
|
33
|
+
get comments() {
|
|
34
|
+
if (!comments) comments = result.comments;
|
|
35
|
+
return comments;
|
|
36
|
+
},
|
|
37
|
+
get errors() {
|
|
38
|
+
if (!errors) errors = result.errors;
|
|
39
|
+
return errors;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
package/wrap.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function wrap(result) {
|
|
2
|
+
let program, module, comments, errors;
|
|
3
|
+
return {
|
|
4
|
+
get program() {
|
|
5
|
+
if (!program) {
|
|
6
|
+
// Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
|
|
7
|
+
// Any changes should be applied in those 2 scripts too.
|
|
8
|
+
program = JSON.parse(result.program, function(key, value) {
|
|
9
|
+
// Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
|
|
10
|
+
// This is not possible to do on Rust side, as neither can be represented correctly in JSON.
|
|
11
|
+
if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
|
|
12
|
+
if (Object.hasOwn(this, 'bigint')) {
|
|
13
|
+
return BigInt(this.bigint);
|
|
14
|
+
}
|
|
15
|
+
if (Object.hasOwn(this, 'regex')) {
|
|
16
|
+
const { regex } = this;
|
|
17
|
+
try {
|
|
18
|
+
return RegExp(regex.pattern, regex.flags);
|
|
19
|
+
} catch (_err) {
|
|
20
|
+
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return program;
|
|
28
|
+
},
|
|
29
|
+
get module() {
|
|
30
|
+
if (!module) module = result.module;
|
|
31
|
+
return module;
|
|
32
|
+
},
|
|
33
|
+
get comments() {
|
|
34
|
+
if (!comments) comments = result.comments;
|
|
35
|
+
return comments;
|
|
36
|
+
},
|
|
37
|
+
get errors() {
|
|
38
|
+
if (!errors) errors = result.errors;
|
|
39
|
+
return errors;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
package/browser.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@oxc-parser/binding-wasm32-wasi'
|