Add formatting rule for import type import keyword and open paren (#23872)

This commit is contained in:
Wesley Wigham 2018-05-03 14:57:01 -07:00 committed by GitHub
parent 406ca06e8e
commit 0d7d75ec64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -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;
}

View file

@ -0,0 +1,9 @@
/// <reference path="fourslash.ts"/>
////var y: import("./c2").mytype;
////var z: import ("./c2").mytype;
format.document();
verify.currentFileContentIs(
`var y: import("./c2").mytype;
var z: import("./c2").mytype;`);