oxc-parser 0.75.1 → 0.77.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.
@@ -182,7 +182,7 @@ const {
182
182
  JSDocNullableType,
183
183
  JSDocNonNullableType,
184
184
  JSDocUnknownType,
185
- } = require('./lazy.js').constructors;
185
+ } = require('./constructors.js');
186
186
 
187
187
  module.exports = walkProgram;
188
188
 
package/index.d.ts CHANGED
@@ -137,8 +137,8 @@ export declare const enum ImportNameKind {
137
137
  export declare function parseAsync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
138
138
 
139
139
  export interface ParserOptions {
140
- /** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
141
- lang?: 'js' | 'jsx' | 'ts' | 'tsx'
140
+ /** Treat the source text as `js`, `jsx`, `ts`, `tsx` or `dts`. */
141
+ lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
142
142
  /** Treat the source text as `script` or `module` code. */
143
143
  sourceType?: 'script' | 'module' | 'unambiguous' | undefined
144
144
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.75.1",
3
+ "version": "0.77.0",
4
4
  "main": "index.js",
5
5
  "browser": "wasm.mjs",
6
6
  "engines": {
@@ -33,9 +33,9 @@
33
33
  "webcontainer-fallback.js",
34
34
  "generated/deserialize/js.js",
35
35
  "generated/deserialize/ts.js",
36
- "generated/deserialize/lazy.js",
37
- "generated/deserialize/lazy-types.js",
38
- "generated/deserialize/lazy-visit.js",
36
+ "generated/lazy/constructors.js",
37
+ "generated/lazy/types.js",
38
+ "generated/lazy/walk.js",
39
39
  "raw-transfer/common.js",
40
40
  "raw-transfer/eager.js",
41
41
  "raw-transfer/lazy.js",
@@ -49,7 +49,7 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@oxc-project/types": "^0.75.1"
52
+ "@oxc-project/types": "^0.77.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@codspeed/vitest-plugin": "^4.0.0",
@@ -89,24 +89,25 @@
89
89
  "dtsHeaderFile": "header.js"
90
90
  },
91
91
  "optionalDependencies": {
92
- "@oxc-parser/binding-win32-x64-msvc": "0.75.1",
93
- "@oxc-parser/binding-win32-arm64-msvc": "0.75.1",
94
- "@oxc-parser/binding-linux-x64-gnu": "0.75.1",
95
- "@oxc-parser/binding-linux-x64-musl": "0.75.1",
96
- "@oxc-parser/binding-freebsd-x64": "0.75.1",
97
- "@oxc-parser/binding-linux-arm64-gnu": "0.75.1",
98
- "@oxc-parser/binding-linux-arm64-musl": "0.75.1",
99
- "@oxc-parser/binding-linux-arm-gnueabihf": "0.75.1",
100
- "@oxc-parser/binding-linux-arm-musleabihf": "0.75.1",
101
- "@oxc-parser/binding-linux-s390x-gnu": "0.75.1",
102
- "@oxc-parser/binding-linux-riscv64-gnu": "0.75.1",
103
- "@oxc-parser/binding-darwin-x64": "0.75.1",
104
- "@oxc-parser/binding-darwin-arm64": "0.75.1",
105
- "@oxc-parser/binding-android-arm64": "0.75.1",
106
- "@oxc-parser/binding-wasm32-wasi": "0.75.1"
92
+ "@oxc-parser/binding-win32-x64-msvc": "0.77.0",
93
+ "@oxc-parser/binding-win32-arm64-msvc": "0.77.0",
94
+ "@oxc-parser/binding-linux-x64-gnu": "0.77.0",
95
+ "@oxc-parser/binding-linux-x64-musl": "0.77.0",
96
+ "@oxc-parser/binding-freebsd-x64": "0.77.0",
97
+ "@oxc-parser/binding-linux-arm64-gnu": "0.77.0",
98
+ "@oxc-parser/binding-linux-arm64-musl": "0.77.0",
99
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.77.0",
100
+ "@oxc-parser/binding-linux-arm-musleabihf": "0.77.0",
101
+ "@oxc-parser/binding-linux-s390x-gnu": "0.77.0",
102
+ "@oxc-parser/binding-linux-riscv64-gnu": "0.77.0",
103
+ "@oxc-parser/binding-darwin-x64": "0.77.0",
104
+ "@oxc-parser/binding-darwin-arm64": "0.77.0",
105
+ "@oxc-parser/binding-android-arm64": "0.77.0",
106
+ "@oxc-parser/binding-wasm32-wasi": "0.77.0"
107
107
  },
108
108
  "scripts": {
109
109
  "build-dev": "napi build --platform --js bindings.js",
110
+ "build-test": "pnpm run build",
110
111
  "build": "pnpm run build-dev --features allocator --release",
111
112
  "postbuild-dev": "node patch.mjs",
112
113
  "build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
@@ -2,8 +2,8 @@
2
2
 
3
3
  const { parseSyncRawImpl, parseAsyncRawImpl, returnBufferToCache } = require('./common.js'),
4
4
  { TOKEN } = require('./lazy-common.js'),
5
- constructLazyData = require('../generated/deserialize/lazy.js').construct,
6
- walkProgram = require('../generated/deserialize/lazy-visit.js'),
5
+ { RawTransferData } = require('../generated/lazy/constructors.js'),
6
+ walkProgram = require('../generated/lazy/walk.js'),
7
7
  { Visitor, getVisitorsArr } = require('./visitor.js');
8
8
 
9
9
  module.exports = { parseSyncLazy, parseAsyncLazy, Visitor };
@@ -104,7 +104,10 @@ function construct(buffer, sourceText, sourceLen) {
104
104
  bufferRecycleRegistry.register(ast, buffer, ast);
105
105
 
106
106
  // Get root data class instance
107
- const data = constructLazyData(ast);
107
+ // (2 * 1024 * 1024 * 1024 - 16) >> 2
108
+ const metadataPos32 = 536870908;
109
+ const rawDataPos = buffer.uint32[metadataPos32];
110
+ const data = new RawTransferData(rawDataPos, ast);
108
111
 
109
112
  return {
110
113
  get program() {
@@ -121,10 +124,7 @@ function construct(buffer, sourceText, sourceLen) {
121
124
  },
122
125
  dispose: dispose.bind(null, ast),
123
126
  visit(visitor) {
124
- // (2 * 1024 * 1024 * 1024 - 16) >> 2
125
- const metadataPos32 = 536870908;
126
- const pos = buffer.uint32[metadataPos32];
127
- walkProgram(pos, ast, getVisitorsArr(visitor));
127
+ walkProgram(rawDataPos, ast, getVisitorsArr(visitor));
128
128
  },
129
129
  };
130
130
  }
@@ -4,7 +4,7 @@ const {
4
4
  NODE_TYPE_IDS_MAP,
5
5
  NODE_TYPES_COUNT,
6
6
  LEAF_NODE_TYPES_COUNT,
7
- } = require('../generated/deserialize/lazy-types.js');
7
+ } = require('../generated/lazy/types.js');
8
8
 
9
9
  // Getter for private `#visitorsArr` property of `Visitor` class. Initialized in class body below.
10
10
  let getVisitorsArr;
@@ -64,7 +64,7 @@ module.exports = { Visitor, getVisitorsArr };
64
64
  */
65
65
  function createVisitorsArr(visitor) {
66
66
  if (visitor === null || typeof visitor !== 'object') {
67
- throw new Error('`visitors` must be an object');
67
+ throw new Error('`visitor` must be an object');
68
68
  }
69
69
 
70
70
  // Create empty visitors array
@@ -77,14 +77,14 @@ function createVisitorsArr(visitor) {
77
77
  for (let name of Object.keys(visitor)) {
78
78
  const visitFn = visitor[name];
79
79
  if (typeof visitFn !== 'function') {
80
- throw new Error(`'${name}' property of \`visitors\` object is not a function`);
80
+ throw new Error(`'${name}' property of \`visitor\` object is not a function`);
81
81
  }
82
82
 
83
83
  const isExit = name.endsWith(':exit');
84
84
  if (isExit) name = name.slice(0, -5);
85
85
 
86
86
  const typeId = NODE_TYPE_IDS_MAP.get(name);
87
- if (typeId === void 0) throw new Error(`Unknown node type '${name}' in \`visitors\` object`);
87
+ if (typeId === void 0) throw new Error(`Unknown node type '${name}' in \`visitor\` object`);
88
88
 
89
89
  if (typeId < LEAF_NODE_TYPES_COUNT) {
90
90
  // Leaf node. Store just 1 function.