Skip to content

Commit 0d7d75e

Browse files
authored
Add formatting rule for import type import keyword and open paren (microsoft#23872)
1 parent 406ca06 commit 0d7d75e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/services/formatting/rules.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ namespace ts.formatting {
5959
rule("NoSpaceBeforeDot", anyToken, SyntaxKind.DotToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
6060
rule("NoSpaceAfterDot", SyntaxKind.DotToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
6161

62+
rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], RuleAction.Delete),
63+
6264
// Special handling of unary operators.
6365
// Prefix operators generally shouldn't have a space between
6466
// them and their target unary expression.
@@ -641,6 +643,10 @@ namespace ts.formatting {
641643
return context.contextNode.kind === SyntaxKind.ArrowFunction;
642644
}
643645

646+
function isImportTypeContext(context: FormattingContext): boolean {
647+
return context.contextNode.kind === SyntaxKind.ImportType;
648+
}
649+
644650
function isNonJsxSameLineTokenContext(context: FormattingContext): boolean {
645651
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
646652
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////var y: import("./c2").mytype;
4+
////var z: import ("./c2").mytype;
5+
6+
format.document();
7+
verify.currentFileContentIs(
8+
`var y: import("./c2").mytype;
9+
var z: import("./c2").mytype;`);

0 commit comments

Comments
 (0)