Skip to content

Commit f6760f9

Browse files
committed
support namespaced tsx
1 parent c29d12d commit f6760f9

37 files changed

+4343
-305
lines changed

.gitignore

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
build/node_modules
2-
build/typings/
1+
node_modules
32
build/*.js
4-
tests/generated/*
5-
tests/node_modules
6-
tests/typings/
7-
tests/*.js
3+
tests/*.js
4+
tests/generated/*

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: node_js
2+
3+
node_js:
4+
- 'stable'
5+
- '8'
6+
7+
sudo: false
8+
9+
env:
10+
- workerCount=2
11+
12+
matrix:
13+
fast_finish: true
14+
15+
branches:
16+
only:
17+
- master
18+
19+
install:
20+
- npm install
21+
22+
cache:
23+
directories:
24+
- node_modules
25+
26+
git:
27+
depth: 1

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# TypeScript-TmLanguage
2-
[![Build status](https://ci.appveyor.com/api/projects/status/i7fp97q9nc5uw5kf?svg=true)](https://ci.appveyor.com/project/zhengbli/typescript-tmlanguage)
2+
[![Build status](https://travis-ci.org/Microsoft/TypeScript-TmLanguage.svg?branch=master)](https://travis-ci.org/Microsoft/TypeScript-TmLanguage)
33

44
This repository contains TmLanguage files that are consumed by TypeScript editors and plugins such as [Visual Studio Code](https://github.com/Microsoft/vscode), [The TypeScript Sublime Plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin), [Atom TypeScript](https://github.com/TypeStrong/atom-typescript), and possibly others.
55

@@ -9,28 +9,24 @@ Latest version of the grammar can be also found as a [VSCode extension](https://
99

1010
The XML files are generated from the YAML files, so contributors should hand-modify the YAML files, and XML files should only be generated by running build script.
1111

12+
## Install dependencies
13+
``` sh
14+
npm install
15+
```
16+
1217
## Build
1318

14-
Update the XML files from within the ```build``` folder
19+
Compile the yaml file into the tmLanguage and tmTheme files
1520

1621
``` sh
17-
cd build
18-
npm install # Installs dependencies required for building
19-
npm start # Compiles & builds the XML files
22+
npm run build:grammar
2023
```
2124

2225
## Tests
2326

24-
Test are run from within the ```tests``` folder and depend on build to make sure XML files are upto date
25-
2627
``` sh
27-
cd build
28-
npm install # Installs dependencies required for building
29-
30-
cd ../tests
31-
npm install # Installs dependencies required for testing
3228
npm test # Compiles & runs tests
3329

3430
npm run diff # Diffs the test baselines with generated one using tool set in environment variable DIFF
3531
npm run accept # Accepts the test baselines
36-
```
32+
```

TypeScript.YAML-tmLanguage

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,45 @@ variables:
1616
nonIdentifierPropertyName: '{{quotedStrings}}|(\[([^\[\]]|\[[^\[\]]*\])+\])'
1717
propertyName: (({{identifier}})|{{nonIdentifierPropertyName}})
1818
constantVar: ({{constantIdentifier}})(?![_$[:alnum:]])
19+
nonPropertyLookBehind: '[^\._$[:alnum:]]'
20+
lookBehindReturn: '^return|{{nonPropertyLookBehind}}return'
21+
lookBehindThrow: '^throw|{{nonPropertyLookBehind}}throw'
22+
lookBehindYield: '^yield|{{nonPropertyLookBehind}}yield'
23+
lookBehindAwait: '^await|{{nonPropertyLookBehind}}await'
24+
lookBehindDefault: '^default|{{nonPropertyLookBehind}}default'
25+
lookBehindIn: '^in|{{nonPropertyLookBehind}}in'
26+
lookBehindOf: '^of|{{nonPropertyLookBehind}}of'
27+
lookBehindTypeof: '^typeof|{{nonPropertyLookBehind}}typeof'
28+
lookBehindCase: '^case|{{nonPropertyLookBehind}}case'
1929
matchingParenthesis: (\([^\(\)]*\))
30+
matchingBraces: (\{[^\{\}]*\})
31+
matchingBrackets: (\[[^\[\]]*\])
2032
# Identifier start | matching braces | matching parenthesis | matching square brackets
21-
typeParamersStart: ([_$[:alpha:]]|(\{[^\{\}]*\})|{{matchingParenthesis}}|(\[[^\[\]]*\]))
33+
typeParamersStart: ([_$[:alpha:]]|{{matchingBraces}}|{{matchingParenthesis}}|{{matchingBrackets}})
2234
typeParameters: (<\s*{{typeParamersStart}}([^=<>]|=[^<]|\<\s*{{typeParamersStart}}([^=<>]|=[^<])*\>)*>\s*)
2335
# Identifier start | matching braces | matching parenthesis | matching square brackets | matching strings
2436
typeArgumentsStart: ({{typeParamersStart}}|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))
25-
typeArgumentsInnerExpressionPart: '[^<>\(]|{{matchingParenthesis}}'
26-
typeArguments: (<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}}|\<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}})*\>)*>\s*)
37+
typeArgumentsInnerExpressionPart: '[^<>\(]|{{matchingParenthesis}}|(?<==)\>'
38+
typeArguments: (<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}}|\<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}})*(?!=)\>)*(?!=)>\s*)
2739
functionCallLookup: \s*(\?\.\s*)?{{typeArguments}}?\(
2840
arrowLookup: |-
2941
# sure shot arrow functions even if => is on new line
3042
(
3143
[(]\s*
3244
(
33-
([)]\s*:) | # ():
34-
((\.\.\.\s*)?{{identifier}}\s*:) # [(]param: | [(]...param:
45+
([)]\s*:) | # ():
46+
((\.\.\.\s*)?{{identifier}}\s*:) # [(]param: | [(]...param:
3547
)
3648
) |
3749
(
38-
[<]\s*{{identifier}}\s+extends\s*[^=>] # < typeparam extends
50+
[<]\s*{{identifier}}\s+extends\s*[^=>] # < typeparam extends
3951
) |
4052
# arrow function possible to detect only with => on same line
4153
(
42-
{{typeParameters}}? # typeparameters
43-
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres
44-
(\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type
45-
\s*=> # arrow operator
54+
{{typeParameters}}? # typeparameters
55+
\(\s*(([_$[:alpha:]]|{{matchingBraces}}|{{matchingBrackets}})([^()]|{{matchingParenthesis}})*)?\) # parameters
56+
(\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type
57+
\s*=> # arrow operator
4658
)
4759
functionOrArrowLookup: |-
4860
\s*(
@@ -70,7 +82,8 @@ variables:
7082
([)]\s*=>)
7183
))
7284
))
73-
))
85+
)) |
86+
(:\s*(=>|{{matchingParenthesis}}|(<[^<>]*>)|[^<>(),=])+={{functionOrArrowLookup}})
7487
7588
patterns:
7689
- include: '#directives'
@@ -226,14 +239,14 @@ repository:
226239
destructuring-variable:
227240
patterns:
228241
- name: meta.object-binding-pattern-variable.ts
229-
begin: (?<!=|:|of|in)\s*(?=\{)
242+
begin: (?<!=|:|{{lookBehindOf}}|{{lookBehindIn}})\s*(?=\{)
230243
end: (?=$|^|[;,=}]|(\s+(of|in)\s+))
231244
patterns:
232245
- include: '#object-binding-pattern'
233246
- include: '#type-annotation'
234247
- include: '#comment'
235248
- name: meta.array-binding-pattern-variable.ts
236-
begin: (?<!=|:|of|in)\s*(?=\[)
249+
begin: (?<!=|:|{{lookBehindOf}}|{{lookBehindIn}})\s*(?=\[)
237250
end: (?=$|^|[;,=}]|(\s+(of|in)\s+))
238251
patterns:
239252
- include: '#array-binding-pattern'
@@ -886,13 +899,14 @@ repository:
886899
patterns:
887900
- include: '#comment'
888901
#(default|*|name) as alias
889-
- match: '{{startOfIdentifier}}(?:(\bdefault)|(\*)|(\b{{identifier}}))\s+(as)\s+(\b{{identifier}})'
902+
- match: '{{startOfIdentifier}}(?:(\bdefault)|(\*)|(\b{{identifier}}))\s+(as)\s+(?:(\bdefault{{endOfIdentifier}})|(\b{{identifier}}))'
890903
captures:
891904
'1': { name: keyword.control.default.ts }
892905
'2': { name: constant.language.import-export-all.ts }
893906
'3': { name: variable.other.readwrite.ts }
894907
'4': { name: keyword.control.as.ts }
895-
'5': { name: variable.other.readwrite.alias.ts }
908+
'5': { name: keyword.control.default.ts }
909+
'6': { name: variable.other.readwrite.alias.ts }
896910
- include: '#punctuation-comma'
897911
- name: constant.language.import-export-all.ts
898912
match: \*
@@ -965,7 +979,7 @@ repository:
965979
#object literals
966980
after-operator-block-as-object-literal:
967981
name: meta.objectliteral.ts
968-
begin: (?<=[=(,\[?+!]|await|return|yield|throw|in|of|typeof|&&|\|\||\*)\s*(\{)
982+
begin: (?<=[=(,\[?+!]|{{lookBehindAwait}}|{{lookBehindReturn}}|{{lookBehindYield}}|{{lookBehindThrow}}|{{lookBehindIn}}|{{lookBehindOf}}|{{lookBehindTypeof}}|&&|\|\||\*)\s*(\{)
969983
beginCaptures:
970984
'1': { name: punctuation.definition.block.ts }
971985
end: \}
@@ -1088,7 +1102,7 @@ repository:
10881102
begin: '{{startOfIdentifier}}(new){{endOfIdentifier}}'
10891103
beginCaptures:
10901104
'1': { name: keyword.operator.new.ts }
1091-
end: (?<=\))|(?=[;),}\]]|$|({{startOfIdentifier}}new{{endOfIdentifier}})|({{startOfIdentifier}}function((\s+{{identifier}})|(\s*[\(]))))
1105+
end: (?<=\))|(?=[;),}\]:]|$|({{startOfIdentifier}}new{{endOfIdentifier}})|({{startOfIdentifier}}function((\s+{{identifier}})|(\s*[\(]))))
10921106
patterns:
10931107
- include: '#paren-expression'
10941108
- include: '#class-declaration'
@@ -1113,7 +1127,7 @@ repository:
11131127
# If '<' is preceeded by 'return', 'throw', 'yield', or 'await', it's most likely a type assertion
11141128
# If '=', '(', ',', ':', or '>' are followed by a '<', it is also likely a type assertion as otherwise it would be a syntax error
11151129
# '<=' and '<<=' are cannot be type assertions, as they are assignment operators.
1116-
begin: (?:(?<=return|throw|yield|await|default|[=(,:>*?\&\|\^]|[^_$[:alnum:]](?:\+\+|\-\-)|[^\+]\+|[^\-]\-))\s*(<)(?!<?\=)
1130+
begin: (?:(?<={{lookBehindReturn}}|{{lookBehindThrow}}|{{lookBehindYield}}|{{lookBehindAwait}}|{{lookBehindDefault}}|[=(,:>*?\&\|\^]|[^_$[:alnum:]](?:\+\+|\-\-)|[^\+]\+|[^\-]\-))\s*(<)(?!<?\=)
11171131
beginCaptures:
11181132
'1': { name: meta.brace.angle.ts }
11191133
end: (\>)\s*
@@ -1221,25 +1235,28 @@ repository:
12211235
- include: '#expression'
12221236
- include: '#punctuation-comma'
12231237

1238+
# With respect to seperators, we allow mroe than is syntacically valid below
1239+
# (multiple consecutive and trailing ones are errors), to be more graceful
1240+
# when the code contains errors
12241241
numeric-literal:
12251242
patterns:
12261243
- name: constant.numeric.hex.ts
1227-
match: \b(?<!\$)0(x|X)[0-9a-fA-F]+\b(?!\$)
1244+
match: \b(?<!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$)
12281245
- name: constant.numeric.binary.ts
1229-
match: \b(?<!\$)0(b|B)[01]+\b(?!\$)
1246+
match: \b(?<!\$)0(b|B)[01][01_]*\b(?!\$)
12301247
- name: constant.numeric.octal.ts
1231-
match: \b(?<!\$)0(o|O)?[0-7]+\b(?!\$)
1248+
match: \b(?<!\$)0(o|O)?[0-7][0-7_]*\b(?!\$)
12321249
- match: |-
12331250
(?x)
12341251
(?<!\$)(?:
1235-
(?:\b[0-9]+(\.)[0-9]+[eE][+-]?[0-9]+\b)| # 1.1E+3
1236-
(?:\b[0-9]+(\.)[eE][+-]?[0-9]+\b)| # 1.E+3
1237-
(?:\B(\.)[0-9]+[eE][+-]?[0-9]+\b)| # .1E+3
1238-
(?:\b[0-9]+[eE][+-]?[0-9]+\b)| # 1E+3
1239-
(?:\b[0-9]+(\.)[0-9]+\b)| # 1.1
1240-
(?:\b[0-9]+(\.)\B)| # 1.
1241-
(?:\B(\.)[0-9]+\b)| # .1
1242-
(?:\b[0-9]+\b(?!\.)) # 1
1252+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
1253+
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
1254+
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
1255+
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
1256+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
1257+
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
1258+
(?:\B(\.)[0-9][0-9_]*\b)| # .1
1259+
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
12431260
)(?!\$)
12441261
captures:
12451262
'0': {name: constant.numeric.decimal.ts}
@@ -1707,6 +1724,7 @@ repository:
17071724
- include: '#type-parameters'
17081725
- include: '#type-tuple'
17091726
- include: '#type-object'
1727+
- include: '#type-conditional'
17101728
- include: '#type-operators'
17111729
- include: '#type-fn-type-parameters'
17121730
- include: '#type-paren-or-function-parameters'
@@ -1758,6 +1776,13 @@ repository:
17581776
- include: '#punctuation-semicolon'
17591777
- include: '#type'
17601778

1779+
#conditional type
1780+
type-conditional:
1781+
match: '{{startOfIdentifier}}({{identifier}})\s+(extends)\s+'
1782+
captures:
1783+
'1': { name: entity.name.type.ts }
1784+
'2': { name: storage.modifier.ts }
1785+
17611786
# Parenthesis can contain either types and function parameters
17621787
# (number | string) or (param: number, param2: string)
17631788
# and it can be nested, for example
@@ -1856,6 +1881,10 @@ repository:
18561881
end: (?=\S)
18571882
- name: keyword.operator.expression.keyof.ts
18581883
match: '{{startOfIdentifier}}keyof{{endOfIdentifier}}'
1884+
- name: keyword.operator.ternary.ts
1885+
match: (\?|\:)
1886+
- name: keyword.operator.expression.infer.ts
1887+
match: '{{startOfIdentifier}}infer(?=\s+[_$[:alpha:]])'
18591888

18601889
type-predicate-operator:
18611890
name: keyword.operator.expression.is.ts
@@ -1951,7 +1980,7 @@ repository:
19511980
regex:
19521981
patterns:
19531982
- name: string.regexp.ts
1954-
begin: (?<=[=(:,\[?+!]|return|case|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
1983+
begin: (?<=[=(:,\[?+!]|{{lookBehindReturn}}|{{lookBehindCase}}|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
19551984
beginCaptures:
19561985
'1': {name: punctuation.definition.string.begin.ts}
19571986
end: (/)([gimuy]*)

TypeScript.YAML-tmTheme

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ settings:
4949
settings: { vsclassificationtype: identifier }
5050

5151
- scope: entity.name.tag
52-
settings: { vsclassificationtype: xml literal - name }
52+
settings: { vsclassificationtype: HTML Element Name }
5353

5454
- scope: entity.other.attribute-name
55-
settings: { vsclassificationtype: XML Attribute }
55+
settings: { vsclassificationtype: HTML Attribute Name }
5656

5757
- scope: meta.tag string.quoted, meta.tag string.quoted punctuation.definition.string, meta.tag string.quoted constant.character.escape
58-
settings: { vsclassificationtype: xml literal - attribute value }
58+
settings: { vsclassificationtype: HTML Attribute Value }
5959
...

0 commit comments

Comments
 (0)