refactor(compiler): add details while throw error during expression convert (#32760)

Fixes #32759

PR Close #32760
This commit is contained in:
mohax 2019-09-19 00:44:21 +03:00 committed by Alex Rickabaugh
parent 15fefdbb8d
commit f4caf263d4
2 changed files with 7 additions and 4 deletions

View File

@ -551,7 +551,10 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
this.usesImplicitReceiver = prevUsesImplicitReceiver;
} else {
// Otherwise it's an error.
throw new Error('Cannot assign to a reference or variable!');
const receiver = ast.name;
const value = (ast.value instanceof cdAst.PropertyRead) ? ast.value.name : undefined;
throw new Error(
`Cannot assign value "${value}" to template variable "${receiver}". Template variables are read-only.`);
}
}
}

View File

@ -662,9 +662,9 @@ const TEST_COMPILER_PROVIDERS: Provider[] = [
}));
it('should throw when trying to assign to a local', fakeAsync(() => {
expect(() => {
_bindSimpleProp('(event)="$event=1"');
}).toThrowError(new RegExp('Cannot assign to a reference or variable!'));
expect(() => { _bindSimpleProp('(event)="$event=1"'); })
.toThrowError(new RegExp(
'Cannot assign value (.*) to template variable (.*). Template variables are read-only.'));
}));
it('should support short-circuiting', fakeAsync(() => {