Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions modules/@angular/compiler/src/expression_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class Parser {
input: string, location: any,
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG): ASTWithSource {
this._checkNoInterpolation(input, location, interpolationConfig);
var tokens = this._lexer.tokenize(this._stripComments(input));
var ast = new _ParseAST(input, location, tokens, true, this.errors).parseChain();
const tokens = this._lexer.tokenize(this._stripComments(input));
const ast = new _ParseAST(input, location, tokens, true, this.errors).parseChain();
return new ASTWithSource(ast, input, location, this.errors);
}

Expand Down Expand Up @@ -155,15 +155,15 @@ export class Parser {
}

private _stripComments(input: string): string {
let i = this._commentStart(input);
const i = this._commentStart(input);
return isPresent(i) ? input.substring(0, i).trim() : input;
}

private _commentStart(input: string): number {
var outerQuote: number = null;
for (var i = 0; i < input.length - 1; i++) {
let char = StringWrapper.charCodeAt(input, i);
let nextChar = StringWrapper.charCodeAt(input, i + 1);
for (let i = 0; i < input.length - 1; i++) {
const char = StringWrapper.charCodeAt(input, i);
const nextChar = StringWrapper.charCodeAt(input, i + 1);

if (char === chars.$SLASH && nextChar == chars.$SLASH && isBlank(outerQuote)) return i;

Expand Down
13 changes: 10 additions & 3 deletions modules/@angular/compiler/src/template_parser/template_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Console, MAX_INTERPOLATION_VALUES} from '../../core_private';
import {ListWrapper, StringMapWrapper, SetWrapper,} from '../facade/collection';
import {RegExpWrapper, isPresent, isBlank} from '../facade/lang';
import {BaseException} from '../facade/exceptions';
import {AST, Interpolation, ASTWithSource, TemplateBinding, RecursiveAstVisitor, BindingPipe, ParserError} from '../expression_parser/ast';
import {EmptyExpr, AST, Interpolation, ASTWithSource, TemplateBinding, RecursiveAstVisitor, BindingPipe, ParserError} from '../expression_parser/ast';
import {Parser} from '../expression_parser/parser';
import {CompileDirectiveMetadata, CompilePipeMetadata, CompileTokenMetadata, removeIdentifierDuplicates,} from '../compile_metadata';
import {HtmlParser, ParseTreeResult} from '../html_parser/html_parser';
Expand Down Expand Up @@ -209,7 +209,7 @@ class TemplateParseVisitor implements html.Visitor {
}

private _reportParserErors(errors: ParserError[], sourceSpan: ParseSourceSpan) {
for (let error of errors) {
for (const error of errors) {
this._reportError(error.message, sourceSpan);
}
}
Expand All @@ -234,9 +234,16 @@ class TemplateParseVisitor implements html.Visitor {

private _parseAction(value: string, sourceSpan: ParseSourceSpan): ASTWithSource {
const sourceInfo = sourceSpan.start.toString();

try {
const ast = this._exprParser.parseAction(value, sourceInfo, this._interpolationConfig);
if (ast) this._reportParserErors(ast.errors, sourceSpan);
if (ast) {
this._reportParserErors(ast.errors, sourceSpan);
}
if (!ast || ast.ast instanceof EmptyExpr) {
this._reportError(`Empty expressions are not allowed`, sourceSpan);
return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo);
}
this._checkPipes(ast, sourceSpan);
return ast;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,18 @@ export function main() {
describe('events', () => {

it('should parse bound events with a target', () => {
expect(humanizeTplAst(parse('<div (window:event)="v">', [
]))).toEqual([[ElementAst, 'div'], [BoundEventAst, 'event', 'window', 'v']]);
expect(humanizeTplAst(parse('<div (window:event)="v">', []))).toEqual([
[ElementAst, 'div'],
[BoundEventAst, 'event', 'window', 'v'],
]);
});

it('should report an error on empty expression', () => {
expect(() => parse('<div (event)="">', []))
.toThrowError(/Empty expressions are not allowed/);

expect(() => parse('<div (event)=" ">', []))
.toThrowError(/Empty expressions are not allowed/);
});

it('should parse bound events via (...) and not report them as attributes', () => {
Expand Down Expand Up @@ -519,10 +529,10 @@ export function main() {
});

describe('providers', () => {
var nextProviderId: any /** TODO #9100 */;
var nextProviderId: number;

function createToken(value: string): CompileTokenMetadata {
var token: any /** TODO #9100 */;
let token: CompileTokenMetadata;
if (value.startsWith('type:')) {
token = new CompileTokenMetadata({
identifier:
Expand Down Expand Up @@ -555,8 +565,8 @@ export function main() {
}

function createProvider(
token: string, {multi = false, deps = /*@ts2dart_const*/[]}:
{multi?: boolean, deps?: string[]} = {}): CompileProviderMetadata {
token: string, {multi = false, deps = []}: {multi?: boolean, deps?: string[]} = {}):
CompileProviderMetadata {
return new CompileProviderMetadata({
token: createToken(token),
multi: multi,
Expand All @@ -566,8 +576,7 @@ export function main() {
}

function createDir(
selector: string, {providers = null, viewProviders = null, deps = /*@ts2dart_const*/[],
queries = /*@ts2dart_const*/[]}: {
selector: string, {providers = null, viewProviders = null, deps = [], queries = []}: {
providers?: CompileProviderMetadata[],
viewProviders?: CompileProviderMetadata[],
deps?: string[],
Expand Down