X Tutup
Skip to content
Closed
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
22 changes: 10 additions & 12 deletions modules/angular2/src/change_detection/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,19 +538,17 @@ class _ParseAST {
this.optionalCharacter($COLON);
var name = null;
var expression = null;
if (this.next !== EOF) {
if (keyIsVar) {
if (this.optionalOperator("=")) {
name = this.expectTemplateBindingKey();
} else {
name = '\$implicit';
}
} else if (!this.peekKeywordVar()) {
var start = this.inputIndex;
var ast = this.parsePipe();
var source = this.input.substring(start, this.inputIndex);
expression = new ASTWithSource(ast, source, this.location);
if (keyIsVar) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this work by only removing the enclosing if (!EOF) { ...}

might need to add an !EOF in the else if

      var name = '\$implicit';
      var expression = null;
      if (keyIsVar) {
        if (this.optionalOperator("=")) {
          name = this.expectTemplateBindingKey();
        }
      } else if (this.next !== EOF && !this.peekKeywordVar()) {
        var start = this.inputIndex;
        var ast = this.parsePipe();
        var source = this.input.substring(start, this.inputIndex);
        expression = new ASTWithSource(ast, source, this.location);
      }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, implemented

if (this.optionalOperator("=")) {
name = this.expectTemplateBindingKey();
} else {
name = '\$implicit';
}
} else if (this.next !== EOF && !this.peekKeywordVar()) {
var start = this.inputIndex;
var ast = this.parsePipe();
var source = this.input.substring(start, this.inputIndex);
expression = new ASTWithSource(ast, source, this.location);
}
ListWrapper.push(bindings, new TemplateBinding(key, keyIsVar, name, expression));
if (!this.optionalCharacter($SEMICOLON)) {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class BaseException extends Error {
constructor(message?: string) {
super(message);
this.message = message;
this.stack = (<any>new Error()).stack;
this.stack = (<any>new Error(message)).stack;
}

toString(): string { return this.message; }
Expand Down
14 changes: 10 additions & 4 deletions modules/angular2/test/change_detection/parser/parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function main() {
function keyValues(templateBindings) {
return ListWrapper.map(templateBindings, (binding) => {
if (binding.keyIsVar) {
return '#' + binding.key + (isBlank(binding.name) ? '' : '=' + binding.name);
return '#' + binding.key + (isBlank(binding.name) ? '=null' : '=' + binding.name);
} else {
return binding.key + (isBlank(binding.expression) ? '' : `=${binding.expression}`)
}
Expand Down Expand Up @@ -508,7 +508,7 @@ export function main() {

it('should detect names as value', () => {
var bindings = parseTemplateBindings("a:#b");
expect(keyValues(bindings)).toEqual(['a', '#b']);
expect(keyValues(bindings)).toEqual(['a', '#b=\$implicit']);
});

it('should allow space and colon as separators', () => {
Expand Down Expand Up @@ -540,10 +540,16 @@ export function main() {

it('should support var/# notation', () => {
var bindings = parseTemplateBindings("var i");
expect(keyValues(bindings)).toEqual(['#i']);
expect(keyValues(bindings)).toEqual(['#i=\$implicit']);

bindings = parseTemplateBindings("#i");
expect(keyValues(bindings)).toEqual(['#i']);
expect(keyValues(bindings)).toEqual(['#i=\$implicit']);

bindings = parseTemplateBindings("var a; var b");
expect(keyValues(bindings)).toEqual(['#a=\$implicit', '#b=\$implicit']);

bindings = parseTemplateBindings("#a; #b;");
expect(keyValues(bindings)).toEqual(['#a=\$implicit', '#b=\$implicit']);

bindings = parseTemplateBindings("var i-a = k-a");
expect(keyValues(bindings)).toEqual(['#i-a=k-a']);
Expand Down
3 changes: 3 additions & 0 deletions test-main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Tun on full stack traces in errors to help debugging
Error.stackTraceLimit=Infinity;

// Use "register" extension from systemjs.
// That's what Traceur outputs: `System.register()`.
register(System);
Expand Down
X Tutup