Skip to content

Commit 92b7884

Browse files
authored
Define a NodeTypes record that plugins can extend to add nodes to AnyNode
FEATURE: The `AnyNode` type is now defined in such a way that plugins can extend it.
1 parent eeb1b73 commit 92b7884

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

acorn/src/acorn.d.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,24 @@ export type ModuleDeclaration =
572572
| ExportDefaultDeclaration
573573
| ExportAllDeclaration
574574

575-
export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportAttribute | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock | VariableDeclarator
575+
/**
576+
* This interface is only used for defining {@link AnyNode}.
577+
* It exists so that it can be extended by plugins:
578+
*
579+
* @example
580+
* ```typescript
581+
* declare module 'acorn' {
582+
* interface NodeTypes {
583+
* pluginName: FirstNode | SecondNode | ThirdNode | ... | LastNode;
584+
* }
585+
* }
586+
* ```
587+
*/
588+
interface NodeTypes {
589+
core: Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportAttribute | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock | VariableDeclarator
590+
}
591+
592+
export type AnyNode = NodeTypes[keyof NodeTypes]
576593

577594
export function parse(input: string, options: Options): Program
578595

0 commit comments

Comments
 (0)