Skip to content

Commit d4d640f

Browse files
Merge branch 'main' into release-5.0
2 parents aa8df3e + 0141d1d commit d4d640f

File tree

74 files changed

+1859
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1859
-540
lines changed

.github/fabricbot.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
"name": "addReply",
3333
"parameters": {
34-
"comment": "Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, and @minestarks for you. Feel free to loop in other consumers/maintainers if necessary"
34+
"comment": "Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary"
3535
}
3636
}
3737
],
@@ -487,7 +487,7 @@
487487
{
488488
"name": "addReply",
489489
"parameters": {
490-
"comment": "Thanks for the PR! It looks like you've changed 'preProcess.ts' in some way. Please ensure that any changes here don't break consumers with unique project systems such as Visual Studio. Pinging @sheetalkamat and @minestarks so they are aware of the changes."
490+
"comment": "Thanks for the PR! It looks like you've changed 'preProcess.ts' in some way. Please ensure that any changes here don't break consumers with unique project systems such as Visual Studio. Pinging @sheetalkamat, @zkat, and @joj so they are aware of the changes."
491491
}
492492
}
493493
]

package-lock.json

Lines changed: 303 additions & 442 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build/options.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ const parsed = minimist(process.argv.slice(2), {
2626
inspect: process.env.inspect || process.env["inspect-brk"] || process.env.i,
2727
host: process.env.TYPESCRIPT_HOST || process.env.host || "node",
2828
browser: process.env.browser || process.env.b || (os.platform() === "win32" ? "edge" : "chrome"),
29-
timeout: process.env.timeout || 40000,
29+
timeout: +(process.env.timeout ?? 0) || 40000,
3030
tests: process.env.test || process.env.tests || process.env.t,
3131
runners: process.env.runners || process.env.runner || process.env.ru,
3232
light: process.env.light === undefined || process.env.light !== "false",
3333
reporter: process.env.reporter || process.env.r,
3434
fix: process.env.fix || process.env.f,
35-
workers: process.env.workerCount || ((os.cpus().length - (ci ? 0 : 1)) || 1),
35+
workers: +(process.env.workerCount ?? 0) || ((os.cpus().length - (ci ? 0 : 1)) || 1),
3636
failed: false,
3737
keepFailed: false,
3838
lkg: true,
@@ -73,11 +73,11 @@ export default options;
7373
* @property {string | boolean} break
7474
* @property {string | boolean} inspect
7575
* @property {string} runners
76-
* @property {string|number} workers
76+
* @property {number} workers
7777
* @property {string} host
7878
* @property {string} reporter
7979
* @property {string} stackTraceLimit
80-
* @property {string|number} timeout
80+
* @property {number} timeout
8181
* @property {boolean} failed
8282
* @property {boolean} keepFailed
8383
* @property {boolean} ci

scripts/build/tests.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ export async function cleanTestDirs() {
175175
* @param {string} runners
176176
* @param {boolean} light
177177
* @param {string} [taskConfigsFolder]
178-
* @param {string | number} [workerCount]
178+
* @param {number} [workerCount]
179179
* @param {string} [stackTraceLimit]
180-
* @param {string | number} [timeout]
180+
* @param {number} [timeout]
181181
* @param {boolean} [keepFailed]
182182
* @param {number | undefined} [shards]
183183
* @param {number | undefined} [shardId]

src/compiler/checker.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ import {
111111
createGetCanonicalFileName,
112112
createGetSymbolWalker,
113113
createModeAwareCacheKey,
114-
createPrinter,
114+
createPrinterWithDefaults,
115+
createPrinterWithRemoveComments,
116+
createPrinterWithRemoveCommentsNeverAsciiEscape,
117+
createPrinterWithRemoveCommentsOmitTrailingSemicolon,
115118
createPropertyNameNodeForIdentifierOrLiteral,
116119
createSymbolTable,
117120
createTextWriter,
@@ -6123,7 +6126,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
61236126
function symbolToStringWorker(writer: EmitTextWriter) {
61246127
const entity = builder(symbol, meaning!, enclosingDeclaration, nodeFlags)!; // TODO: GH#18217
61256128
// add neverAsciiEscape for GH#39027
6126-
const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile ? createPrinter({ removeComments: true, neverAsciiEscape: true }) : createPrinter({ removeComments: true });
6129+
const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile
6130+
? createPrinterWithRemoveCommentsNeverAsciiEscape()
6131+
: createPrinterWithRemoveComments();
61276132
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
61286133
printer.writeNode(EmitHint.Unspecified, entity, /*sourceFile*/ sourceFile, writer);
61296134
return writer;
@@ -6142,7 +6147,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
61426147
sigOutput = kind === SignatureKind.Construct ? SyntaxKind.ConstructSignature : SyntaxKind.CallSignature;
61436148
}
61446149
const sig = nodeBuilder.signatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName);
6145-
const printer = createPrinter({ removeComments: true, omitTrailingSemicolon: true });
6150+
const printer = createPrinterWithRemoveCommentsOmitTrailingSemicolon();
61466151
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
61476152
printer.writeNode(EmitHint.Unspecified, sig!, /*sourceFile*/ sourceFile, getTrailingSemicolonDeferringWriter(writer)); // TODO: GH#18217
61486153
return writer;
@@ -6155,8 +6160,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
61556160
if (typeNode === undefined) return Debug.fail("should always get typenode");
61566161
// The unresolved type gets a synthesized comment on `any` to hint to users that it's not a plain `any`.
61576162
// Otherwise, we always strip comments out.
6158-
const options = { removeComments: type !== unresolvedType };
6159-
const printer = createPrinter(options);
6163+
const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
61606164
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
61616165
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ sourceFile, writer);
61626166
const result = writer.getText();
@@ -9636,7 +9640,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
96369640
typePredicate.kind === TypePredicateKind.Identifier || typePredicate.kind === TypePredicateKind.AssertsIdentifier ? factory.createIdentifier(typePredicate.parameterName) : factory.createThisTypeNode(),
96379641
typePredicate.type && nodeBuilder.typeToTypeNode(typePredicate.type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName)! // TODO: GH#18217
96389642
);
9639-
const printer = createPrinter({ removeComments: true });
9643+
const printer = createPrinterWithRemoveComments();
96409644
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
96419645
printer.writeNode(EmitHint.Unspecified, predicate, /*sourceFile*/ sourceFile, writer);
96429646
return writer;
@@ -27211,7 +27215,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2721127215
isFunctionLike(node) && !getImmediatelyInvokedFunctionExpression(node) ||
2721227216
node.kind === SyntaxKind.ModuleBlock ||
2721327217
node.kind === SyntaxKind.SourceFile ||
27214-
node.kind === SyntaxKind.CatchClause ||
2721527218
node.kind === SyntaxKind.PropertyDeclaration)!;
2721627219
}
2721727220

