Skip to content

Commit c26be70

Browse files
committed
Add missing definition
1 parent c258c02 commit c26be70

File tree

7 files changed

+131
-5
lines changed

7 files changed

+131
-5
lines changed

generator-scripts/definition-check.ts

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
4+
import { Node } from '../src/helpers'
5+
import { definitions } from '../src/definitions'
6+
7+
const nodeTypesMap: {
8+
[K in Node['type']]: 0
9+
} = {
10+
CatchClause: 0,
11+
ClassBody: 0,
12+
Identifier: 0,
13+
Literal: 0,
14+
MethodDefinition: 0,
15+
PrivateIdentifier: 0,
16+
Program: 0,
17+
Property: 0,
18+
PropertyDefinition: 0,
19+
SpreadElement: 0,
20+
Super: 0,
21+
SwitchCase: 0,
22+
TemplateElement: 0,
23+
VariableDeclarator: 0,
24+
JSXIdentifier: 0,
25+
JSXNamespacedName: 0,
26+
JSXMemberExpression: 0,
27+
JSXEmptyExpression: 0,
28+
JSXExpressionContainer: 0,
29+
JSXSpreadAttribute: 0,
30+
JSXAttribute: 0,
31+
JSXOpeningElement: 0,
32+
JSXOpeningFragment: 0,
33+
JSXClosingElement: 0,
34+
JSXClosingFragment: 0,
35+
JSXElement: 0,
36+
JSXFragment: 0,
37+
JSXText: 0,
38+
ArrayExpression: 0,
39+
ArrowFunctionExpression: 0,
40+
AssignmentExpression: 0,
41+
AwaitExpression: 0,
42+
BinaryExpression: 0,
43+
CallExpression: 0,
44+
ChainExpression: 0,
45+
ClassExpression: 0,
46+
ConditionalExpression: 0,
47+
FunctionExpression: 0,
48+
ImportExpression: 0,
49+
LogicalExpression: 0,
50+
MemberExpression: 0,
51+
MetaProperty: 0,
52+
NewExpression: 0,
53+
ObjectExpression: 0,
54+
SequenceExpression: 0,
55+
TaggedTemplateExpression: 0,
56+
TemplateLiteral: 0,
57+
ThisExpression: 0,
58+
UnaryExpression: 0,
59+
UpdateExpression: 0,
60+
YieldExpression: 0,
61+
ClassDeclaration: 0,
62+
FunctionDeclaration: 0,
63+
ImportDeclaration: 0,
64+
ExportNamedDeclaration: 0,
65+
ExportDefaultDeclaration: 0,
66+
ExportAllDeclaration: 0,
67+
ImportSpecifier: 0,
68+
ImportDefaultSpecifier: 0,
69+
ImportNamespaceSpecifier: 0,
70+
ExportSpecifier: 0,
71+
ObjectPattern: 0,
72+
ArrayPattern: 0,
73+
RestElement: 0,
74+
AssignmentPattern: 0,
75+
ExpressionStatement: 0,
76+
BlockStatement: 0,
77+
StaticBlock: 0,
78+
EmptyStatement: 0,
79+
DebuggerStatement: 0,
80+
WithStatement: 0,
81+
ReturnStatement: 0,
82+
LabeledStatement: 0,
83+
BreakStatement: 0,
84+
ContinueStatement: 0,
85+
IfStatement: 0,
86+
SwitchStatement: 0,
87+
ThrowStatement: 0,
88+
TryStatement: 0,
89+
WhileStatement: 0,
90+
DoWhileStatement: 0,
91+
ForStatement: 0,
92+
ForInStatement: 0,
93+
ForOfStatement: 0,
94+
VariableDeclaration: 0,
95+
JSXSpreadChild: 0,
96+
ImportAttribute: 0
97+
}
98+
const nodeTypes = new Set(Object.keys(nodeTypesMap))
99+
const definitionKeys = new Set(Object.keys(definitions))
100+
const missing: string[] = []
101+
102+
nodeTypes.forEach((nodeType) => {
103+
if (!definitionKeys.has(nodeType)) {
104+
missing.push(nodeType)
105+
}
106+
})
107+
108+
if (missing.length) {
109+
throw new Error(`Following nodes are missing their definition: ${missing.join(', ')}`);
110+
}

generator-scripts/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './definition-check';
12
import './builders-type';
23
import './types';
34
import './is-type';

