Skip to content

Commit 609036a

Browse files
committed
PR feedback and baseline updates
1 parent eec39c2 commit 609036a

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

src/compiler/utilities.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,22 @@ module ts {
150150
return !nodeIsMissing(node);
151151
}
152152

153-
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile, skipDecorators?: boolean): number {
153+
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
154154
// With nodes that have no width (i.e. 'Missing' nodes), we actually *don't*
155155
// want to skip trivia because this will launch us forward to the next token.
156156
if (nodeIsMissing(node)) {
157157
return node.pos;
158158
}
159159

160-
let pos = node.pos;
161-
if (skipDecorators && node.decorators) {
162-
// Skip past decorators
163-
pos = node.decorators.end;
160+
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
161+
}
162+
163+
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
164+
if (nodeIsMissing(node) || !node.decorators) {
165+
return getTokenPosOfNode(node, sourceFile);
164166
}
165167

166-
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, pos);
168+
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
167169
}
168170

169171
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string {

src/services/formatting/formatting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ module ts.formatting {
330330
let startLine = sourceFile.getLineAndCharacterOfPosition(enclosingNode.getStart(sourceFile)).line;
331331
let undecoratedStartLine = startLine;
332332
if (enclosingNode.decorators) {
333-
undecoratedStartLine = sourceFile.getLineAndCharacterOfPosition(enclosingNode.getStart(sourceFile, /*skipDecorators*/ true)).line;
333+
undecoratedStartLine = sourceFile.getLineAndCharacterOfPosition(getNonDecoratorTokenPosOfNode(enclosingNode, sourceFile)).line;
334334
}
335335

336336
let delta = getOwnOrInheritedDelta(enclosingNode, options, sourceFile);
@@ -561,7 +561,7 @@ module ts.formatting {
561561

562562
let undecoratedChildStartLine = childStartLine;
563563
if (child.decorators) {
564-
undecoratedChildStartLine = sourceFile.getLineAndCharacterOfPosition(child.getStart(sourceFile, /*skipDecorators*/ true)).line;
564+
undecoratedChildStartLine = sourceFile.getLineAndCharacterOfPosition(getNonDecoratorTokenPosOfNode(child, sourceFile)).line;
565565
}
566566

567567
// if child is a list item - try to get its indentation

src/services/formatting/rules.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -670,18 +670,10 @@ module ts.formatting {
670670
}
671671

672672
static NodeIsInDecoratorContext(node: Node): boolean {
673-
if (node.parserContextFlags & ParserContextFlags.Decorator) {
674-
return true;
673+
while (isExpression(node)) {
674+
node = node.parent;
675675
}
676-
while (node) {
677-
if (isExpression(node)) {
678-
node = node.parent;
679-
}
680-
else {
681-
return node.kind === SyntaxKind.Decorator;
682-
}
683-
}
684-
return false;
676+
return node.kind === SyntaxKind.Decorator;
685677
}
686678

687679
static IsStartOfVariableDeclarationList(context: FormattingContext): boolean {

src/services/services.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module ts {
1919
getChildCount(sourceFile?: SourceFile): number;
2020
getChildAt(index: number, sourceFile?: SourceFile): Node;
2121
getChildren(sourceFile?: SourceFile): Node[];
22-
getStart(sourceFile?: SourceFile, skipDecorators?: boolean): number;
22+
getStart(sourceFile?: SourceFile): number;
2323
getFullStart(): number;
2424
getEnd(): number;
2525
getWidth(sourceFile?: SourceFile): number;
@@ -149,8 +149,8 @@ module ts {
149149
return getSourceFileOfNode(this);
150150
}
151151

152-
public getStart(sourceFile?: SourceFile, skipDecorators?: boolean): number {
153-
return getTokenPosOfNode(this, sourceFile, skipDecorators);
152+
public getStart(sourceFile?: SourceFile): number {
153+
return getTokenPosOfNode(this, sourceFile);
154154
}
155155

156156
public getFullStart(): number {

tests/baselines/reference/APISample_linter.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ export function delint(sourceFile: ts.SourceFile) {
237237
>sourceFile : ts.SourceFile
238238
>getLineAndCharacterOfPosition : (pos: number) => ts.LineAndCharacter
239239
>node.getStart() : number
240-
>node.getStart : (sourceFile?: ts.SourceFile, skipDecorators?: boolean) => number
240+
>node.getStart : (sourceFile?: ts.SourceFile) => number
241241
>node : ts.Node
242-
>getStart : (sourceFile?: ts.SourceFile, skipDecorators?: boolean) => number
242+
>getStart : (sourceFile?: ts.SourceFile) => number
243243

244244
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
245245
>console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`) : any

tests/cases/fourslash/formattingDecorators.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
/// <reference path='fourslash.ts' />
22

3-
/////*1*/ @ decorator1
3+
/////*1*/ @ decorator1
44
/////*2*/ @ decorator2
55
/////*3*/ @decorator3
66
/////*4*/ @ decorator4 @ decorator5
77
/////*5*/class C {
8-
/////*6*/ @ decorator6
8+
/////*6*/ @ decorator6
99
/////*7*/ @ decorator7
1010
/////*8*/ @decorator8
1111
/////*9*/ method1() { }
1212
////
1313
/////*10*/ @ decorator9 @ decorator10 @decorator11 method2() { }
1414
////
1515
//// method3(
16-
/////*11*/ @ decorator12
16+
/////*11*/ @ decorator12
1717
/////*12*/ @ decorator13
1818
/////*13*/ @decorator14
1919
/////*14*/ x) { }
2020
////
2121
//// method4(
2222
/////*15*/ @ decorator15 @ decorator16 @decorator17 x) { }
2323
////
24-
/////*16*/ @ decorator18
24+
/////*16*/ @ decorator18
2525
/////*17*/ @ decorator19
26-
/////*18*/ @decorator20
26+
/////*18*/ @decorator20
2727
/////*19*/ ["computed1"]() { }
2828
////
2929
/////*20*/ @ decorator21 @ decorator22 @decorator23 ["computed2"]() { }
3030
////
31-
/////*21*/ @ decorator24
31+
/////*21*/ @ decorator24
3232
/////*22*/ @ decorator25
3333
/////*23*/ @decorator26
3434
/////*24*/ get accessor1() { }
3535
////
3636
/////*25*/ @ decorator27 @ decorator28 @decorator29 get accessor2() { }
3737
////
38-
/////*26*/ @ decorator30
38+
/////*26*/ @ decorator30
3939
/////*27*/ @ decorator31
4040
/////*28*/ @decorator32
4141
/////*29*/ property1;

0 commit comments

Comments
 (0)