oxc-parser 0.68.0 → 0.69.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.68.0",
3
+ "version": "0.69.0",
4
4
  "main": "index.js",
5
5
  "browser": "wasm.mjs",
6
6
  "engines": {
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@oxc-project/types": "^0.68.0"
42
+ "@oxc-project/types": "^0.69.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@codspeed/vitest-plugin": "^4.0.0",
@@ -57,9 +57,12 @@
57
57
  "aarch64-pc-windows-msvc",
58
58
  "x86_64-unknown-linux-gnu",
59
59
  "x86_64-unknown-linux-musl",
60
+ "x86_64-unknown-freebsd",
60
61
  "aarch64-unknown-linux-gnu",
61
62
  "aarch64-unknown-linux-musl",
62
63
  "armv7-unknown-linux-gnueabihf",
64
+ "s390x-unknown-linux-gnu",
65
+ "riscv64gc-unknown-linux-gnu",
63
66
  "x86_64-apple-darwin",
64
67
  "aarch64-apple-darwin",
65
68
  "wasm32-wasip1-threads"
@@ -72,16 +75,19 @@
72
75
  "dtsHeaderFile": "header.js"
73
76
  },
74
77
  "optionalDependencies": {
75
- "@oxc-parser/binding-win32-x64-msvc": "0.68.0",
76
- "@oxc-parser/binding-win32-arm64-msvc": "0.68.0",
77
- "@oxc-parser/binding-linux-x64-gnu": "0.68.0",
78
- "@oxc-parser/binding-linux-x64-musl": "0.68.0",
79
- "@oxc-parser/binding-linux-arm64-gnu": "0.68.0",
80
- "@oxc-parser/binding-linux-arm64-musl": "0.68.0",
81
- "@oxc-parser/binding-linux-arm-gnueabihf": "0.68.0",
82
- "@oxc-parser/binding-darwin-x64": "0.68.0",
83
- "@oxc-parser/binding-darwin-arm64": "0.68.0",
84
- "@oxc-parser/binding-wasm32-wasi": "0.68.0"
78
+ "@oxc-parser/binding-win32-x64-msvc": "0.69.0",
79
+ "@oxc-parser/binding-win32-arm64-msvc": "0.69.0",
80
+ "@oxc-parser/binding-linux-x64-gnu": "0.69.0",
81
+ "@oxc-parser/binding-linux-x64-musl": "0.69.0",
82
+ "@oxc-parser/binding-freebsd-x64": "0.69.0",
83
+ "@oxc-parser/binding-linux-arm64-gnu": "0.69.0",
84
+ "@oxc-parser/binding-linux-arm64-musl": "0.69.0",
85
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.69.0",
86
+ "@oxc-parser/binding-linux-s390x-gnu": "0.69.0",
87
+ "@oxc-parser/binding-linux-riscv64-gnu": "0.69.0",
88
+ "@oxc-parser/binding-darwin-x64": "0.69.0",
89
+ "@oxc-parser/binding-darwin-arm64": "0.69.0",
90
+ "@oxc-parser/binding-wasm32-wasi": "0.69.0"
85
91
  },
86
92
  "scripts": {
87
93
  "build-dev": "napi build --no-dts-cache --platform --js bindings.js",
package/wrap.cjs CHANGED
@@ -23,25 +23,36 @@ module.exports.wrap = function wrap(result) {
23
23
  };
24
24
  };
25
25
 
26
- function jsonParseAst(program) {
27
- return JSON.parse(program, transform);
26
+ // Set `value` field of `Literal`s which are `BigInt`s or `RegExp`s.
27
+ //
28
+ // Returned JSON contains an array `fixes` with paths to these nodes
29
+ // e.g. for `123n; foo(/xyz/)`, `fixes` will be
30
+ // `[["body", 0, "expression"], ["body", 1, "expression", "arguments", 2]]`.
31
+ //
32
+ // Walk down the AST to these nodes and alter them.
33
+ // Compiling the list of fixes on Rust side avoids having to do a full AST traversal on JS side
34
+ // to locate the likely very few `Literal`s which need fixing.
35
+ function jsonParseAst(programJson) {
36
+ const { node: program, fixes } = JSON.parse(programJson);
37
+ for (const fixPath of fixes) {
38
+ applyFix(program, fixPath);
39
+ }
40
+ return program;
28
41
  }
29
42
 
30
- function transform(key, value) {
31
- // Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
32
- // This is not possible to do on Rust side, as neither can be represented correctly in JSON.
33
- if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
34
- if (Object.hasOwn(this, 'bigint')) {
35
- return BigInt(this.bigint);
36
- }
37
- if (Object.hasOwn(this, 'regex')) {
38
- const { regex } = this;
39
- try {
40
- return RegExp(regex.pattern, regex.flags);
41
- } catch (_err) {
42
- // Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
43
- }
43
+ function applyFix(program, fixPath) {
44
+ let node = program;
45
+ for (const key of fixPath) {
46
+ node = node[key];
47
+ }
48
+
49
+ if (node.bigint) {
50
+ node.value = BigInt(node.bigint);
51
+ } else {
52
+ try {
53
+ node.value = RegExp(node.regex.pattern, node.regex.flags);
54
+ } catch (_err) {
55
+ // Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
44
56
  }
45
57
  }
46
- return value;
47
58
  }
package/wrap.mjs CHANGED
@@ -23,26 +23,38 @@ export function wrap(result) {
23
23
  };
24
24
  }
25
25
 
26
- // Used by napi/playground/patch.mjs
27
- export function jsonParseAst(program) {
28
- return JSON.parse(program, transform);
26
+ // Used by `napi/playground/patch.mjs`.
27
+ //
28
+ // Set `value` field of `Literal`s which are `BigInt`s or `RegExp`s.
29
+ //
30
+ // Returned JSON contains an array `fixes` with paths to these nodes
31
+ // e.g. for `123n; foo(/xyz/)`, `fixes` will be
32
+ // `[["body", 0, "expression"], ["body", 1, "expression", "arguments", 2]]`.
33
+ //
34
+ // Walk down the AST to these nodes and alter them.
35
+ // Compiling the list of fixes on Rust side avoids having to do a full AST traversal on JS side
36
+ // to locate the likely very few `Literal`s which need fixing.
37
+ export function jsonParseAst(programJson) {
38
+ const { node: program, fixes } = JSON.parse(programJson);
39
+ for (const fixPath of fixes) {
40
+ applyFix(program, fixPath);
41
+ }
42
+ return program;
29
43
  }
30
44
 
31
- function transform(key, value) {
32
- // Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
33
- // This is not possible to do on Rust side, as neither can be represented correctly in JSON.
34
- if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
35
- if (Object.hasOwn(this, 'bigint')) {
36
- return BigInt(this.bigint);
37
- }
38
- if (Object.hasOwn(this, 'regex')) {
39
- const { regex } = this;
40
- try {
41
- return RegExp(regex.pattern, regex.flags);
42
- } catch (_err) {
43
- // Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
44
- }
45
+ function applyFix(program, fixPath) {
46
+ let node = program;
47
+ for (const key of fixPath) {
48
+ node = node[key];
49
+ }
50
+
51
+ if (node.bigint) {
52
+ node.value = BigInt(node.bigint);
53
+ } else {
54
+ try {
55
+ node.value = RegExp(node.regex.pattern, node.regex.flags);
56
+ } catch (_err) {
57
+ // Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
45
58
  }
46
59
  }
47
- return value;
48
60
  }