oxc-parser 0.68.1 → 0.70.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/index.d.ts CHANGED
@@ -140,9 +140,10 @@ export interface OxcError {
140
140
  export declare function parseAsync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
141
141
 
142
142
  export interface ParserOptions {
143
- sourceType?: 'script' | 'module' | 'unambiguous' | undefined
144
143
  /** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
145
144
  lang?: 'js' | 'jsx' | 'ts' | 'tsx'
145
+ /** Treat the source text as `script` or `module` code. */
146
+ sourceType?: 'script' | 'module' | 'unambiguous' | undefined
146
147
  /**
147
148
  * Return an AST which includes TypeScript-related properties, or excludes them.
148
149
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.68.1",
3
+ "version": "0.70.0",
4
4
  "main": "index.js",
5
5
  "browser": "wasm.mjs",
6
6
  "engines": {
@@ -39,15 +39,16 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@oxc-project/types": "^0.68.1"
42
+ "@oxc-project/types": "^0.70.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@codspeed/vitest-plugin": "^4.0.0",
46
46
  "@napi-rs/wasm-runtime": "^0.2.7",
47
- "@vitest/browser": "3.1.2",
47
+ "@vitest/browser": "3.1.3",
48
48
  "esbuild": "^0.25.0",
49
49
  "playwright": "^1.51.0",
50
- "vitest": "3.1.2"
50
+ "vitest": "3.1.3",
51
+ "typescript": "5.8.3"
51
52
  },
52
53
  "napi": {
53
54
  "binaryName": "parser",
@@ -57,9 +58,13 @@
57
58
  "aarch64-pc-windows-msvc",
58
59
  "x86_64-unknown-linux-gnu",
59
60
  "x86_64-unknown-linux-musl",
61
+ "x86_64-unknown-freebsd",
60
62
  "aarch64-unknown-linux-gnu",
61
63
  "aarch64-unknown-linux-musl",
62
64
  "armv7-unknown-linux-gnueabihf",
65
+ "armv7-unknown-linux-musleabihf",
66
+ "s390x-unknown-linux-gnu",
67
+ "riscv64gc-unknown-linux-gnu",
63
68
  "x86_64-apple-darwin",
64
69
  "aarch64-apple-darwin",
65
70
  "wasm32-wasip1-threads"
@@ -72,16 +77,20 @@
72
77
  "dtsHeaderFile": "header.js"
73
78
  },
74
79
  "optionalDependencies": {
75
- "@oxc-parser/binding-win32-x64-msvc": "0.68.1",
76
- "@oxc-parser/binding-win32-arm64-msvc": "0.68.1",
77
- "@oxc-parser/binding-linux-x64-gnu": "0.68.1",
78
- "@oxc-parser/binding-linux-x64-musl": "0.68.1",
79
- "@oxc-parser/binding-linux-arm64-gnu": "0.68.1",
80
- "@oxc-parser/binding-linux-arm64-musl": "0.68.1",
81
- "@oxc-parser/binding-linux-arm-gnueabihf": "0.68.1",
82
- "@oxc-parser/binding-darwin-x64": "0.68.1",
83
- "@oxc-parser/binding-darwin-arm64": "0.68.1",
84
- "@oxc-parser/binding-wasm32-wasi": "0.68.1"
80
+ "@oxc-parser/binding-win32-x64-msvc": "0.70.0",
81
+ "@oxc-parser/binding-win32-arm64-msvc": "0.70.0",
82
+ "@oxc-parser/binding-linux-x64-gnu": "0.70.0",
83
+ "@oxc-parser/binding-linux-x64-musl": "0.70.0",
84
+ "@oxc-parser/binding-freebsd-x64": "0.70.0",
85
+ "@oxc-parser/binding-linux-arm64-gnu": "0.70.0",
86
+ "@oxc-parser/binding-linux-arm64-musl": "0.70.0",
87
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.70.0",
88
+ "@oxc-parser/binding-linux-arm-musleabihf": "0.70.0",
89
+ "@oxc-parser/binding-linux-s390x-gnu": "0.70.0",
90
+ "@oxc-parser/binding-linux-riscv64-gnu": "0.70.0",
91
+ "@oxc-parser/binding-darwin-x64": "0.70.0",
92
+ "@oxc-parser/binding-darwin-arm64": "0.70.0",
93
+ "@oxc-parser/binding-wasm32-wasi": "0.70.0"
85
94
  },
86
95
  "scripts": {
87
96
  "build-dev": "napi build --no-dts-cache --platform --js bindings.js",
@@ -90,7 +99,7 @@
90
99
  "build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
91
100
  "build-npm-dir": "rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir .",
92
101
  "build-browser-bundle": "node build-browser-bundle.mjs",
93
- "test": "pnpm run test-node run && tsc",
102
+ "test": "tsc && pnpm run test-node run",
94
103
  "test-node": "vitest --dir ./test",
95
104
  "test-browser": "vitest -c vitest.config.browser.mts",
96
105
  "bench": "vitest bench --run ./bench.bench.mjs"
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
  }