Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/generated/ast_changes_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ src:
- 'napi/parser/generated/lazy/constructors.mjs'
- 'napi/parser/generated/lazy/types.mjs'
- 'napi/parser/generated/lazy/walk.mjs'
- 'napi/parser/generated/visit/keys.mjs'
- 'napi/parser/src/generated/assert_layouts.rs'
- 'napi/parser/src/generated/derive_estree.rs'
- 'napi/parser/src/generated/raw_transfer_constants.rs'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ jobs:
cache-key: ast_changes
save-cache: ${{ github.ref_name == 'main' }}

- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
if: steps.filter.outputs.src == 'true'

- name: Restore dprint plugin cache
if: steps.filter.outputs.src == 'true'
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions napi/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ import { Statement } from '@oxc-project/types';

[oxc-walker](https://www.npmjs.com/package/oxc-walker) or [estree-walker](https://www.npmjs.com/package/estree-walker) can be used.

This package exports visitor keys which can be used with any ESTree walker.

```js
import { visitorKeys } from 'oxc-parser';
```

### Fast Mode

By default, Oxc parser does not produce semantic errors where symbols and scopes are needed.
Expand Down
172 changes: 172 additions & 0 deletions napi/parser/generated/visit/keys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/estree_visit.rs`.

export default {
// Leaf nodes
DebuggerStatement: [],
EmptyStatement: [],
Literal: [],
PrivateIdentifier: [],
Super: [],
TemplateElement: [],
ThisExpression: [],
JSXClosingFragment: [],
JSXEmptyExpression: [],
JSXIdentifier: [],
JSXOpeningFragment: [],
JSXText: [],
TSAnyKeyword: [],
TSBigIntKeyword: [],
TSBooleanKeyword: [],
TSIntrinsicKeyword: [],
TSJSDocUnknownType: [],
TSNeverKeyword: [],
TSNullKeyword: [],
TSNumberKeyword: [],
TSObjectKeyword: [],
TSStringKeyword: [],
TSSymbolKeyword: [],
TSThisType: [],
TSUndefinedKeyword: [],
TSUnknownKeyword: [],
TSVoidKeyword: [],
// Non-leaf nodes
AccessorProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
ArrayExpression: ['elements'],
ArrayPattern: ['decorators', 'elements', 'typeAnnotation'],
ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'],
AssignmentExpression: ['left', 'right'],
AssignmentPattern: ['decorators', 'left', 'right', 'typeAnnotation'],
AwaitExpression: ['argument'],
BinaryExpression: ['left', 'right'],
BlockStatement: ['body'],
BreakStatement: ['label'],
CallExpression: ['callee', 'typeArguments', 'arguments'],
CatchClause: ['param', 'body'],
ChainExpression: ['expression'],
ClassBody: ['body'],
ClassDeclaration: ['decorators', 'id', 'typeParameters', 'superClass', 'superTypeArguments', 'implements', 'body'],
ClassExpression: ['decorators', 'id', 'typeParameters', 'superClass', 'superTypeArguments', 'implements', 'body'],
ConditionalExpression: ['test', 'consequent', 'alternate'],
ContinueStatement: ['label'],
Decorator: ['expression'],
DoWhileStatement: ['body', 'test'],
ExportAllDeclaration: ['exported', 'source', 'attributes'],
ExportDefaultDeclaration: ['declaration'],
ExportNamedDeclaration: ['declaration', 'specifiers', 'source', 'attributes'],
ExportSpecifier: ['local', 'exported'],
ExpressionStatement: ['expression'],
ForInStatement: ['left', 'right', 'body'],
ForOfStatement: ['left', 'right', 'body'],
ForStatement: ['init', 'test', 'update', 'body'],
FunctionDeclaration: ['id', 'typeParameters', 'params', 'returnType', 'body'],
FunctionExpression: ['id', 'typeParameters', 'params', 'returnType', 'body'],
Identifier: ['decorators', 'typeAnnotation'],
IfStatement: ['test', 'consequent', 'alternate'],
ImportAttribute: ['key', 'value'],
ImportDeclaration: ['specifiers', 'source', 'attributes'],
ImportDefaultSpecifier: ['local'],
ImportExpression: ['source', 'options'],
ImportNamespaceSpecifier: ['local'],
ImportSpecifier: ['imported', 'local'],
LabeledStatement: ['label', 'body'],
LogicalExpression: ['left', 'right'],
MemberExpression: ['object', 'property'],
MetaProperty: ['meta', 'property'],
MethodDefinition: ['decorators', 'key', 'value'],
NewExpression: ['callee', 'typeArguments', 'arguments'],
ObjectExpression: ['properties'],
ObjectPattern: ['decorators', 'properties', 'typeAnnotation'],
ParenthesizedExpression: ['expression'],
Program: ['body'],
Property: ['key', 'value'],
PropertyDefinition: ['decorators', 'key', 'typeAnnotation', 'value'],
RestElement: ['decorators', 'argument', 'typeAnnotation'],
ReturnStatement: ['argument'],
SequenceExpression: ['expressions'],
SpreadElement: ['argument'],
StaticBlock: ['body'],
SwitchCase: ['test', 'consequent'],
SwitchStatement: ['discriminant', 'cases'],
TaggedTemplateExpression: ['tag', 'typeArguments', 'quasi'],
TemplateLiteral: ['quasis', 'expressions'],
ThrowStatement: ['argument'],
TryStatement: ['block', 'handler', 'finalizer'],
UnaryExpression: ['argument'],
UpdateExpression: ['argument'],
V8IntrinsicExpression: ['name', 'arguments'],
VariableDeclaration: ['declarations'],
VariableDeclarator: ['id', 'init'],
WhileStatement: ['test', 'body'],
WithStatement: ['object', 'body'],
YieldExpression: ['argument'],
JSXAttribute: ['name', 'value'],
JSXClosingElement: ['name'],
JSXElement: ['openingElement', 'children', 'closingElement'],
JSXExpressionContainer: ['expression'],
JSXFragment: ['openingFragment', 'children', 'closingFragment'],
JSXMemberExpression: ['object', 'property'],
JSXNamespacedName: ['namespace', 'name'],
JSXOpeningElement: ['name', 'typeArguments', 'attributes'],
JSXSpreadAttribute: ['argument'],
JSXSpreadChild: ['expression'],
TSAbstractAccessorProperty: ['decorators', 'key', 'typeAnnotation'],
TSAbstractMethodDefinition: ['key', 'value'],
TSAbstractPropertyDefinition: ['decorators', 'key', 'typeAnnotation'],
TSArrayType: ['elementType'],
TSAsExpression: ['expression', 'typeAnnotation'],
TSCallSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
TSClassImplements: ['expression', 'typeArguments'],
TSConditionalType: ['checkType', 'extendsType', 'trueType', 'falseType'],
TSConstructSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
TSConstructorType: ['typeParameters', 'params', 'returnType'],
TSDeclareFunction: ['id', 'typeParameters', 'params', 'returnType', 'body'],
TSEmptyBodyFunctionExpression: ['id', 'typeParameters', 'params', 'returnType'],
TSEnumBody: ['members'],
TSEnumDeclaration: ['id', 'body'],
TSEnumMember: ['id', 'initializer'],
TSExportAssignment: ['expression'],
TSExternalModuleReference: ['expression'],
TSFunctionType: ['typeParameters', 'params', 'returnType'],
TSImportEqualsDeclaration: ['id', 'moduleReference'],
TSImportType: ['argument', 'options', 'qualifier', 'typeArguments'],
TSIndexSignature: ['parameters', 'typeAnnotation'],
TSIndexedAccessType: ['objectType', 'indexType'],
TSInferType: ['typeParameter'],
TSInstantiationExpression: ['expression', 'typeArguments'],
TSInterfaceBody: ['body'],
TSInterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'],
TSInterfaceHeritage: ['expression', 'typeArguments'],
TSIntersectionType: ['types'],
TSJSDocNonNullableType: ['typeAnnotation'],
TSJSDocNullableType: ['typeAnnotation'],
TSLiteralType: ['literal'],
TSMappedType: ['key', 'constraint', 'nameType', 'typeAnnotation'],
TSMethodSignature: ['key', 'typeParameters', 'params', 'returnType'],
TSModuleBlock: ['body'],
TSModuleDeclaration: ['id', 'body'],
TSNamedTupleMember: ['label', 'elementType'],
TSNamespaceExportDeclaration: ['id'],
TSNonNullExpression: ['expression'],
TSOptionalType: ['typeAnnotation'],
TSParameterProperty: ['decorators', 'parameter'],
TSParenthesizedType: ['typeAnnotation'],
TSPropertySignature: ['key', 'typeAnnotation'],
TSQualifiedName: ['left', 'right'],
TSRestType: ['typeAnnotation'],
TSSatisfiesExpression: ['expression', 'typeAnnotation'],
TSTemplateLiteralType: ['quasis', 'types'],
TSTupleType: ['elementTypes'],
TSTypeAliasDeclaration: ['id', 'typeParameters', 'typeAnnotation'],
TSTypeAnnotation: ['typeAnnotation'],
TSTypeAssertion: ['typeAnnotation', 'expression'],
TSTypeLiteral: ['members'],
TSTypeOperator: ['typeAnnotation'],
TSTypeParameter: ['name', 'constraint', 'default'],
TSTypeParameterDeclaration: ['params'],
TSTypeParameterInstantiation: ['params'],
TSTypePredicate: ['parameterName', 'typeAnnotation'],
TSTypeQuery: ['exprName', 'typeArguments'],
TSTypeReference: ['typeName', 'typeArguments'],
TSUnionType: ['types'],
};
2 changes: 2 additions & 0 deletions napi/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"generated/lazy/constructors.mjs",
"generated/lazy/types.mjs",
"generated/lazy/walk.mjs",
"generated/visit/keys.mjs",
"src-js/bindings.mjs",
"src-js/index.d.ts",
"src-js/index.mjs",
Expand All @@ -68,6 +69,7 @@
"devDependencies": {
"@codspeed/vitest-plugin": "^4.0.0",
"@napi-rs/wasm-runtime": "catalog:",
"@typescript-eslint/visitor-keys": "^8.44.0",
"@vitest/browser": "3.2.4",
"esbuild": "^0.25.0",
"playwright": "^1.51.0",
Expand Down
4 changes: 4 additions & 0 deletions napi/parser/scripts/visitor-keys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { visitorKeys } from '@typescript-eslint/visitor-keys';

const keys = Object.entries(visitorKeys).map(([name, keys]) => ({ name, keys }));
console.log(JSON.stringify(keys));
2 changes: 2 additions & 0 deletions napi/parser/src-js/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createRequire } from 'node:module';
import { parseAsync as parseAsyncBinding, parseSync as parseSyncBinding } from './bindings.mjs';
import { wrap } from './wrap.mjs';

export { default as visitorKeys } from '../generated/visit/keys.mjs';

export {
ExportExportNameKind,
ExportImportNameKind,
Expand Down
10 changes: 9 additions & 1 deletion napi/parser/test/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Worker } from 'node:worker_threads';
import { describe, expect, it, test } from 'vitest';

import { parseAsync, parseSync } from '../src-js/index.mjs';
import { parseAsync, parseSync, visitorKeys } from '../src-js/index.mjs';
import type {
ExpressionStatement,
ParserOptions,
Expand Down Expand Up @@ -874,6 +874,14 @@ describe('error', () => {
});
});

it('visitor keys', () => {
expect(visitorKeys.Literal).toEqual([]);
expect(visitorKeys.VariableDeclaration).toEqual(['declarations']);
expect(visitorKeys.ObjectPattern).toEqual(['decorators', 'properties', 'typeAnnotation']);
expect(visitorKeys.ParenthesizedExpression).toEqual(['expression']);
expect(visitorKeys.V8IntrinsicExpression).toEqual(['name', 'arguments']);
});

describe('worker', () => {
it('should run', async () => {
const code = await new Promise((resolve, reject) => {
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tasks/ast_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ cow-utils = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
lazy-regex = { workspace = true }
oxc_index = { workspace = true }
oxc_index = { workspace = true, features = ["serde"] }
phf = { workspace = true, features = ["macros"] }
phf_codegen = { workspace = true }
prettyplease = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
rayon = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
syn = { workspace = true, features = ["clone-impls", "derive", "extra-traits", "full", "parsing", "printing", "proc-macro"] }
Loading
Loading