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
29 changes: 29 additions & 0 deletions napi/parser/generate-visitor-keys.mjs
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`);
143 changes: 143 additions & 0 deletions napi/parser/generated/visitor-keys.cjs
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;
143 changes: 143 additions & 0 deletions napi/parser/generated/visitor-keys.mjs
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;
4 changes: 3 additions & 1 deletion napi/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"browser": "wasm.mjs",
"scripts": {
"build-dev": "napi build --no-dts-cache --platform --js bindings.js",
"build-dev": "node generate-visitor-keys.mjs && napi build --no-dts-cache --platform --js bindings.js",
"build": "pnpm run build-dev --features allocator --release",
"postbuild-dev": "node patch.mjs",
"build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
Expand Down Expand Up @@ -43,6 +43,7 @@
"wasm.mjs",
"bindings.js",
"webcontainer-fallback.js",
"generated/visitor-keys.js",
"generated/deserialize/js.js",
"generated/deserialize/ts.js"
],
Expand All @@ -56,6 +57,7 @@
"devDependencies": {
"@codspeed/vitest-plugin": "^4.0.0",
"@napi-rs/wasm-runtime": "^0.2.7",
"@typescript-eslint/visitor-keys": "^8.31.1",
"@vitest/browser": "3.1.2",
"esbuild": "^0.25.0",
"playwright": "^1.51.0",
Expand Down
Loading
Loading