8000 feat(napi/parser): add experimental lazy visitor by overlookmotel · Pull Request #11837 · oxc-project/oxc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(napi/parser): add experimental lazy visitor #11837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

overlookmotel
Copy link
Contributor
@overlookmotel overlookmotel commented Jun 20, 2025

Add lazy visitor to oxc-parser.

This API is experimental and not ready for use yet. AST is not ESTree-compatible at present (same as lazy deserializer).

Usage:

import { parseSync, experimentalGetLazyVisitor } from 'oxc-parser';

// Get `Visitor` class.
// `Visitor` is not exported directly from `oxc-parser` as all code
// related to lazy deserialization is lazy-loaded.
const Visitor = experimentalGetLazyVisitor();

// Define visitor.
// This visitor counts how many identifiers in AST.
let identCount = 0;
const visitor = new Visitor({
  BindingIdentifier(ident) {
    identCount++;
  },
  IdentifierReference(ident) {
    identCount++;
  },
  IdentifierName(ident) {
    identCount++;
  },
});

const code = 'let x, y; x = { z: 2 };';
const { visit, dispose } = parseSync('test.js', code, { experimentalLazy: true });

visit(visitor);

assert(identCount === 4);

// Dispose of AST now we're done with it.
// This returns buffer storing AST data to the pool for reuse.
dispose();

Copy link
Contributor Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-ast-tools Area - AST tools C-enhancement Category - New feature or request labels Jun 20, 2025
@overlookmotel overlookmotel marked this pull request as ready for review June 20, 2025 18:21
@overlookmotel overlookmotel changed the title feat(napi/parser): add lazy visitor feat(napi/parser): add experimental lazy visitor Jun 20, 2025
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jun 20, 2025
Copy link
Contributor Author
overlookmotel commented Jun 20, 2025

Merge activity

Add lazy visitor to `oxc-parser`.

This API is experimental and not ready for use yet. AST is not ESTree-compatible at present (same as lazy deserializer).

Usage:

```js
import { parseSync, experimentalGetLazyVisitor } from 'oxc-parser';

// Get `Visitor` class.
// `Visitor` is not exported directly from `oxc-parser` as all code
// related to lazy deserialization is lazy-loaded.
const Visitor = experimentalGetLazyVisitor();

// Define visitor.
// This visitor counts how many identifiers in AST.
let identCount = 0;
const visitor = new Visitor({
  BindingIdentifier(ident) {
    identCount++;
  },
  IdentifierReference(ident) {
    identCount++;
  },
  IdentifierName(ident) {
    identCount++;
  },
});

const code = 'let x, y; x = { z: 2 };';
const { visit, dispose } = parseSync('test.js', code, { experimentalLazy: true });

visit(visitor);

assert(identCount === 4);

// Dispose of AST now we're done with it.
// This returns buffer storing AST data to the pool for reuse.
dispose();
```
@graphite-app graphite-app bot force-pushed the 06-17-feat_napi_parser_add_lazy_visitor branch from 4df07a1 to 93069a5 Compare June 20, 2025 18:23
@graphite-app graphite-app bot merged commit 93069a5 into main Jun 20, 2025
15 checks passed
@graphite-app graphite-app bot deleted the 06-17-feat_napi_parser_add_lazy_visitor branch June 20, 2025 18:31
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast-tools Area - AST tools C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0