Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ast-spec): make
BaseNode
& BaseToken
more type-safe
- Loading branch information
1 parent
8cfe933
commit f698b62
Showing
6 changed files
with
32 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,22 +1,15 @@ | ||
// import type { Node } from '../unions/Node'; | ||
import type { Range } from './Range'; | ||
import type { SourceLocation } from './SourceLocation'; | ||
import type { AST_NODE_TYPES } from '../ast-node-types'; | ||
import type { NodeOrTokenData } from './NodeOrTokenData'; | ||
|
||
export interface BaseNode { | ||
/** | ||
* The source location information of the node. | ||
* @see {SourceLocation} | ||
*/ | ||
loc: SourceLocation; | ||
/** | ||
* @see {Range} | ||
*/ | ||
range: Range; | ||
export interface BaseNode extends NodeOrTokenData { | ||
/** | ||
* The parent node of the current node | ||
* | ||
* This is added in the @typescript-eslint/types package as ESLint adds it | ||
* while traversing. | ||
*/ | ||
// parent?: Node; | ||
|
||
// every node *will* have a type, but let the nodes define their own exact string | ||
// type: string; | ||
type: AST_NODE_TYPES; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import type { BaseNode } from './BaseNode'; | ||
import type { AST_TOKEN_TYPES } from '../ast-token-types'; | ||
import type { NodeOrTokenData } from './NodeOrTokenData'; | ||
|
||
/* | ||
* Token and Comment are pseudo-nodes to represent pieces of source code | ||
*/ | ||
export interface BaseToken extends BaseNode { | ||
export interface BaseToken extends NodeOrTokenData { | ||
type: AST_TOKEN_TYPES; | ||
value: string; | ||
} |
This file contains 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,17 @@ | ||
import type { Range } from './Range'; | ||
import type { SourceLocation } from './SourceLocation'; | ||
|
||
export interface NodeOrTokenData { | ||
/** | ||
* The source location information of the node. | ||
* @see {SourceLocation} | ||
*/ | ||
loc: SourceLocation; | ||
|
||
/** | ||
* @see {Range} | ||
*/ | ||
range: Range; | ||
|
||
type: string; | ||
} |
This file contains 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
This file contains 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
This file contains 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