fix(vscode-extension): handle template literals when detecting suppor… · angular/angular@f2cf65a · GitHub
Skip to content

Commit f2cf65a

Browse files
aparziatscott
authored andcommitted
fix(vscode-extension): handle template literals when detecting supported decorator fields
The client decides whether a position in a TypeScript file belongs to a supported `@Component` field (`template`, `styles`, ...) with a lightweight `ts.Scanner` loop before forwarding requests to the language server and the HTML/CSS providers. `ts.Scanner#scan` doesn't handle template substitutions on its own: the `}` closing a `${...}` substitution is reported as a plain `CloseBraceToken` and the rest of the template literal is scanned as the start of a new one, swallowing everything up to the next backtick. As a result, once a template literal with substitutions appears in a file, every position after it is considered to be inside a template string, and TypeScript completions get polluted with HTML completions. The scanner is now driven the same way the TypeScript parser does it, re-scanning the brace that closes a substitution as a `TemplateMiddle`/`TemplateTail` token. In addition, the property assignment context previously only ended at a terminator found at the top level of the file, so it leaked from `template:` to every string literal that followed it inside the same decorator and class body. The context now ends at the first terminator found at the nesting depth where it was entered. Two kinds of strings were only recognized thanks to that leak, and only when declared after `template`: inline `styles` and the arguments of `@HostBinding`/`@HostListener` decorators, both of which the language service supports. They are now recognized explicitly, regardless of where they appear. Fixes #65494
1 parent 467b37b commit f2cf65a

2 files changed

Lines changed: 262 additions & 30 deletions

File tree

vscode-ng-language-service/client/src/embedded_support.ts

Lines changed: 123 additions & 30 deletions

vscode-ng-language-service/client/src/tests/embedded_support_spec.ts

Lines changed: 139 additions & 0 deletions

0 commit comments

Comments
 (0)