Skip to content

Commit

Permalink
[JavaScript] Fix const arrow functions in TSX (#4114)
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe authored Dec 21, 2024
1 parent 4b9b82f commit 737d31d
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 208 deletions.
127 changes: 58 additions & 69 deletions JavaScript/JSX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ variables:
contexts:
expression-begin:
- meta_prepend: true
- include: jsx-tag-hack
- include: jsx-tag

jsx-interpolation:
- match: (?={/\*)
Expand Down Expand Up @@ -66,97 +66,103 @@ contexts:
pop: 1
- include: expressions

jsx-expect-tag-end:
- meta_content_scope: meta.tag.js
- match: '>{2,}' # ignore invalid punctuation
- match: '>'
scope: meta.tag.js punctuation.definition.tag.end.js
pop: 1
- include: else-pop

jsx-meta:
- meta_include_prototype: false
- meta_scope: meta.jsx.js
- include: immediately-pop

jsx-tag:
- match: '<(?=\s*[/>{{jsx_tag_name_start}}])'
- match: <(?=\s*[/>{{jsx_tag_name_start}}])
scope: punctuation.definition.tag.begin.js
set:
- jsx-meta
- jsx-tag-attributes-top

jsx-tag-hack: # Ugly hack so that TSX can un-include this in expression-begin
- include: jsx-tag
- jsx-tag-begin

jsx-tag-attributes-top:
jsx-tag-begin:
- meta_include_prototype: false
- meta_scope: meta.tag.js
- match: '/'
- match: /
scope: punctuation.definition.tag.begin.js
set:
- jsx-meta-unmatched-tag
- jsx-expect-tag-end
- jsx-expect-unmatched-tag-end
- jsx-tag-name

- match: (?=\S)
set:
- jsx-tag-attributes
- jsx-tag-name

jsx-meta-unmatched-tag:
jsx-expect-unmatched-tag-end:
- meta_include_prototype: false
- meta_scope: invalid.illegal.unmatched-tag.js
- include: immediately-pop
- meta_content_scope: meta.tag.js
- include: jsx-expect-tag-end

jsx-child-tag:
- match: <(?=\s*[/>{{jsx_tag_name_start}}])
scope: punctuation.definition.tag.begin.js
set: jsx-child-tag-begin

jsx-child-tag-begin:
- meta_include_prototype: false
- meta_scope: meta.tag.js
- match: /
scope: punctuation.definition.tag.begin.js
set:
- jsx-expect-tag-end
- jsx-tag-name
- match: (?=\S)
set:
- jsx-body
- jsx-tag-attributes
- jsx-tag-name

jsx-expect-tag-end:
- meta_content_scope: meta.tag.js
- match: '>{2,}' # ignore invalid punctuation
- match: '>'
scope: meta.tag.js punctuation.definition.tag.end.js
pop: 1
- include: else-pop

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

- match: '>{2,}' # ignore invalid punctuation
- match: '>'
scope: meta.tag.js punctuation.definition.tag.end.js
set: jsx-body

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

- include: jsx-interpolation

- match: '{{jsx_identifier}}'
scope: entity.other.attribute-name.js

- match: '='
scope: punctuation.separator.key-value.js
push: jsx-attribute-value

jsx-attribute-value:
- include: jsx-tag
- include: jsx-interpolation

- match: "'"
- match: \"
scope: punctuation.definition.string.begin.js
set:
- meta_include_prototype: false
- meta_scope: string.quoted.single.js
- match: \'
scope: punctuation.definition.string.end.js
pop: 1
- include: jsx-html-escapes
- match: '"'
push: jsx-double-quoted-string-body
- match: \'
scope: punctuation.definition.string.begin.js
set:
- meta_include_prototype: false
- meta_scope: string.quoted.double.js
- match: \"
scope: punctuation.definition.string.end.js
pop: 1
- include: jsx-html-escapes
push: jsx-single-quoted-string-body
- include: jsx-interpolation

- include: else-pop
jsx-double-quoted-string-body:
- meta_include_prototype: false
- meta_scope: meta.string.js string.quoted.double.js
- match: \"
scope: punctuation.definition.string.end.js
pop: 1
- include: jsx-html-escapes

jsx-single-quoted-string-body:
- meta_include_prototype: false
- meta_scope: meta.string.js string.quoted.single.js
- match: \'
scope: punctuation.definition.string.end.js
pop: 1
- include: jsx-html-escapes

jsx-html-escapes:
- match: '(&)#?[[:alnum:]]+(;)'
- match: (&)#?[[:alnum:]]+(;)
scope: constant.character.escape.js
captures:
1: punctuation.definition.entity.js
Expand Down Expand Up @@ -196,23 +202,6 @@ contexts:

jsx-body:
- meta_include_prototype: false
- match: '<(?=\s*[/>{{jsx_tag_name_start}}])'
scope: punctuation.definition.tag.begin.js
set:
- meta_include_prototype: false
- meta_scope: meta.tag.js

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

- match: (?=\S)
set:
- jsx-body
- jsx-tag-attributes
- jsx-tag-name

- include: jsx-child-tag
- include: jsx-html-escapes
- include: jsx-interpolation
17 changes: 9 additions & 8 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ contexts:
set:
- detect-arrow
- parenthesized-expression
- match: (?={{identifier_start}})
- match: ''
set:
- detect-arrow
- literal-variable
Expand Down Expand Up @@ -2055,13 +2055,14 @@ contexts:
parenthesized-expression:
- match: \(
scope: punctuation.section.group.begin.js
set:
- meta_scope: meta.group.js
- match: \)
scope: punctuation.section.group.end.js
pop: 1
- match: (?=\S)
push: expression
set: parenthesized-expression-body

parenthesized-expression-body:
- meta_scope: meta.group.js
- match: \)
scope: punctuation.section.group.end.js
pop: 1
- include: expressions

function-call-arguments:
- meta_content_scope: meta.function-call.js
Expand Down
48 changes: 27 additions & 21 deletions JavaScript/TSX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,49 @@ first_line_match: |-
)
contexts:
branch-possible-arrow-function:
- meta_prepend: true
- include: jsx-tag

