2016-08-12 01:38:31 +03:00
|
|
|
# [PackageDev] target_format: plist, ext: tmLanguage
|
2015-11-06 00:14:57 +03:00
|
|
|
# Similar to TypeScript.YAML-tmLanguage except:
|
2016-01-27 13:13:21 +03:00
|
|
|
# - Remove type assertion (cast.expr.tsx)
|
2015-11-06 00:14:57 +03:00
|
|
|
# - Add JSX expression (HTML-like expression).
|
|
|
|
---
|
|
|
|
name: TypeScriptReact
|
|
|
|
scopeName: source.tsx
|
|
|
|
fileTypes: [tsx]
|
|
|
|
uuid: 805375ec-d614-41f5-8993-5843fe63ea82
|
|
|
|
|
2018-03-10 02:46:14 +03:00
|
|
|
variables:
|
2019-07-18 01:47:32 +03:00
|
|
|
# because tsx cannot have cast expression, we can say <T extends starts the type parameter of arrow
|
|
|
|
typeparamertStartOfArrow: |-
|
|
|
|
(
|
|
|
|
[<]\s*{{identifier}}\s+extends\s*[^=>] # < typeparam extends
|
|
|
|
) |
|
2018-07-20 22:52:00 +03:00
|
|
|
#possiblyMultilineArrowExpressionBeforeEndOfLine: ({{typeParameters}})?\(
|
2019-10-31 00:08:21 +03:00
|
|
|
possiblyMultilineArrow: ((<\s*$)|({{possiblyMultilineArrowWithoutTypeParameters}})) # during lookup treat ( followed by line end as arrow
|
2018-08-21 11:23:27 +03:00
|
|
|
jsxTagOrAtrributeIdentifier: '[_$[:alpha:]][-_$[:alnum:].]*'
|
2018-07-26 23:04:41 +03:00
|
|
|
jsxTagNamespace: (?:({{jsxTagOrAtrributeIdentifier}})(?<!\.|-)(:))?
|
|
|
|
jsxTagName: \s*{{jsxTagNamespace}}((?:[a-z][a-z0-9]*|({{jsxTagOrAtrributeIdentifier}}))(?<!\.|-))
|
2018-03-10 02:46:14 +03:00
|
|
|
jsxOpeningTagWithoutAttributes: (<){{jsxTagName}}?\s*(>)
|
|
|
|
jsxClosingTag: (</){{jsxTagName}}?\s*(>)
|
2018-07-03 23:19:52 +03:00
|
|
|
jsxTagStart: (<){{jsxTagName}}(?=((<\s*)|(\s+))(?!\?)|\/?>)
|
2018-03-10 02:46:14 +03:00
|
|
|
jsxTagStartLookahead: (?={{jsxTagStart}})
|
2019-07-18 01:01:56 +03:00
|
|
|
jsxLookBehindInExpression: (?<!\+\+|--)(?<=[({\[,?=>:*]|&&|\|\||\?|\*\/|{{lookBehindAwait}}|{{lookBehindReturn}}|{{lookBehindDefault}}|{{lookBehindYield}}|^)\s*
|
2018-03-10 02:46:14 +03:00
|
|
|
|
2015-11-06 00:14:57 +03:00
|
|
|
repository:
|
2016-09-20 22:25:38 +03:00
|
|
|
# Additions:
|
2016-09-21 21:08:12 +03:00
|
|
|
# expression repository need to include jsx first followed by whaterver ts grammar says
|
2017-12-14 20:30:49 +03:00
|
|
|
expressionWithoutIdentifiers:
|
2016-04-27 19:36:09 +03:00
|
|
|
patterns:
|
2016-08-18 02:08:00 +03:00
|
|
|
- include: '#jsx'
|
2016-03-17 20:49:23 +03:00
|
|
|
|
2016-09-20 22:25:38 +03:00
|
|
|
# Overrides:
|
2017-09-28 21:34:53 +03:00
|
|
|
|
2016-09-20 22:25:38 +03:00
|
|
|
# We need to override this to make sure cast is not matched from typescript
|
|
|
|
# We can safely include jsx because thats the first rule matched anyways so it wont impact at all
|
|
|
|
cast:
|
2015-11-06 00:14:57 +03:00
|
|
|
patterns:
|
2016-09-20 22:25:38 +03:00
|
|
|
- include: '#jsx'
|
2015-11-06 00:14:57 +03:00
|
|
|
|
|
|
|
# jsx syntax is taken from https://github.com/babel/babel-sublime
|
2017-09-28 21:34:53 +03:00
|
|
|
jsx:
|
2015-11-06 00:14:57 +03:00
|
|
|
patterns:
|
2017-09-28 21:34:53 +03:00
|
|
|
- include: '#jsx-tag-without-attributes-in-expression'
|
|
|
|
- include: '#jsx-tag-in-expression'
|
2015-11-06 00:14:57 +03:00
|
|
|
|
2017-09-28 21:34:53 +03:00
|
|
|
#jsx tags
|
2017-06-27 02:32:50 +03:00
|
|
|
jsx-tag-without-attributes-in-expression:
|
2018-03-13 23:17:19 +03:00
|
|
|
begin: '{{jsxLookBehindInExpression}}(?={{jsxOpeningTagWithoutAttributes}})'
|
|
|
|
end: (?!{{jsxOpeningTagWithoutAttributes}})
|
2017-06-27 02:32:50 +03:00
|
|
|
patterns:
|
|
|
|
- include: '#jsx-tag-without-attributes'
|
|
|
|
|
2015-11-06 00:14:57 +03:00
|
|
|
jsx-tag-without-attributes:
|
2016-08-16 23:07:17 +03:00
|
|
|
name: meta.tag.without-attributes.tsx
|
2018-03-10 02:46:14 +03:00
|
|
|
begin: '{{jsxOpeningTagWithoutAttributes}}'
|
|
|
|
end: '{{jsxClosingTag}}'
|
2015-11-06 00:14:57 +03:00
|
|
|
beginCaptures:
|
|
|
|
'1': {name: punctuation.definition.tag.begin.tsx}
|
2018-03-02 15:41:49 +03:00
|
|
|
'2': {name: entity.name.tag.namespace.tsx}
|
|
|
|
'3': {name: punctuation.separator.namespace.tsx}
|
|
|
|
'4': {name: entity.name.tag.tsx}
|
|
|
|
'5': {name: support.class.component.tsx}
|
|
|
|
'6': {name: punctuation.definition.tag.end.tsx}
|
2015-11-06 00:14:57 +03:00
|
|
|
endCaptures:
|
|
|
|
'1': {name: punctuation.definition.tag.begin.tsx}
|
2018-03-02 15:41:49 +03:00
|
|
|
'2': {name: entity.name.tag.namespace.tsx}
|
|
|
|
'3': {name: punctuation.separator.namespace.tsx}
|
|
|
|
'4': {name: entity.name.tag.tsx}
|
|
|
|
'5': {name: support.class.component.tsx}
|
|
|
|
'6': {name: punctuation.definition.tag.end.tsx}
|
2016-08-31 22:23:59 +03:00
|
|
|
contentName: meta.jsx.children.tsx
|
2015-11-06 00:14:57 +03:00
|
|
|
patterns:
|
|
|
|
- include: '#jsx-children'
|
|
|
|
|
2016-10-04 21:13:52 +03:00
|
|
|
jsx-tag-in-expression:
|
2016-09-21 21:08:12 +03:00
|
|
|
# We need to differentiate between the relational '<' operator and the beginning of a tag using the surrounding context.
|
2016-11-19 02:29:38 +03:00
|
|
|
begin: |-
|
2015-11-06 00:14:57 +03:00
|
|
|
(?x)
|
2018-03-13 23:17:19 +03:00
|
|
|
{{jsxLookBehindInExpression}}
|
2016-09-22 02:29:02 +03:00
|
|
|
(?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow
|
2018-03-10 02:46:14 +03:00
|
|
|
{{jsxTagStartLookahead}}
|
2018-03-13 23:17:19 +03:00
|
|
|
end: (?!{{jsxTagStart}})
|
2016-08-31 22:11:14 +03:00
|
|
|
patterns:
|
2016-10-04 21:13:52 +03:00
|
|
|
- include: '#jsx-tag'
|
|
|
|
|
2018-03-13 23:17:19 +03:00
|
|
|
jsx-tag:
|
|
|
|
name: meta.tag.tsx
|
2018-03-10 02:46:14 +03:00
|
|
|
begin: '{{jsxTagStartLookahead}}'
|
|
|
|
end: (/>)|(?:{{jsxClosingTag}})
|
2016-10-04 21:13:52 +03:00
|
|
|
endCaptures:
|
2018-03-02 15:41:49 +03:00
|
|
|
'1': { name: punctuation.definition.tag.end.tsx }
|
|
|
|
'2': { name: punctuation.definition.tag.begin.tsx }
|
|
|
|
'3': { name: entity.name.tag.namespace.tsx }
|
|
|
|
'4': { name: punctuation.separator.namespace.tsx }
|
|
|
|
'5': { name: entity.name.tag.tsx }
|
|
|
|
'6': { name: support.class.component.tsx }
|
|
|
|
'7': { name: punctuation.definition.tag.end.tsx }
|
2016-10-04 21:13:52 +03:00
|
|
|
patterns:
|
2018-03-10 02:46:14 +03:00
|
|
|
- begin: '{{jsxTagStart}}'
|
2016-08-31 22:11:14 +03:00
|
|
|
beginCaptures:
|
2016-09-21 21:08:12 +03:00
|
|
|
'1': { name: punctuation.definition.tag.begin.tsx }
|
2018-03-02 15:41:49 +03:00
|
|
|
'2': { name: entity.name.tag.namespace.tsx }
|
|
|
|
'3': { name: punctuation.separator.namespace.tsx }
|
|
|
|
'4': { name: entity.name.tag.tsx }
|
|
|
|
'5': { name: support.class.component.tsx }
|
2016-10-04 21:13:52 +03:00
|
|
|
end: (?=[/]?>)
|
2016-08-31 22:11:14 +03:00
|
|
|
patterns:
|
2016-10-04 21:13:52 +03:00
|
|
|
- include: '#comment'
|
2018-03-13 23:09:00 +03:00
|
|
|
- include: '#type-arguments'
|
2016-10-04 21:13:52 +03:00
|
|
|
- include: '#jsx-tag-attributes'
|
|
|
|
- begin: (>)
|
|
|
|
beginCaptures:
|
|
|
|
'1': { name: punctuation.definition.tag.end.tsx }
|
|
|
|
end: (?=</)
|
|
|
|
contentName: meta.jsx.children.tsx
|
|
|
|
patterns:
|
|
|
|
- include: '#jsx-children'
|
2015-11-06 00:14:57 +03:00
|
|
|
|
2017-09-28 21:34:53 +03:00
|
|
|
#jsx children
|
2015-11-06 00:14:57 +03:00
|
|
|
jsx-children:
|
|
|
|
patterns:
|
|
|
|
- include: '#jsx-tag-without-attributes'
|
2018-03-13 23:17:19 +03:00
|
|
|
# Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
|
|
|
|
- include: '#jsx-tag'
|
2015-11-06 00:14:57 +03:00
|
|
|
- include: '#jsx-evaluated-code'
|
|
|
|
- include: '#jsx-entities'
|
|
|
|
|
2017-09-28 21:34:53 +03:00
|
|
|
#entities and evaluated code
|
|
|
|
jsx-evaluated-code:
|
2019-10-11 18:52:04 +03:00
|
|
|
contentName: meta.embedded.expression.tsx
|
2017-09-28 21:34:53 +03:00
|
|
|
begin: \{
|
|
|
|
end: \}
|
|
|
|
beginCaptures:
|
|
|
|
'0': { name: punctuation.section.embedded.begin.tsx }
|
|
|
|
endCaptures:
|
|
|
|
'0': { name: punctuation.section.embedded.end.tsx }
|
2015-11-06 00:14:57 +03:00
|
|
|
patterns:
|
2017-09-28 21:34:53 +03:00
|
|
|
- include: '#expression'
|
|
|
|
|
|
|
|
jsx-entities:
|
|
|
|
patterns:
|
|
|
|
- name: constant.character.entity.tsx
|
|
|
|
match: (&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)
|
|
|
|
captures:
|
|
|
|
'1': {name: punctuation.definition.entity.tsx}
|
|
|
|
'3': {name: punctuation.definition.entity.tsx}
|
|
|
|
|
|
|
|
#jsx attributes
|
|
|
|
jsx-tag-attributes:
|
2018-03-13 23:33:08 +03:00
|
|
|
name: meta.tag.attributes.tsx
|
|
|
|
begin: \s+
|
|
|
|
end: (?=[/]?>)
|
2017-09-28 21:34:53 +03:00
|
|
|
patterns:
|
2018-03-24 01:36:04 +03:00
|
|
|
- include: '#comment'
|
2017-09-28 21:34:53 +03:00
|
|
|
- include: '#jsx-tag-attribute-name'
|
|
|
|
- include: '#jsx-tag-attribute-assignment'
|
|
|
|
- include: '#jsx-string-double-quoted'
|
|
|
|
- include: '#jsx-string-single-quoted'
|
|
|
|
- include: '#jsx-evaluated-code'
|
2018-03-13 23:33:08 +03:00
|
|
|
- include: '#jsx-tag-attributes-illegal'
|
2017-09-28 21:34:53 +03:00
|
|
|
|
|
|
|
jsx-tag-attribute-name:
|
|
|
|
match: |-
|
|
|
|
(?x)
|
|
|
|
\s*
|
2018-07-26 23:04:41 +03:00
|
|
|
(?:({{jsxTagOrAtrributeIdentifier}})(:))?
|
2018-08-21 11:23:27 +03:00
|
|
|
([_$[:alpha:]][-_$[:alnum:]]*)
|
2017-09-28 21:34:53 +03:00
|
|
|
(?=\s|=|/?>|/\*|//)
|
|
|
|
captures:
|
2018-03-02 15:41:49 +03:00
|
|
|
'1': {name: entity.other.attribute-name.namespace.tsx}
|
|
|
|
'2': {name: punctuation.separator.namespace.tsx}
|
|
|
|
'3': {name: entity.other.attribute-name.tsx}
|
2017-09-28 21:34:53 +03:00
|
|
|
|
|
|
|
jsx-tag-attribute-assignment:
|
|
|
|
name: keyword.operator.assignment.tsx
|
|
|
|
match: =(?=\s*(?:'|"|{|/\*|//|\n))
|
|
|
|
|
|
|
|
jsx-string-double-quoted:
|
|
|
|
name: string.quoted.double.tsx
|
|
|
|
begin: '"'
|
|
|
|
end: '"'
|
|
|
|
beginCaptures:
|
|
|
|
'0': {name: punctuation.definition.string.begin.tsx}
|
|
|
|
endCaptures:
|
|
|
|
'0': {name: punctuation.definition.string.end.tsx}
|
|
|
|
patterns:
|
|
|
|
- include: '#jsx-entities'
|
|
|
|
|
|
|
|
jsx-string-single-quoted:
|
|
|
|
name: string.quoted.single.tsx
|
|
|
|
begin: "'"
|
|
|
|
end: "'"
|
|
|
|
beginCaptures:
|
|
|
|
'0': {name: punctuation.definition.string.begin.tsx}
|
|
|
|
endCaptures:
|
|
|
|
'0': {name: punctuation.definition.string.end.tsx}
|
|
|
|
patterns:
|
|
|
|
- include: '#jsx-entities'
|
|
|
|
|
|
|
|
jsx-tag-attributes-illegal:
|
|
|
|
name: invalid.illegal.attribute.tsx
|
|
|
|
match: \S+
|
2015-11-06 00:14:57 +03:00
|
|
|
|
2016-02-02 04:10:11 +03:00
|
|
|
...
|