refactor(compiler): use options
argument for parsers (#28055)
This commit consolidates the options that can modify the parsing of text (e.g. HTML, Angular templates, CSS, i18n) into an AST for further processing into a single `options` hash. This makes the code cleaner and more readable, but also enables us to support further options to parsing without triggering wide ranging changes to code that should not be affected by these new options. Specifically, it will let us pass information about the placement of a template that is being parsed in its containing file, which is essential for accurate SourceMap processing. PR Close #28055
This commit is contained in:

committed by
Misko Hevery

parent
81df5dcfc0
commit
673ac2945c
@ -41,7 +41,8 @@ const extract = (from: string, regex: any, transformFn: (match: any[]) => any) =
|
||||
const verifyTranslationIds =
|
||||
(source: string, output: string, exceptions = {},
|
||||
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG) => {
|
||||
const parseResult = htmlParser.parse(source, 'path:://to/template', true);
|
||||
const parseResult =
|
||||
htmlParser.parse(source, 'path:://to/template', {tokenizeExpansionForms: true});
|
||||
const extractedIdToMsg = new Map<string, any>();
|
||||
const extractedIds = new Set<string>();
|
||||
const generatedIds = new Set<string>();
|
||||
|
@ -157,12 +157,7 @@ export class DiagnosticContext {
|
||||
};
|
||||
const urlResolver = createOfflineCompileUrlResolver();
|
||||
const htmlParser = new class extends HtmlParser {
|
||||
parse(
|
||||
source: string, url: string, parseExpansionForms: boolean = false,
|
||||
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG):
|
||||
ParseTreeResult {
|
||||
return new ParseTreeResult([], []);
|
||||
}
|
||||
parse(): ParseTreeResult { return new ParseTreeResult([], []); }
|
||||
};
|
||||
|
||||
// This tracks the CompileConfig in codegen.ts. Currently these options
|
||||
@ -209,7 +204,7 @@ function compileTemplate(context: DiagnosticContext, type: StaticSymbol, templat
|
||||
const parser = new TemplateParser(
|
||||
config, context.reflector, expressionParser, new DomElementSchemaRegistry(), htmlParser,
|
||||
null !, []);
|
||||
const htmlResult = htmlParser.parse(template, '', true);
|
||||
const htmlResult = htmlParser.parse(template, '', {tokenizeExpansionForms: true});
|
||||
const analyzedModules = context.analyzedModules;
|
||||
// let errors: Diagnostic[]|undefined = undefined;
|
||||
let ngModule = analyzedModules.ngModuleByPipeOrDirective.get(type);
|
||||
|
Reference in New Issue
Block a user