From 0d7d75ec64b0b129c892d4062fdbc14a790a292a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 3 May 2018 14:57:01 -0700 Subject: [PATCH] Add formatting rule for import type import keyword and open paren (#23872) --- src/services/formatting/rules.ts | 6 ++++++ tests/cases/fourslash/importTypeFormatting.ts | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/importTypeFormatting.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index a658cc41c65..901dbf761f3 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -59,6 +59,8 @@ namespace ts.formatting { rule("NoSpaceBeforeDot", anyToken, SyntaxKind.DotToken, [isNonJsxSameLineTokenContext], RuleAction.Delete), rule("NoSpaceAfterDot", SyntaxKind.DotToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Delete), + rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], RuleAction.Delete), + // Special handling of unary operators. // Prefix operators generally shouldn't have a space between // them and their target unary expression. @@ -641,6 +643,10 @@ namespace ts.formatting { return context.contextNode.kind === SyntaxKind.ArrowFunction; } + function isImportTypeContext(context: FormattingContext): boolean { + return context.contextNode.kind === SyntaxKind.ImportType; + } + function isNonJsxSameLineTokenContext(context: FormattingContext): boolean { return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText; } diff --git a/tests/cases/fourslash/importTypeFormatting.ts b/tests/cases/fourslash/importTypeFormatting.ts new file mode 100644 index 00000000000..2b7983d893c --- /dev/null +++ b/tests/cases/fourslash/importTypeFormatting.ts @@ -0,0 +1,9 @@ +/// + +////var y: import("./c2").mytype; +////var z: import ("./c2").mytype; + +format.document(); +verify.currentFileContentIs( +`var y: import("./c2").mytype; +var z: import("./c2").mytype;`);