Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using {{ and }} in strings in templates breaks the compiler #40133

Closed
elliotleelewis opened this issue Dec 15, 2020 · 8 comments
Closed

Using {{ and }} in strings in templates breaks the compiler #40133

elliotleelewis opened this issue Dec 15, 2020 · 8 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser
Milestone

Comments

@elliotleelewis
Copy link

elliotleelewis commented Dec 15, 2020

馃悶 bug report

Affected Package

I believe this is caused by incorrect lexer grammars in @angular/compiler.

Is this a regression?

Not that I'm aware of.

Description

Using {{ ... }} inside a string inside a template binding throws compile errors, complaining that it cannot parse the input.

For example:

<p>{{ 'This is a string literal which breaks the angular compiler... {{ }} <-------- ' }}</p>

image

This shouldn't be the case. Strings should be by-definition any characters, and shouldn't stop the app from compiling correctly.

In our use-case, we have a custom i18n solution that uses that syntax for variable replacement within localized strings, and without this fixed, we have to define those strings as class properties in the component's class file instead.

馃敩 Minimal Reproduction

https://stackblitz.com/edit/angular-string-brace-bug?file=src/app/app.component.html

馃敟 Exception or Error

Error: src/app/app.component.html:1:1 - error NG5002: Parser Error: Unexpected token Lexer Error: Unterminated quote at column 16 in expression [ "Hello {{ test ] at column 17 in [{{ "Hello {{ test }}!" }} ] in /PATH/TO/PROJECTS/test/src/app/app.component.html@0:0

馃實 Your Environment

Angular Version:


Angular CLI: 11.1.0-next.2
Node: 12.15.0
OS: darwin x64

Angular: 11.1.0-next.2
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.3
@angular-devkit/build-angular   0.1101.0-next.2
@angular-devkit/core            11.1.0-next.2
@angular-devkit/schematics      11.1.0-next.2
@angular/fire                   6.1.4
@schematics/angular             11.1.0-next.2
@schematics/update              0.1101.0-next.2
rxjs                            6.6.3
typescript                      4.1.2

Anything else relevant?

I don't think so.

@JoostK
Copy link
Member

JoostK commented Dec 15, 2020

I believe this was fixed in #39826 which will be part of this week's release :-)

@JoostK JoostK added area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser labels Dec 15, 2020
@ngbot ngbot bot added this to the needsTriage milestone Dec 15, 2020
@elliotleelewis
Copy link
Author

@JoostK Wow, good timing!! 馃槀

This issue can probably be closed then.

@JoostK
Copy link
Member

JoostK commented Dec 15, 2020

Could you test with the snapshot builds?

"@angular/compiler": "https://github.com/angular/compiler-builds"
"@angular/compiler-cli": "https://github.com/angular/compiler-cli-builds"

@elliotleelewis
Copy link
Author

elliotleelewis commented Dec 15, 2020

@JoostK Yep that seems to work fine. Although of course my IDE (WebStorm) is still complaining about it.

image

EDIT: Looks like VS Code has similar problems:

image

@JoostK
Copy link
Member

JoostK commented Dec 15, 2020

Great to hear it's indeed been resolved. I am not sure about the LS (Language Service) integration; I suspect that WebStorm has its own parsing infrastructure, and VS Code is somewhat unexpected to m but maybe it uses a different version altogether (although I don't think so). There is currently work underway to more tightly integrate the LS with the compiler itself, but I couldn't tell if that would make a difference here.

@atscott
Copy link
Contributor

atscott commented Dec 17, 2020

Closing this as resolved.
With respect to the errors in the language service, Webstorm has its own implementation that we don't control. As for the VScode issue, this would be resolved by the upcoming Ivy Native Language Service, which we'll be releasing as experimental in 11.1. One of the main goals of that project was to ensure the LS diagnostics matched the diagnostics you would get from the compiler.

@atscott atscott closed this as completed Dec 17, 2020
@elliotleelewis
Copy link
Author

Sweet! Thanks for your help on this guys! 馃憤

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser
Projects
None yet
Development

No branches or pull requests

3 participants