File tree Expand file tree Collapse file tree 6 files changed +25
-31
lines changed
Expand file tree Collapse file tree 6 files changed +25
-31
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11/// <reference path='fourslash.ts' />
22
3- /////*1*/ @ decorator1
3+ /////*1*/ @ decorator1
44/////*2*/ @ decorator2
55/////*3*/ @decorator 3
66/////*4*/ @ decorator4 @ decorator5
77/////*5*/class C {
8- /////*6*/ @ decorator6
8+ /////*6*/ @ decorator6
99/////*7*/ @ decorator7
1010/////*8*/ @decorator 8
1111/////*9*/ method1() { }
1212////
1313/////*10*/ @ decorator9 @ decorator10 @decorator 11 method2() { }
1414////
1515//// method3(
16- /////*11*/ @ decorator12
16+ /////*11*/ @ decorator12
1717/////*12*/ @ decorator13
1818/////*13*/ @decorator 14
1919/////*14*/ x) { }
2020////
2121//// method4(
2222/////*15*/ @ decorator15 @ decorator16 @decorator 17 x) { }
2323////
24- /////*16*/ @ decorator18
24+ /////*16*/ @ decorator18
2525/////*17*/ @ decorator19
26- /////*18*/ @decorator 20
26+ /////*18*/ @decorator 20
2727/////*19*/ ["computed1"]() { }
2828////
2929/////*20*/ @ decorator21 @ decorator22 @decorator 23 ["computed2"]() { }
3030////
31- /////*21*/ @ decorator24
31+ /////*21*/ @ decorator24
3232/////*22*/ @ decorator25
3333/////*23*/ @decorator 26
3434/////*24*/ get accessor1() { }
3535////
3636/////*25*/ @ decorator27 @ decorator28 @decorator 29 get accessor2() { }
3737////
38- /////*26*/ @ decorator30
38+ /////*26*/ @ decorator30
3939/////*27*/ @ decorator31
4040/////*28*/ @decorator 32
4141/////*29*/ property1;
You can’t perform that action at this time.
0 commit comments