@@ -27587,7 +27590,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2758727590
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
2758827591
const declarationContainer = getControlFlowContainer(declaration);
2758927592
let flowContainer = getControlFlowContainer(node);
27590-
const isCatch = flowContainer.kind === SyntaxKind.CatchClause;
2759127593
const isOuterVariable = flowContainer !== declarationContainer;
2759227594
const isSpreadDestructuringAssignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
2759327595
const isModuleExports = symbol.flags & SymbolFlags.ModuleExports;
@@ -27602,7 +27604,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2760227604
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
2760327605
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
2760427606
// declaration container are the same).
27605-
const assumeInitialized = isParameter || isCatch || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
27607+
const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
2760627608
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 ||
2760727609
isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
2760827610
node.parent.kind === SyntaxKind.NonNullExpression ||
@@ -43901,6 +43903,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4390143903
}
4390243904

4390343905
const isIllegalExportDefaultInCJS = !node.isExportEquals &&
43906+
!(node.flags & NodeFlags.Ambient) &&
4390443907
compilerOptions.verbatimModuleSyntax &&
4390543908
(moduleKind === ModuleKind.CommonJS || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS);
4390643909

src/compiler/emitter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,18 @@ const enum PipelinePhase {
13431343
Emit,
13441344
}
13451345

