Skip to content

Commit 8c7482b

Browse files
authored
Add support for 'using' and 'await using' declarations (#984)
1 parent eac74a1 commit 8c7482b

File tree

7 files changed

+7009
-44
lines changed

7 files changed

+7009
-44
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ variables:
3636
propertyName: ({{anyNumber}}|({{identifier}})|{{nonIdentifierPropertyName}})
3737
propertyNameWithPrivate: ({{anyNumber}}|({{propertyIdentifier}})|{{nonIdentifierPropertyName}})
3838
constantVar: ({{constantIdentifier}})(?![_$[:alnum:]])
39-
constructsAndModifiers: '(?:abstract|async|break|case|catch|class|const|continue|declare|do|else|enum|export|finally|function|for|goto|if|import|interface|let|module|namespace|switch|return|throw|try|type|var|while)\b'
39+
usingKeyword: '(?:\busing(?=\s+(?!in\b|of\b(?!\s*(?:of\b|=)))[_$[:alpha:]])\b)'
40+
awaitUsingKeyword: '(?:\bawait\s+{{usingKeyword}}\b)'
41+
constructsAndModifiers: '(?:abstract|async|{{awaitUsingKeyword}}|break|case|catch|class|const|continue|declare|do|else|enum|export|finally|function|for|goto|if|import|interface|let|module|namespace|switch|return|throw|try|type|{{usingKeyword}}|var|while)\b'
4042
endOfStatement: ';|^\s*$|(?:^\s*{{constructsAndModifiers}})'
4143
varExprStart: '{{startOfDeclaration}}\b(var|let){{endOfIdentifier}}'
4244
constExprStart: '{{startOfDeclaration}}\b(const(?!\s+enum\b)){{endOfIdentifier}}'
45+
usingExprStart: '{{startOfDeclaration}}\b({{usingKeyword}}|{{awaitUsingKeyword}}){{endOfIdentifier}}'
4346
nonPropertyLookBehind: '[^\._$[:alnum:]]'
4447
lookBehindReturn: '^return|{{nonPropertyLookBehind}}return'
4548
lookBehindThrow: '^throw|{{nonPropertyLookBehind}}throw'
@@ -48,6 +51,8 @@ variables:
4851
lookBehindDefault: '^default|{{nonPropertyLookBehind}}default'
4952
lookBehindConst: '^const|{{nonPropertyLookBehind}}const'
5053
lookBehindLet: '^let|{{nonPropertyLookBehind}}let'
54+
lookBehindUsing: '^using|{{nonPropertyLookBehind}}using'
55+
lookBehindAwaitUsing: '^await\s+using|{{nonPropertyLookBehind}}await\s+using'
5156
lookBehindVar: '^var|{{nonPropertyLookBehind}}var'
5257
lookBehindIn: '^in|{{nonPropertyLookBehind}}in'
5358
lookBehindOf: '^of|{{nonPropertyLookBehind}}of'
@@ -134,7 +139,7 @@ variables:
134139
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
135140
{{functionLikeType}} |
136141
(:\s*(=>|{{matchingParenthesis}}|(<[^<>]*>)|[^<>(),=])+={{functionOrArrowLookup}})
137-
arrowFunctionEnd: (?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))
142+
arrowFunctionEnd: (?==>|\{|(^\s*(export|function|class|interface|let|var|{{usingKeyword}}|{{awaitUsingKeyword}}|const|import|enum|namespace|module|type|abstract|declare)\s+))
138143
regexpTail: ([dgimsuy]+|(?![\/\*])|(?=\/\*))(?!\s*[a-zA-Z0-9_$])
139144
completeRegexp: \/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)*\])+\/{{regexpTail}})
140145

@@ -322,6 +327,34 @@ repository:
322327
- include: '#var-single-const'
323328
- include: '#punctuation-comma'
324329
- include: '#punctuation-comma'
330+
# using/await using
331+
- name: meta.var.expr.ts
332+
begin: (?={{usingExprStart}})
333+
beginCaptures:
334+
'1': { name: keyword.control.export.ts }
335+
'2': { name: storage.modifier.ts }
336+
'3': { name: storage.type.ts }
337+
end: (?!{{usingExprStart}})((?=;|}|({{startOfIdentifier}}(of|in)\s+)|{{endOfStatement}})|((?<!{{lookBehindUsing}}|{{lookBehindAwaitUsing}})(?=\s*$)))
338+
patterns:
339+
- begin: '{{usingExprStart}}\s*'
340+
beginCaptures:
341+
'1': { name: keyword.control.export.ts }
342+
'2': { name: storage.modifier.ts }
343+
'3': { name: storage.type.ts }
344+
end: (?=\S)
345+
- include: '#var-single-const'
346+
- include: '#variable-initializer'
347+
- include: '#comment'
348+
- begin: (,)\s*((?!\S)|(?=\/\/))
349+
beginCaptures:
350+
'1': { name: punctuation.separator.comma.ts }
351+
end: (?<!,)(((?==|;|}|({{startOfIdentifier}}(of|in)\s+)|^\s*$))|((?<=\S)(?=\s*$)))
352+
patterns:
353+
- include: '#single-line-comment-consuming-line-ending'
354+
- include: '#comment'
355+
- include: '#var-single-const'
356+
- include: '#punctuation-comma'
357+
- include: '#punctuation-comma'
325358

326359
var-single-variable:
327360
patterns:

0 commit comments

Comments
 (0)