src/definitions.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export type Definition<N extends Node = Node> = {
2727

2828
export type Definitions = {
2929
[N in Node as `${N['type']}`]: Definition<N>;
30-
} & {
31-
XP: Definition<Node>
3230
}
3331

3432
const anyValidate = {
@@ -1151,6 +1149,20 @@ export const definitions = cleanObj<Definitions>({
11511149
innerComments: anyValidate
11521150
}
11531151
},
1152+
ImportAttribute: {
1153+
indices: {
1154+
key: 0,
1155+
value: 1
1156+
},
1157+
fields: {
1158+
key: {
1159+
validate: a.node('Identifier', 'Literal')
1160+
},
1161+
value: {
1162+
validate: a.node('Literal'),
1163+
}
1164+
}
1165+
},
11541166

11551167
/// JSX
11561168
JSXIdentifier: {

src/generated/builders-type.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Generated file. Do not modify by hands.
22
// Run "npm run generate" to re-generate this file.
33

4-
import { Identifier, Literal, Program, FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchCase, CatchClause, VariableDeclarator, ExpressionStatement, BlockStatement, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, VariableDeclaration, ClassDeclaration, ThisExpression, ArrayExpression, ObjectExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, Property, Super, TemplateElement, SpreadElement, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, ClassBody, MethodDefinition, ImportDeclaration, ExportNamedDeclaration, ExportDefaultDeclaration, ExportAllDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ExportSpecifier, PrivateIdentifier, PropertyDefinition, StaticBlock, JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText } from 'estree-jsx';
4+
import { Identifier, Literal, Program, FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchCase, CatchClause, VariableDeclarator, ExpressionStatement, BlockStatement, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, VariableDeclaration, ClassDeclaration, ThisExpression, ArrayExpression, ObjectExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, Property, Super, TemplateElement, SpreadElement, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, ClassBody, MethodDefinition, ImportDeclaration, ExportNamedDeclaration, ExportDefaultDeclaration, ExportAllDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ExportSpecifier, PrivateIdentifier, PropertyDefinition, StaticBlock, ImportAttribute, JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText } from 'estree-jsx';
55

66
export type Builders = {
77
identifier(name: Identifier['name']): Identifier;
@@ -75,6 +75,7 @@ export type Builders = {
7575
privateIdentifier(name: PrivateIdentifier['name']): PrivateIdentifier;
7676
propertyDefinition(key: PropertyDefinition['key'], value: PropertyDefinition['value'], computed?: PropertyDefinition['computed'], _static?: PropertyDefinition['static']): PropertyDefinition;
7777
staticBlock(body: StaticBlock['body']): StaticBlock;
78+
importAttribute(key: ImportAttribute['key'], value: ImportAttribute['value']): ImportAttribute;
7879
jsxIdentifier(name: JSXIdentifier['name']): JSXIdentifier;
7980
jsxNamespacedName(namespace: JSXNamespacedName['namespace'], name: JSXNamespacedName['name']): JSXNamespacedName;
8081
jsxMemberExpression(object: JSXMemberExpression['object'], property: JSXMemberExpression['property']): JSXMemberExpression;

src/generated/is-type.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Run "npm run generate" to re-generate this file.
33

44
import { Node, BaseNode } from '../helpers';
5-
import { Identifier, Literal, Program, FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchCase, CatchClause, VariableDeclarator, ExpressionStatement, BlockStatement, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, VariableDeclaration, ClassDeclaration, ThisExpression, ArrayExpression, ObjectExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, Property, Super, TemplateElement, SpreadElement, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, ClassBody, MethodDefinition, ImportDeclaration, ExportNamedDeclaration, ExportDefaultDeclaration, ExportAllDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ExportSpecifier, PrivateIdentifier, PropertyDefinition, StaticBlock, JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText } from 'estree-jsx';
5+
import { Identifier, Literal, Program, FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchCase, CatchClause, VariableDeclarator, ExpressionStatement, BlockStatement, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, VariableDeclaration, ClassDeclaration, ThisExpression, ArrayExpression, ObjectExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, Property, Super, TemplateElement, SpreadElement, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, ClassBody, MethodDefinition, ImportDeclaration, ExportNamedDeclaration, ExportDefaultDeclaration, ExportAllDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ExportSpecifier, PrivateIdentifier, PropertyDefinition, StaticBlock, ImportAttribute, JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText } from 'estree-jsx';
66
import { NodePath } from '../nodepath';
77
import type { AliasMap } from '../aliases';
88

@@ -87,6 +87,7 @@ export type Is = {
8787
privateIdentifier: Checker<PrivateIdentifier>;
8888
propertyDefinition: Checker<PropertyDefinition>;
8989
staticBlock: Checker<StaticBlock>;
90+
importAttribute: Checker<ImportAttribute>;
9091
jsxIdentifier: Checker<JSXIdentifier>;
9192
jsxNamespacedName: Checker<JSXNamespacedName>;
9293
jsxMemberExpression: Checker<JSXMemberExpression>;

src/generated/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Run "npm run generate" to re-generate this file.
33

44
export { Node } from '../helpers';
5-
export { SimpleLiteral, RegExpLiteral, Identifier, Literal, Program, FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchCase, CatchClause, VariableDeclarator, ExpressionStatement, BlockStatement, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, VariableDeclaration, ClassDeclaration, ThisExpression, ArrayExpression, ObjectExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, Property, Super, TemplateElement, SpreadElement, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, ClassBody, MethodDefinition, ImportDeclaration, ExportNamedDeclaration, ExportDefaultDeclaration, ExportAllDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ExportSpecifier, PrivateIdentifier, PropertyDefinition, StaticBlock, JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText } from 'estree-jsx';
5+
export { SimpleLiteral, RegExpLiteral, Identifier, Literal, Program, FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, SwitchCase, CatchClause, VariableDeclarator, ExpressionStatement, BlockStatement, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, VariableDeclaration, ClassDeclaration, ThisExpression, ArrayExpression, ObjectExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, Property, Super, TemplateElement, SpreadElement, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, ClassBody, MethodDefinition, ImportDeclaration, ExportNamedDeclaration, ExportDefaultDeclaration, ExportAllDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ExportSpecifier, PrivateIdentifier, PropertyDefinition, StaticBlock, ImportAttribute, JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText } from 'estree-jsx';
66
import type { AliasMap } from '../aliases';
77

88
export type Function = AliasMap['Function'];

tests/snapshots/helpers.test.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ exportSpecifier
8484
privateIdentifier
8585
propertyDefinition
8686
staticBlock
87+
importAttribute
8788
jsxIdentifier
8889
jsxNamespacedName
8990
jsxMemberExpression

0 commit comments

Comments
 (0)