Skip to content

Commit

Permalink
refactor(compiler): add details while throw error during expression c…
Browse files Browse the repository at this point in the history
…onvert

Fixes angular#32759
  • Loading branch information
mohaxspb committed Oct 27, 2019
1 parent cf9b17c commit e3663f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/compiler/src/compiler_util/expression_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,11 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
this.usesImplicitReceiver = prevUsesImplicitReceiver;
} else {
// Otherwise it's an error.
const exprName = ast.constructor.name;
const receiver = ast.name;
const value = (ast.value instanceof cdAst.PropertyRead) ? ast.value.name : undefined;
throw new Error(
`LocalExpr is not instance of ReadPropExpr in _AstToIrVisitor#visitPropertyWrite at expression_converter.ts! ` +
`Do not assign to local variable in template! Failed expression details: ${JSON.stringify(ast)}`);
`ReadPropExpr expected but ${exprName} found with receiver "${receiver}" and value "${value}"`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ const TEST_COMPILER_PROVIDERS: Provider[] = [
it('should throw when trying to assign to a local', fakeAsync(() => {
expect(() => { _bindSimpleProp('(event)="$event=1"'); })
.toThrowError(new RegExp(
'LocalExpr is not instance of ReadPropExpr in _AstToIrVisitor#visitPropertyWrite at expression_converter.ts! ' +
'Do not assign to local variable in template! Failed expression details: .'));
'ReadPropExpr expected but (.*) found with receiver (.*) and value (.*)'));
}));

it('should support short-circuiting', fakeAsync(() => {
Expand Down

0 comments on commit e3663f3

Please sign in to comment.