Skip to content

Commit

Permalink
[JavaScript] Fix JSX attribute meta scopes (#3739)
Browse files Browse the repository at this point in the history
This commit fixes an issue which caused `/` in self-closing tags 
being scoped `meta.tag.attributes`.
  • Loading branch information
deathaxe authored May 11, 2023
1 parent 33e153c commit 03188c9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
6 changes: 3 additions & 3 deletions JavaScript/JSX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ contexts:
- include: immediately-pop

jsx-tag-attributes:
- meta_scope: meta.tag.attributes.js
- meta_content_scope: meta.tag.attributes.js

- match: '>'
scope: punctuation.definition.tag.end.js
scope: meta.tag.js punctuation.definition.tag.end.js
set: jsx-body

- match: '/'
scope: punctuation.definition.tag.end.js
scope: meta.tag.js punctuation.definition.tag.end.js
set: jsx-expect-tag-end

- include: jsx-interpolation
Expand Down
31 changes: 28 additions & 3 deletions JavaScript/tests/syntax_test_jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,36 @@
//^^^^^^^^^^^^^^^^^^^^ comment.line.other.js - meta.preprocessor

<foo />;
// ^^^^^^^ meta.jsx meta.tag
// ^ meta.jsx meta.tag
// ^^^^ meta.jsx meta.tag.name
// ^^ meta.jsx meta.tag - meta.tag.attributes
// ^ punctuation.definition.tag.begin
// ^^^ meta.tag.name entity.name.tag.native
// ^^^ entity.name.tag.native
// ^^ punctuation.definition.tag.end

<foo attr= />;
// ^ meta.jsx meta.tag
// ^^^^ meta.jsx meta.tag.name
// ^^^^^^ meta.jsx meta.tag.attributes
// ^^ meta.jsx meta.tag - meta.tag.attributes
// ^ punctuation.definition.tag.begin
// ^^^ entity.name.tag.native
// ^^^^ entity.other.attribute-name
// ^ punctuation.separator.key-value
// ^^ punctuation.definition.tag.end

<foo attr="val" />;
// ^ meta.jsx meta.tag
// ^^^^ meta.jsx meta.tag.name
// ^^^^^^^^^^^ meta.jsx meta.tag.attributes
// ^^ meta.jsx meta.tag - meta.tag.attributes
// ^ punctuation.definition.tag.begin
// ^^^ entity.name.tag.native
// ^^^^ entity.other.attribute-name
// ^ punctuation.separator.key-value
// ^^^^^ string.quoted.double
// ^^ punctuation.definition.tag.end

<foo>Hello!</foo>;
// ^^^^^^^^^^^^^^^^^ meta.jsx
// ^^^^^ meta.tag
Expand Down Expand Up @@ -283,4 +308,4 @@
</foo>;

<Class />;
// ^^^^^ entity.name.tag - entity.name.tag.native
// ^^^^^ entity.name.tag.component - entity.name.tag.native
3 changes: 2 additions & 1 deletion JavaScript/tests/syntax_test_tsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,13 @@ if (a < b || c <= d) {}
// ^ punctuation.definition.generic.begin
// ^ support.class
// ^ punctuation.definition.generic.end
// ^^^^^^^^^ meta.tag.attributes
// ^^^^^^^^ meta.tag.attributes
// ^ entity.other.attribute-name
// ^ punctuation.separator.key-value
// ^^^^^ string.quoted.double
// ^ punctuation.definition.string.begin
// ^ punctuation.definition.string.end
// ^^ - meta.tag.attributes
// ^ punctuation.definition.tag.end
// ^ meta.tag punctuation.definition.tag.end
// ^ punctuation.terminator.statement
Expand Down

0 comments on commit 03188c9

Please sign in to comment.