Provide parser error when :global appears without selector in CSS #4936
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4930
Prevent a compiler crash when
:global
appears by itself in a CSS selector by adding an extra check when walking the style AST. If a node meets the following conditions:type
is'PseudoClassSelector'
,name
is'global'
, andchildren
isnull
,then the parser reports an error:
:global() must contain a selector, cannot be used on its own
.Long-time user, first-time contributor -- please forgive any naive errors in putting together this PR. In particular, I wasn't quite sure of the right way to report the location of the error. In the file I touched,
src/compiler/parse/read/style.ts
, one of the existing checks uses the node'sloc.start.offset
property, while the other uses thestart
property. The former seemed to make the most sense with the test case I wrote, so I went with that -- but happy to correct if I was wrong.Before submitting the PR, please make sure you do the following
npm run lint
!)Tests
npm test
oryarn test
)