diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage
index 2b305a9a..2989fcf9 100644
--- a/TypeScript.YAML-tmLanguage
+++ b/TypeScript.YAML-tmLanguage
@@ -1066,15 +1066,16 @@ repository:
import-equals-declaration:
patterns:
- name: meta.import-equals.external.ts
- begin: '{{startOfDeclaration}}\b(import)\s+({{identifier}})\s*(=)\s*(require)\s*(\()'
+ begin: '{{startOfDeclaration}}\b(import)(?:\s+(type))?\s+({{identifier}})\s*(=)\s*(require)\s*(\()'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: keyword.control.import.ts }
- '4': { name: variable.other.readwrite.alias.ts }
- '5': { name: keyword.operator.assignment.ts }
- '6': { name: keyword.control.require.ts }
- '7': { name: meta.brace.round.ts }
+ '4': { name: keyword.control.type.ts }
+ '5': { name: variable.other.readwrite.alias.ts }
+ '6': { name: keyword.operator.assignment.ts }
+ '7': { name: keyword.control.require.ts }
+ '8': { name: meta.brace.round.ts }
end: \)
endCaptures:
'0': { name: meta.brace.round.ts }
@@ -1082,13 +1083,14 @@ repository:
- include: '#comment'
- include: '#string'
- name: meta.import-equals.internal.ts
- begin: '{{startOfDeclaration}}\b(import)\s+({{identifier}})\s*(=)\s*(?!require\b)'
+ begin: '{{startOfDeclaration}}\b(import)(?:\s+(type))?\s+({{identifier}})\s*(=)\s*(?!require\b)'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: keyword.control.import.ts }
- '4': { name: variable.other.readwrite.alias.ts }
- '5': { name: keyword.operator.assignment.ts }
+ '4': { name: keyword.control.type.ts }
+ '5': { name: variable.other.readwrite.alias.ts }
+ '6': { name: keyword.operator.assignment.ts }
end: (?=;|$|^)
patterns:
- include: '#single-line-comment-consuming-line-ending'
@@ -1103,11 +1105,12 @@ repository:
import-declaration:
name: meta.import.ts
- begin: '{{startOfDeclaration}}\b(import)(?!\s*[:\(]){{endOfIdentifier}}'
+ begin: '{{startOfDeclaration}}\b(import)(?:\s+(type)(?!\s+from))?(?!\s*[:\(]){{endOfIdentifier}}'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: keyword.control.import.ts }
+ '4': { name: keyword.control.type.ts }
end: (?name
meta.import-equals.external.ts
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()
beginCaptures
1
@@ -3403,19 +3403,24 @@
4
name
- variable.other.readwrite.alias.ts
+ keyword.control.type.ts
5
name
- keyword.operator.assignment.ts
+ variable.other.readwrite.alias.ts
6
name
- keyword.control.require.ts
+ keyword.operator.assignment.ts
7
+
+ name
+ keyword.control.require.ts
+
+ 8
name
meta.brace.round.ts
@@ -3447,7 +3452,7 @@
name
meta.import-equals.internal.ts
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)
beginCaptures
1
@@ -3468,9 +3473,14 @@
4
name
- variable.other.readwrite.alias.ts
+ keyword.control.type.ts
5
+
+ name
+ variable.other.readwrite.alias.ts
+
+ 6
name
keyword.operator.assignment.ts
@@ -3525,7 +3535,7 @@
name
meta.import.ts
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type)(?!\s+from))?(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))
beginCaptures
1
@@ -3543,6 +3553,11 @@
name
keyword.control.import.ts
+ 4
+
+ name
+ keyword.control.type.ts
+
end
(?<!^import|[^\._$[:alnum:]]import)(?=;|$|^)
@@ -3622,7 +3637,7 @@
name
meta.export.default.ts
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:\s+(type))?(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))
beginCaptures
1
@@ -3633,9 +3648,14 @@
2
name
- keyword.operator.assignment.ts
+ keyword.control.type.ts
3
+
+ name
+ keyword.operator.assignment.ts
+
+ 4
name
keyword.control.default.ts
@@ -3659,14 +3679,19 @@
name
meta.export.ts
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)\b(?!(\$)|(\s*:))((?=\s*[\{*])|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:\s+(type))?\b(?!(\$)|(\s*:))((?=\s*[\{*])|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))
beginCaptures
- 0
+ 1
name
keyword.control.export.ts
+ 2
+
+ name
+ keyword.control.type.ts
+
end
(?=$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))
diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage
index 3571c30a..d94fc778 100644
--- a/TypeScriptReact.tmLanguage
+++ b/TypeScriptReact.tmLanguage
@@ -3404,7 +3404,7 @@
name
meta.import-equals.external.tsx
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()
beginCaptures
1
@@ -3425,19 +3425,24 @@
4
name
- variable.other.readwrite.alias.tsx
+ keyword.control.type.tsx
5
name
- keyword.operator.assignment.tsx
+ variable.other.readwrite.alias.tsx
6
name
- keyword.control.require.tsx
+ keyword.operator.assignment.tsx
7
+
+ name
+ keyword.control.require.tsx
+
+ 8
name
meta.brace.round.tsx
@@ -3469,7 +3474,7 @@
name
meta.import-equals.internal.tsx
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)
beginCaptures
1
@@ -3490,9 +3495,14 @@
4
name
- variable.other.readwrite.alias.tsx
+ keyword.control.type.tsx
5
+
+ name
+ variable.other.readwrite.alias.tsx
+
+ 6
name
keyword.operator.assignment.tsx
@@ -3547,7 +3557,7 @@
name
meta.import.tsx
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type)(?!\s+from))?(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))
beginCaptures
1
@@ -3565,6 +3575,11 @@
name
keyword.control.import.tsx
+ 4
+
+ name
+ keyword.control.type.tsx
+
end
(?<!^import|[^\._$[:alnum:]]import)(?=;|$|^)
@@ -3644,7 +3659,7 @@
name
meta.export.default.tsx
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:\s+(type))?(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))
beginCaptures
1
@@ -3655,9 +3670,14 @@
2
name
- keyword.operator.assignment.tsx
+ keyword.control.type.tsx
3
+
+ name
+ keyword.operator.assignment.tsx
+
+ 4
name
keyword.control.default.tsx
@@ -3681,14 +3701,19 @@
name
meta.export.tsx
begin
- (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)\b(?!(\$)|(\s*:))((?=\s*[\{*])|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))
+ (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:\s+(type))?\b(?!(\$)|(\s*:))((?=\s*[\{*])|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))
beginCaptures
- 0
+ 1
name
keyword.control.export.tsx
+ 2
+
+ name
+ keyword.control.type.tsx
+
end
(?=$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))
diff --git a/package.json b/package.json
index 6985e846..f2721413 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
"pretest": "npm run build",
"test": "mocha --full-trace tests/test.js --reporter mocha-multi-reporters",
"diff": "cross-env-shell $DIFF tests/baselines tests/generated",
- "accept": "copyfiles \"tests/generated/*\" tests/baselines"
+ "accept": "copyfiles -u 2 \"tests/generated/*\" tests/baselines"
},
"dependencies": {
"@types/chai": "latest",
diff --git a/tests/baselines/exportDeclarations.baseline.txt b/tests/baselines/exportDeclarations.baseline.txt
index 589356f2..a6be2bf2 100644
--- a/tests/baselines/exportDeclarations.baseline.txt
+++ b/tests/baselines/exportDeclarations.baseline.txt
@@ -3,6 +3,9 @@ original file
export { a as b, x };
export * from "AnotherModule";
export { k as m, l } from "AnotherModule";
+export type { T };
+export type { U } from "AnotherModule";
+
-----------------------------------
Grammar: TypeScript.tmLanguage
@@ -101,4 +104,61 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.export.ts string.quoted.double.ts punctuation.definition.string.end.ts
^
- source.ts punctuation.terminator.statement.ts
\ No newline at end of file
+ source.ts punctuation.terminator.statement.ts
+>export type { T };
+ ^^^^^^
+ source.ts meta.export.ts keyword.control.export.ts
+ ^
+ source.ts meta.export.ts
+ ^^^^
+ source.ts meta.export.ts keyword.control.type.ts
+ ^
+ source.ts meta.export.ts
+ ^
+ source.ts meta.export.ts meta.block.ts punctuation.definition.block.ts
+ ^
+ source.ts meta.export.ts meta.block.ts
+ ^
+ source.ts meta.export.ts meta.block.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.export.ts meta.block.ts
+ ^
+ source.ts meta.export.ts meta.block.ts punctuation.definition.block.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>export type { U } from "AnotherModule";
+ ^^^^^^
+ source.ts meta.export.ts keyword.control.export.ts
+ ^
+ source.ts meta.export.ts
+ ^^^^
+ source.ts meta.export.ts keyword.control.type.ts
+ ^
+ source.ts meta.export.ts
+ ^
+ source.ts meta.export.ts meta.block.ts punctuation.definition.block.ts
+ ^
+ source.ts meta.export.ts meta.block.ts
+ ^
+ source.ts meta.export.ts meta.block.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.export.ts meta.block.ts
+ ^
+ source.ts meta.export.ts meta.block.ts punctuation.definition.block.ts
+ ^
+ source.ts meta.export.ts
+ ^^^^
+ source.ts meta.export.ts keyword.control.from.ts
+ ^
+ source.ts meta.export.ts
+ ^
+ source.ts meta.export.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^^^^^^^^^^^
+ source.ts meta.export.ts string.quoted.double.ts
+ ^
+ source.ts meta.export.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>
+ ^
+ source.ts
\ No newline at end of file
diff --git a/tests/baselines/importTypeOnly.baseline.txt b/tests/baselines/importTypeOnly.baseline.txt
new file mode 100644
index 00000000..abafaa73
--- /dev/null
+++ b/tests/baselines/importTypeOnly.baseline.txt
@@ -0,0 +1,192 @@
+original file
+-----------------------------------
+import type T from "mod";
+import type { U, V } from "mod";
+import type * as types from "mod";
+import type from "mod";
+import type = require("mod");
+import type T = require("mod");
+
+-----------------------------------
+
+Grammar: TypeScript.tmLanguage
+-----------------------------------
+>import type T from "mod";
+ ^^^^^^
+ source.ts meta.import.ts keyword.control.import.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.type.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.from.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^
+ source.ts meta.import.ts string.quoted.double.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>import type { U, V } from "mod";
+ ^^^^^^
+ source.ts meta.import.ts keyword.control.import.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.type.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts meta.block.ts punctuation.definition.block.ts
+ ^
+ source.ts meta.import.ts meta.block.ts
+ ^
+ source.ts meta.import.ts meta.block.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import.ts meta.block.ts punctuation.separator.comma.ts
+ ^
+ source.ts meta.import.ts meta.block.ts
+ ^
+ source.ts meta.import.ts meta.block.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import.ts meta.block.ts
+ ^
+ source.ts meta.import.ts meta.block.ts punctuation.definition.block.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.from.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^
+ source.ts meta.import.ts string.quoted.double.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>import type * as types from "mod";
+ ^^^^^^
+ source.ts meta.import.ts keyword.control.import.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.type.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts constant.language.import-export-all.ts
+ ^
+ source.ts meta.import.ts
+ ^^
+ source.ts meta.import.ts keyword.control.as.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^^
+ source.ts meta.import.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.from.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^
+ source.ts meta.import.ts string.quoted.double.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>import type from "mod";
+ ^^^^^^
+ source.ts meta.import.ts keyword.control.import.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import.ts
+ ^^^^
+ source.ts meta.import.ts keyword.control.from.ts
+ ^
+ source.ts meta.import.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^
+ source.ts meta.import.ts string.quoted.double.ts
+ ^
+ source.ts meta.import.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>import type = require("mod");
+ ^^^^^^
+ source.ts meta.import-equals.external.ts keyword.control.import.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^^^^
+ source.ts meta.import-equals.external.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^
+ source.ts meta.import-equals.external.ts keyword.operator.assignment.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^^^^^^^
+ source.ts meta.import-equals.external.ts keyword.control.require.ts
+ ^
+ source.ts meta.import-equals.external.ts meta.brace.round.ts
+ ^
+ source.ts meta.import-equals.external.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^
+ source.ts meta.import-equals.external.ts string.quoted.double.ts
+ ^
+ source.ts meta.import-equals.external.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts meta.import-equals.external.ts meta.brace.round.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>import type T = require("mod");
+ ^^^^^^
+ source.ts meta.import-equals.external.ts keyword.control.import.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^^^^
+ source.ts meta.import-equals.external.ts keyword.control.type.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^
+ source.ts meta.import-equals.external.ts variable.other.readwrite.alias.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^
+ source.ts meta.import-equals.external.ts keyword.operator.assignment.ts
+ ^
+ source.ts meta.import-equals.external.ts
+ ^^^^^^^
+ source.ts meta.import-equals.external.ts keyword.control.require.ts
+ ^
+ source.ts meta.import-equals.external.ts meta.brace.round.ts
+ ^
+ source.ts meta.import-equals.external.ts string.quoted.double.ts punctuation.definition.string.begin.ts
+ ^^^
+ source.ts meta.import-equals.external.ts string.quoted.double.ts
+ ^
+ source.ts meta.import-equals.external.ts string.quoted.double.ts punctuation.definition.string.end.ts
+ ^
+ source.ts meta.import-equals.external.ts meta.brace.round.ts
+ ^
+ source.ts punctuation.terminator.statement.ts
+>
+ ^
+ source.ts
\ No newline at end of file
diff --git a/tests/cases/exportDeclarations.ts b/tests/cases/exportDeclarations.ts
index c46c807b..392ab621 100644
--- a/tests/cases/exportDeclarations.ts
+++ b/tests/cases/exportDeclarations.ts
@@ -1,3 +1,5 @@
export { a as b, x };
export * from "AnotherModule";
-export { k as m, l } from "AnotherModule";
\ No newline at end of file
+export { k as m, l } from "AnotherModule";
+export type { T };
+export type { U } from "AnotherModule";
diff --git a/tests/cases/importTypeOnly.ts b/tests/cases/importTypeOnly.ts
new file mode 100644
index 00000000..9ae6b1d8
--- /dev/null
+++ b/tests/cases/importTypeOnly.ts
@@ -0,0 +1,6 @@
+import type T from "mod";
+import type { U, V } from "mod";
+import type * as types from "mod";
+import type from "mod";
+import type = require("mod");
+import type T = require("mod");