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

[JavaScript] Fix JSX interpolation scopes #4116

Merged
merged 2 commits into from
Dec 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions JavaScript/JSX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,35 @@ contexts:
push: jsx-interpolation-plain

jsx-interpolation-comment:
- match: '({)(/\*)'
- match: ({)(/\*)
captures:
1: punctuation.definition.interpolation.begin.js
1: punctuation.section.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: 1
- match: (?=\*/)
fail: jsx-interpolation-comment
set: jsx-interpolation-comment-body

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

jsx-interpolation-plain:
- match: '{'
scope: punctuation.definition.interpolation.begin.js
set:
- - meta_scope: meta.interpolation.js
- meta_content_scope: source.js.embedded.jsx
- match: '}'
scope: punctuation.definition.interpolation.end.js
pop: 1
- expression
- match: \{
scope: punctuation.section.interpolation.begin.js
set: jsx-interpolation-plain-body

jsx-interpolation-plain-body:
- meta_scope: meta.interpolation.js
- meta_content_scope: source.js.embedded.jsx
- match: \}
scope: punctuation.section.interpolation.end.js
pop: 1
- include: expressions

jsx-expect-tag-end:
- meta_content_scope: meta.tag.js
Expand Down
24 changes: 12 additions & 12 deletions JavaScript/tests/syntax_test_jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,18 @@

baz={xyzzy}
// ^^^^^^^ meta.interpolation
// ^ punctuation.definition.interpolation.begin
// ^ punctuation.section.interpolation.begin
// ^^^^^ source.js.embedded.jsx variable.other.readwrite
// ^ punctuation.definition.interpolation.end
// ^ punctuation.section.interpolation.end

baz={{ xyzzy:42 }}
// ^^^^^^^^^^^^^^ meta.interpolation
// ^ punctuation.definition.interpolation.begin
// ^ punctuation.section.interpolation.begin
// ^^^^^^^^^^^^ source.js.embedded.jsx meta.mapping
// ^^^^^ meta.mapping.key
// ^ punctuation.separator.key-value
// ^^ meta.number.integer.decimal.js constant.numeric.value.js
// ^ punctuation.definition.interpolation.end
// ^ punctuation.section.interpolation.end


{...attrs}
Expand All @@ -240,7 +240,7 @@
// ^^^^^ meta.mapping.key
// ^ punctuation.separator.key-value
// ^^ meta.number.integer.decimal.js constant.numeric.value.js
// ^ punctuation.definition.interpolation.end
// ^ punctuation.section.interpolation.end

// baz
// ^^^^^^ comment.line.double-slash
Expand Down Expand Up @@ -278,32 +278,32 @@
// ^^^^^ meta.mapping.key
// ^ punctuation.separator.key-value
// ^^ meta.number.integer.decimal.js constant.numeric.value.js
// ^ punctuation.definition.interpolation.end
// ^ punctuation.section.interpolation.end

{//}
// ^ punctuation.definition.interpolation.begin
// ^ punctuation.section.interpolation.begin
// ^^^ comment.line.double-slash
// ^^ punctuation.definition.comment
// ^ - punctuation
}
// ^ punctuation.definition.interpolation.end
// ^ punctuation.section.interpolation.end

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

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

</foo>;

Expand Down
Loading