Merge pull request #32088 from orta/fix-32068

Handle making sure that two less thans are never converted into >>
This commit is contained in:
Orta 2019-06-26 14:10:02 -07:00 committed by GitHub
commit a50a5d309c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -229,6 +229,7 @@ namespace ts.formatting {
rule("NoSpaceBeforeNonNullAssertionOperator", anyToken, SyntaxKind.ExclamationToken, [isNonJsxSameLineTokenContext, isNonNullAssertionContext], RuleAction.Delete),
rule("NoSpaceAfterNewKeywordOnConstructorSignature", SyntaxKind.NewKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isConstructorSignatureContext], RuleAction.Delete),
rule("SpaceLessThanAndNonJSXTypeAnnotation", SyntaxKind.LessThanToken, SyntaxKind.LessThanToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
];
// These rules are applied after high priority
@ -349,6 +350,18 @@ namespace ts.formatting {
];
}
/**
* A rule takes a two tokens (left/right) and a particular context
* for which you're meant to look at them. You then declare what should the
* whitespace annotation be between these tokens via the action param.
*
* @param debugName Name to print
* @param left The left side of the comparison
* @param right The right side of the comparison
* @param context A set of filters to narrow down the space in which this formatter rule applies
* @param action a declaration of the expected whitespace
* @param flags whether the rule deletes a line or not, defaults to no-op
*/
function rule(
debugName: string,
left: SyntaxKind | ReadonlyArray<SyntaxKind> | TokenRange,

View File

@ -0,0 +1,8 @@
///<reference path="fourslash.ts"/>
// https://github.com/microsoft/TypeScript/issues/14589
/////*1*/if (<number>foo < <number>bar) {}
format.document();
goTo.marker("1")
verify.currentLineContentIs(`if (<number>foo < <number>bar) { }`)