oxc-parser 0.77.0 → 0.77.2

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.
@@ -0,0 +1,16 @@
1
+ // Auto-generated code, DO NOT EDIT DIRECTLY!
2
+ // To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.
3
+
4
+ const BUFFER_SIZE = 2147483632,
5
+ BUFFER_ALIGN = 4294967296,
6
+ DATA_POINTER_POS_32 = 536870906,
7
+ IS_TS_FLAG_POS = 2147483628,
8
+ PROGRAM_OFFSET = 0;
9
+
10
+ module.exports = {
11
+ BUFFER_SIZE,
12
+ BUFFER_ALIGN,
13
+ DATA_POINTER_POS_32,
14
+ IS_TS_FLAG_POS,
15
+ PROGRAM_OFFSET,
16
+ };
@@ -5,25 +5,22 @@
5
5
 
6
6
  module.exports = deserialize;
7
7
 
8
- let uint8, uint32, float64, sourceText, sourceIsAscii, sourceLen;
8
+ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceByteLen;
9
9
 
10
10
  const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
11
11
  decodeStr = textDecoder.decode.bind(textDecoder),
12
12
  { fromCodePoint } = String;
13
13
 
14
- function deserialize(buffer, sourceTextInput, sourceLenInput) {
14
+ function deserialize(buffer, sourceTextInput, sourceByteLenInput) {
15
15
  uint8 = buffer;
16
16
  uint32 = buffer.uint32;
17
17
  float64 = buffer.float64;
18
18
 
19
19
  sourceText = sourceTextInput;
20
- sourceLen = sourceLenInput;
21
- sourceIsAscii = sourceText.length === sourceLen;
20
+ sourceByteLen = sourceByteLenInput;
21
+ sourceIsAscii = sourceText.length === sourceByteLen;
22
22
 
23
- // (2 * 1024 * 1024 * 1024 - 16) >> 2
24
- const metadataPos32 = 536870908;
25
-
26
- const data = deserializeRawTransferData(uint32[metadataPos32]);
23
+ const data = deserializeRawTransferData(uint32[536870906]);
27
24
 
28
25
  uint8 =
29
26
  uint32 =
@@ -3639,11 +3636,11 @@ function deserializeTSTupleElement(pos) {
3639
3636
  function deserializeTSTypeName(pos) {
3640
3637
  switch (uint8[pos]) {
3641
3638
  case 0:
3642
- let id = deserializeBoxIdentifierReference(pos + 8);
3643
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3644
- return id;
3639
+ return deserializeBoxIdentifierReference(pos + 8);
3645
3640
  case 1:
3646
3641
  return deserializeBoxTSQualifiedName(pos + 8);
3642
+ case 2:
3643
+ return deserializeBoxThisExpression(pos + 8);
3647
3644
  default:
3648
3645
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeName`);
3649
3646
  }
@@ -3741,12 +3738,12 @@ function deserializeTSModuleDeclarationBody(pos) {
3741
3738
  function deserializeTSTypeQueryExprName(pos) {
3742
3739
  switch (uint8[pos]) {
3743
3740
  case 0:
3744
- let id = deserializeBoxIdentifierReference(pos + 8);
3745
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3746
- return id;
3741
+ return deserializeBoxIdentifierReference(pos + 8);
3747
3742
  case 1:
3748
3743
  return deserializeBoxTSQualifiedName(pos + 8);
3749
3744
  case 2:
3745
+ return deserializeBoxThisExpression(pos + 8);
3746
+ case 3:
3750
3747
  return deserializeBoxTSImportType(pos + 8);
3751
3748
  default:
3752
3749
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeQueryExprName`);
@@ -3769,12 +3766,12 @@ function deserializeTSMappedTypeModifierOperator(pos) {
3769
3766
  function deserializeTSModuleReference(pos) {
3770
3767
  switch (uint8[pos]) {
3771
3768
  case 0:
3772
- let id = deserializeBoxIdentifierReference(pos + 8);
3773
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3774
- return id;
3769
+ return deserializeBoxIdentifierReference(pos + 8);
3775
3770
  case 1:
3776
3771
  return deserializeBoxTSQualifiedName(pos + 8);
3777
3772
  case 2:
3773
+ return deserializeBoxThisExpression(pos + 8);
3774
+ case 3:
3778
3775
  return deserializeBoxTSExternalModuleReference(pos + 8);
3779
3776
  default:
3780
3777
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSModuleReference`);
@@ -4029,7 +4026,7 @@ function deserializeStr(pos) {
4029
4026
  if (len === 0) return '';
4030
4027
 
4031
4028
  pos = uint32[pos32];
4032
- if (sourceIsAscii && pos < sourceLen) return sourceText.substr(pos, len);
4029
+ if (sourceIsAscii && pos < sourceByteLen) return sourceText.substr(pos, len);
4033
4030
 
4034
4031
  // Longer strings use `TextDecoder`
4035
4032
  // TODO: Find best switch-over point
@@ -5224,7 +5221,7 @@ function deserializeOptionBoxObjectExpression(pos) {
5224
5221
  }
5225
5222
 
5226
5223
  function deserializeOptionTSTypeName(pos) {
5227
- if (uint8[pos] === 2) return null;
5224
+ if (uint8[pos] === 3) return null;
5228
5225
  return deserializeTSTypeName(pos);
5229
5226
  }
5230
5227
 
@@ -5,25 +5,22 @@
5
5
 
6
6
  module.exports = deserialize;
7
7
 
8
- let uint8, uint32, float64, sourceText, sourceIsAscii, sourceLen;
8
+ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceByteLen;
9
9
 
10
10
  const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
11
11
  decodeStr = textDecoder.decode.bind(textDecoder),
12
12
  { fromCodePoint } = String;
13
13
 
14
- function deserialize(buffer, sourceTextInput, sourceLenInput) {
14
+ function deserialize(buffer, sourceTextInput, sourceByteLenInput) {
15
15
  uint8 = buffer;
16
16
  uint32 = buffer.uint32;
17
17
  float64 = buffer.float64;
18
18
 
19
19
  sourceText = sourceTextInput;
20
- sourceLen = sourceLenInput;
21
- sourceIsAscii = sourceText.length === sourceLen;
20
+ sourceByteLen = sourceByteLenInput;
21
+ sourceIsAscii = sourceText.length === sourceByteLen;
22
22
 
23
- // (2 * 1024 * 1024 * 1024 - 16) >> 2
24
- const metadataPos32 = 536870908;
25
-
26
- const data = deserializeRawTransferData(uint32[metadataPos32]);
23
+ const data = deserializeRawTransferData(uint32[536870906]);
27
24
 
28
25
  uint8 =
29
26
  uint32 =
@@ -3770,11 +3767,11 @@ function deserializeTSTupleElement(pos) {
3770
3767
  function deserializeTSTypeName(pos) {
3771
3768
  switch (uint8[pos]) {
3772
3769
  case 0:
3773
- let id = deserializeBoxIdentifierReference(pos + 8);
3774
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3775
- return id;
3770
+ return deserializeBoxIdentifierReference(pos + 8);
3776
3771
  case 1:
3777
3772
  return deserializeBoxTSQualifiedName(pos + 8);
3773
+ case 2:
3774
+ return deserializeBoxThisExpression(pos + 8);
3778
3775
  default:
3779
3776
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeName`);
3780
3777
  }
@@ -3872,12 +3869,12 @@ function deserializeTSModuleDeclarationBody(pos) {
3872
3869
  function deserializeTSTypeQueryExprName(pos) {
3873
3870
  switch (uint8[pos]) {
3874
3871
  case 0:
3875
- let id = deserializeBoxIdentifierReference(pos + 8);
3876
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3877
- return id;
3872
+ return deserializeBoxIdentifierReference(pos + 8);
3878
3873
  case 1:
3879
3874
  return deserializeBoxTSQualifiedName(pos + 8);
3880
3875
  case 2:
3876
+ return deserializeBoxThisExpression(pos + 8);
3877
+ case 3:
3881
3878
  return deserializeBoxTSImportType(pos + 8);
3882
3879
  default:
3883
3880
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeQueryExprName`);
@@ -3900,12 +3897,12 @@ function deserializeTSMappedTypeModifierOperator(pos) {
3900
3897
  function deserializeTSModuleReference(pos) {
3901
3898
  switch (uint8[pos]) {
3902
3899
  case 0:
3903
- let id = deserializeBoxIdentifierReference(pos + 8);
3904
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3905
- return id;
3900
+ return deserializeBoxIdentifierReference(pos + 8);
3906
3901
  case 1:
3907
3902
  return deserializeBoxTSQualifiedName(pos + 8);
3908
3903
  case 2:
3904
+ return deserializeBoxThisExpression(pos + 8);
3905
+ case 3:
3909
3906
  return deserializeBoxTSExternalModuleReference(pos + 8);
3910
3907
  default:
3911
3908
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSModuleReference`);
@@ -4160,7 +4157,7 @@ function deserializeStr(pos) {
4160
4157
  if (len === 0) return '';
4161
4158
 
4162
4159
  pos = uint32[pos32];
4163
- if (sourceIsAscii && pos < sourceLen) return sourceText.substr(pos, len);
4160
+ if (sourceIsAscii && pos < sourceByteLen) return sourceText.substr(pos, len);
4164
4161
 
4165
4162
  // Longer strings use `TextDecoder`
4166
4163
  // TODO: Find best switch-over point
@@ -5355,7 +5352,7 @@ function deserializeOptionBoxObjectExpression(pos) {
5355
5352
  }
5356
5353
 
5357
5354
  function deserializeOptionTSTypeName(pos) {
5358
- if (uint8[pos] === 2) return null;
5355
+ if (uint8[pos] === 3) return null;
5359
5356
  return deserializeTSTypeName(pos);
5360
5357
  }
5361
5358
 
@@ -9286,6 +9286,8 @@ function constructTSTypeName(pos, ast) {
9286
9286
  return constructBoxIdentifierReference(pos + 8, ast);
9287
9287
  case 1:
9288
9288
  return constructBoxTSQualifiedName(pos + 8, ast);
9289
+ case 2:
9290
+ return constructBoxThisExpression(pos + 8, ast);
9289
9291
  default:
9290
9292
  throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSTypeName`);
9291
9293
  }
@@ -10603,6 +10605,8 @@ function constructTSTypeQueryExprName(pos, ast) {
10603
10605
  case 1:
10604
10606
  return constructBoxTSQualifiedName(pos + 8, ast);
10605
10607
  case 2:
10608
+ return constructBoxThisExpression(pos + 8, ast);
10609
+ case 3:
10606
10610
  return constructBoxTSImportType(pos + 8, ast);
10607
10611
  default:
10608
10612
  throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSTypeQueryExprName`);
@@ -11149,6 +11153,8 @@ function constructTSModuleReference(pos, ast) {
11149
11153
  case 1:
11150
11154
  return constructBoxTSQualifiedName(pos + 8, ast);
11151
11155
  case 2:
11156
+ return constructBoxThisExpression(pos + 8, ast);
11157
+ case 3:
11152
11158
  return constructBoxTSExternalModuleReference(pos + 8, ast);
11153
11159
  default:
11154
11160
  throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleReference`);
@@ -12474,7 +12480,7 @@ function constructStr(pos, ast) {
12474
12480
  if (len === 0) return '';
12475
12481
 
12476
12482
  pos = uint32[pos32];
12477
- if (ast.sourceIsAscii && pos < ast.sourceLen) return ast.sourceText.substr(pos, len);
12483
+ if (ast.sourceIsAscii && pos < ast.sourceByteLen) return ast.sourceText.substr(pos, len);
12478
12484
 
12479
12485
  // Longer strings use `TextDecoder`
12480
12486
  // TODO: Find best switch-over point
@@ -13729,7 +13735,7 @@ function constructOptionBoxObjectExpression(pos, ast) {
13729
13735
  }
13730
13736
 
13731
13737
  function constructOptionTSTypeName(pos, ast) {
13732
- if (ast.buffer[pos] === 2) return null;
13738
+ if (ast.buffer[pos] === 3) return null;
13733
13739
  return constructTSTypeName(pos, ast);
13734
13740
  }
13735
13741
 
@@ -3707,6 +3707,9 @@ function walkTSTypeName(pos, ast, visitors) {
3707
3707
  case 1:
3708
3708
  walkBoxTSQualifiedName(pos + 8, ast, visitors);
3709
3709
  return;
3710
+ case 2:
3711
+ walkBoxThisExpression(pos + 8, ast, visitors);
3712
+ return;
3710
3713
  default:
3711
3714
  throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSTypeName`);
3712
3715
  }
@@ -4098,6 +4101,9 @@ function walkTSTypeQueryExprName(pos, ast, visitors) {
4098
4101
  walkBoxTSQualifiedName(pos + 8, ast, visitors);
4099
4102
  return;
4100
4103
  case 2:
4104
+ walkBoxThisExpression(pos + 8, ast, visitors);
4105
+ return;
4106
+ case 3:
4101
4107
  walkBoxTSImportType(pos + 8, ast, visitors);
4102
4108
  return;
4103
4109
  default:
@@ -4253,6 +4259,9 @@ function walkTSModuleReference(pos, ast, visitors) {
4253
4259
  walkBoxTSQualifiedName(pos + 8, ast, visitors);
4254
4260
  return;
4255
4261
  case 2:
4262
+ walkBoxThisExpression(pos + 8, ast, visitors);
4263
+ return;
4264
+ case 3:
4256
4265
  walkBoxTSExternalModuleReference(pos + 8, ast, visitors);
4257
4266
  return;
4258
4267
  default:
@@ -5449,7 +5458,7 @@ function walkOptionBoxObjectExpression(pos, ast, visitors) {
5449
5458
  }
5450
5459
 
5451
5460
  function walkOptionTSTypeName(pos, ast, visitors) {
5452
- if (!(ast.buffer[pos] === 2)) walkTSTypeName(pos, ast, visitors);
5461
+ if (!(ast.buffer[pos] === 3)) walkTSTypeName(pos, ast, visitors);
5453
5462
  }
5454
5463
 
5455
5464
  function walkBoxTSExternalModuleReference(pos, ast, visitors) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.77.0",
3
+ "version": "0.77.2",
4
4
  "main": "index.js",
5
5
  "browser": "wasm.mjs",
6
6
  "engines": {
@@ -31,6 +31,7 @@
31
31
  "wasm.mjs",
32
32
  "bindings.js",
33
33
  "webcontainer-fallback.js",
34
+ "generated/constants.js",
34
35
  "generated/deserialize/js.js",
35
36
  "generated/deserialize/ts.js",
36
37
  "generated/lazy/constructors.js",
@@ -49,7 +50,7 @@
49
50
  "access": "public"
50
51
  },
51
52
  "dependencies": {
52
- "@oxc-project/types": "^0.77.0"
53
+ "@oxc-project/types": "^0.77.2"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@codspeed/vitest-plugin": "^4.0.0",
@@ -89,21 +90,21 @@
89
90
  "dtsHeaderFile": "header.js"
90
91
  },
91
92
  "optionalDependencies": {
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"
93
+ "@oxc-parser/binding-win32-x64-msvc": "0.77.2",
94
+ "@oxc-parser/binding-win32-arm64-msvc": "0.77.2",
95
+ "@oxc-parser/binding-linux-x64-gnu": "0.77.2",
96
+ "@oxc-parser/binding-linux-x64-musl": "0.77.2",
97
+ "@oxc-parser/binding-freebsd-x64": "0.77.2",
98
+ "@oxc-parser/binding-linux-arm64-gnu": "0.77.2",
99
+ "@oxc-parser/binding-linux-arm64-musl": "0.77.2",
100
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.77.2",
101
+ "@oxc-parser/binding-linux-arm-musleabihf": "0.77.2",
102
+ "@oxc-parser/binding-linux-s390x-gnu": "0.77.2",
103
+ "@oxc-parser/binding-linux-riscv64-gnu": "0.77.2",
104
+ "@oxc-parser/binding-darwin-x64": "0.77.2",
105
+ "@oxc-parser/binding-darwin-arm64": "0.77.2",
106
+ "@oxc-parser/binding-android-arm64": "0.77.2",
107
+ "@oxc-parser/binding-wasm32-wasi": "0.77.2"
107
108
  },
108
109
  "scripts": {
109
110
  "build-dev": "napi build --platform --js bindings.js",
@@ -7,6 +7,7 @@ const {
7
7
  parseAsyncRaw: parseAsyncRawBinding,
8
8
  getBufferOffset,
9
9
  } = require('../bindings.js');
10
+ const { BUFFER_SIZE, BUFFER_ALIGN, IS_TS_FLAG_POS } = require('../generated/constants.js');
10
11
 
11
12
  module.exports = {
12
13
  parseSyncRawImpl,
@@ -16,6 +17,18 @@ module.exports = {
16
17
  returnBufferToCache,
17
18
  };
18
19
 
20
+ // Throw an error if running on a platform which raw transfer doesn't support.
21
+ //
22
+ // Note: This module is lazy-loaded only when user calls `parseSync` or `parseAsync` with
23
+ // `experimentalRawTransfer` or `experimentalLazy` options, or calls `experimentalGetLazyVisitor`.
24
+ if (!rawTransferSupported()) {
25
+ throw new Error(
26
+ '`experimentalRawTransfer` and `experimentalLazy` options are not supported ' +
27
+ 'on 32-bit or big-endian systems, versions of NodeJS prior to v22.0.0, ' +
28
+ 'versions of Deno prior to v2.0.0, or other runtimes',
29
+ );
30
+ }
31
+
19
32
  /**
20
33
  * Parse JS/TS source synchronously on current thread using raw transfer.
21
34
  *
@@ -28,7 +41,6 @@ module.exports = {
28
41
  * @param {Object|undefined} options - Parsing options
29
42
  * @param {function} convert - Function to convert the buffer returned from Rust into a JS object
30
43
  * @returns {Object} - The return value of `convert`
31
- * @throws {Error} - If raw transfer is not supported on this platform
32
44
  */
33
45
  function parseSyncRawImpl(filename, sourceText, options, convert) {
34
46
  const { buffer, sourceByteLen } = prepareRaw(sourceText);
@@ -88,7 +100,6 @@ const queue = [];
88
100
  * @param {Object|undefined} options - Parsing options
89
101
  * @param {function} convert - Function to convert the buffer returned from Rust into a JS object
90
102
  * @returns {Object} - The return value of `convert`
91
- * @throws {Error} - If raw transfer is not supported on this platform
92
103
  */
93
104
  async function parseAsyncRawImpl(filename, sourceText, options, convert) {
94
105
  // Wait for a free CPU core if all CPUs are currently busy.
@@ -130,9 +141,8 @@ async function parseAsyncRawImpl(filename, sourceText, options, convert) {
130
141
  return data;
131
142
  }
132
143
 
133
- const ONE_GIB = 1 << 30,
134
- TWO_GIB = ONE_GIB * 2,
135
- SIX_GIB = ONE_GIB * 6;
144
+ const ARRAY_BUFFER_SIZE = BUFFER_SIZE + BUFFER_ALIGN;
145
+ const ONE_GIB = 1 << 30;
136
146
 
137
147
  // We keep a cache of buffers for raw transfer, so we can reuse them as much as possible.
138
148
  //
@@ -177,17 +187,8 @@ const textEncoder = new TextEncoder();
177
187
  * - `buffer`: `Uint8Array` containing the AST in raw form.
178
188
  * - `sourceByteLen`: Length of source text in UTF-8 bytes
179
189
  * (which may not be equal to `sourceText.length` if source contains non-ASCII characters).
180
- * @throws {Error} - If raw transfer is not supported on this platform
181
190
  */
182
191
  function prepareRaw(sourceText) {
183
- if (!rawTransferSupported()) {
184
- throw new Error(
185
- '`experimentalRawTransfer` and `experimentalLazy` options are not supported ' +
186
- 'on 32-bit or big-endian systems, versions of NodeJS prior to v22.0.0, ' +
187
- 'versions of Deno prior to v2.0.0, or other runtimes',
188
- );
189
- }
190
-
191
192
  // Cancel timeout for clearing buffers
192
193
  if (clearBuffersTimeout !== null) {
193
194
  clearTimeout(clearBuffersTimeout);
@@ -226,9 +227,7 @@ function prepareRaw(sourceText) {
226
227
  * @returns {boolean} - `true` if AST is JS, `false` if TS
227
228
  */
228
229
  function isJsAst(buffer) {
229
- // 2147483636 = (2 * 1024 * 1024 * 1024) - 12
230
- // i.e. 12 bytes from end of 2 GiB buffer
231
- return buffer[2147483636] === 0;
230
+ return buffer[IS_TS_FLAG_POS] === 0;
232
231
  }
233
232
 
234
233
  /**
@@ -277,10 +276,10 @@ function clearBuffersCache() {
277
276
  * @returns {Uint8Array} - Buffer
278
277
  */
279
278
  function createBuffer() {
280
- const arrayBuffer = new ArrayBuffer(SIX_GIB);
279
+ const arrayBuffer = new ArrayBuffer(ARRAY_BUFFER_SIZE);
281
280
  const offset = getBufferOffset(new Uint8Array(arrayBuffer));
282
- const buffer = new Uint8Array(arrayBuffer, offset, TWO_GIB);
283
- buffer.uint32 = new Uint32Array(arrayBuffer, offset, TWO_GIB / 4);
284
- buffer.float64 = new Float64Array(arrayBuffer, offset, TWO_GIB / 8);
281
+ const buffer = new Uint8Array(arrayBuffer, offset, BUFFER_SIZE);
282
+ buffer.uint32 = new Uint32Array(arrayBuffer, offset, BUFFER_SIZE / 4);
283
+ buffer.float64 = new Float64Array(arrayBuffer, offset, BUFFER_SIZE / 8);
285
284
  return buffer;
286
285
  }
@@ -11,7 +11,6 @@ module.exports = { parseSyncRaw, parseAsyncRaw };
11
11
  * @param {string} sourceText - Source text of file
12
12
  * @param {Object} options - Parsing options
13
13
  * @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`
14
- * @throws {Error} - If raw transfer is not supported on this platform
15
14
  */
16
15
  function parseSyncRaw(filename, sourceText, options) {
17
16
  let _;
@@ -36,7 +35,6 @@ function parseSyncRaw(filename, sourceText, options) {
36
35
  * @param {string} sourceText - Source text of file
37
36
  * @param {Object} options - Parsing options
38
37
  * @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`
39
- * @throws {Error} - If raw transfer is not supported on this platform
40
38
  */
41
39
  function parseAsyncRaw(filename, sourceText, options) {
42
40
  let _;
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { parseSyncRawImpl, parseAsyncRawImpl, returnBufferToCache } = require('./common.js'),
4
4
  { TOKEN } = require('./lazy-common.js'),
5
+ { DATA_POINTER_POS_32, PROGRAM_OFFSET } = require('../generated/constants.js'),
5
6
  { RawTransferData } = require('../generated/lazy/constructors.js'),
6
7
  walkProgram = require('../generated/lazy/walk.js'),
7
8
  { Visitor, getVisitorsArr } = require('./visitor.js');
@@ -30,7 +31,6 @@ module.exports = { parseSyncLazy, parseAsyncLazy, Visitor };
30
31
  * @param {Object} options - Parsing options
31
32
  * @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`,
32
33
  * and `dispose` and `visit` methods
33
- * @throws {Error} - If raw transfer is not supported on this platform
34
34
  */
35
35
  function parseSyncLazy(filename, sourceText, options) {
36
36
  let _;
@@ -64,7 +64,6 @@ function parseSyncLazy(filename, sourceText, options) {
64
64
  * @param {Object} options - Parsing options
65
65
  * @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`,
66
66
  * and `dispose` and `visit` methods
67
- * @throws {Error} - If raw transfer is not supported on this platform
68
67
  */
69
68
  function parseAsyncLazy(filename, sourceText, options) {
70
69
  let _;
@@ -94,19 +93,17 @@ const bufferRecycleRegistry = typeof FinalizationRegistry === 'undefined'
94
93
  * @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`,
95
94
  * and `dispose` and `visit` methods
96
95
  */
97
- function construct(buffer, sourceText, sourceLen) {
96
+ function construct(buffer, sourceText, sourceByteLen) {
98
97
  // Create AST object
99
- const sourceIsAscii = sourceText.length === sourceLen;
100
- const ast = { buffer, sourceText, sourceLen, sourceIsAscii, nodes: new Map(), token: TOKEN };
98
+ const sourceIsAscii = sourceText.length === sourceByteLen;
99
+ const ast = { buffer, sourceText, sourceByteLen, sourceIsAscii, nodes: new Map(), token: TOKEN };
101
100
 
102
101
  // Register `ast` with the recycle registry so buffer is returned to cache
103
102
  // when `ast` is garbage collected
104
103
  bufferRecycleRegistry.register(ast, buffer, ast);
105
104
 
106
105
  // Get root data class instance
107
- // (2 * 1024 * 1024 * 1024 - 16) >> 2
108
- const metadataPos32 = 536870908;
109
- const rawDataPos = buffer.uint32[metadataPos32];
106
+ const rawDataPos = buffer.uint32[DATA_POINTER_POS_32];
110
107
  const data = new RawTransferData(rawDataPos, ast);
111
108
 
112
109
  return {
@@ -124,7 +121,7 @@ function construct(buffer, sourceText, sourceLen) {
124
121
  },
125
122
  dispose: dispose.bind(null, ast),
126
123
  visit(visitor) {
127
- walkProgram(rawDataPos, ast, getVisitorsArr(visitor));
124
+ walkProgram(rawDataPos + PROGRAM_OFFSET, ast, getVisitorsArr(visitor));
128
125
  },
129
126
  };
130
127
  }