fix(compiler): give ASTWithSource its own visit method (#31347)
ASTWithSource contains more information that AST and should have its own visit method, if desired. This implements that. PR Close #31347
This commit is contained in:
parent
50c4ec6687
commit
6aaca21c27
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AbsoluteSourceSpan, IdentifierKind} from '..';
|
import {AbsoluteSourceSpan, IdentifierKind} from '..';
|
||||||
|
import {runInEachFileSystem} from '../../file_system/testing';
|
||||||
import {getTemplateIdentifiers} from '../src/template';
|
import {getTemplateIdentifiers} from '../src/template';
|
||||||
import * as util from './util';
|
import * as util from './util';
|
||||||
|
|
||||||
|
@ -17,7 +18,8 @@ function bind(template: string) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('getTemplateIdentifiers', () => {
|
runInEachFileSystem(() => {
|
||||||
|
describe('getTemplateIdentifiers', () => {
|
||||||
it('should generate nothing in HTML-only template', () => {
|
it('should generate nothing in HTML-only template', () => {
|
||||||
const refs = getTemplateIdentifiers(bind('<div></div>'));
|
const refs = getTemplateIdentifiers(bind('<div></div>'));
|
||||||
|
|
||||||
|
@ -125,4 +127,5 @@ describe('getTemplateIdentifiers', () => {
|
||||||
expect(ref.name).toBe('foo');
|
expect(ref.name).toBe('foo');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -209,7 +209,12 @@ export class ASTWithSource extends AST {
|
||||||
public errors: ParserError[]) {
|
public errors: ParserError[]) {
|
||||||
super(new ParseSpan(0, source == null ? 0 : source.length));
|
super(new ParseSpan(0, source == null ? 0 : source.length));
|
||||||
}
|
}
|
||||||
visit(visitor: AstVisitor, context: any = null): any { return this.ast.visit(visitor, context); }
|
visit(visitor: AstVisitor, context: any = null): any {
|
||||||
|
if (visitor.visitASTWithSource) {
|
||||||
|
return visitor.visitASTWithSource(this, context);
|
||||||
|
}
|
||||||
|
return this.ast.visit(visitor, context);
|
||||||
|
}
|
||||||
toString(): string { return `${this.source} in ${this.location}`; }
|
toString(): string { return `${this.source} in ${this.location}`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +245,7 @@ export interface AstVisitor {
|
||||||
visitQuote(ast: Quote, context: any): any;
|
visitQuote(ast: Quote, context: any): any;
|
||||||
visitSafeMethodCall(ast: SafeMethodCall, context: any): any;
|
visitSafeMethodCall(ast: SafeMethodCall, context: any): any;
|
||||||
visitSafePropertyRead(ast: SafePropertyRead, context: any): any;
|
visitSafePropertyRead(ast: SafePropertyRead, context: any): any;
|
||||||
|
visitASTWithSource?(ast: ASTWithSource, context: any): any;
|
||||||
visit?(ast: AST, context?: any): any;
|
visit?(ast: AST, context?: any): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue