-
-
Notifications
You must be signed in to change notification settings - Fork 862
perf(parser): use visitor instead of JSON.parse reviver #10791
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
overlookmotel
merged 10 commits into
oxc-project:main
from
ArnaudBarre:drop-json-reviver
May 5, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0c9aaaf
perf(parser): use visitor instead of JSON.parse reviver
ArnaudBarre cc8224e
Remove licenses
overlookmotel 743d4eb
Standardize generated file header
overlookmotel cf71c3d
Refactor generator
overlookmotel 71ffca1
Allow generate script to be run from anywhere
overlookmotel 2811cf9
Check in generated code to git
overlookmotel 10ba132
Rename vars
overlookmotel d4de0fa
refactor: add blocks to `for` loops
overlookmotel 0b1cf2d
Add visitor keys for `ParenthesizedExpression` and `TSParenthesizedType`
overlookmotel a760ebc
Fix `wrap.mjs`
overlookmotel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { visitorKeys as visitorKeysOriginal } from '@typescript-eslint/visitor-keys'; | ||
| import { writeFileSync } from 'node:fs'; | ||
| import { join as pathJoin } from 'node:path'; | ||
|
|
||
| const PATH_CJS = pathJoin(import.meta.dirname, 'generated/visitor-keys.cjs'); | ||
| const PATH_MJS = pathJoin(import.meta.dirname, 'generated/visitor-keys.mjs'); | ||
|
|
||
| // Add keys for `ParenthesizedExpression` and `TSParenthesizedType`, which TS-ESLint doesn't have | ||
| const visitorKeys = { | ||
| ...visitorKeysOriginal, | ||
| ParenthesizedExpression: ['expression'], | ||
| TSParenthesizedType: ['typeAnnotation'], | ||
| }; | ||
|
|
||
| const keys = Object.entries(visitorKeys) | ||
| .filter(([, v]) => v?.length) | ||
| .map(([k, v]) => ` ${k}: [${v.map((v) => `'${v}'`).join(', ')}],`) | ||
| .join('\n'); | ||
|
|
||
| const code = `// Auto-generated code, DO NOT EDIT DIRECTLY! | ||
| // To edit this generated file you have to edit \`napi/parser/generate-visitor-keys.mjs\`. | ||
|
|
||
| const visitorKeys = { | ||
| ${keys} | ||
| }; | ||
| `; | ||
|
|
||
| writeFileSync(PATH_CJS, `${code}module.exports = visitorKeys;\n`); | ||
| writeFileSync(PATH_MJS, `${code}export default visitorKeys;\n`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // Auto-generated code, DO NOT EDIT DIRECTLY! | ||
| // To edit this generated file you have to edit `napi/parser/generate-visitor-keys.mjs`. | ||
|
|
||
| const visitorKeys = { | ||
| 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'], | ||
| DoWhileStatement: ['body', 'test'], | ||
| ExperimentalRestProperty: ['argument'], | ||
| ExperimentalSpreadProperty: ['argument'], | ||
| ExportAllDeclaration: ['exported', 'source', 'attributes'], | ||
| ExportDefaultDeclaration: ['declaration'], | ||
| ExportNamedDeclaration: ['declaration', 'specifiers', 'source', 'attributes'], | ||
| ExportSpecifier: ['exported', 'local'], | ||
| 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'], | ||
| 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'], | ||
| 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'], | ||
| 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'], | ||
| VariableDeclaration: ['declarations'], | ||
| VariableDeclarator: ['id', 'init'], | ||
| WhileStatement: ['test', 'body'], | ||
| WithStatement: ['object', 'body'], | ||
| YieldExpression: ['argument'], | ||
| AccessorProperty: ['decorators', 'key', 'typeAnnotation', 'value'], | ||
| Decorator: ['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'], | ||
| TSConstructorType: ['typeParameters', 'params', 'returnType'], | ||
| TSConstructSignatureDeclaration: ['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', 'qualifier', 'typeArguments', 'options'], | ||
| TSIndexedAccessType: ['indexType', 'objectType'], | ||
| TSIndexSignature: ['parameters', 'typeAnnotation'], | ||
| TSInferType: ['typeParameter'], | ||
| TSInstantiationExpression: ['expression', 'typeArguments'], | ||
| TSInterfaceBody: ['body'], | ||
| TSInterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'], | ||
| TSInterfaceHeritage: ['expression', 'typeArguments'], | ||
| TSIntersectionType: ['types'], | ||
| TSLiteralType: ['literal'], | ||
| TSMappedType: ['key', 'constraint', 'nameType', 'typeAnnotation'], | ||
| TSMethodSignature: ['typeParameters', 'key', 'params', 'returnType'], | ||
| TSModuleBlock: ['body'], | ||
| TSModuleDeclaration: ['id', 'body'], | ||
| TSNamedTupleMember: ['label', 'elementType'], | ||
| TSNamespaceExportDeclaration: ['id'], | ||
| TSNonNullExpression: ['expression'], | ||
| TSOptionalType: ['typeAnnotation'], | ||
| TSParameterProperty: ['decorators', 'parameter'], | ||
| TSPropertySignature: ['typeAnnotation', 'key'], | ||
| 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: ['typeAnnotation', 'parameterName'], | ||
| TSTypeQuery: ['exprName', 'typeArguments'], | ||
| TSTypeReference: ['typeName', 'typeArguments'], | ||
| TSUnionType: ['types'], | ||
| ParenthesizedExpression: ['expression'], | ||
| TSParenthesizedType: ['typeAnnotation'], | ||
| }; | ||
| module.exports = visitorKeys; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // Auto-generated code, DO NOT EDIT DIRECTLY! | ||
| // To edit this generated file you have to edit `napi/parser/generate-visitor-keys.mjs`. | ||
|
|
||
| const visitorKeys = { | ||
| 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'], | ||
| DoWhileStatement: ['body', 'test'], | ||
| ExperimentalRestProperty: ['argument'], | ||
| ExperimentalSpreadProperty: ['argument'], | ||
| ExportAllDeclaration: ['exported', 'source', 'attributes'], | ||
| ExportDefaultDeclaration: ['declaration'], | ||
| ExportNamedDeclaration: ['declaration', 'specifiers', 'source', 'attributes'], | ||
| ExportSpecifier: ['exported', 'local'], | ||
| 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'], | ||
| 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'], | ||
| 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'], | ||
| 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'], | ||
| VariableDeclaration: ['declarations'], | ||
| VariableDeclarator: ['id', 'init'], | ||
| WhileStatement: ['test', 'body'], | ||
| WithStatement: ['object', 'body'], | ||
| YieldExpression: ['argument'], | ||
| AccessorProperty: ['decorators', 'key', 'typeAnnotation', 'value'], | ||
| Decorator: ['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'], | ||
| TSConstructorType: ['typeParameters', 'params', 'returnType'], | ||
| TSConstructSignatureDeclaration: ['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', 'qualifier', 'typeArguments', 'options'], | ||
| TSIndexedAccessType: ['indexType', 'objectType'], | ||
| TSIndexSignature: ['parameters', 'typeAnnotation'], | ||
| TSInferType: ['typeParameter'], | ||
| TSInstantiationExpression: ['expression', 'typeArguments'], | ||
| TSInterfaceBody: ['body'], | ||
| TSInterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'], | ||
| TSInterfaceHeritage: ['expression', 'typeArguments'], | ||
| TSIntersectionType: ['types'], | ||
| TSLiteralType: ['literal'], | ||
| TSMappedType: ['key', 'constraint', 'nameType', 'typeAnnotation'], | ||
| TSMethodSignature: ['typeParameters', 'key', 'params', 'returnType'], | ||
| TSModuleBlock: ['body'], | ||
| TSModuleDeclaration: ['id', 'body'], | ||
| TSNamedTupleMember: ['label', 'elementType'], | ||
| TSNamespaceExportDeclaration: ['id'], | ||
| TSNonNullExpression: ['expression'], | ||
| TSOptionalType: ['typeAnnotation'], | ||
| TSParameterProperty: ['decorators', 'parameter'], | ||
| TSPropertySignature: ['typeAnnotation', 'key'], | ||
| 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: ['typeAnnotation', 'parameterName'], | ||
| TSTypeQuery: ['exprName', 'typeArguments'], | ||
| TSTypeReference: ['typeName', 'typeArguments'], | ||
| TSUnionType: ['types'], | ||
| ParenthesizedExpression: ['expression'], | ||
| TSParenthesizedType: ['typeAnnotation'], | ||
| }; | ||
| export default visitorKeys; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.