diff --git a/packages/@glimmer/syntax/lib/types/nodes.ts b/packages/@glimmer/syntax/lib/types/nodes.ts index 9ce5e65aa5..c5390e51a6 100644 --- a/packages/@glimmer/syntax/lib/types/nodes.ts +++ b/packages/@glimmer/syntax/lib/types/nodes.ts @@ -1,3 +1,5 @@ +import { VisitorKeysMap } from './visitor-keys'; + export type Option = T | null; export interface BaseNode { @@ -206,29 +208,6 @@ export interface Nodes { HashPair: HashPair; } -export interface VisitorKeysMap { - Program: ['body']; - MustacheStatement: ['path', 'params', 'hash']; - BlockStatement: ['path', 'params', 'hash', 'program', 'inverse']; - ElementModifierStatement: ['path', 'params', 'hash']; - PartialStatement: ['name', 'params', 'hash']; - CommentStatement: never[]; - MustacheCommentStatement: never[]; - ElementNode: ['attributes', 'modifiers', 'children', 'comments']; - AttrNode: ['value']; - TextNode: never[]; - ConcatStatement: ['parts']; - SubExpression: ['path', 'params', 'hash']; - PathExpression: never[]; - StringLiteral: never[]; - BooleanLiteral: never[]; - NumberLiteral: never[]; - NullLiteral: never[]; - UndefinedLiteral: never[]; - Hash: ['pairs']; - HashPair: ['value']; -} - export type NodeType = keyof Nodes; export type Node = Nodes[NodeType]; diff --git a/packages/@glimmer/syntax/lib/types/visitor-keys.ts b/packages/@glimmer/syntax/lib/types/visitor-keys.ts index f2094b857e..99b1e9b238 100644 --- a/packages/@glimmer/syntax/lib/types/visitor-keys.ts +++ b/packages/@glimmer/syntax/lib/types/visitor-keys.ts @@ -1,31 +1,37 @@ -import { VisitorKeysMap } from './nodes'; +function tuple(): never[]; +function tuple(...args: T): T; +function tuple(...args: T[]): T[] { + return args; +} // ensure stays in sync with typing // ParentNode and ChildKey types are derived from VisitorKeysMap -const visitorKeys: VisitorKeysMap = { - Program: ['body'], - MustacheStatement: ['path', 'params', 'hash'], - BlockStatement: ['path', 'params', 'hash', 'program', 'inverse'], - ElementModifierStatement: ['path', 'params', 'hash'], - PartialStatement: ['name', 'params', 'hash'], - CommentStatement: [], - MustacheCommentStatement: [], - ElementNode: ['attributes', 'modifiers', 'children', 'comments'], - AttrNode: ['value'], - TextNode: [], +const visitorKeys = { + Program: tuple('body'), + MustacheStatement: tuple('path', 'params', 'hash'), + BlockStatement: tuple('path', 'params', 'hash', 'program', 'inverse'), + ElementModifierStatement: tuple('path', 'params', 'hash'), + PartialStatement: tuple('name', 'params', 'hash'), + CommentStatement: tuple(), + MustacheCommentStatement: tuple(), + ElementNode: tuple('attributes', 'modifiers', 'children', 'comments'), + AttrNode: tuple('value'), + TextNode: tuple(), - ConcatStatement: ['parts'], - SubExpression: ['path', 'params', 'hash'], - PathExpression: [], + ConcatStatement: tuple('parts'), + SubExpression: tuple('path', 'params', 'hash'), + PathExpression: tuple(), - StringLiteral: [], - BooleanLiteral: [], - NumberLiteral: [], - NullLiteral: [], - UndefinedLiteral: [], + StringLiteral: tuple(), + BooleanLiteral: tuple(), + NumberLiteral: tuple(), + NullLiteral: tuple(), + UndefinedLiteral: tuple(), - Hash: ['pairs'], - HashPair: ['value'], + Hash: tuple('pairs'), + HashPair: tuple('value'), }; export default visitorKeys; + +export type VisitorKeysMap = typeof visitorKeys;