mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Merge pull request #1906 from Microsoft/formattingTriggerInComment
ensure that autoformat is not triggered from inside comments
This commit is contained in:
@@ -120,7 +120,14 @@ module ts.formatting {
|
||||
|
||||
function findOutermostParent(position: number, expectedTokenKind: SyntaxKind, sourceFile: SourceFile): Node {
|
||||
var precedingToken = findPrecedingToken(position, sourceFile);
|
||||
if (!precedingToken || precedingToken.kind !== expectedTokenKind) {
|
||||
|
||||
// when it is claimed that trigger character was typed at given position
|
||||
// we verify that there is a token with a matching kind whose end is equal to position (because the character was just typed).
|
||||
// If this condition is not hold - then trigger character was typed in some other context,
|
||||
// i.e.in comment and thus should not trigger autoformatting
|
||||
if (!precedingToken ||
|
||||
precedingToken.kind !== expectedTokenKind ||
|
||||
position !== precedingToken.getEnd()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
13
tests/cases/fourslash/formattingInComment.ts
Normal file
13
tests/cases/fourslash/formattingInComment.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
////class A {
|
||||
////foo( ); // /*1*/
|
||||
////}
|
||||
////function foo() { var x; } // /*2*/
|
||||
|
||||
goTo.marker("1");
|
||||
edit.insert(";");
|
||||
verify.currentLineContentIs("foo( ); // ;")
|
||||
|
||||
goTo.marker("2");
|
||||
edit.insert("}");
|
||||
verify.currentLineContentIs("function foo() { var x; } // }");
|
||||
Reference in New Issue
Block a user