oxc-parser 0.99.0 → 0.101.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.
@@ -1,4 +1,4 @@
1
- import { constructorError, TOKEN } from './lazy-common.js';
1
+ import { constructorError, TOKEN } from "./lazy-common.js";
2
2
 
3
3
  // Internal symbol to get `NodeArray` from a proxy wrapping a `NodeArray`.
4
4
  //
@@ -109,11 +109,17 @@ export class NodeArray extends Array {
109
109
  }
110
110
 
111
111
  const { stride } = internal;
112
- return new NodeArray(internal.pos + start * stride, sliceLength, stride, internal.construct, internal.ast);
112
+ return new NodeArray(
113
+ internal.pos + start * stride,
114
+ sliceLength,
115
+ stride,
116
+ internal.construct,
117
+ internal.ast,
118
+ );
113
119
  }
114
120
 
115
121
  // Make `console.log` deserialize all elements.
116
- [Symbol.for('nodejs.util.inspect.custom')]() {
122
+ [Symbol.for("nodejs.util.inspect.custom")]() {
117
123
  const values = [...this.values()];
118
124
  Object.setPrototypeOf(values, DebugNodeArray.prototype);
119
125
  return values;
@@ -139,7 +145,7 @@ export class NodeArray extends Array {
139
145
  *
140
146
  * @param {NodeArray} arr - `NodeArray` object
141
147
  * @param {number} index - Index of element to get
142
- * @returns {*|undefined} - Element at index `index`, or `undefined` if out of bounds
148
+ * @returns {*} - Element at index `index`, or `undefined` if out of bounds
143
149
  */
144
150
  getElement = (arr, index) => {
145
151
  const internal = arr.#internal;
@@ -265,7 +271,7 @@ const PROXY_HANDLERS = {
265
271
  // Methods of `NodeArray` are called with `this` being the proxy, rather than the `NodeArray` itself.
266
272
  // They can "unwrap" the proxy by getting `this[ARRAY]`.
267
273
  if (key === ARRAY) return arr;
268
- if (key === 'length') return getLength(arr);
274
+ if (key === "length") return getLength(arr);
269
275
  const index = toIndex(key);
270
276
  if (index !== null) return getElement(arr, index);
271
277
 
@@ -274,7 +280,7 @@ const PROXY_HANDLERS = {
274
280
 
275
281
  // Get descriptors for elements and length.
276
282
  getOwnPropertyDescriptor(arr, key) {
277
- if (key === 'length') {
283
+ if (key === "length") {
278
284
  // Cannot return `writable: false` unfortunately
279
285
  return { value: getLength(arr), writable: true, enumerable: false, configurable: false };
280
286
  }
@@ -298,7 +304,7 @@ const PROXY_HANDLERS = {
298
304
  // * `Object.defineProperty(arr, 'length', {value: 0})`.
299
305
  // * Other operations which mutate entries e.g. `arr.push(123)`.
300
306
  defineProperty(arr, key, descriptor) {
301
- if (key === 'length' || toIndex(key) !== null) return false;
307
+ if (key === "length" || toIndex(key) !== null) return false;
302
308
  return Reflect.defineProperty(arr, key, descriptor);
303
309
  },
304
310
 
@@ -314,7 +320,7 @@ const PROXY_HANDLERS = {
314
320
  const keys = [],
315
321
  length = getLength(arr);
316
322
  for (let i = 0; i < length; i++) {
317
- keys.push(i + '');
323
+ keys.push(i + "");
318
324
  }
319
325
  keys.push(...Reflect.ownKeys(arr));
320
326
  return keys;
@@ -332,8 +338,8 @@ const PROXY_HANDLERS = {
332
338
  * @returns {number|null} - `key` converted to integer, if it's a valid array index, otherwise `null`.
333
339
  */
334
340
  function toIndex(key) {
335
- if (typeof key === 'string') {
336
- if (key === '0') return 0;
341
+ if (typeof key === "string") {
342
+ if (key === "0") return 0;
337
343
  if (INDEX_REGEX.test(key)) {
338
344
  const index = +key;
339
345
  if (index < 4294967295) return index;
@@ -1,4 +1,4 @@
1
- import { rawTransferSupported as rawTransferSupportedBinding } from '../bindings.js';
1
+ import { rawTransferSupported as rawTransferSupportedBinding } from "../bindings.js";
2
2
 
3
3
  let rawTransferIsSupported = null;
4
4
 
@@ -44,7 +44,7 @@ function rawTransferRuntimeSupported() {
44
44
  return !!match && match[1] * 1 >= 2;
45
45
  }
46
46
 
47
- const isNode = global.process?.release?.name === 'node';
47
+ const isNode = global.process?.release?.name === "node";
48
48
  if (!isNode) return false;
49
49
 
50
50
  const match = process.version?.match(/^v(\d+)\./);
@@ -1,4 +1,8 @@
1
- import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../../generated/lazy/type_ids.js';
1
+ import {
2
+ LEAF_NODE_TYPES_COUNT,
3
+ NODE_TYPE_IDS_MAP,
4
+ NODE_TYPES_COUNT,
5
+ } from "../../generated/lazy/type_ids.js";
2
6
 
3
7
  // Getter for private `#visitorsArr` property of `Visitor` class. Initialized in class body below.
4
8
  let getVisitorsArrTemp;
@@ -57,8 +61,8 @@ export const getVisitorsArr = getVisitorsArrTemp;
57
61
  * @returns {Array<Object|Function|null>} - Array of visitors
58
62
  */
59
63
  function createVisitorsArr(visitor) {
60
- if (visitor === null || typeof visitor !== 'object') {
61
- throw new Error('`visitor` must be an object');
64
+ if (visitor === null || typeof visitor !== "object") {
65
+ throw new Error("`visitor` must be an object");
62
66
  }
63
67
 
64
68
  // Create empty visitors array
@@ -70,11 +74,11 @@ function createVisitorsArr(visitor) {
70
74
  // Populate visitors array from provided object
71
75
  for (let name of Object.keys(visitor)) {
72
76
  const visitFn = visitor[name];
73
- if (typeof visitFn !== 'function') {
77
+ if (typeof visitFn !== "function") {
74
78
  throw new Error(`'${name}' property of \`visitor\` object is not a function`);
75
79
  }
76
80
 
77
- const isExit = name.endsWith(':exit');
81
+ const isExit = name.endsWith(":exit");
78
82
  if (isExit) name = name.slice(0, -5);
79
83
 
80
84
  const typeId = NODE_TYPE_IDS_MAP.get(name);
@@ -1,4 +1,4 @@
1
- import { createRequire } from 'node:module';
1
+ import { createRequire } from "node:module";
2
2
 
3
3
  // Lazy-loaded when first construct a `Visitor`
4
4
  let walkProgram = null,
@@ -15,8 +15,12 @@ export class Visitor {
15
15
  constructor(visitor) {
16
16
  if (walkProgram === null) {
17
17
  const require = createRequire(import.meta.url);
18
- ({ walkProgram } = require('../../generated/visit/walk.js'));
19
- ({ addVisitorToCompiled, createCompiledVisitor, finalizeCompiledVisitor } = require('./visitor.js'));
18
+ ({ walkProgram } = require("../../generated/visit/walk.js"));
19
+ ({
20
+ addVisitorToCompiled,
21
+ createCompiledVisitor,
22
+ finalizeCompiledVisitor,
23
+ } = require("./visitor.js"));
20
24
  }
21
25
 
22
26
  const compiledVisitor = createCompiledVisitor();
@@ -72,7 +72,11 @@
72
72
  // for objects created by user code in visitors. If ephemeral user-created objects all fit in new space,
73
73
  // it will avoid full GC runs, which should greatly improve performance.
74
74
 
75
- import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../../generated/visit/type_ids.js';
75
+ import {
76
+ LEAF_NODE_TYPES_COUNT,
77
+ NODE_TYPE_IDS_MAP,
78
+ NODE_TYPES_COUNT,
79
+ } from "../../generated/visit/type_ids.js";
76
80
 
77
81
  const { isArray } = Array;
78
82
 
@@ -190,7 +194,8 @@ export function initCompiledVisitor() {
190
194
  * @param visitor - Visitor object
191
195
  */
192
196
  export function addVisitorToCompiled(visitor) {
193
- if (visitor === null || typeof visitor !== 'object') throw new TypeError('Visitor must be an object');
197
+ if (visitor === null || typeof visitor !== "object")
198
+ throw new TypeError("Visitor must be an object");
194
199
 
195
200
  // Exit if is empty visitor
196
201
  const keys = Object.keys(visitor),
@@ -204,11 +209,11 @@ export function addVisitorToCompiled(visitor) {
204
209
  let name = keys[i];
205
210
 
206
211
  const visitFn = visitor[name];
207
- if (typeof visitFn !== 'function') {
212
+ if (typeof visitFn !== "function") {
208
213
  throw new TypeError(`'${name}' property of visitor object is not a function`);
209
214
  }
210
215
 
211
- const isExit = name.endsWith(':exit');
216
+ const isExit = name.endsWith(":exit");
212
217
  if (isExit) name = name.slice(0, -5);
213
218
 
214
219
  const typeId = NODE_TYPE_IDS_MAP.get(name);
@@ -361,12 +366,12 @@ function mergeVisitFns(visitFns) {
361
366
  */
362
367
  function createMerger(fnCount) {
363
368
  const args = [];
364
- let body = 'return node=>{';
369
+ let body = "return node=>{";
365
370
  for (let i = 1; i <= fnCount; i++) {
366
371
  args.push(`visit${i}`);
367
372
  body += `visit${i}(node);`;
368
373
  }
369
- body += '}';
374
+ body += "}";
370
375
  args.push(body);
371
376
  // oxlint-disable-next-line typescript/no-implied-eval
372
377
  return new Function(...args);
package/src-js/wasm.js CHANGED
@@ -1,6 +1,6 @@
1
- export * from '@oxc-parser/binding-wasm32-wasi';
2
- import * as bindings from '@oxc-parser/binding-wasm32-wasi';
3
- import { wrap } from './wrap.js';
1
+ export * from "@oxc-parser/binding-wasm32-wasi";
2
+ import * as bindings from "@oxc-parser/binding-wasm32-wasi";
3
+ import { wrap } from "./wrap.js";
4
4
 
5
5
  export async function parse(...args) {
6
6
  return wrap(await bindings.parse(...args));
@@ -1,7 +1,7 @@
1
- const fs = require('node:fs');
2
- const childProcess = require('node:child_process');
1
+ const fs = require("node:fs");
2
+ const childProcess = require("node:child_process");
3
3
 
4
- const pkg = JSON.parse(fs.readFileSync(require.resolve('oxc-parser/package.json'), 'utf-8'));
4
+ const pkg = JSON.parse(fs.readFileSync(require.resolve("oxc-parser/package.json"), "utf-8"));
5
5
  const version = pkg.version;
6
6
  const baseDir = `/tmp/oxc-parser-${version}`;
7
7
  const bindingEntry = `${baseDir}/node_modules/@oxc-parser/binding-wasm32-wasi/parser.wasi.cjs`;
@@ -10,11 +10,11 @@ if (!fs.existsSync(bindingEntry)) {
10
10
  fs.rmSync(baseDir, { recursive: true, force: true });
11
11
  fs.mkdirSync(baseDir, { recursive: true });
12
12
  const bindingPkg = `@oxc-parser/binding-wasm32-wasi@${version}`;
13
- // eslint-disable-next-line: no-console
13
+ // oxlint-disable-next-line no-console
14
14
  console.log(`[oxc-parser] Downloading ${bindingPkg} on WebContainer...`);
15
- childProcess.execFileSync('pnpm', ['i', bindingPkg], {
15
+ childProcess.execFileSync("pnpm", ["i", bindingPkg], {
16
16
  cwd: baseDir,
17
- stdio: 'inherit',
17
+ stdio: "inherit",
18
18
  });
19
19
  }
20
20