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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose template string chars as nodes #276

Closed
wants to merge 3 commits into from

Conversation

helixbass
Copy link
Contributor

@helixbass helixbass commented Nov 14, 2023

Fixes #275

This exposes template_chars as a node (so that template string text contents are visible in "leaf" nodes)

Checklist:

  • All tests pass in CI.
  • The script/parse-examples passes without issues.
  • There are sufficient tests for the new fix/feature.
  • Grammar rules have not been renamed unless absolutely necessary.
  • The conflicts section hasn't grown too much.
  • The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).

@@ -7,7 +7,9 @@
(member_expression
property: (property_identifier) @injection.language)
]
arguments: (template_string) @injection.content)
arguments: (template_string
(template_chars) @injection.content
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/highlight/injection.js was failing, which tests that for the source text:

eval(js `var foo`)

the var foo gets highlighted as JS content (eg var gets highlighted as a keyword)

My understanding is that the reason that test started failing is because the way that injections work, by default this @injection.content doesn't include ("re-parse") any child nodes' content of this (template_string) node. And now there is a (template_chars) child node, so the re-parsing of the (template_string) node doesn't include the var foo content

So this gets that test passing by specifying that the new (template_chars) node should be used as the thing to be re-parsed instead

I have no idea if this is hacky or not, eg not sure how the old version vs this version would behave when highlighting eg a template string with multiple text sections (eval(`is this text parsed as JS ${foo} and then this text is also parsed as JS`))

@helixbass helixbass changed the title WIP: Expose template string chars as nodes Expose template string chars as nodes Nov 14, 2023
@amaanq
Copy link
Member

amaanq commented Jan 31, 2024

Think this should be ok now on 0.20.2

@amaanq amaanq closed this Jan 31, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose template string chars as nodes?
2 participants