oxc-parser 0.76.0 → 0.77.1

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
+ };
@@ -20,10 +20,7 @@ function deserialize(buffer, sourceTextInput, sourceLenInput) {
20
20
  sourceLen = sourceLenInput;
21
21
  sourceIsAscii = sourceText.length === sourceLen;
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 =
@@ -1627,9 +1624,10 @@ function deserializeTSTypeAliasDeclaration(pos) {
1627
1624
  function deserializeTSClassImplements(pos) {
1628
1625
  let expression = deserializeTSTypeName(pos + 8);
1629
1626
  if (expression.type === 'TSQualifiedName') {
1627
+ let object = expression.left;
1630
1628
  let parent = expression = {
1631
1629
  type: 'MemberExpression',
1632
- object: expression.left,
1630
+ object,
1633
1631
  property: expression.right,
1634
1632
  optional: false,
1635
1633
  computed: false,
@@ -1637,17 +1635,18 @@ function deserializeTSClassImplements(pos) {
1637
1635
  end: expression.end,
1638
1636
  };
1639
1637
 
1640
- while (parent.object.type === 'TSQualifiedName') {
1641
- const object = parent.object;
1638
+ while (object.type === 'TSQualifiedName') {
1639
+ const { left } = object;
1642
1640
  parent = parent.object = {
1643
1641
  type: 'MemberExpression',
1644
- object: object.left,
1642
+ object: left,
1645
1643
  property: object.right,
1646
1644
  optional: false,
1647
1645
  computed: false,
1648
1646
  start: object.start,
1649
1647
  end: object.end,
1650
1648
  };
1649
+ object = left;
1651
1650
  }
1652
1651
  }
1653
1652
  return {
@@ -3637,11 +3636,11 @@ function deserializeTSTupleElement(pos) {
3637
3636
  function deserializeTSTypeName(pos) {
3638
3637
  switch (uint8[pos]) {
3639
3638
  case 0:
3640
- let id = deserializeBoxIdentifierReference(pos + 8);
3641
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3642
- return id;
3639
+ return deserializeBoxIdentifierReference(pos + 8);
3643
3640
  case 1:
3644
3641
  return deserializeBoxTSQualifiedName(pos + 8);
3642
+ case 2:
3643
+ return deserializeBoxThisExpression(pos + 8);
3645
3644
  default:
3646
3645
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeName`);
3647
3646
  }
@@ -3739,12 +3738,12 @@ function deserializeTSModuleDeclarationBody(pos) {
3739
3738
  function deserializeTSTypeQueryExprName(pos) {
3740
3739
  switch (uint8[pos]) {
3741
3740
  case 0:
3742
- let id = deserializeBoxIdentifierReference(pos + 8);
3743
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3744
- return id;
3741
+ return deserializeBoxIdentifierReference(pos + 8);
3745
3742
  case 1:
3746
3743
  return deserializeBoxTSQualifiedName(pos + 8);
3747
3744
  case 2:
3745
+ return deserializeBoxThisExpression(pos + 8);
3746
+ case 3:
3748
3747
  return deserializeBoxTSImportType(pos + 8);
3749
3748
  default:
3750
3749
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeQueryExprName`);
@@ -3767,12 +3766,12 @@ function deserializeTSMappedTypeModifierOperator(pos) {
3767
3766
  function deserializeTSModuleReference(pos) {
3768
3767
  switch (uint8[pos]) {
3769
3768
  case 0:
3770
- let id = deserializeBoxIdentifierReference(pos + 8);
3771
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3772
- return id;
3769
+ return deserializeBoxIdentifierReference(pos + 8);
3773
3770
  case 1:
3774
3771
  return deserializeBoxTSQualifiedName(pos + 8);
3775
3772
  case 2:
3773
+ return deserializeBoxThisExpression(pos + 8);
3774
+ case 3:
3776
3775
  return deserializeBoxTSExternalModuleReference(pos + 8);
3777
3776
  default:
3778
3777
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSModuleReference`);
@@ -5222,7 +5221,7 @@ function deserializeOptionBoxObjectExpression(pos) {
5222
5221
  }
5223
5222
 
5224
5223
  function deserializeOptionTSTypeName(pos) {
5225
- if (uint8[pos] === 2) return null;
5224
+ if (uint8[pos] === 3) return null;
5226
5225
  return deserializeTSTypeName(pos);
5227
5226
  }
5228
5227
 
@@ -20,10 +20,7 @@ function deserialize(buffer, sourceTextInput, sourceLenInput) {
20
20
  sourceLen = sourceLenInput;
21
21
  sourceIsAscii = sourceText.length === sourceLen;
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 =
@@ -1758,9 +1755,10 @@ function deserializeTSTypeAliasDeclaration(pos) {
1758
1755
  function deserializeTSClassImplements(pos) {
1759
1756
  let expression = deserializeTSTypeName(pos + 8);
1760
1757
  if (expression.type === 'TSQualifiedName') {
1758
+ let object = expression.left;
1761
1759
  let parent = expression = {
1762
1760
  type: 'MemberExpression',
1763
- object: expression.left,
1761
+ object,
1764
1762
  property: expression.right,
1765
1763
  optional: false,
1766
1764
  computed: false,
@@ -1768,17 +1766,18 @@ function deserializeTSClassImplements(pos) {
1768
1766
  end: expression.end,
1769
1767
  };
1770
1768
 
1771
- while (parent.object.type === 'TSQualifiedName') {
1772
- const object = parent.object;
1769
+ while (object.type === 'TSQualifiedName') {
1770
+ const { left } = object;
1773
1771
  parent = parent.object = {
1774
1772
  type: 'MemberExpression',
1775
- object: object.left,
1773
+ object: left,
1776
1774
  property: object.right,
1777
1775
  optional: false,
1778
1776
  computed: false,
1779
1777
  start: object.start,
1780
1778
  end: object.end,
1781
1779
  };
1780
+ object = left;
1782
1781
  }
1783
1782
  }
1784
1783
  return {
@@ -3768,11 +3767,11 @@ function deserializeTSTupleElement(pos) {
3768
3767
  function deserializeTSTypeName(pos) {
3769
3768
  switch (uint8[pos]) {
3770
3769
  case 0:
3771
- let id = deserializeBoxIdentifierReference(pos + 8);
3772
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3773
- return id;
3770
+ return deserializeBoxIdentifierReference(pos + 8);
3774
3771
  case 1:
3775
3772
  return deserializeBoxTSQualifiedName(pos + 8);
3773
+ case 2:
3774
+ return deserializeBoxThisExpression(pos + 8);
3776
3775
  default:
3777
3776
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeName`);
3778
3777
  }
@@ -3870,12 +3869,12 @@ function deserializeTSModuleDeclarationBody(pos) {
3870
3869
  function deserializeTSTypeQueryExprName(pos) {
3871
3870
  switch (uint8[pos]) {
3872
3871
  case 0:
3873
- let id = deserializeBoxIdentifierReference(pos + 8);
3874
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3875
- return id;
3872
+ return deserializeBoxIdentifierReference(pos + 8);
3876
3873
  case 1:
3877
3874
  return deserializeBoxTSQualifiedName(pos + 8);
3878
3875
  case 2:
3876
+ return deserializeBoxThisExpression(pos + 8);
3877
+ case 3:
3879
3878
  return deserializeBoxTSImportType(pos + 8);
3880
3879
  default:
3881
3880
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeQueryExprName`);
@@ -3898,12 +3897,12 @@ function deserializeTSMappedTypeModifierOperator(pos) {
3898
3897
  function deserializeTSModuleReference(pos) {
3899
3898
  switch (uint8[pos]) {
3900
3899
  case 0:
3901
- let id = deserializeBoxIdentifierReference(pos + 8);
3902
- if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
3903
- return id;
3900
+ return deserializeBoxIdentifierReference(pos + 8);
3904
3901
  case 1:
3905
3902
  return deserializeBoxTSQualifiedName(pos + 8);
3906
3903
  case 2:
3904
+ return deserializeBoxThisExpression(pos + 8);
3905
+ case 3:
3907
3906
  return deserializeBoxTSExternalModuleReference(pos + 8);
3908
3907
  default:
3909
3908
  throw new Error(`Unexpected discriminant ${uint8[pos]} for TSModuleReference`);
@@ -5353,7 +5352,7 @@ function deserializeOptionBoxObjectExpression(pos) {
5353
5352
  }
5354
5353
 
5355
5354
  function deserializeOptionTSTypeName(pos) {
5356
- if (uint8[pos] === 2) return null;
5355
+ if (uint8[pos] === 3) return null;
5357
5356
  return deserializeTSTypeName(pos);
5358
5357
  }
5359
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`);
@@ -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/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.76.0",
3
+ "version": "0.77.1",
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.76.0"
53
+ "@oxc-project/types": "^0.77.1"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@codspeed/vitest-plugin": "^4.0.0",
@@ -89,24 +90,25 @@
89
90
  "dtsHeaderFile": "header.js"
90
91
  },
91
92
  "optionalDependencies": {
92
- "@oxc-parser/binding-win32-x64-msvc": "0.76.0",
93
- "@oxc-parser/binding-win32-arm64-msvc": "0.76.0",
94
- "@oxc-parser/binding-linux-x64-gnu": "0.76.0",
95
- "@oxc-parser/binding-linux-x64-musl": "0.76.0",
96
- "@oxc-parser/binding-freebsd-x64": "0.76.0",
97
- "@oxc-parser/binding-linux-arm64-gnu": "0.76.0",
98
- "@oxc-parser/binding-linux-arm64-musl": "0.76.0",
99
- "@oxc-parser/binding-linux-arm-gnueabihf": "0.76.0",
100
- "@oxc-parser/binding-linux-arm-musleabihf": "0.76.0",
101
- "@oxc-parser/binding-linux-s390x-gnu": "0.76.0",
102
- "@oxc-parser/binding-linux-riscv64-gnu": "0.76.0",
103
- "@oxc-parser/binding-darwin-x64": "0.76.0",
104
- "@oxc-parser/binding-darwin-arm64": "0.76.0",
105
- "@oxc-parser/binding-android-arm64": "0.76.0",
106
- "@oxc-parser/binding-wasm32-wasi": "0.76.0"
93
+ "@oxc-parser/binding-win32-x64-msvc": "0.77.1",
94
+ "@oxc-parser/binding-win32-arm64-msvc": "0.77.1",
95
+ "@oxc-parser/binding-linux-x64-gnu": "0.77.1",
96
+ "@oxc-parser/binding-linux-x64-musl": "0.77.1",
97
+ "@oxc-parser/binding-freebsd-x64": "0.77.1",
98
+ "@oxc-parser/binding-linux-arm64-gnu": "0.77.1",
99
+ "@oxc-parser/binding-linux-arm64-musl": "0.77.1",
100
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.77.1",
101
+ "@oxc-parser/binding-linux-arm-musleabihf": "0.77.1",
102
+ "@oxc-parser/binding-linux-s390x-gnu": "0.77.1",
103
+ "@oxc-parser/binding-linux-riscv64-gnu": "0.77.1",
104
+ "@oxc-parser/binding-darwin-x64": "0.77.1",
105
+ "@oxc-parser/binding-darwin-arm64": "0.77.1",
106
+ "@oxc-parser/binding-android-arm64": "0.77.1",
107
+ "@oxc-parser/binding-wasm32-wasi": "0.77.1"
107
108
  },
108
109
  "scripts": {
109
110
  "build-dev": "napi build --platform --js bindings.js",
111
+ "build-test": "pnpm run build",
110
112
  "build": "pnpm run build-dev --features allocator --release",
111
113
  "postbuild-dev": "node patch.mjs",
112
114
  "build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
@@ -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 _;
@@ -104,9 +103,7 @@ function construct(buffer, sourceText, sourceLen) {
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
  }