Skip to content

Commit fbb73b7

Browse files
committed
cr feedback
1 parent f66c238 commit fbb73b7

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

src/services/formatting/formatting.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ namespace ts.formatting {
445445
if ((<MethodDeclaration>node).asteriskToken) {
446446
return SyntaxKind.AsteriskToken;
447447
}
448-
// fall-through
448+
// fall-through
449449

450450
case SyntaxKind.PropertyDeclaration:
451451
case SyntaxKind.Parameter:
@@ -788,7 +788,7 @@ namespace ts.formatting {
788788
}
789789
else {
790790
lineAdded =
791-
processPair(range, rangeStart.line, parent, previousRange, previousRangeStartLine, previousParent, contextNode, dynamicIndentation)
791+
processPair(range, rangeStart.line, parent, previousRange, previousRangeStartLine, previousParent, contextNode, dynamicIndentation)
792792
}
793793
}
794794

@@ -934,7 +934,7 @@ namespace ts.formatting {
934934
let lineEndPosition = getEndLinePosition(line, sourceFile);
935935

936936
// do not trim whitespaces in comments or template expression
937-
if (range && (isComment(range.kind) || isTemplate(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) {
937+
if (range && (isComment(range.kind) || isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) {
938938
continue;
939939
}
940940

src/services/utilities.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts {
99
export function getEndLinePosition(line: number, sourceFile: SourceFile): number {
1010
Debug.assert(line >= 0);
1111
let lineStarts = sourceFile.getLineStarts();
12-
12+
1313
let lineIndex = line;
1414
if (lineIndex + 1 === lineStarts.length) {
1515
// last line - return EOF
@@ -170,7 +170,7 @@ namespace ts {
170170
case SyntaxKind.VoidExpression:
171171
case SyntaxKind.YieldExpression:
172172
case SyntaxKind.SpreadElementExpression:
173-
let unaryWordExpression = (<TypeOfExpression|DeleteExpression|VoidExpression|YieldExpression|SpreadElementExpression>n);
173+
let unaryWordExpression = (<TypeOfExpression | DeleteExpression | VoidExpression | YieldExpression | SpreadElementExpression>n);
174174
return isCompletedNode(unaryWordExpression.expression, sourceFile);
175175

176176
case SyntaxKind.TaggedTemplateExpression:
@@ -252,7 +252,7 @@ namespace ts {
252252
});
253253

254254
// Either we didn't find an appropriate list, or the list must contain us.
255-
Debug.assert(!syntaxList || contains(syntaxList.getChildren(), node));
255+
Debug.assert(!syntaxList || contains(syntaxList.getChildren(), node));
256256
return syntaxList;
257257
}
258258

@@ -388,7 +388,7 @@ namespace ts {
388388
// if this is the case - then we should assume that token in question is located in previous child.
389389
if (position < child.end && (nodeHasTokens(child) || child.kind === SyntaxKind.JsxText)) {
390390
const start = child.getStart(sourceFile);
391-
const lookInPreviousChild =
391+
const lookInPreviousChild =
392392
(start >= position) || // cursor in the leading trivia
393393
(child.kind === SyntaxKind.JsxText && start === child.end); // whitespace only JsxText
394394

@@ -425,7 +425,7 @@ namespace ts {
425425
}
426426
}
427427
}
428-
428+
429429
export function isInString(sourceFile: SourceFile, position: number) {
430430
let token = getTokenAtPosition(sourceFile, position);
431431
return token && token.kind === SyntaxKind.StringLiteral && position > token.getStart();
@@ -473,7 +473,7 @@ namespace ts {
473473
let commentRanges = getLeadingCommentRanges(sourceFile.text, token.pos);
474474

475475
return forEach(commentRanges, jsDocPrefix);
476-
476+
477477
function jsDocPrefix(c: CommentRange): boolean {
478478
var text = sourceFile.text;
479479
return text.length >= c.pos + 3 && text[c.pos] === '/' && text[c.pos + 1] === '*' && text[c.pos + 2] === '*';
@@ -562,8 +562,13 @@ namespace ts {
562562
return kind === SyntaxKind.SingleLineCommentTrivia || kind === SyntaxKind.MultiLineCommentTrivia;
563563
}
564564

565-
export function isTemplate(kind: SyntaxKind): boolean {
566-
return kind >= SyntaxKind.FirstTemplateToken && kind <= SyntaxKind.LastTemplateToken;
565+
export function isStringOrRegularExpressionOrTemplateLiteral(kind: SyntaxKind): boolean {
566+
if (kind === SyntaxKind.StringLiteral
567+
|| kind === SyntaxKind.RegularExpressionLiteral
568+
|| isTemplateLiteralKind(kind)) {
569+
return true;
570+
}
571+
return false;
567572
}
568573

569574
export function isPunctuation(kind: SyntaxKind): boolean {
@@ -693,7 +698,7 @@ namespace ts {
693698
}
694699

695700
export function displayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart {
696-
return <SymbolDisplayPart> {
701+
return <SymbolDisplayPart>{
697702
text: text,
698703
kind: SymbolDisplayPartKind[kind]
699704
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let t = "foo \
4+
////bar \
5+
////"/*1*/
6+
7+
goTo.marker('1');
8+
edit.insert(";");
9+
10+
verify.currentFileContentIs("let t = \"foo \\\nbar \\ \n\";");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////var re = /\w+ /*1*//;
4+
5+
goTo.marker('1');
6+
edit.insert("\n");
7+
8+
verify.currentFileContentIs("var re = /\\w+ \n /;");

0 commit comments

Comments
 (0)