Skip to content

Commit 8bab586

Browse files
author
Andy Hanson
committed
getTokenAtPosition: default includeJsDocComment to true
1 parent 3bab6af commit 8bab586

36 files changed

+45
-45
lines changed

src/services/breakpoints.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts.BreakpointResolver {
99
return undefined;
1010
}
1111

12-
let tokenAtLocation = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false);
12+
let tokenAtLocation = getTokenAtPosition(sourceFile, position);
1313
const lineOfPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
1414
if (sourceFile.getLineAndCharacterOfPosition(tokenAtLocation.getStart(sourceFile)).line > lineOfPosition) {
1515
// Get previous token if the token is returned starts on new line

src/services/codefixes/addMissingInvocationForDecorator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ts.codefix {
1313
});
1414

1515
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
16-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
16+
const token = getTokenAtPosition(sourceFile, pos);
1717
const decorator = findAncestor(token, isDecorator)!;
1818
Debug.assert(!!decorator, "Expected position to be owned by a decorator.");
1919
const replacement = createCall(decorator.expression, /*typeArguments*/ undefined, /*argumentsArray*/ undefined);

src/services/codefixes/annotateWithTypeFromJSDoc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace ts.codefix {
1818
});
1919

2020
function getDeclaration(file: SourceFile, pos: number): DeclarationWithType | undefined {
21-
const name = getTokenAtPosition(file, pos, /*includeJsDocComment*/ false);
21+
const name = getTokenAtPosition(file, pos);
2222
// For an arrow function with no name, 'name' lands on the first parameter.
2323
return tryCast(isParameter(name.parent) ? name.parent.parent : name.parent, parameterShouldGetTypeFromJSDoc);
2424
}

src/services/codefixes/convertFunctionToEs6Class.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ts.codefix {
1414

1515
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, position: number, checker: TypeChecker): void {
1616
const deletedNodes: { node: Node, inList: boolean }[] = [];
17-
const ctorSymbol = checker.getSymbolAtLocation(getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false))!;
17+
const ctorSymbol = checker.getSymbolAtLocation(getTokenAtPosition(sourceFile, position))!;
1818

