Add formatting rule for import type import keyword and open paren (#23872)
This commit is contained in:
parent
406ca06e8e
commit
0d7d75ec64
|
@ -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;
|
||||
}
|
||||
|
|
9
tests/cases/fourslash/importTypeFormatting.ts
Normal file
9
tests/cases/fourslash/importTypeFormatting.ts
Normal 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;`);
|
Loading…
Reference in a new issue