1346+
/** @internal */
1347+
export const createPrinterWithDefaults = memoize(() => createPrinter({}));
1348+
1349+
/** @internal */
1350+
export const createPrinterWithRemoveComments = memoize(() => createPrinter({ removeComments: true }));
1351+
1352+
/** @internal */
1353+
export const createPrinterWithRemoveCommentsNeverAsciiEscape = memoize(() => createPrinter({ removeComments: true, neverAsciiEscape: true }));
1354+
1355+
/** @internal */
1356+
export const createPrinterWithRemoveCommentsOmitTrailingSemicolon = memoize(() => createPrinter({ removeComments: true, omitTrailingSemicolon: true }));
1357+
13461358
export function createPrinter(printerOptions: PrinterOptions = {}, handlers: PrintHandlers = {}): Printer {
13471359
const {
13481360
hasGlobalName,

src/compiler/utilities.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,20 @@ export function getScriptTargetFeatures(): ScriptTargetFeatures {
12791279
BigUint64Array: ["at"],
12801280
ObjectConstructor: ["hasOwn"],
12811281
Error: ["cause"]
1282+
},
1283+
es2023: {
1284+
Array: ["findLastIndex", "findLast"],
1285+
Int8Array: ["findLastIndex", "findLast"],
1286+
Uint8Array: ["findLastIndex", "findLast"],
1287+
Uint8ClampedArray: ["findLastIndex", "findLast"],
1288+
Int16Array: ["findLastIndex", "findLast"],
1289+
Uint16Array: ["findLastIndex", "findLast"],
1290+
Int32Array: ["findLastIndex", "findLast"],
1291+
Uint32Array: ["findLastIndex", "findLast"],
1292+
Float32Array: ["findLastIndex", "findLast"],
1293+
Float64Array: ["findLastIndex", "findLast"],
1294+
BigInt64Array: ["findLastIndex", "findLast"],
1295+
BigUint64Array: ["findLastIndex", "findLast"],
12821296
}
12831297
};
12841298
}

src/harness/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ export class SessionClient implements LanguageService {
727727
return notImplemented();
728728
}
729729

