Skip to content

Commit 662e93c

Browse files
author
Andy Hanson
committed
Fix error where node in tsconfig file was missing a source file
1 parent 19d7309 commit 662e93c

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

src/services/breakpoints.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace ts.BreakpointResolver {
4141
}
4242

4343
function textSpanEndingAtNextToken(startNode: Node, previousTokenToFindNextEndToken: Node): TextSpan {
44-
return textSpan(startNode, findNextToken(previousTokenToFindNextEndToken, previousTokenToFindNextEndToken.parent));
44+
return textSpan(startNode, findNextToken(previousTokenToFindNextEndToken, previousTokenToFindNextEndToken.parent, sourceFile));
4545
}
4646

4747
function spanInNodeIfStartsOnSameLine(node: Node, otherwiseOnNode?: Node): TextSpan {
@@ -60,7 +60,7 @@ namespace ts.BreakpointResolver {
6060
}
6161

6262
function spanInNextNode(node: Node): TextSpan {
63-
return spanInNode(findNextToken(node, node.parent));
63+
return spanInNode(findNextToken(node, node.parent, sourceFile));
6464
}
6565

6666
function spanInNode(node: Node): TextSpan {

src/services/formatting/smartIndenter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ namespace ts.formatting {
269269
}
270270

271271
function nextTokenIsCurlyBraceOnSameLineAsCursor(precedingToken: Node, current: Node, lineAtPosition: number, sourceFile: SourceFile): NextTokenKind {
272-
const nextToken = findNextToken(precedingToken, current);
272+
const nextToken = findNextToken(precedingToken, current, sourceFile);
273273
if (!nextToken) {
274274
return NextTokenKind.Unknown;
275275
}

src/services/refactors/moveToNewFile.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ namespace ts.refactor {
5353
const newFileAbsolutePath = normalizePath(combinePaths(oldFileName, "..", newFileNameWithExtension));
5454
const newFilePath = getRelativePathFromFile(cfg.fileName, newFileAbsolutePath, getCanonicalFileName);
5555

56-
const filesProp = cfg.jsonObject && find(cfg.jsonObject.properties, (prop): prop is PropertyAssignment =>
56+
const cfgObject = cfg.statements[0] && tryCast(cfg.statements[0].expression, isObjectLiteralExpression);
57+
const filesProp = cfgObject && find(cfgObject.properties, (prop): prop is PropertyAssignment =>
5758
isPropertyAssignment(prop) && isStringLiteral(prop.name) && prop.name.text === "files");
5859
if (filesProp && isArrayLiteralExpression(filesProp.initializer)) {
5960
changes.insertNodeInListAfter(cfg, last(filesProp.initializer.elements), createLiteral(newFilePath), filesProp.initializer.elements);

src/services/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ts {
1313
getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number;
1414
getFullStart(): number;
1515
getEnd(): number;
16-
getWidth(sourceFile?: SourceFile): number;
16+
getWidth(sourceFile?: SourceFileLike): number;
1717
getFullWidth(): number;
1818
getLeadingTriviaWidth(sourceFile?: SourceFile): number;
1919
getFullText(sourceFile?: SourceFile): string;

src/services/utilities.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ namespace ts {
707707
return findPrecedingToken(position, file);
708708
}
709709

710-
export function findNextToken(previousToken: Node, parent: Node): Node {
710+
export function findNextToken(previousToken: Node, parent: Node, sourceFile: SourceFile): Node {
711711
return find(parent);
712712

713713
function find(n: Node): Node {
@@ -724,7 +724,7 @@ namespace ts {
724724
// previous token ends exactly at the beginning of child
725725
(child.pos === previousToken.end);
726726

727-
if (shouldDiveInChildNode && nodeHasTokens(child)) {
727+
if (shouldDiveInChildNode && nodeHasTokens(child, sourceFile)) {
728728
return find(child);
729729
}
730730
}
@@ -759,12 +759,12 @@ namespace ts {
759759
const start = child.getStart(sourceFile, includeJsDoc);
760760
const lookInPreviousChild =
761761
(start >= position) || // cursor in the leading trivia
762-
!nodeHasTokens(child) ||
762+
!nodeHasTokens(child, sourceFile) ||
763763
isWhiteSpaceOnlyJsxText(child);
764764

765765
if (lookInPreviousChild) {
766766
// actual start of the node is past the position - previous token should be at the end of previous child
767-
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i);
767+
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
768768
return candidate && findRightmostToken(candidate, sourceFile);
769769
}
770770
else {
@@ -781,7 +781,7 @@ namespace ts {
781781
// Try to find the rightmost token in the file without filtering.
782782
// Namely we are skipping the check: 'position < node.end'
783783
if (children.length) {
784-
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length);
784+
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
785785
return candidate && findRightmostToken(candidate, sourceFile);
786786
}
787787
}
@@ -797,21 +797,21 @@ namespace ts {
797797
}
798798

799799
const children = n.getChildren(sourceFile);
800-
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length);
800+
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
801801
return candidate && findRightmostToken(candidate, sourceFile);
802802
}
803803

804804
/**
805805
* Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
806806
*/
807-
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number): Node | undefined {
807+
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFile): Node | undefined {
808808
for (let i = exclusiveStartPosition - 1; i >= 0; i--) {
809809
const child = children[i];
810810

811811
if (isWhiteSpaceOnlyJsxText(child)) {
812812
Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
813813
}
814-
else if (nodeHasTokens(children[i])) {
814+
else if (nodeHasTokens(children[i], sourceFile)) {
815815
return children[i];
816816
}
817817
}
@@ -1022,10 +1022,10 @@ namespace ts {
10221022
}
10231023
}
10241024

1025-
function nodeHasTokens(n: Node): boolean {
1025+
function nodeHasTokens(n: Node, sourceFile: SourceFileLike): boolean {
10261026
// If we have a token or node that has a non-zero width, it must have tokens.
10271027
// Note: getWidth() does not take trivia into account.
1028-
return n.getWidth() !== 0;
1028+
return n.getWidth(sourceFile) !== 0;
10291029
}
10301030

10311031
export function getNodeModifiers(node: Node): string {

tests/baselines/reference/api/tsserverlibrary.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ declare namespace ts {
43264326
getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number;
43274327
getFullStart(): number;
43284328
getEnd(): number;
4329-
getWidth(sourceFile?: SourceFile): number;
4329+
getWidth(sourceFile?: SourceFileLike): number;
43304330
getFullWidth(): number;
43314331
getLeadingTriviaWidth(sourceFile?: SourceFile): number;
43324332
getFullText(sourceFile?: SourceFile): string;

tests/baselines/reference/api/typescript.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ declare namespace ts {
43264326
getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number;
43274327
getFullStart(): number;
43284328
getEnd(): number;
4329-
getWidth(sourceFile?: SourceFile): number;
4329+
getWidth(sourceFile?: SourceFileLike): number;
43304330
getFullWidth(): number;
43314331
getLeadingTriviaWidth(sourceFile?: SourceFile): number;
43324332
getFullText(sourceFile?: SourceFile): string;

0 commit comments

Comments
 (0)