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 const arrow functions in TSX #4114

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
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 @@ -62,97 +62,103 @@ contexts:
pop: 1
- expression

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-begin

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

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 @@ -192,23 +198,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
Loading