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

Type-only imports and exports #792

Merged
merged 4 commits into from
Jan 7, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Handle import export type at local matching rules
sheetalkamat committed Dec 5, 2019
commit 84988bf966aa61f046ec20457e28f04b6fb6f6d1
37 changes: 19 additions & 18 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
@@ -51,7 +51,6 @@ variables:
lookBehindTypeof: '^typeof|{{nonPropertyLookBehind}}typeof'
lookBehindCase: '^case|{{nonPropertyLookBehind}}case'
lookBehindImport: '^import|{{nonPropertyLookBehind}}import'
lookBehindExport: '^export|{{nonPropertyLookBehind}}export'
matchingParenthesis: (\(([^\(\)]|(\([^\(\)]*\)))*\))
matchingBraces: (\{([^\{\}]|(\{[^\{\}]*\}))*\})
matchingBrackets: (\[([^\[\]]|(\[[^\[\]]*\]))*\])
@@ -1067,29 +1066,31 @@ 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 }
patterns:
- 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'
@@ -1104,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: (?<!{{lookBehindImport}})(?=;|$|^)
patterns:
- include: '#single-line-comment-consuming-line-ending'
@@ -1131,19 +1133,21 @@ repository:
'3': { name: storage.type.namespace.ts }
'4': { name: entity.name.type.module.ts }
- name: meta.export.default.ts
begin: '{{startOfIdentifier}}(export)(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))'
begin: '{{startOfIdentifier}}(export)(?:\s+(type))?(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: keyword.operator.assignment.ts }
'3': { name: keyword.control.default.ts }
'2': { name: keyword.control.type.ts }
'3': { name: keyword.operator.assignment.ts }
'4': { name: keyword.control.default.ts }
end: (?=$|{{endOfStatement}})
patterns:
- include: '#interface-declaration'
- include: '#expression'
- name: meta.export.ts
begin: '{{startOfIdentifier}}(export)\b(?!(\$)|(\s*:))((?=\s*(?:(?:type\s*)??\{|\*))|((?=\s*{{identifier}}(\s|,))(?!\s*{{constructsAndModifiers}})))'
begin: '{{startOfIdentifier}}(export)(?:\s+(type))?\b(?!(\$)|(\s*:))((?=\s*[\{*])|((?=\s*{{identifier}}(\s|,))(?!\s*{{constructsAndModifiers}})))'
beginCaptures:
'0': { name: keyword.control.export.ts }
'1': { name: keyword.control.export.ts }
'2': { name: keyword.control.type.ts }
end: (?=$|{{endOfStatement}})
patterns:
- include: '#import-export-declaration'
@@ -1156,9 +1160,6 @@ repository:
- name: keyword.control.from.ts
match: \bfrom\b
- include: '#import-export-clause'
- match: '(?<={{lookBehindImport}}|{{lookBehindExport}})\s+(type)(?!\s*from)'
captures:
'1': { name: keyword.control.type.ts }

import-export-block:
name: meta.block.ts
59 changes: 36 additions & 23 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
@@ -3382,7 +3382,7 @@
<key>name</key>
<string>meta.import-equals.external.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3403,19 +3403,24 @@
<key>4</key>
<dict>
<key>name</key>
<string>variable.other.readwrite.alias.ts</string>
<string>keyword.control.type.ts</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.ts</string>
<string>variable.other.readwrite.alias.ts</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>keyword.control.require.ts</string>
<string>keyword.operator.assignment.ts</string>
</dict>
<key>7</key>
<dict>
<key>name</key>
<string>keyword.control.require.ts</string>
</dict>
<key>8</key>
<dict>
<key>name</key>
<string>meta.brace.round.ts</string>
@@ -3447,7 +3452,7 @@
<key>name</key>
<string>meta.import-equals.internal.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3468,9 +3473,14 @@
<key>4</key>
<dict>
<key>name</key>
<string>variable.other.readwrite.alias.ts</string>
<string>keyword.control.type.ts</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>variable.other.readwrite.alias.ts</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.ts</string>
@@ -3525,7 +3535,7 @@
<key>name</key>
<string>meta.import.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type)(?!\s+from))?(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3543,6 +3553,11 @@
<key>name</key>
<string>keyword.control.import.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.control.type.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?&lt;!^import|[^\._$[:alnum:]]import)(?=;|$|^)</string>
@@ -3622,7 +3637,7 @@
<key>name</key>
<string>meta.export.default.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(export)(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(export)(?:\s+(type))?(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3633,9 +3648,14 @@
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.ts</string>
<string>keyword.control.type.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.control.default.ts</string>
@@ -3659,14 +3679,19 @@
<key>name</key>
<string>meta.export.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(export)\b(?!(\$)|(\s*:))((?=\s*(?:(?:type\s*)??\{|\*))|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(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)))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.control.type.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))</string>
@@ -3706,18 +3731,6 @@
<key>include</key>
<string>#import-export-clause</string>
</dict>
<dict>
<key>match</key>
<string>(?&lt;=^import|[^\._$[:alnum:]]import|^export|[^\._$[:alnum:]]export)\s+(type)(?!\s*from)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.type.ts</string>
</dict>
</dict>
</dict>
</array>
</dict>
<key>import-export-block</key>
59 changes: 36 additions & 23 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
@@ -3404,7 +3404,7 @@
<key>name</key>
<string>meta.import-equals.external.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3425,19 +3425,24 @@
<key>4</key>
<dict>
<key>name</key>
<string>variable.other.readwrite.alias.tsx</string>
<string>keyword.control.type.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.tsx</string>
<string>variable.other.readwrite.alias.tsx</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>keyword.control.require.tsx</string>
<string>keyword.operator.assignment.tsx</string>
</dict>
<key>7</key>
<dict>
<key>name</key>
<string>keyword.control.require.tsx</string>
</dict>
<key>8</key>
<dict>
<key>name</key>
<string>meta.brace.round.tsx</string>
@@ -3469,7 +3474,7 @@
<key>name</key>
<string>meta.import-equals.internal.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3490,9 +3495,14 @@
<key>4</key>
<dict>
<key>name</key>
<string>variable.other.readwrite.alias.tsx</string>
<string>keyword.control.type.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>variable.other.readwrite.alias.tsx</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.tsx</string>
@@ -3547,7 +3557,7 @@
<key>name</key>
<string>meta.import.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type)(?!\s+from))?(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3565,6 +3575,11 @@
<key>name</key>
<string>keyword.control.import.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.control.type.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?&lt;!^import|[^\._$[:alnum:]]import)(?=;|$|^)</string>
@@ -3644,7 +3659,7 @@
<key>name</key>
<string>meta.export.default.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(export)(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(export)(?:\s+(type))?(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -3655,9 +3670,14 @@
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.tsx</string>
<string>keyword.control.type.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.control.default.tsx</string>
@@ -3681,14 +3701,19 @@
<key>name</key>
<string>meta.export.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(export)\b(?!(\$)|(\s*:))((?=\s*(?:(?:type\s*)??\{|\*))|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(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)))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.control.type.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))</string>
@@ -3728,18 +3753,6 @@
<key>include</key>
<string>#import-export-clause</string>
</dict>
<dict>
<key>match</key>
<string>(?&lt;=^import|[^\._$[:alnum:]]import|^export|[^\._$[:alnum:]]export)\s+(type)(?!\s*from)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.type.tsx</string>
</dict>
</dict>
</dict>
</array>
</dict>
<key>import-export-block</key>
Loading