jsx-tag-hack: []

jsx-tag-name:
- meta_include_prototype: false
- match: ''
ts-old-type-assertion:
# old type assertions are replaced by JSX tags
- match: <
scope: punctuation.definition.tag.begin.js
set:
- jsx-tag-name-meta
- tsx-tag-generic-arguments
- jsx-tag-name-end
- jsx-tag-name-component-possibly-native
- jsx-meta
- jsx-tag-begin

tsx-tag-generic-arguments:
- include: ts-generic-type-arguments
- include: else-pop
jsx-tag: [] # replaced by `ts-old-type-assertion`

jsx-tag-attributes-top:
jsx-tag-begin:
- meta_include_prototype: false
- meta_scope: meta.tag.js
- match: '/'
# note: type parameter modifiers indicate generic lambda
- match: (?=(?:in|out|const){{identifier_break}})
fail: arrow-function
- match: /
scope: punctuation.definition.tag.begin.js
set:
- jsx-meta-unmatched-tag
- jsx-expect-tag-end
- jsx-expect-unmatched-tag-end
- jsx-tag-name

- match: (?=\S)
set:
- jsx-tag-attributes
- tsx-tag-check
- jsx-tag-name

jsx-tag-name:
- meta_include_prototype: false
- match: ''
set:
- jsx-tag-name-meta
- tsx-tag-generic-arguments
- jsx-tag-name-end
- jsx-tag-name-component-possibly-native

tsx-tag-generic-arguments:
- include: ts-generic-type-arguments
- include: else-pop

tsx-tag-check:
- match: 'extends{{jsx_identifier_break}}'
- match: extends{{jsx_identifier_break}}
scope: entity.other.attribute-name.js
set:
- meta_include_prototype: false
Expand Down
Loading

0 comments on commit 737d31d

Please sign in to comment.