730-
getDocCommentTemplateAtPosition(_fileName: string, _position: number, _options?: DocCommentTemplateOptions): TextInsertion {
730+
getDocCommentTemplateAtPosition(_fileName: string, _position: number, _options?: DocCommentTemplateOptions, _formatOptions?: FormatCodeSettings): TextInsertion {
731731
return notImplemented();
732732
}
733733

src/harness/fourslashImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3249,7 +3249,7 @@ export class TestState {
32493249

32503250
public verifyDocCommentTemplate(expected: ts.TextInsertion | undefined, options?: ts.DocCommentTemplateOptions) {
32513251
const name = "verifyDocCommentTemplate";
3252-
const actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition, options || { generateReturnInDocTemplate: true })!;
3252+
const actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition, options || { generateReturnInDocTemplate: true }, this.formatCodeSettings)!;
32533253

32543254
if (expected === undefined) {
32553255
if (actual) {

src/harness/fourslashInterfaceImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export class Verify extends VerifyNegatable {
452452

453453
public docCommentTemplateAt(marker: string | FourSlash.Marker, expectedOffset: number, expectedText: string, options?: ts.DocCommentTemplateOptions) {
454454
this.state.goToMarker(marker);
455-
this.state.verifyDocCommentTemplate({ newText: expectedText.replace(/\r?\n/g, "\r\n"), caretOffset: expectedOffset }, options);
455+
this.state.verifyDocCommentTemplate({ newText: expectedText.replace(/\r?\n/g, ts.testFormatSettings.newLineCharacter!), caretOffset: expectedOffset }, options);
456456
}
457457

458458
public noDocCommentTemplateAt(marker: string | FourSlash.Marker) {

src/harness/harnessLanguageService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ class LanguageServiceShimProxy implements ts.LanguageService {
587587
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: ts.FormatCodeOptions): ts.TextChange[] {
588588
return unwrapJSONCallResult(this.shim.getFormattingEditsAfterKeystroke(fileName, position, key, JSON.stringify(options)));
589589
}
590-
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: ts.DocCommentTemplateOptions): ts.TextInsertion {
591-
return unwrapJSONCallResult(this.shim.getDocCommentTemplateAtPosition(fileName, position, options));
590+
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: ts.DocCommentTemplateOptions, formatOptions?: ts.FormatCodeSettings): ts.TextInsertion {
591+
return unwrapJSONCallResult(this.shim.getDocCommentTemplateAtPosition(fileName, position, options, formatOptions));
592592
}
593593
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
594594
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ export class Session<TMessage = string> implements EventSender {
20832083
private getDocCommentTemplate(args: protocol.FileLocationRequestArgs) {
20842084
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
20852085
const position = this.getPositionInFile(args, file);
2086-
return languageService.getDocCommentTemplateAtPosition(file, position, this.getPreferences(file));
2086+
return languageService.getDocCommentTemplateAtPosition(file, position, this.getPreferences(file), this.getFormatOptions(file));
20872087
}
20882088

20892089
private getSpanOfEnclosingComment(args: protocol.SpanOfEnclosingCommentRequestArgs) {

src/services/callHierarchy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ClassLikeDeclaration,
1515
ClassStaticBlockDeclaration,
1616
compareStringsCaseSensitive,
17-
createPrinter,
17+
createPrinterWithRemoveCommentsOmitTrailingSemicolon,
1818
createTextRangeFromNode,
1919
createTextSpanFromBounds,
2020
createTextSpanFromRange,
@@ -245,7 +245,7 @@ function getCallHierarchyItemName(program: Program, node: CallHierarchyDeclarati
245245
}
246246
if (text === undefined) {
247247
// get the text from printing the node on a single line without comments...
248-
const printer = createPrinter({ removeComments: true, omitTrailingSemicolon: true });
248+
const printer = createPrinterWithRemoveCommentsOmitTrailingSemicolon();
249249
text = usingSingleLineStringWriter(writer => printer.writeNode(EmitHint.Unspecified, node, node.getSourceFile(), writer));
250250
}
251251
return { text, pos: declName.getStart(), end: declName.getEnd() };

src/services/codefixes/fixUnmatchedParameter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function getDeleteAction(context: CodeFixContext, { name, jsDocHost, jsDocParame
8383
);
8484
}
8585

86-
function getRenameAction(context: CodeFixContext, { name, signature, jsDocParameterTag }: Info) {
86+
function getRenameAction(context: CodeFixContext, { name, jsDocHost, signature, jsDocParameterTag }: Info) {
8787
if (!length(signature.parameters)) return undefined;
8888

8989
const sourceFile = context.sourceFile;
@@ -110,7 +110,7 @@ function getRenameAction(context: CodeFixContext, { name, signature, jsDocParame
110110
jsDocParameterTag.comment
111111
);
112112
const changes = textChanges.ChangeTracker.with(context, changeTracker =>
113-
changeTracker.replaceJSDocComment(sourceFile, signature, map(tags, t => t === jsDocParameterTag ? newJSDocParameterTag : t)));
113+
changeTracker.replaceJSDocComment(sourceFile, jsDocHost, map(tags, t => t === jsDocParameterTag ? newJSDocParameterTag : t)));
114114
return createCodeFixActionWithoutFixAll(renameUnmatchedParameter, changes, [Diagnostics.Rename_param_tag_name_0_to_1, name.getText(sourceFile), parameterName]);
115115
}
116116

src/services/inlayHints.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
__String,
33
ArrowFunction,
44
CallExpression,
5-
createPrinter,
5+
createPrinterWithRemoveComments,
66
Debug,
77
EmitHint,
88
EnumMember,
@@ -53,7 +53,6 @@ import {
5353
NodeBuilderFlags,
5454
ParameterDeclaration,
5555
PrefixUnaryExpression,
56-
PrinterOptions,
5756
PropertyDeclaration,
5857
Signature,
5958
skipParentheses,
@@ -383,8 +382,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
383382

384383
function printTypeInSingleLine(type: Type) {
385384
const flags = NodeBuilderFlags.IgnoreErrors | TypeFormatFlags.AllowUniqueESSymbolType | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
386-
const options: PrinterOptions = { removeComments: true };
387-
const printer = createPrinter(options);
385+
const printer = createPrinterWithRemoveComments();
388386

389387
return usingSingleLineStringWriter(writer => {
390388
const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags);

src/services/jsDoc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ const jsDocTagNames = [
135135
"lends",
136136
"license",
137137
"link",
138+
"linkcode",
139+
"linkplain",
138140
"listens",
139141
"member",
140142
"memberof",
@@ -147,6 +149,7 @@ const jsDocTagNames = [
147149
"package",
148150
"param",
149151
"private",
152+
"prop",
150153
"property",
151154
"protected",
152155
"public",

src/services/services.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,8 +2436,9 @@ export function createLanguageService(
24362436
: Promise.reject("Host does not implement `installPackage`");
24372437
}
24382438

2439-
function getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): TextInsertion | undefined {
2440-
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host, /*formatSettings*/ undefined), syntaxTreeCache.getCurrentSourceFile(fileName), position, options);
2439+
function getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions, formatOptions?: FormatCodeSettings): TextInsertion | undefined {
2440+
const formatSettings = formatOptions ? formatting.getFormatContext(formatOptions, host).options : undefined;
2441+
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host, formatSettings), syntaxTreeCache.getCurrentSourceFile(fileName), position, options);
24412442
}
24422443

24432444
function isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {

0 commit comments

Comments
 (0)