diff --git a/modules/@angular/compiler/src/template_parser.ts b/modules/@angular/compiler/src/template_parser.ts index 2f3994e645..8cda2520cd 100644 --- a/modules/@angular/compiler/src/template_parser.ts +++ b/modules/@angular/compiler/src/template_parser.ts @@ -15,7 +15,7 @@ import {RegExpWrapper, isPresent, StringWrapper, isBlank, isArray} from '../src/ import {BaseException} from '../src/facade/exceptions'; import {AST, Interpolation, ASTWithSource, TemplateBinding, RecursiveAstVisitor, BindingPipe, ParserError} from './expression_parser/ast'; import {Parser} from './expression_parser/parser'; -import {CompileDirectiveMetadata, CompilePipeMetadata, CompileMetadataWithType,} from './compile_metadata'; +import {CompileDirectiveMetadata, CompilePipeMetadata, CompileMetadataWithType, CompileTokenMetadata,} from './compile_metadata'; import {HtmlParser} from './html_parser'; import {splitNsName, mergeNsAndName} from './html_tags'; import {ParseSourceSpan, ParseError, ParseErrorLevel} from './parse_util'; @@ -47,7 +47,7 @@ import {ProviderElementContext, ProviderViewContext} from './provider_parser'; // Group 9 = identifier inside [()] // Group 10 = identifier inside [] // Group 11 = identifier inside () -var BIND_NAME_REGEXP = +const BIND_NAME_REGEXP = /^(?:(?:(?:(bind-)|(var-)|(let-)|(ref-|#)|(on-)|(bindon-)|(animate-|@))(.+))|\[\(([^\)]+)\)\]|\[([^\]]+)\]|\(([^\)]+)\))$/g; const TEMPLATE_ELEMENT = 'template'; @@ -55,12 +55,12 @@ const TEMPLATE_ATTR = 'template'; const TEMPLATE_ATTR_PREFIX = '*'; const CLASS_ATTR = 'class'; -var PROPERTY_PARTS_SEPARATOR = '.'; +const PROPERTY_PARTS_SEPARATOR = '.'; const ATTRIBUTE_PREFIX = 'attr'; const CLASS_PREFIX = 'class'; const STYLE_PREFIX = 'style'; -var TEXT_CSS_SELECTOR = CssSelector.parse('*')[0]; +const TEXT_CSS_SELECTOR = CssSelector.parse('*')[0]; /** * Provides an array of {@link TemplateAstVisitor}s which will be used to transform @@ -91,14 +91,14 @@ export class TemplateParser { parse( component: CompileDirectiveMetadata, template: string, directives: CompileDirectiveMetadata[], pipes: CompilePipeMetadata[], templateUrl: string): TemplateAst[] { - var result = this.tryParse(component, template, directives, pipes, templateUrl); - var warnings = result.errors.filter(error => error.level === ParseErrorLevel.WARNING); - var errors = result.errors.filter(error => error.level === ParseErrorLevel.FATAL); + const result = this.tryParse(component, template, directives, pipes, templateUrl); + const warnings = result.errors.filter(error => error.level === ParseErrorLevel.WARNING); + const errors = result.errors.filter(error => error.level === ParseErrorLevel.FATAL); if (warnings.length > 0) { this._console.warn(`Template parse warnings:\n${warnings.join('\n')}`); } if (errors.length > 0) { - var errorString = errors.join('\n'); + const errorString = errors.join('\n'); throw new BaseException(`Template parse errors:\n${errorString}`); } return result.templateAst; @@ -107,19 +107,19 @@ export class TemplateParser { tryParse( component: CompileDirectiveMetadata, template: string, directives: CompileDirectiveMetadata[], pipes: CompilePipeMetadata[], templateUrl: string): TemplateParseResult { - var htmlAstWithErrors = this._htmlParser.parse(template, templateUrl); - var errors: ParseError[] = htmlAstWithErrors.errors; - var result: any /** TODO #???? */; + const htmlAstWithErrors = this._htmlParser.parse(template, templateUrl); + const errors: ParseError[] = htmlAstWithErrors.errors; + let result: any[]; if (htmlAstWithErrors.rootNodes.length > 0) { - var uniqDirectives = removeDuplicates(directives); - var uniqPipes = removeDuplicates(pipes); - var providerViewContext = + const uniqDirectives = removeDuplicates(directives); + const uniqPipes = removeDuplicates(pipes); + const providerViewContext = new ProviderViewContext(component, htmlAstWithErrors.rootNodes[0].sourceSpan); - var parseVisitor = new TemplateParseVisitor( + const parseVisitor = new TemplateParseVisitor( providerViewContext, uniqDirectives, uniqPipes, this._exprParser, this._schemaRegistry); result = htmlVisitAll(parseVisitor, htmlAstWithErrors.rootNodes, EMPTY_ELEMENT_CONTEXT); - errors = errors.concat(parseVisitor.errors).concat(providerViewContext.errors); + errors.push(...parseVisitor.errors, ...providerViewContext.errors); } else { result = []; } @@ -176,7 +176,7 @@ class TemplateParseVisitor implements HtmlAstVisitor { } ListWrapper.forEachWithIndex( directives, (directive: CompileDirectiveMetadata, index: number) => { - var selector = CssSelector.parse(directive.selector); + const selector = CssSelector.parse(directive.selector); this.selectorMatcher.addSelectables(selector, directive); this.directivesIndex.set(directive, index); }); @@ -197,9 +197,9 @@ class TemplateParseVisitor implements HtmlAstVisitor { } private _parseInterpolation(value: string, sourceSpan: ParseSourceSpan): ASTWithSource { - var sourceInfo = sourceSpan.start.toString(); + const sourceInfo = sourceSpan.start.toString(); try { - var ast = this._exprParser.parseInterpolation(value, sourceInfo, this._interpolationConfig); + const ast = this._exprParser.parseInterpolation(value, sourceInfo, this._interpolationConfig); if (ast) this._reportParserErors(ast.errors, sourceSpan); this._checkPipes(ast, sourceSpan); if (isPresent(ast) && @@ -215,9 +215,9 @@ class TemplateParseVisitor implements HtmlAstVisitor { } private _parseAction(value: string, sourceSpan: ParseSourceSpan): ASTWithSource { - var sourceInfo = sourceSpan.start.toString(); + const sourceInfo = sourceSpan.start.toString(); try { - var ast = this._exprParser.parseAction(value, sourceInfo, this._interpolationConfig); + const ast = this._exprParser.parseAction(value, sourceInfo, this._interpolationConfig); if (ast) this._reportParserErors(ast.errors, sourceSpan); this._checkPipes(ast, sourceSpan); return ast; @@ -228,9 +228,9 @@ class TemplateParseVisitor implements HtmlAstVisitor { } private _parseBinding(value: string, sourceSpan: ParseSourceSpan): ASTWithSource { - var sourceInfo = sourceSpan.start.toString(); + const sourceInfo = sourceSpan.start.toString(); try { - var ast = this._exprParser.parseBinding(value, sourceInfo, this._interpolationConfig); + const ast = this._exprParser.parseBinding(value, sourceInfo, this._interpolationConfig); if (ast) this._reportParserErors(ast.errors, sourceSpan); this._checkPipes(ast, sourceSpan); return ast; @@ -241,9 +241,9 @@ class TemplateParseVisitor implements HtmlAstVisitor { } private _parseTemplateBindings(value: string, sourceSpan: ParseSourceSpan): TemplateBinding[] { - var sourceInfo = sourceSpan.start.toString(); + const sourceInfo = sourceSpan.start.toString(); try { - var bindingsResult = this._exprParser.parseTemplateBindings(value, sourceInfo); + const bindingsResult = this._exprParser.parseTemplateBindings(value, sourceInfo); this._reportParserErors(bindingsResult.errors, sourceSpan); bindingsResult.templateBindings.forEach((binding) => { if (isPresent(binding.expression)) { @@ -261,7 +261,7 @@ class TemplateParseVisitor implements HtmlAstVisitor { private _checkPipes(ast: ASTWithSource, sourceSpan: ParseSourceSpan) { if (isPresent(ast)) { - var collector = new PipeCollector(); + const collector = new PipeCollector(); ast.visit(collector); collector.pipes.forEach((pipeName) => { if (!this.pipesByName.has(pipeName)) { @@ -276,8 +276,8 @@ class TemplateParseVisitor implements HtmlAstVisitor { visitExpansionCase(ast: HtmlExpansionCaseAst, context: any): any { return null; } visitText(ast: HtmlTextAst, parent: ElementContext): any { - var ngContentIndex = parent.findNgContentIndex(TEXT_CSS_SELECTOR); - var expr = this._parseInterpolation(ast.value, ast.sourceSpan); + const ngContentIndex = parent.findNgContentIndex(TEXT_CSS_SELECTOR); + const expr = this._parseInterpolation(ast.value, ast.sourceSpan); if (isPresent(expr)) { return new BoundTextAst(expr, ngContentIndex, ast.sourceSpan); } else { @@ -292,8 +292,8 @@ class TemplateParseVisitor implements HtmlAstVisitor { visitComment(ast: HtmlCommentAst, context: any): any { return null; } visitElement(element: HtmlElementAst, parent: ElementContext): any { - var nodeName = element.name; - var preparsedElement = preparseElement(element); + const nodeName = element.name; + const preparsedElement = preparseElement(element); if (preparsedElement.type === PreparsedElementType.SCRIPT || preparsedElement.type === PreparsedElementType.STYLE) { // Skipping