refactor(compiler): stricter types for HTML AST (#41360)
A Node can only be an instance of one of the six classes. This relation can be accurately expressed using a union type. PR Close #41360
This commit is contained in:
parent
4d7294d9f7
commit
209768a570
|
@ -10,12 +10,14 @@ import {AstPath} from '../ast_path';
|
|||
import {I18nMeta} from '../i18n/i18n_ast';
|
||||
import {ParseSourceSpan} from '../parse_util';
|
||||
|
||||
export interface Node {
|
||||
interface BaseNode {
|
||||
sourceSpan: ParseSourceSpan;
|
||||
visit(visitor: Visitor, context: any): any;
|
||||
}
|
||||
|
||||
export abstract class NodeWithI18n implements Node {
|
||||
export type Node = Attribute|Comment|Element|Expansion|ExpansionCase|Text;
|
||||
|
||||
export abstract class NodeWithI18n implements BaseNode {
|
||||
constructor(public sourceSpan: ParseSourceSpan, public i18n?: I18nMeta) {}
|
||||
abstract visit(visitor: Visitor, context: any): any;
|
||||
}
|
||||
|
@ -40,7 +42,7 @@ export class Expansion extends NodeWithI18n {
|
|||
}
|
||||
}
|
||||
|
||||
export class ExpansionCase implements Node {
|
||||
export class ExpansionCase implements BaseNode {
|
||||
constructor(
|
||||
public value: string, public expression: Node[], public sourceSpan: ParseSourceSpan,
|
||||
public valueSourceSpan: ParseSourceSpan, public expSourceSpan: ParseSourceSpan) {}
|
||||
|
@ -74,7 +76,7 @@ export class Element extends NodeWithI18n {
|
|||
}
|
||||
}
|
||||
|
||||
export class Comment implements Node {
|
||||
export class Comment implements BaseNode {
|
||||
constructor(public value: string|null, public sourceSpan: ParseSourceSpan) {}
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitComment(this, context);
|
||||
|
|
Loading…
Reference in New Issue