-
Notifications
You must be signed in to change notification settings - Fork 586
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JavaScript] Basic support for syntax highlighting in tagged templates #4019
[JavaScript] Basic support for syntax highlighting in tagged templates #4019
Conversation
This commit adds support for syntax highlighting of CSS/JS/JSON/HTML within tagged template strings.
There's a couple of test failures with the latest commit, otherwise looks good to me |
This commit... 1. adds a `literal-string-templates` context to include templates into contexts without popping it off stack. 2. adjusts tag scopes to already existing `variable.function.tagged-template`. 3. adds support for whitespace between template tag and punctuation 4. drops supportt for block quotes between template tag and punctuation for simplicity reasons. It's jugdged unlikely enough to appear in real world code.
They revealed dome shortcommings of my implementation. Those are fixed. I am still a bit uncertain about tags' scopes.
Does it make sense to specify a common scoped used everywhere? |
I am in favor of standardization, but it doesn't have to be in this PR necessarily. |
This commit adjusts syntax definition and indentation rules to ensure content of tagged templates is indented, automatically. It includes consuming all trailing/leading whitespace after opening and in front of closing string punctuation, to ensure JavaScript indentation rules being applied, when hitting enter after an opening template punctuation.
Applied some changes to auto-indent content of tagged templates, correctly. This commit will create a conflict with #4015 and might need further tweak after that has been merged to apply changes to the new indentation rule file as well. |
Pretty sure 1 is due to how js calls a function for the tagged template literals so seems correct for js. 2 is likely a relic of html tag scoping - it shouldn't IMO be an |
This commit strips embedded source scope after opening and before closing string punctuation only, if those are located on a separate line. In single line tagged template strings, embedded scope is applied to leading and trailing whitespace as well.
Tweaked patterns so embedded source scopes are stripped only, when needed - not in single line template strings. Related with #4020. |
Resolves #179
This commit adds support for syntax highlighting of CSS/JS/JSON/HTML within tagged template strings.
JavaScript embeds extended syntax definitions to enable
${...}
interpolation in highlighted template tags, very much like most other template syntaxes (e.g.: Go Templates, Jinja2, Liquid, ...).As templates are embedded, impact on syntax cache size and complexity of JavaScript itself is negligible. They are loaded on demand and thus shouldn't effect other template languages, significantly.
Compatibility notes:
{{ ... }}
within tagged template tags.js`...`
tags very much like other template syntaxes do. JavaScript however already highlights${...}
as some sort of dollar variable in various situations. It's currently not clear, if that would be enough which would mean to removeprototype
manipulations.