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

[JSX] Improve commenting behavior. #2787

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion JavaScript/Comments.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.js, source.jsx, source.ts, source.tsx</string>
<string>source.js, source.jsx, source.ts, source.tsx, meta.jsx meta.tag.name, meta.jsx meta.tag.attributes</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
Expand Down
2 changes: 1 addition & 1 deletion JavaScript/JSX Comments.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>name</key>
<string>JSX Comments</string>
<key>scope</key>
<string>source.jsx meta.jsx - source.jsx.embedded.jsx, source.tsx meta.jsx - source.tsx.embedded.jsx</string>
<string>meta.jsx</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
Expand Down
29 changes: 27 additions & 2 deletions JavaScript/JSX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,34 @@ contexts:
- include: jsx-tag

jsx-interpolation:
- match: (?={/\*)
branch_point: jsx-interpolation-comment
branch:
- jsx-interpolation-comment
- jsx-interpolation-plain
- match: (?={)
push: jsx-interpolation-plain

jsx-interpolation-comment:
- match: '({)(/\*)'
captures:
1: punctuation.definition.interpolation.begin.js
2: punctuation.definition.comment.begin.js
set:
- meta_include_prototype: false
- meta_scope: meta.interpolation.js comment.block.js
- match: '(\*/)(})'
captures:
1: punctuation.definition.comment.end.js
2: punctuation.definition.interpolation.end.js
pop: true
- match: (?=\*/)
fail: jsx-interpolation-comment

jsx-interpolation-plain:
- match: '{'
scope: punctuation.definition.interpolation.begin.js
push:
set:
- - meta_scope: meta.interpolation.js
- meta_content_scope: source.js.embedded.jsx
- match: '}'
Expand Down Expand Up @@ -62,7 +87,7 @@ contexts:
- jsx-tag-name

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

- match: '>'
scope: punctuation.definition.tag.end.js
Expand Down
24 changes: 21 additions & 3 deletions JavaScript/tests/syntax_test_jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<foo
bar
// ^^^ meta.jsx meta.tag entity.other.attribute-name
// ^^^ meta.jsx meta.tag.attributes entity.other.attribute-name

=
// ^ punctuation.separator.key-value
Expand All @@ -80,15 +80,15 @@
// ^^^^^^ string.quoted.single

baz='test'
// ^^^^^^^^^^ meta.jsx meta.tag
// ^^^^^^^^^^ meta.jsx meta.tag.attributes
// ^^^ entity.other.attribute-name
// ^ punctuation.separator.key-value
// ^^^^^^ string.quoted.single
// ^ punctuation.definition.string.begin
// ^ punctuation.definition.string.end

baz="test"
// ^^^^^^^^^^ meta.jsx meta.tag
// ^^^^^^^^^^ meta.jsx meta.tag.attributes
// ^^^ entity.other.attribute-name
// ^ punctuation.separator.key-value
// ^^^^^^ string.quoted.double
Expand Down Expand Up @@ -181,6 +181,24 @@
// ^ - punctuation
}
// ^ punctuation.definition.interpolation.end

{/* foo */}
// ^^^^^^^^^^^ meta.jsx meta.interpolation comment.block - source.embedded
// ^ punctuation.definition.interpolation.begin
// ^^ punctuation.definition.comment.begin
// ^^ punctuation.definition.comment.end
// ^ punctuation.definition.interpolation.end

{/* foo */ bar}
// ^^^^^^^^^^^^^^^ meta.jsx meta.interpolation
// ^^^^^^^^^^^^^ source.js.embedded
// ^ punctuation.definition.interpolation.begin - comment
// ^^ punctuation.definition.comment.begin
// ^^ punctuation.definition.comment.end
// ^^^^^ - comment
// ^^^ meta.jsx meta.interpolation variable.other.readwrite
// ^ punctuation.definition.interpolation.end

</foo>;

<class />;
Expand Down