File tree 3 files changed +21
-26
lines changed
3 files changed +21
-26
lines changed Original file line number Diff line number Diff line change @@ -7243,17 +7243,17 @@ namespace ts {
7243
7243
forEachChild ( sourceFile , visit ) ;
7244
7244
7245
7245
if ( lastNodeEntirelyBeforePosition ) {
7246
- const lastChildOfLastEntireNodeBeforePosition = getLastChild ( lastNodeEntirelyBeforePosition ) ;
7246
+ const lastChildOfLastEntireNodeBeforePosition = getLastDescendant ( lastNodeEntirelyBeforePosition ) ;
7247
7247
if ( lastChildOfLastEntireNodeBeforePosition . pos > bestResult . pos ) {
7248
7248
bestResult = lastChildOfLastEntireNodeBeforePosition ;
7249
7249
}
7250
7250
}
7251
7251
7252
7252
return bestResult ;
7253
7253
7254
- function getLastChild ( node : Node ) : Node {
7254
+ function getLastDescendant ( node : Node ) : Node {
7255
7255
while ( true ) {
7256
- const lastChild = getLastChildWorker ( node ) ;
7256
+ const lastChild = getLastChild ( node ) ;
7257
7257
if ( lastChild ) {
7258
7258
node = lastChild ;
7259
7259
}
@@ -7263,16 +7263,6 @@ namespace ts {
7263
7263
}
7264
7264
}
7265
7265
7266
- function getLastChildWorker ( node : Node ) : Node | undefined {
7267
- let last : Node ;
7268
- forEachChild ( node , child => {
7269
- if ( nodeIsPresent ( child ) ) {
7270
- last = child ;
7271
- }
7272
- } ) ;
7273
- return last ;
7274
- }
7275
-
7276
7266
function visit ( child : Node ) {
7277
7267
if ( nodeIsMissing ( child ) ) {
7278
7268
// Missing nodes are effectively invisible to us. We never even consider them
Original file line number Diff line number Diff line change @@ -3883,6 +3883,24 @@ namespace ts {
3883
3883
return isStringLiteral ( moduleSpecifier ) ? moduleSpecifier . text : getTextOfNode ( moduleSpecifier ) ;
3884
3884
}
3885
3885
3886
+ export function getLastChild ( node : Node ) : Node | undefined {
3887
+ let lastChild : Node | undefined ;
3888
+ forEachChild ( node ,
3889
+ child => {
3890
+ if ( nodeIsPresent ( child ) ) lastChild = child ;
3891
+ } ,
3892
+ children => {
3893
+ // As an optimization, jump straight to the end of the list.
3894
+ for ( let i = children . length - 1 ; i >= 0 ; i -- ) {
3895
+ if ( nodeIsPresent ( children [ i ] ) ) {
3896
+ lastChild = children [ i ] ;
3897
+ break ;
3898
+ }
3899
+ }
3900
+ } ) ;
3901
+ return lastChild ;
3902
+ }
3903
+
3886
3904
/** Add a value to a set, and return true if it wasn't already present. */
3887
3905
export function addToSeen ( seen : Map < true > , key : string | number ) : boolean {
3888
3906
key = String ( key ) ;
Original file line number Diff line number Diff line change @@ -1499,17 +1499,4 @@ namespace ts {
1499
1499
function getFirstChild ( node : Node ) : Node | undefined {
1500
1500
return node . forEachChild ( child => child ) ;
1501
1501
}
1502
-
1503
- function getLastChild ( node : Node ) : Node | undefined {
1504
- let lastChild : Node | undefined ;
1505
- node . forEachChild (
1506
- child => { lastChild = child ; } ,
1507
- children => {
1508
- // As an optimization, jump straight to the end of the list.
1509
- if ( children . length ) {
1510
- lastChild = last ( children ) ;
1511
- }
1512
- } ) ;
1513
- return lastChild ;
1514
- }
1515
1502
}
You can’t perform that action at this time.
0 commit comments