oxc-parser 0.58.1 → 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 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 + 16),
156
- tail: deserializeBool(pos + 8),
155
+ value: deserializeTemplateElementValue(pos + 8),
156
+ tail: deserializeBool(pos + 40),
157
157
  };
158
158
  }
159
159
 
@@ -1533,7 +1533,7 @@ function deserializeTSTypeReference(pos) {
1533
1533
  start: deserializeU32(pos),
1534
1534
  end: deserializeU32(pos + 4),
1535
1535
  typeName: deserializeTSTypeName(pos + 8),
1536
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1536
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1537
1537
  };
1538
1538
  }
1539
1539
 
@@ -1597,7 +1597,7 @@ function deserializeTSClassImplements(pos) {
1597
1597
  start: deserializeU32(pos),
1598
1598
  end: deserializeU32(pos + 4),
1599
1599
  expression: deserializeTSTypeName(pos + 8),
1600
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1600
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1601
1601
  };
1602
1602
  }
1603
1603
 
@@ -1703,7 +1703,7 @@ function deserializeTSInterfaceHeritage(pos) {
1703
1703
  start: deserializeU32(pos),
1704
1704
  end: deserializeU32(pos + 4),
1705
1705
  expression: deserializeExpression(pos + 8),
1706
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1706
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1707
1707
  };
1708
1708
  }
1709
1709
 
@@ -1765,7 +1765,7 @@ function deserializeTSTypeQuery(pos) {
1765
1765
  start: deserializeU32(pos),
1766
1766
  end: deserializeU32(pos + 4),
1767
1767
  exprName: deserializeTSTypeQueryExprName(pos + 8),
1768
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1768
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1769
1769
  };
1770
1770
  }
1771
1771
 
@@ -2919,9 +2919,9 @@ function deserializeVariableDeclarationKind(pos) {
2919
2919
  case 0:
2920
2920
  return 'var';
2921
2921
  case 1:
2922
- return 'const';
2923
- case 2:
2924
2922
  return 'let';
2923
+ case 2:
2924
+ return 'const';
2925
2925
  case 3:
2926
2926
  return 'using';
2927
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
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 96),
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 + 16),
157
- tail: deserializeBool(pos + 8),
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
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 56),
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
- superTypeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 104),
857
- implements: deserializeOptionVecTSClassImplements(pos + 112),
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
 
@@ -1187,7 +1189,7 @@ function deserializeJSXOpeningElement(pos) {
1187
1189
  attributes: deserializeVecJSXAttributeItem(pos + 32),
1188
1190
  name: deserializeJSXElementName(pos + 16),
1189
1191
  selfClosing: deserializeBool(pos + 8),
1190
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 64),
1192
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 64),
1191
1193
  };
1192
1194
  }
1193
1195
 
@@ -1586,7 +1588,7 @@ function deserializeTSTypeReference(pos) {
1586
1588
  start: deserializeU32(pos),
1587
1589
  end: deserializeU32(pos + 4),
1588
1590
  typeName: deserializeTSTypeName(pos + 8),
1589
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1591
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1590
1592
  };
1591
1593
  }
1592
1594
 
@@ -1650,7 +1652,7 @@ function deserializeTSClassImplements(pos) {
1650
1652
  start: deserializeU32(pos),
1651
1653
  end: deserializeU32(pos + 4),
1652
1654
  expression: deserializeTSTypeName(pos + 8),
1653
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1655
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1654
1656
  };
1655
1657
  }
1656
1658
 
@@ -1756,7 +1758,7 @@ function deserializeTSInterfaceHeritage(pos) {
1756
1758
  start: deserializeU32(pos),
1757
1759
  end: deserializeU32(pos + 4),
1758
1760
  expression: deserializeExpression(pos + 8),
1759
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1761
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1760
1762
  };
1761
1763
  }
1762
1764
 
@@ -1818,7 +1820,7 @@ function deserializeTSTypeQuery(pos) {
1818
1820
  start: deserializeU32(pos),
1819
1821
  end: deserializeU32(pos + 4),
1820
1822
  exprName: deserializeTSTypeQueryExprName(pos + 8),
1821
- typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1823
+ typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
1822
1824
  };
1823
1825
  }
1824
1826
 
@@ -2972,9 +2974,9 @@ function deserializeVariableDeclarationKind(pos) {
2972
2974
  case 0:
2973
2975
  return 'var';
2974
2976
  case 1:
2975
- return 'const';
2976
- case 2:
2977
2977
  return 'let';
2978
+ case 2:
2979
+ return 'const';
2978
2980
  case 3:
2979
2981
  return 'using';
2980
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.58.1",
3
+ "version": "0.60.0",
4
4
  "main": "index.js",
5
- "browser": "browser.js",
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
- "browser.js",
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.58.1"
41
+ "@oxc-project/types": "^0.60.0"
40
42
  },
41
43
  "devDependencies": {
42
44
  "@codspeed/vitest-plugin": "^4.0.0",
43
- "vitest": "3.0.7"
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": true
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.58.1",
69
- "@oxc-parser/binding-win32-arm64-msvc": "0.58.1",
70
- "@oxc-parser/binding-linux-x64-gnu": "0.58.1",
71
- "@oxc-parser/binding-linux-x64-musl": "0.58.1",
72
- "@oxc-parser/binding-linux-arm64-gnu": "0.58.1",
73
- "@oxc-parser/binding-linux-arm64-musl": "0.58.1",
74
- "@oxc-parser/binding-linux-arm-gnueabihf": "0.58.1",
75
- "@oxc-parser/binding-darwin-x64": "0.58.1",
76
- "@oxc-parser/binding-darwin-arm64": "0.58.1",
77
- "@oxc-parser/binding-wasm32-wasi": "0.58.1"
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
- "test": "vitest --typecheck run ./test && tsc",
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'