From f4caf263d420ca6a93f1bbd594a0eaf919b3f663 Mon Sep 17 00:00:00 2001 From: mohax Date: Thu, 19 Sep 2019 00:44:21 +0300 Subject: [PATCH] refactor(compiler): add details while throw error during expression convert (#32760) Fixes #32759 PR Close #32760 --- packages/compiler/src/compiler_util/expression_converter.ts | 5 ++++- .../core/test/linker/change_detection_integration_spec.ts | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/compiler/src/compiler_util/expression_converter.ts b/packages/compiler/src/compiler_util/expression_converter.ts index 5eb7ab27a9..2b9cb229c5 100644 --- a/packages/compiler/src/compiler_util/expression_converter.ts +++ b/packages/compiler/src/compiler_util/expression_converter.ts @@ -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.`); } } } diff --git a/packages/core/test/linker/change_detection_integration_spec.ts b/packages/core/test/linker/change_detection_integration_spec.ts index a0af686da2..5d365cf9ef 100644 --- a/packages/core/test/linker/change_detection_integration_spec.ts +++ b/packages/core/test/linker/change_detection_integration_spec.ts @@ -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(() => {