From 44331b9fa32999d4aade7433c10cd3ec8596957e Mon Sep 17 00:00:00 2001 From: Joost Koehoorn Date: Mon, 7 Oct 2024 20:12:47 +0200 Subject: [PATCH 1/5] Fix grammar issue in TS9025 diagnostic message (#60136) --- src/compiler/diagnosticMessages.json | 2 +- .../transformers/declarations/diagnostics.ts | 2 +- .../fixMissingTypeAnnotationOnExports.ts | 2 +- .../declarationFunctionDeclarations.d.ts | 36 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index cab78bae9e082..7f686076f1824 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -7058,7 +7058,7 @@ "category": "Error", "code": 9023 }, - "Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.": { + "Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.": { "category": "Error", "code": 9025 }, diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index ccd95b06651a4..84e952da136df 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -772,7 +772,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod return createExpressionError(node.initializer); } const message = addUndefined ? - Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : + Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_supported_with_isolatedDeclarations : errorByDeclarationKind[node.kind]; const diag = createDiagnosticForNode(node, message); const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); diff --git a/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts b/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts index 3a76444aa8266..a82ccb01f00ff 100644 --- a/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts +++ b/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts @@ -135,7 +135,7 @@ const errorCodes = [ Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations.code, Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations.code, Diagnostics.Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function.code, - Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations.code, + Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_supported_with_isolatedDeclarations.code, Diagnostics.Type_containing_private_name_0_can_t_be_used_with_isolatedDeclarations.code, Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_the_type_explicit.code, ]; diff --git a/tests/baselines/reference/transpile/declarationFunctionDeclarations.d.ts b/tests/baselines/reference/transpile/declarationFunctionDeclarations.d.ts index 660699a4426c3..7814e7759fa75 100644 --- a/tests/baselines/reference/transpile/declarationFunctionDeclarations.d.ts +++ b/tests/baselines/reference/transpile/declarationFunctionDeclarations.d.ts @@ -125,15 +125,15 @@ export {}; //// [Diagnostics reported] -fnDecl.ts(12,27): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(16,36): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(20,26): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(24,56): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(28,46): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(32,45): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(37,47): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(41,37): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. -fnDecl.ts(45,35): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +fnDecl.ts(12,27): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(16,36): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(20,26): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(24,56): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(28,46): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(32,45): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(37,47): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(41,37): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. +fnDecl.ts(45,35): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. ==== fnDecl.ts (9 errors) ==== @@ -150,42 +150,42 @@ fnDecl.ts(45,35): error TS9025: Declaration emit for this parameter requires imp export function fnDeclHasUndefined(p: T | undefined = [], rParam: string): void { }; export function fnDeclBad(p: T = [], rParam: string): void { }; ~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:12:27: Add a type annotation to the parameter p. export const fnExprOk1 = function (array: number[] = [], rParam: string): void { }; export const fnExprOk2 = function (array: T | undefined = [], rParam: string): void { }; export const fnExprBad = function (array: T = [], rParam: string): void { }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:16:36: Add a type annotation to the parameter array. export const arrowOk1 = (array: number[] = [], rParam: string): void => { }; export const arrowOk2 = (array: T | undefined = [], rParam: string): void => { }; export const arrowBad = (array: T = [], rParam: string): void => { }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:20:26: Add a type annotation to the parameter array. export const inObjectLiteralFnExprOk1 = { o: function (array: number[] = [], rParam: string): void { } }; export const inObjectLiteralFnExprOk2 = { o: function (array: T | undefined = [], rParam: string): void { } }; export const inObjectLiteralFnExprBad = { o: function (array: T = [], rParam: string): void { } }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:24:56: Add a type annotation to the parameter array. export const inObjectLiteralArrowOk1 = { o: (array: number[] = [], rParam: string): void => { } }; export const inObjectLiteralArrowOk2 = { o: (array: T | undefined = [], rParam: string): void => { } }; export const inObjectLiteralArrowBad = { o: (array: T = [], rParam: string): void => { } }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:28:46: Add a type annotation to the parameter array. export const inObjectLiteralMethodOk1 = { o(array: number[] = [], rParam: string): void { } }; export const inObjectLiteralMethodOk2 = { o(array: T | undefined = [], rParam: string): void { } }; export const inObjectLiteralMethodBad = { o(array: T = [], rParam: string): void { } }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:32:45: Add a type annotation to the parameter array. @@ -193,21 +193,21 @@ fnDecl.ts(45,35): error TS9025: Declaration emit for this parameter requires imp export class InClassFnExprOk2 { o = function (array: T | undefined = [], rParam: string): void { } }; export class InClassFnExprBad { o = function (array: T = [], rParam: string): void { } }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:37:47: Add a type annotation to the parameter array. export class InClassArrowOk1 { o = (array: number[] = [], rParam: string): void => { } }; export class InClassArrowOk2 { o = (array: T | undefined = [], rParam: string): void => { } }; export class InClassArrowBad { o = (array: T = [], rParam: string): void => { } }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:41:37: Add a type annotation to the parameter array. export class InClassMethodOk1 { o(array: number[] = [], rParam: string): void { } }; export class InClassMethodOk2 { o(array: T | undefined = [], rParam: string): void { } }; export class InClassMethodBad { o(array: T = [], rParam: string): void { } }; ~~~~~~~~~~~~~ -!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations. !!! related TS9028 fnDecl.ts:45:35: Add a type annotation to the parameter array. From a719df49d448f1929c44ca6e3506b9149f3afbb8 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Mon, 7 Oct 2024 12:25:31 -0700 Subject: [PATCH 2/5] add filenames to error messages in verify file content functions in fourslash (#60143) --- src/harness/fourslashImpl.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 89b0e236a2485..e83d4bf1d5124 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -3069,7 +3069,7 @@ export class TestState { private verifyFileContent(fileName: string, text: string) { const actual = this.getFileContent(fileName); if (actual !== text) { - throw new Error(`verifyFileContent failed:\n${showTextDiff(text, actual)}`); + throw new Error(`verifyFileContent in file '${fileName}' failed:\n${showTextDiff(text, actual)}`); } } @@ -3404,10 +3404,11 @@ export class TestState { return ts.first(ranges); } - private verifyTextMatches(actualText: string, includeWhitespace: boolean, expectedText: string) { + private verifyTextMatches(actualText: string, includeWhitespace: boolean, expectedText: string, fileName?: string) { const removeWhitespace = (s: string): string => includeWhitespace ? s : this.removeWhitespace(s); if (removeWhitespace(actualText) !== removeWhitespace(expectedText)) { - this.raiseError(`Actual range text doesn't match expected text.\n${showTextDiff(expectedText, actualText)}`); + const addFileName = fileName ? ` in file '${fileName}'` : ""; + this.raiseError(`Actual range text${addFileName} doesn't match expected text.\n${showTextDiff(expectedText, actualText)}`); } } @@ -3485,7 +3486,7 @@ export class TestState { const newText = ts.textChanges.applyChanges(this.getFileContent(this.activeFile.fileName), change.textChanges); const newRange = updateTextRangeForTextChanges(this.getOnlyRange(this.activeFile.fileName), change.textChanges); const actualText = newText.slice(newRange.pos, newRange.end); - this.verifyTextMatches(actualText, /*includeWhitespace*/ true, newRangeContent); + this.verifyTextMatches(actualText, /*includeWhitespace*/ true, newRangeContent, change.fileName); } else { if (newFileContent === undefined) throw ts.Debug.fail(); @@ -3497,7 +3498,7 @@ export class TestState { } const oldText = this.tryGetFileContent(change.fileName); const newContent = change.isNewFile ? ts.first(change.textChanges).newText : ts.textChanges.applyChanges(oldText!, change.textChanges); - this.verifyTextMatches(newContent, /*includeWhitespace*/ true, expectedNewContent); + this.verifyTextMatches(newContent, /*includeWhitespace*/ true, expectedNewContent, change.fileName); } for (const newFileName in newFileContent) { ts.Debug.assert(changes.some(c => c.fileName === newFileName), "No change in file", () => newFileName); From 20f67d791cc2101f8bfe3ddcb8c1705b090281cf Mon Sep 17 00:00:00 2001 From: Austin Henrie <113467168+epistemancering@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:55:37 -0600 Subject: [PATCH 3/5] fix automatic type acquisition (#60157) --- src/typingsInstaller/nodeTypingsInstaller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/typingsInstaller/nodeTypingsInstaller.ts b/src/typingsInstaller/nodeTypingsInstaller.ts index 7c66ca29f56d6..ea34149c9037b 100644 --- a/src/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/typingsInstaller/nodeTypingsInstaller.ts @@ -1,4 +1,4 @@ -import { execFileSync } from "child_process"; +import { execSync } from "child_process"; import * as fs from "fs"; import * as path from "path"; @@ -172,7 +172,7 @@ class NodeTypingsInstaller extends ts.server.typingsInstaller.TypingsInstaller { this.log.writeLine(`Exec: ${command}`); } try { - const stdout = execFileSync(command, { ...options, encoding: "utf-8" }); + const stdout = execSync(command, { ...options, encoding: "utf-8" }); if (this.log.isEnabled()) { this.log.writeLine(` Succeeded. stdout:${indent(sys.newLine, stdout)}`); } From 009b3ffdda1ec62cf06b9670b2292f04cec0a146 Mon Sep 17 00:00:00 2001 From: "Oleksandr T." Date: Mon, 7 Oct 2024 22:58:15 +0300 Subject: [PATCH 4/5] fix(59825): getNavigationTree crash on invalid class merge and function merge with expando members (#60152) --- src/services/navigationBar.ts | 1 + .../fourslash/navigationBarItemsClass6.ts | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/cases/fourslash/navigationBarItemsClass6.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 6ca2a1804a8ce..b4c32d566b126 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -760,6 +760,7 @@ function isSynthesized(node: Node) { // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }` // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };` function isOwnChild(n: Node, parent: NavigationBarNode): boolean { + if (n.parent === undefined) return false; const par = isModuleBlock(n.parent) ? n.parent.parent : n.parent; return par === parent.node || contains(parent.additionalNodes, par); } diff --git a/tests/cases/fourslash/navigationBarItemsClass6.ts b/tests/cases/fourslash/navigationBarItemsClass6.ts new file mode 100644 index 0000000000000..7dc7290356d18 --- /dev/null +++ b/tests/cases/fourslash/navigationBarItemsClass6.ts @@ -0,0 +1,31 @@ +/// + +////function Z() { } +//// +////Z.foo = 42 +//// +////class Z { } + +verify.navigationTree({ + text: "", + kind: "script", + childItems: [ + { + text: "Z", + kind: "class", + childItems: [ + { + text: "constructor", + kind: "constructor" + }, + { + text: "foo" + } + ] + }, + { + text: "Z", + kind: "class" + } + ] +}); From cd6c0a0b6b8659f49344951219c74a516fdec9a2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 7 Oct 2024 13:41:43 -0700 Subject: [PATCH 5/5] Fix the type of `growable` on `SharedArrayBuffer`. (#60163) --- src/lib/es2024.sharedmemory.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/es2024.sharedmemory.d.ts b/src/lib/es2024.sharedmemory.d.ts index e520374568c68..672c714508b0d 100644 --- a/src/lib/es2024.sharedmemory.d.ts +++ b/src/lib/es2024.sharedmemory.d.ts @@ -28,7 +28,7 @@ interface SharedArrayBuffer { * * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable) */ - get growable(): number; + get growable(): boolean; /** * If this SharedArrayBuffer is growable, returns the maximum byte length given during construction; returns the byte length if not.