1919
if (!ctorSymbol || !(ctorSymbol.flags & (SymbolFlags.Function | SymbolFlags.Variable))) {
2020
// Bad input

src/services/codefixes/convertToMappedObjectType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace ts.codefix {
2525

2626
interface Info { readonly indexSignature: IndexSignatureDeclaration; readonly container: FixableDeclaration; }
2727
function getInfo(sourceFile: SourceFile, pos: number): Info | undefined {
28-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
28+
const token = getTokenAtPosition(sourceFile, pos);
2929
const indexSignature = cast(token.parent.parent, isIndexSignatureDeclaration);
3030
if (isClassDeclaration(indexSignature.parent)) return undefined;
3131
const container = isInterfaceDeclaration(indexSignature.parent) ? indexSignature.parent : cast(indexSignature.parent.parent, isTypeAliasDeclaration);

src/services/codefixes/correctQualifiedNameToIndexedAccessType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace ts.codefix {
2121
});
2222

2323
function getQualifiedName(sourceFile: SourceFile, pos: number): QualifiedName & { left: Identifier } | undefined {
24-
const qualifiedName = findAncestor(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ true), isQualifiedName)!;
24+
const qualifiedName = findAncestor(getTokenAtPosition(sourceFile, pos), isQualifiedName)!;
2525
Debug.assert(!!qualifiedName, "Expected position to be owned by a qualified name.");
2626
return isIdentifier(qualifiedName.left) ? qualifiedName as QualifiedName & { left: Identifier } : undefined;
2727
}

src/services/codefixes/fixAddMissingMember.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace ts.codefix {
5252
// The identifier of the missing property. eg:
5353
// this.missing = 1;
5454
// ^^^^^^^
55-
const token = getTokenAtPosition(tokenSourceFile, tokenPos, /*includeJsDocComment*/ false);
55+
const token = getTokenAtPosition(tokenSourceFile, tokenPos);
5656
if (!isIdentifier(token)) {
5757
return undefined;
5858
}

src/services/codefixes/fixAddModuleReferTypeMissingTypeof.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ts.codefix {
1717
});
1818

1919
function getImportTypeNode(sourceFile: SourceFile, pos: number): ImportTypeNode {
20-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
20+
const token = getTokenAtPosition(sourceFile, pos);
2121
Debug.assert(token.kind === SyntaxKind.ImportKeyword);
2222
Debug.assert(token.parent.kind === SyntaxKind.ImportType);
2323
return <ImportTypeNode>token.parent;

src/services/codefixes/fixAwaitInSyncFunction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace ts.codefix {
3434
}
3535

3636
function getNodes(sourceFile: SourceFile, start: number): { insertBefore: Node, returnType: TypeNode | undefined } | undefined {
37-
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
37+
const token = getTokenAtPosition(sourceFile, start);
3838
const containingFunction = getContainingFunction(token);
3939
if (!containingFunction) {
4040
return;

src/services/codefixes/fixCannotFindModule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace ts.codefix {
2828
}
2929

3030
function getTypesPackageNameToInstall(host: LanguageServiceHost, sourceFile: SourceFile, pos: number, diagCode: number): string | undefined {
31-
const moduleName = cast(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false), isStringLiteral).text;
31+
const moduleName = cast(getTokenAtPosition(sourceFile, pos), isStringLiteral).text;
3232
const { packageName } = getPackageName(moduleName);
3333
return diagCode === errorCodeCannotFindModule
3434
? (JsTyping.nodeCoreModules.has(packageName) ? "@types/node" : undefined)

src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace ts.codefix {
2828
function getClass(sourceFile: SourceFile, pos: number): ClassLikeDeclaration {
2929
// Token is the identifier in the case of a class declaration
3030
// or the class keyword token in the case of a class expression.
31-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
31+
const token = getTokenAtPosition(sourceFile, pos);
3232
return cast(token.parent, isClassLike);
3333
}
3434

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ts.codefix {
2929
});
3030

3131
function getClass(sourceFile: SourceFile, pos: number): ClassLikeDeclaration {
32-
return Debug.assertDefined(getContainingClass(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false)));
32+
return Debug.assertDefined(getContainingClass(getTokenAtPosition(sourceFile, pos)));
3333
}
3434

3535
function symbolPointsToNonPrivateMember (symbol: Symbol) {

src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts.codefix {
3333
}
3434

3535
function getNodes(sourceFile: SourceFile, pos: number): { readonly constructor: ConstructorDeclaration, readonly superCall: ExpressionStatement } | undefined {
36-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
36+
const token = getTokenAtPosition(sourceFile, pos);
3737
if (token.kind !== SyntaxKind.ThisKeyword) return undefined;
3838
const constructor = getContainingFunction(token) as ConstructorDeclaration;
3939
const superCall = findSuperCall(constructor.body!);

src/services/codefixes/fixConstructorForDerivedNeedSuperCall.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ts.codefix {
1616
});
1717

1818
function getNode(sourceFile: SourceFile, pos: number): ConstructorDeclaration {
19-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
19+
const token = getTokenAtPosition(sourceFile, pos);
2020
Debug.assert(token.kind === SyntaxKind.ConstructorKeyword);
2121
return token.parent as ConstructorDeclaration;
2222
}

src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ts.codefix {
2020
});
2121

2222
function getNodes(sourceFile: SourceFile, pos: number) {
23-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
23+
const token = getTokenAtPosition(sourceFile, pos);
2424
const heritageClauses = getContainingClass(token)!.heritageClauses!;
2525
const extendsToken = heritageClauses[0].getFirstToken()!;
2626
return extendsToken.kind === SyntaxKind.ExtendsKeyword ? { extendsToken, heritageClauses } : undefined;

src/services/codefixes/fixForgottenThisPropertyAccess.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace ts.codefix {
2626

2727
interface Info { readonly node: Identifier; readonly className: string | undefined; }
2828
function getInfo(sourceFile: SourceFile, pos: number, diagCode: number): Info | undefined {
29-
const node = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
29+
const node = getTokenAtPosition(sourceFile, pos);
3030
if (!isIdentifier(node)) return undefined;
3131
return { node, className: diagCode === didYouMeanStaticMemberCode ? getContainingClass(node)!.name!.text : undefined };
3232
}

src/services/codefixes/fixInvalidImportSyntax.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace ts.codefix {
4040
function getActionsForUsageOfInvalidImport(context: CodeFixContext): CodeFixAction[] | undefined {
4141
const sourceFile = context.sourceFile;
4242
const targetKind = Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures.code === context.errorCode ? SyntaxKind.CallExpression : SyntaxKind.NewExpression;
43-
const node = findAncestor(getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false), a => a.kind === targetKind && a.getStart() === context.span.start && a.getEnd() === (context.span.start + context.span.length)) as CallExpression | NewExpression;
43+
const node = findAncestor(getTokenAtPosition(sourceFile, context.span.start), a => a.kind === targetKind && a.getStart() === context.span.start && a.getEnd() === (context.span.start + context.span.length)) as CallExpression | NewExpression;
4444
if (!node) {
4545
return [];
4646
}
@@ -69,7 +69,7 @@ namespace ts.codefix {
6969

7070
function getActionsForInvalidImportLocation(context: CodeFixContext): CodeFixAction[] | undefined {
7171
const sourceFile = context.sourceFile;
72-
const node = findAncestor(getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false), a => a.getStart() === context.span.start && a.getEnd() === (context.span.start + context.span.length));
72+
const node = findAncestor(getTokenAtPosition(sourceFile, context.span.start), a => a.getStart() === context.span.start && a.getEnd() === (context.span.start + context.span.length));
7373
if (!node) {
7474
return [];
7575
}

src/services/codefixes/fixJSDocTypes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace ts.codefix {
4444
}
4545

4646
function getInfo(sourceFile: SourceFile, pos: number, checker: TypeChecker): { readonly typeNode: TypeNode, readonly type: Type } | undefined {
47-
const decl = findAncestor(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false), isTypeContainer);
47+
const decl = findAncestor(getTokenAtPosition(sourceFile, pos), isTypeContainer);
4848
const typeNode = decl && decl.type;
4949
return typeNode && { typeNode, type: checker.getTypeFromTypeNode(typeNode) };
5050
}

src/services/codefixes/fixSpelling.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ts.codefix {
2929
// This is the identifier of the misspelled word. eg:
3030
// this.speling = 1;
3131
// ^^^^^^^
32-
const node = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false); // TODO: GH#15852
32+
const node = getTokenAtPosition(sourceFile, pos);
3333
const checker = context.program.getTypeChecker();
3434

3535
let suggestion: string | undefined;

src/services/codefixes/fixStrictClassInitialization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace ts.codefix {
4848
});
4949

5050
function getPropertyDeclaration (sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined {
51-
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
51+
const token = getTokenAtPosition(sourceFile, pos);
5252
return isIdentifier(token) ? cast(token.parent, isPropertyDeclaration) : undefined;
5353
}
5454

src/services/codefixes/fixUnreachableCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ts.codefix {
1313
});
1414

1515
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, start: number): void {
16-
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
16+
const token = getTokenAtPosition(sourceFile, start);
1717
const statement = findAncestor(token, isStatement)!;
1818
Debug.assert(statement.getStart(sourceFile) === token.getStart(sourceFile));
1919

src/services/codefixes/fixUnusedIdentifier.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ts.codefix {
1616
getCodeActions(context) {
1717
const { errorCode, sourceFile, program } = context;
1818
const checker = program.getTypeChecker();
19-
const startToken = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
19+
const startToken = getTokenAtPosition(sourceFile, context.span.start);
2020

2121
const importDecl = tryGetFullImport(startToken);
2222
if (importDecl) {
@@ -54,7 +54,7 @@ namespace ts.codefix {
5454
const { sourceFile, program } = context;
5555
const checker = program.getTypeChecker();
5656
return codeFixAll(context, errorCodes, (changes, diag) => {
57-
const startToken = getTokenAtPosition(sourceFile, diag.start, /*includeJsDocComment*/ false);
57+
const startToken = getTokenAtPosition(sourceFile, diag.start);
5858
const token = findPrecedingToken(textSpanEnd(diag), diag.file)!;
5959
switch (context.fixId) {
6060
case fixIdPrefix:
@@ -173,8 +173,8 @@ namespace ts.codefix {
173173
const typeParameters = getEffectiveTypeParameterDeclarations(<DeclarationWithTypeParameters>parent.parent);
174174
if (typeParameters.length === 1) {
175175
const { pos, end } = cast(typeParameters, isNodeArray);
176-
const previousToken = getTokenAtPosition(sourceFile, pos - 1, /*includeJsDocComment*/ false);
177-
const nextToken = getTokenAtPosition(sourceFile, end, /*includeJsDocComment*/ false);
176+
const previousToken = getTokenAtPosition(sourceFile, pos - 1);
177+
const nextToken = getTokenAtPosition(sourceFile, end);
178178
Debug.assert(previousToken.kind === SyntaxKind.LessThanToken);
179179
Debug.assert(nextToken.kind === SyntaxKind.GreaterThanToken);
180180

@@ -251,7 +251,7 @@ namespace ts.codefix {
251251
else {
252252
// import |d,| * as ns from './file'
253253
const start = importClause.name!.getStart(sourceFile);
254-
const nextToken = getTokenAtPosition(sourceFile, importClause.name!.end, /*includeJsDocComment*/ false);
254+
const nextToken = getTokenAtPosition(sourceFile, importClause.name!.end);
255255
if (nextToken && nextToken.kind === SyntaxKind.CommaToken) {
256256
// shift first non-whitespace position after comma to the start position of the node
257257
const end = skipTrivia(sourceFile.text, nextToken.end, /*stopAfterLineBreaks*/ false, /*stopAtComments*/ true);
@@ -285,7 +285,7 @@ namespace ts.codefix {
285285
// Delete named imports while preserving the default import
286286
// import d|, * as ns| from './file'
287287
// import d|, { a }| from './file'
288-
const previousToken = getTokenAtPosition(sourceFile, namedBindings.pos - 1, /*includeJsDocComment*/ false);
288+
const previousToken = getTokenAtPosition(sourceFile, namedBindings.pos - 1);
289289
if (previousToken && previousToken.kind === SyntaxKind.CommaToken) {
290290
changes.deleteRange(sourceFile, { pos: previousToken.getStart(), end: namedBindings.end });
291291
}

src/services/codefixes/fixUnusedLabel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ts.codefix {
1313
});
1414

1515
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, start: number): void {
16-
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
16+
const token = getTokenAtPosition(sourceFile, start);
1717
const labeledStatement = cast(token.parent, isLabeledStatement);
1818
const pos = token.getStart(sourceFile);
1919
const statementPos = labeledStatement.statement.getStart(sourceFile);

src/services/codefixes/importFixes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ namespace ts.codefix {
326326
}
327327

328328
function getActionsForUMDImport(context: CodeFixContext): CodeFixAction[] | undefined {
329-
const token = getTokenAtPosition(context.sourceFile, context.span.start, /*includeJsDocComment*/ false);
329+
const token = getTokenAtPosition(context.sourceFile, context.span.start);
330330
const checker = context.program.getTypeChecker();
331331

332332
let umdSymbol: Symbol | undefined;
@@ -385,7 +385,7 @@ namespace ts.codefix {
385385
// This will always be an Identifier, since the diagnostics we fix only fail on identifiers.
386386
const { sourceFile, span, program, cancellationToken } = context;
387387
const checker = program.getTypeChecker();
388-
const symbolToken = getTokenAtPosition(sourceFile, span.start, /*includeJsDocComment*/ false);
388+
const symbolToken = getTokenAtPosition(sourceFile, span.start);
389389
// If we're at `<Foo/>`, we must check if `Foo` is already in scope, and if so, get an import for `React` instead.
390390
const symbolName = isJsxOpeningLikeElement(symbolToken.parent)
391391
&& symbolToken.parent.tagName === symbolToken

src/services/codefixes/inferFromUsage.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ts.codefix {
3030
return undefined; // TODO: GH#20113
3131
}
3232

33-
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
33+
const token = getTokenAtPosition(sourceFile, start);
3434
let declaration!: Declaration | undefined;
3535
const changes = textChanges.ChangeTracker.with(context, changes => { declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeenseen*/ returnTrue); });
3636
return changes.length === 0 ? undefined
@@ -41,7 +41,7 @@ namespace ts.codefix {
4141
const { sourceFile, program, cancellationToken } = context;
4242
const markSeen = nodeSeenTracker();
4343
return codeFixAll(context, errorCodes, (changes, err) => {
44-
doChange(changes, sourceFile, getTokenAtPosition(err.file, err.start, /*includeJsDocComment*/ false), err.code, program, cancellationToken, markSeen);
44+
doChange(changes, sourceFile, getTokenAtPosition(err.file, err.start), err.code, program, cancellationToken, markSeen);
4545
});
4646
},
4747
});

src/services/codefixes/requireInTs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace ts.codefix {
2121

2222
interface Info { readonly statement: VariableStatement; readonly name: Identifier; readonly required: StringLiteralLike; }
2323
function getInfo(sourceFile: SourceFile, pos: number): Info {
24-
const { parent } = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
24+
const { parent } = getTokenAtPosition(sourceFile, pos);
2525
if (!isRequireCall(parent, /*checkArgumentIsStringLiteralLike*/ true)) throw Debug.failBadSyntaxKind(parent);
2626
const decl = cast(parent.parent, isVariableDeclaration);
2727
return { statement: cast(decl.parent.parent, isVariableStatement), name: cast(decl.name, isIdentifier), required: parent.arguments[0] };

src/services/codefixes/useDefaultImport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace ts.codefix {
2424
readonly moduleSpecifier: Expression;
2525
}
2626
function getInfo(sourceFile: SourceFile, pos: number): Info | undefined {
27-
const name = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
27+
const name = getTokenAtPosition(sourceFile, pos);
2828
if (!isIdentifier(name)) return undefined; // bad input
2929
const { parent } = name;
3030
if (isImportEqualsDeclaration(parent) && isExternalModuleReference(parent.moduleReference)) {

src/services/completions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ namespace ts.Completions {
849849
return { kind: CompletionDataKind.JsDocTagName };
850850
}
851851
if (isTagWithTypeExpression(tag) && tag.typeExpression && tag.typeExpression.kind === SyntaxKind.JSDocTypeExpression) {
852-
currentToken = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ true);
852+
currentToken = getTokenAtPosition(sourceFile, position);
853853
if (!currentToken ||
854854
(!isDeclarationName(currentToken) &&
855855
(currentToken.parent.kind !== SyntaxKind.JSDocPropertyTag ||

0 commit comments

Comments
 (0)