From d2366c7ad0b8b7063a73f10322319e7be2ed6858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 4 Jan 2026 01:14:00 +0100 Subject: [PATCH 1/3] Ignore computed name parents when looking up containing functions --- src/compiler/utilities.ts | 35 +++- .../convertParamsToDestructuredObject.ts | 2 +- .../reference/classStaticBlock29.errors.txt | 20 +++ .../reference/classStaticBlock29.symbols | 21 +++ .../reference/classStaticBlock29.types | 52 ++++++ ...ticPropertyAssignmentInherited1.errors.txt | 39 +++++ .../staticPropertyAssignmentInherited1.js | 44 +++++ ...staticPropertyAssignmentInherited1.symbols | 81 +++++++++ .../staticPropertyAssignmentInherited1.types | 154 ++++++++++++++++++ ...ticPropertyAssignmentInherited2.errors.txt | 39 +++++ .../staticPropertyAssignmentInherited2.js | 44 +++++ ...staticPropertyAssignmentInherited2.symbols | 81 +++++++++ .../staticPropertyAssignmentInherited2.types | 154 ++++++++++++++++++ .../staticPropertyAssignmentInherited3.js | 49 ++++++ ...staticPropertyAssignmentInherited3.symbols | 78 +++++++++ .../staticPropertyAssignmentInherited3.types | 151 +++++++++++++++++ ...ContextuallyTypedObjectNoCrash1.errors.txt | 14 ++ ...eOfContextuallyTypedObjectNoCrash1.symbols | 17 ++ ...ameOfContextuallyTypedObjectNoCrash1.types | 26 +++ ...edNameOfContextuallyTypedObjectNoCrash1.ts | 11 ++ .../classStaticBlock/classStaticBlock29.ts | 11 ++ .../staticPropertyAssignmentInherited1.ts | 33 ++++ .../staticPropertyAssignmentInherited2.ts | 33 ++++ .../staticPropertyAssignmentInherited3.ts | 31 ++++ ...ramsToDestructuredObject_inComputedName.ts | 19 +++ 25 files changed, 1234 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock29.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock29.symbols create mode 100644 tests/baselines/reference/classStaticBlock29.types create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited1.js create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited1.symbols create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited1.types create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited2.js create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited2.symbols create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited2.types create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited3.js create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited3.symbols create mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited3.types create mode 100644 tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.errors.txt create mode 100644 tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.symbols create mode 100644 tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.types create mode 100644 tests/cases/compiler/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock29.ts create mode 100644 tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts create mode 100644 tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts create mode 100644 tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts create mode 100644 tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inComputedName.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ba6b6d253a31c..b945db6891734 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3078,12 +3078,30 @@ export function forEachTsConfigPropArray(tsConfigSourceFile: TsConfigSourceFi /** @internal */ export function getContainingFunction(node: Node): SignatureDeclaration | undefined { - return findAncestor(node.parent, isFunctionLike); + while (node = node.parent) { + if (node.kind === SyntaxKind.ComputedPropertyName) { + node = node.parent.parent; + continue; + } + if (isFunctionLike(node)) { + return node; + } + } + return undefined; } /** @internal */ -export function getContainingFunctionDeclaration(node: Node): FunctionLikeDeclaration | undefined { - return findAncestor(node.parent, isFunctionLikeDeclaration); +export function getContainingFunctionDeclaration(node: Node, includeComputedPropertyName: boolean): FunctionLikeDeclaration | undefined { + while (node = node.parent) { + if (!includeComputedPropertyName && node.kind === SyntaxKind.ComputedPropertyName) { + node = node.parent.parent; + continue; + } + if (isFunctionLikeDeclaration(node)) { + return node; + } + } + return undefined; } /** @internal */ @@ -3103,7 +3121,16 @@ export function getContainingClassStaticBlock(node: Node): Node | undefined { /** @internal */ export function getContainingFunctionOrClassStaticBlock(node: Node): SignatureDeclaration | ClassStaticBlockDeclaration | undefined { - return findAncestor(node.parent, isFunctionLikeOrClassStaticBlockDeclaration); + while (node = node.parent) { + if (node.kind === SyntaxKind.ComputedPropertyName) { + node = node.parent.parent; + continue; + } + if (isFunctionLikeOrClassStaticBlockDeclaration(node)) { + return node; + } + } + return undefined; } /** @internal */ diff --git a/src/services/refactors/convertParamsToDestructuredObject.ts b/src/services/refactors/convertParamsToDestructuredObject.ts index 9c1792b9b8cbe..8ba8bca180af6 100644 --- a/src/services/refactors/convertParamsToDestructuredObject.ts +++ b/src/services/refactors/convertParamsToDestructuredObject.ts @@ -434,7 +434,7 @@ function entryToType(entry: FindAllReferences.NodeEntry): Node | undefined { function getFunctionDeclarationAtPosition(file: SourceFile, startPosition: number, checker: TypeChecker): ValidFunctionDeclaration | undefined { const node = getTouchingToken(file, startPosition); - const functionDeclaration = getContainingFunctionDeclaration(node); + const functionDeclaration = getContainingFunctionDeclaration(node, /*includeComputedPropertyName*/ true); // don't offer refactor on top-level JSDoc if (isTopLevelJSDoc(node)) return undefined; diff --git a/tests/baselines/reference/classStaticBlock29.errors.txt b/tests/baselines/reference/classStaticBlock29.errors.txt new file mode 100644 index 0000000000000..2932f2f593e1e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock29.errors.txt @@ -0,0 +1,20 @@ +classStaticBlock29.ts(3,19): error TS18037: 'await' expression cannot be used inside a class static block. +classStaticBlock29.ts(4,19): error TS18037: 'await' expression cannot be used inside a class static block. +classStaticBlock29.ts(5,23): error TS18037: 'await' expression cannot be used inside a class static block. + + +==== classStaticBlock29.ts (3 errors) ==== + class C { + static { + const o1 = { [await 1]: '' }; + ~~~~~~~ +!!! error TS18037: 'await' expression cannot be used inside a class static block. + const o2 = { [await 1]() { return ''; } }; + ~~~~~~~ +!!! error TS18037: 'await' expression cannot be used inside a class static block. + const o3 = { get [await 1]() { return ''; } }; + ~~~~~~~ +!!! error TS18037: 'await' expression cannot be used inside a class static block. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock29.symbols b/tests/baselines/reference/classStaticBlock29.symbols new file mode 100644 index 0000000000000..94892fe8e01cc --- /dev/null +++ b/tests/baselines/reference/classStaticBlock29.symbols @@ -0,0 +1,21 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticBlock29.ts] //// + +=== classStaticBlock29.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock29.ts, 0, 0)) + + static { + const o1 = { [await 1]: '' }; +>o1 : Symbol(o1, Decl(classStaticBlock29.ts, 2, 9)) +>[await 1] : Symbol([await 1], Decl(classStaticBlock29.ts, 2, 16)) + + const o2 = { [await 1]() { return ''; } }; +>o2 : Symbol(o2, Decl(classStaticBlock29.ts, 3, 9)) +>[await 1] : Symbol([await 1], Decl(classStaticBlock29.ts, 3, 16)) + + const o3 = { get [await 1]() { return ''; } }; +>o3 : Symbol(o3, Decl(classStaticBlock29.ts, 4, 9)) +>[await 1] : Symbol([await 1], Decl(classStaticBlock29.ts, 4, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock29.types b/tests/baselines/reference/classStaticBlock29.types new file mode 100644 index 0000000000000..7c832a9048c37 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock29.types @@ -0,0 +1,52 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticBlock29.ts] //// + +=== classStaticBlock29.ts === +class C { +>C : C +> : ^ + + static { + const o1 = { [await 1]: '' }; +>o1 : { 1: string; } +> : ^^^^^^^^^^^^^^ +>{ [await 1]: '' } : { 1: string; } +> : ^^^^^^^^^^^^^^ +>[await 1] : string +> : ^^^^^^ +>await 1 : 1 +> : ^ +>1 : 1 +> : ^ +>'' : "" +> : ^^ + + const o2 = { [await 1]() { return ''; } }; +>o2 : { 1(): string; } +> : ^^^^^^^^^^^^^^^^ +>{ [await 1]() { return ''; } } : { 1(): string; } +> : ^^^^^^^^^^^^^^^^ +>[await 1] : () => string +> : ^^^^^^^^^^^^ +>await 1 : 1 +> : ^ +>1 : 1 +> : ^ +>'' : "" +> : ^^ + + const o3 = { get [await 1]() { return ''; } }; +>o3 : {} +> : ^^ +>{ get [await 1]() { return ''; } } : {} +> : ^^ +>[await 1] : string +> : ^^^^^^ +>await 1 : 1 +> : ^ +>1 : 1 +> : ^ +>'' : "" +> : ^^ + } +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt b/tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt new file mode 100644 index 0000000000000..593089bfc7853 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt @@ -0,0 +1,39 @@ +staticPropertyAssignmentInherited1.js(9,7): error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. + Types of property 'value1' are incompatible. + Type 'number | undefined' is not assignable to type 'string | number'. + Type 'undefined' is not assignable to type 'string | number'. + + +==== staticPropertyAssignmentInherited1.js (1 errors) ==== + let v = Math.random() ? '' : 0; + + class Base { + static value1 = v; + static value2 = v; + static value3 = v; + } + + class Derived extends Base { + ~~~~~~~ +!!! error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. +!!! error TS2417: Types of property 'value1' are incompatible. +!!! error TS2417: Type 'number | undefined' is not assignable to type 'string | number'. +!!! error TS2417: Type 'undefined' is not assignable to type 'string | number'. + static { + this.value1 = 10; + this.value4 = { + [this.value2 = 20]: '' + } + this.value5 = { + get [this.value3 = 30]() { return ''; } + } + } + } + + /** @param {typeof Derived} cls */ + function test(cls) { + cls.value1; + cls.value2; + cls.value3; + } + \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.js b/tests/baselines/reference/staticPropertyAssignmentInherited1.js new file mode 100644 index 0000000000000..901c03a45ec8e --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// + +//// [staticPropertyAssignmentInherited1.js] +let v = Math.random() ? '' : 0; + +class Base { + static value1 = v; + static value2 = v; + static value3 = v; +} + +class Derived extends Base { + static { + this.value1 = 10; + this.value4 = { + [this.value2 = 20]: '' + } + this.value5 = { + get [this.value3 = 30]() { return ''; } + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { + cls.value1; + cls.value2; + cls.value3; +} + + + + +//// [staticPropertyAssignmentInherited1.d.ts] +/** @param {typeof Derived} cls */ +declare function test(cls: typeof Derived): void; +declare let v: string | number; +declare class Base { + static value1: string | number; + static value2: string | number; + static value3: string | number; +} +declare class Derived extends Base { +} diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols new file mode 100644 index 0000000000000..9b6678b89c3f2 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols @@ -0,0 +1,81 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// + +=== staticPropertyAssignmentInherited1.js === +let v = Math.random() ? '' : 0; +>v : Symbol(v, Decl(staticPropertyAssignmentInherited1.js, 0, 3)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +class Base { +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited1.js, 0, 31)) + + static value1 = v; +>value1 : Symbol(Base.value1, Decl(staticPropertyAssignmentInherited1.js, 2, 12)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited1.js, 0, 3)) + + static value2 = v; +>value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited1.js, 3, 20)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited1.js, 0, 3)) + + static value3 = v; +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited1.js, 0, 3)) +} + +class Derived extends Base { +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited1.js, 0, 31)) + + static { + this.value1 = 10; +>this.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited1.js, 9, 10)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) +>value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited1.js, 9, 10)) + + this.value4 = { +>this.value4 : Symbol(Derived.value4, Decl(staticPropertyAssignmentInherited1.js, 10, 21)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) +>value4 : Symbol(Derived.value4, Decl(staticPropertyAssignmentInherited1.js, 10, 21)) + + [this.value2 = 20]: '' +>[this.value2 = 20] : Symbol([this.value2 = 20], Decl(staticPropertyAssignmentInherited1.js, 11, 19)) +>this.value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited1.js, 12, 7)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) +>value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited1.js, 12, 7)) + } + this.value5 = { +>this.value5 : Symbol(Derived.value5, Decl(staticPropertyAssignmentInherited1.js, 13, 5)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) +>value5 : Symbol(Derived.value5, Decl(staticPropertyAssignmentInherited1.js, 13, 5)) + + get [this.value3 = 30]() { return ''; } +>[this.value3 = 30] : Symbol([this.value3 = 30], Decl(staticPropertyAssignmentInherited1.js, 14, 19)) +>this.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) +>value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { +>test : Symbol(test, Decl(staticPropertyAssignmentInherited1.js, 18, 1)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited1.js, 21, 14)) + + cls.value1; +>cls.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited1.js, 9, 10)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited1.js, 21, 14)) +>value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited1.js, 9, 10)) + + cls.value2; +>cls.value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited1.js, 12, 7)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited1.js, 21, 14)) +>value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited1.js, 12, 7)) + + cls.value3; +>cls.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited1.js, 21, 14)) +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.types b/tests/baselines/reference/staticPropertyAssignmentInherited1.types new file mode 100644 index 0000000000000..3af568113baf6 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.types @@ -0,0 +1,154 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// + +=== staticPropertyAssignmentInherited1.js === +let v = Math.random() ? '' : 0; +>v : string | number +> : ^^^^^^^^^^^^^^^ +>Math.random() ? '' : 0 : "" | 0 +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +>'' : "" +> : ^^ +>0 : 0 +> : ^ + +class Base { +>Base : Base +> : ^^^^ + + static value1 = v; +>value1 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ + + static value2 = v; +>value2 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ + + static value3 = v; +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ +} + +class Derived extends Base { +>Derived : Derived +> : ^^^^^^^ +>Base : Base +> : ^^^^ + + static { + this.value1 = 10; +>this.value1 = 10 : 10 +> : ^^ +>this.value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>10 : 10 +> : ^^ + + this.value4 = { +>this.value4 = { [this.value2 = 20]: '' } : { 20: string; } +> : ^^^^^^^^^^^^^^^ +>this.value4 : { 20: string; } | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value4 : { 20: string; } | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [this.value2 = 20]: '' } : { 20: string; } +> : ^^^^^^^^^^^^^^^ + + [this.value2 = 20]: '' +>[this.value2 = 20] : string +> : ^^^^^^ +>this.value2 = 20 : 20 +> : ^^ +>this.value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>20 : 20 +> : ^^ +>'' : "" +> : ^^ + } + this.value5 = { +>this.value5 = { get [this.value3 = 30]() { return ''; } } : {} +> : ^^ +>this.value5 : {} | undefined +> : ^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value5 : {} | undefined +> : ^^^^^^^^^^^^^^ +>{ get [this.value3 = 30]() { return ''; } } : {} +> : ^^ + + get [this.value3 = 30]() { return ''; } +>[this.value3 = 30] : string +> : ^^^^^^ +>this.value3 = 30 : 30 +> : ^^ +>this.value3 : string | number +> : ^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +>30 : 30 +> : ^^ +>'' : "" +> : ^^ + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { +>test : (cls: typeof Derived) => void +> : ^ ^^ ^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ + + cls.value1; +>cls.value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + cls.value2; +>cls.value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + cls.value3; +>cls.value3 : string | number +> : ^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt b/tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt new file mode 100644 index 0000000000000..2efd02a07c570 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt @@ -0,0 +1,39 @@ +staticPropertyAssignmentInherited2.js(9,7): error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. + Types of property 'value1' are incompatible. + Type 'number | undefined' is not assignable to type 'string | number'. + Type 'undefined' is not assignable to type 'string | number'. + + +==== staticPropertyAssignmentInherited2.js (1 errors) ==== + let v = Math.random() ? '' : 0; + + class Base { + static value1 = v; + static value2 = v; + static value3 = v; + } + + class Derived extends Base { + ~~~~~~~ +!!! error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. +!!! error TS2417: Types of property 'value1' are incompatible. +!!! error TS2417: Type 'number | undefined' is not assignable to type 'string | number'. +!!! error TS2417: Type 'undefined' is not assignable to type 'string | number'. + static { + this.value1 = 10; + this.value4 = { + [this.value2 = 20]: '' + } + this.value5 = { + get [this.value3 = 30]() { return ''; } + } + } + } + + /** @param {typeof Derived} cls */ + function test(cls) { + cls.value1; + cls.value2; + cls.value3; + } + \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.js b/tests/baselines/reference/staticPropertyAssignmentInherited2.js new file mode 100644 index 0000000000000..ba0d4ce910fb3 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// + +//// [staticPropertyAssignmentInherited2.js] +let v = Math.random() ? '' : 0; + +class Base { + static value1 = v; + static value2 = v; + static value3 = v; +} + +class Derived extends Base { + static { + this.value1 = 10; + this.value4 = { + [this.value2 = 20]: '' + } + this.value5 = { + get [this.value3 = 30]() { return ''; } + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { + cls.value1; + cls.value2; + cls.value3; +} + + + + +//// [staticPropertyAssignmentInherited2.d.ts] +/** @param {typeof Derived} cls */ +declare function test(cls: typeof Derived): void; +declare let v: string | number; +declare class Base { + static value1: string | number; + static value2: string | number; + static value3: string | number; +} +declare class Derived extends Base { +} diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols new file mode 100644 index 0000000000000..d9ab39f7db669 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols @@ -0,0 +1,81 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// + +=== staticPropertyAssignmentInherited2.js === +let v = Math.random() ? '' : 0; +>v : Symbol(v, Decl(staticPropertyAssignmentInherited2.js, 0, 3)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +class Base { +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited2.js, 0, 31)) + + static value1 = v; +>value1 : Symbol(Base.value1, Decl(staticPropertyAssignmentInherited2.js, 2, 12)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited2.js, 0, 3)) + + static value2 = v; +>value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited2.js, 3, 20)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited2.js, 0, 3)) + + static value3 = v; +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited2.js, 0, 3)) +} + +class Derived extends Base { +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited2.js, 0, 31)) + + static { + this.value1 = 10; +>this.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited2.js, 9, 10)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) +>value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited2.js, 9, 10)) + + this.value4 = { +>this.value4 : Symbol(Derived.value4, Decl(staticPropertyAssignmentInherited2.js, 10, 21)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) +>value4 : Symbol(Derived.value4, Decl(staticPropertyAssignmentInherited2.js, 10, 21)) + + [this.value2 = 20]: '' +>[this.value2 = 20] : Symbol([this.value2 = 20], Decl(staticPropertyAssignmentInherited2.js, 11, 19)) +>this.value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited2.js, 12, 7)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) +>value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited2.js, 12, 7)) + } + this.value5 = { +>this.value5 : Symbol(Derived.value5, Decl(staticPropertyAssignmentInherited2.js, 13, 5)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) +>value5 : Symbol(Derived.value5, Decl(staticPropertyAssignmentInherited2.js, 13, 5)) + + get [this.value3 = 30]() { return ''; } +>[this.value3 = 30] : Symbol([this.value3 = 30], Decl(staticPropertyAssignmentInherited2.js, 14, 19)) +>this.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +>this : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) +>value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { +>test : Symbol(test, Decl(staticPropertyAssignmentInherited2.js, 18, 1)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited2.js, 21, 14)) + + cls.value1; +>cls.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited2.js, 9, 10)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited2.js, 21, 14)) +>value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited2.js, 9, 10)) + + cls.value2; +>cls.value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited2.js, 12, 7)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited2.js, 21, 14)) +>value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited2.js, 12, 7)) + + cls.value3; +>cls.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited2.js, 21, 14)) +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.types b/tests/baselines/reference/staticPropertyAssignmentInherited2.types new file mode 100644 index 0000000000000..d2e471f962cb8 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.types @@ -0,0 +1,154 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// + +=== staticPropertyAssignmentInherited2.js === +let v = Math.random() ? '' : 0; +>v : string | number +> : ^^^^^^^^^^^^^^^ +>Math.random() ? '' : 0 : "" | 0 +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +>'' : "" +> : ^^ +>0 : 0 +> : ^ + +class Base { +>Base : Base +> : ^^^^ + + static value1 = v; +>value1 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ + + static value2 = v; +>value2 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ + + static value3 = v; +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ +} + +class Derived extends Base { +>Derived : Derived +> : ^^^^^^^ +>Base : Base +> : ^^^^ + + static { + this.value1 = 10; +>this.value1 = 10 : 10 +> : ^^ +>this.value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>10 : 10 +> : ^^ + + this.value4 = { +>this.value4 = { [this.value2 = 20]: '' } : { 20: string; } +> : ^^^^^^^^^^^^^^^ +>this.value4 : { 20: string; } | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value4 : { 20: string; } | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [this.value2 = 20]: '' } : { 20: string; } +> : ^^^^^^^^^^^^^^^ + + [this.value2 = 20]: '' +>[this.value2 = 20] : string +> : ^^^^^^ +>this.value2 = 20 : 20 +> : ^^ +>this.value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>20 : 20 +> : ^^ +>'' : "" +> : ^^ + } + this.value5 = { +>this.value5 = { get [this.value3 = 30]() { return ''; } } : {} +> : ^^ +>this.value5 : {} | undefined +> : ^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value5 : {} | undefined +> : ^^^^^^^^^^^^^^ +>{ get [this.value3 = 30]() { return ''; } } : {} +> : ^^ + + get [this.value3 = 30]() { return ''; } +>[this.value3 = 30] : string +> : ^^^^^^ +>this.value3 = 30 : 30 +> : ^^ +>this.value3 : string | number +> : ^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +>30 : 30 +> : ^^ +>'' : "" +> : ^^ + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { +>test : (cls: typeof Derived) => void +> : ^ ^^ ^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ + + cls.value1; +>cls.value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value1 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + cls.value2; +>cls.value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + cls.value3; +>cls.value3 : string | number +> : ^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.js b/tests/baselines/reference/staticPropertyAssignmentInherited3.js new file mode 100644 index 0000000000000..03472bbe7b3a6 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// + +//// [staticPropertyAssignmentInherited3.js] +let v = Math.random() ? '' : 0; + +class Base { + static value1 = v; + static value2 = v; + static value3 = v; +} + +class Derived extends Base {} + +Derived.value1 = 10; +Derived.value4 = { + [Derived.value2 = 20]: '' +} +Derived.value5 = { + get [Derived.value3 = 30]() { return ''; } +} + +/** @param {typeof Derived} cls */ +function test(cls) { + cls.value1; + cls.value2; + cls.value3; +} + + + + +//// [staticPropertyAssignmentInherited3.d.ts] +/** @param {typeof Derived} cls */ +declare function test(cls: typeof Derived): void; +declare let v: string | number; +declare class Base { + static value1: string | number; + static value2: string | number; + static value3: string | number; +} +declare class Derived extends Base { +} +declare namespace Derived { + let value1: number; + let value4: { + 20: string; + }; + let value5: {}; +} diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols new file mode 100644 index 0000000000000..69b4990e7ef01 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols @@ -0,0 +1,78 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// + +=== staticPropertyAssignmentInherited3.js === +let v = Math.random() ? '' : 0; +>v : Symbol(v, Decl(staticPropertyAssignmentInherited3.js, 0, 3)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +class Base { +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited3.js, 0, 31)) + + static value1 = v; +>value1 : Symbol(Base.value1, Decl(staticPropertyAssignmentInherited3.js, 2, 12)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited3.js, 0, 3)) + + static value2 = v; +>value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited3.js, 3, 20)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited3.js, 0, 3)) + + static value3 = v; +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited3.js, 4, 20)) +>v : Symbol(v, Decl(staticPropertyAssignmentInherited3.js, 0, 3)) +} + +class Derived extends Base {} +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited3.js, 0, 31)) + +Derived.value1 = 10; +>Derived.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited3.js, 8, 29)) +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited3.js, 8, 29)) + +Derived.value4 = { +>Derived.value4 : Symbol(Derived.value4, Decl(staticPropertyAssignmentInherited3.js, 10, 20)) +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>value4 : Symbol(Derived.value4, Decl(staticPropertyAssignmentInherited3.js, 10, 20)) + + [Derived.value2 = 20]: '' +>[Derived.value2 = 20] : Symbol([Derived.value2 = 20], Decl(staticPropertyAssignmentInherited3.js, 11, 18)) +>Derived.value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited3.js, 3, 20)) +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited3.js, 3, 20)) +} +Derived.value5 = { +>Derived.value5 : Symbol(Derived.value5, Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>value5 : Symbol(Derived.value5, Decl(staticPropertyAssignmentInherited3.js, 13, 1)) + + get [Derived.value3 = 30]() { return ''; } +>[Derived.value3 = 30] : Symbol([Derived.value3 = 30], Decl(staticPropertyAssignmentInherited3.js, 14, 18)) +>Derived.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited3.js, 4, 20)) +>Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited3.js, 4, 20)) +} + +/** @param {typeof Derived} cls */ +function test(cls) { +>test : Symbol(test, Decl(staticPropertyAssignmentInherited3.js, 16, 1)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited3.js, 19, 14)) + + cls.value1; +>cls.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited3.js, 8, 29)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited3.js, 19, 14)) +>value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited3.js, 8, 29)) + + cls.value2; +>cls.value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited3.js, 3, 20)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited3.js, 19, 14)) +>value2 : Symbol(Base.value2, Decl(staticPropertyAssignmentInherited3.js, 3, 20)) + + cls.value3; +>cls.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited3.js, 4, 20)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited3.js, 19, 14)) +>value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited3.js, 4, 20)) +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.types b/tests/baselines/reference/staticPropertyAssignmentInherited3.types new file mode 100644 index 0000000000000..83a990c3ac4a3 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// + +=== staticPropertyAssignmentInherited3.js === +let v = Math.random() ? '' : 0; +>v : string | number +> : ^^^^^^^^^^^^^^^ +>Math.random() ? '' : 0 : "" | 0 +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +>'' : "" +> : ^^ +>0 : 0 +> : ^ + +class Base { +>Base : Base +> : ^^^^ + + static value1 = v; +>value1 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ + + static value2 = v; +>value2 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ + + static value3 = v; +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +>v : string | number +> : ^^^^^^^^^^^^^^^ +} + +class Derived extends Base {} +>Derived : Derived +> : ^^^^^^^ +>Base : Base +> : ^^^^ + +Derived.value1 = 10; +>Derived.value1 = 10 : 10 +> : ^^ +>Derived.value1 : number +> : ^^^^^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value1 : number +> : ^^^^^^ +>10 : 10 +> : ^^ + +Derived.value4 = { +>Derived.value4 = { [Derived.value2 = 20]: ''} : { 20: string; } +> : ^^^^^^^^^^^^^^^ +>Derived.value4 : { 20: string; } +> : ^^^^^^^^^^^^^^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value4 : { 20: string; } +> : ^^^^^^^^^^^^^^^ +>{ [Derived.value2 = 20]: ''} : { 20: string; } +> : ^^^^^^^^^^^^^^^ + + [Derived.value2 = 20]: '' +>[Derived.value2 = 20] : string +> : ^^^^^^ +>Derived.value2 = 20 : 20 +> : ^^ +>Derived.value2 : string | number +> : ^^^^^^^^^^^^^^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : string | number +> : ^^^^^^^^^^^^^^^ +>20 : 20 +> : ^^ +>'' : "" +> : ^^ +} +Derived.value5 = { +>Derived.value5 = { get [Derived.value3 = 30]() { return ''; }} : {} +> : ^^ +>Derived.value5 : {} +> : ^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value5 : {} +> : ^^ +>{ get [Derived.value3 = 30]() { return ''; }} : {} +> : ^^ + + get [Derived.value3 = 30]() { return ''; } +>[Derived.value3 = 30] : string +> : ^^^^^^ +>Derived.value3 = 30 : 30 +> : ^^ +>Derived.value3 : string | number +> : ^^^^^^^^^^^^^^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +>30 : 30 +> : ^^ +>'' : "" +> : ^^ +} + +/** @param {typeof Derived} cls */ +function test(cls) { +>test : (cls: typeof Derived) => void +> : ^ ^^ ^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ + + cls.value1; +>cls.value1 : number +> : ^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value1 : number +> : ^^^^^^ + + cls.value2; +>cls.value2 : string | number +> : ^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : string | number +> : ^^^^^^^^^^^^^^^ + + cls.value3; +>cls.value3 : string | number +> : ^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number +> : ^^^^^^^^^^^^^^^ +} + diff --git a/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.errors.txt b/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.errors.txt new file mode 100644 index 0000000000000..46113a10d1db2 --- /dev/null +++ b/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.errors.txt @@ -0,0 +1,14 @@ +yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts(5,7): error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation. + + +==== yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts (1 errors) ==== + // https://github.com/microsoft/TypeScript/issues/62941 + + function* g() { + let x: any = { + *[yield 0]() {}, + ~~~~~ +!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation. + }; + } + \ No newline at end of file diff --git a/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.symbols b/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.symbols new file mode 100644 index 0000000000000..4e406efe09834 --- /dev/null +++ b/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.symbols @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts] //// + +=== yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts === +// https://github.com/microsoft/TypeScript/issues/62941 + +function* g() { +>g : Symbol(g, Decl(yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts, 0, 0)) + + let x: any = { +>x : Symbol(x, Decl(yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts, 3, 5)) + + *[yield 0]() {}, +>[yield 0] : Symbol([yield 0], Decl(yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts, 3, 16)) + + }; +} + diff --git a/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.types b/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.types new file mode 100644 index 0000000000000..752d47808f1db --- /dev/null +++ b/tests/baselines/reference/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.types @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts] //// + +=== yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts === +// https://github.com/microsoft/TypeScript/issues/62941 + +function* g() { +>g : () => Generator +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + let x: any = { +>x : any +> : ^^^ +>{ *[yield 0]() {}, } : { [x: number]: () => Generator; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + *[yield 0]() {}, +>[yield 0] : () => Generator +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>yield 0 : any +> : ^^^ +>0 : 0 +> : ^ + + }; +} + diff --git a/tests/cases/compiler/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts b/tests/cases/compiler/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts new file mode 100644 index 0000000000000..081cebcab3d9d --- /dev/null +++ b/tests/cases/compiler/yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts @@ -0,0 +1,11 @@ +// @strict: true +// @target: esnext +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/62941 + +function* g() { + let x: any = { + *[yield 0]() {}, + }; +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock29.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock29.ts new file mode 100644 index 0000000000000..5a086ffbe53bc --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock29.ts @@ -0,0 +1,11 @@ +// @strict: true +// @target: esnext +// @noEmit: true + +class C { + static { + const o1 = { [await 1]: '' }; + const o2 = { [await 1]() { return ''; } }; + const o3 = { get [await 1]() { return ''; } }; + } +} diff --git a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts new file mode 100644 index 0000000000000..5ee8d88d27b1f --- /dev/null +++ b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts @@ -0,0 +1,33 @@ +// @checkJs: true +// @strict: true +// @emitDeclarationOnly: true +// @declaration: true + +// @filename: staticPropertyAssignmentInherited1.js + +let v = Math.random() ? '' : 0; + +class Base { + static value1 = v; + static value2 = v; + static value3 = v; +} + +class Derived extends Base { + static { + this.value1 = 10; + this.value4 = { + [this.value2 = 20]: '' + } + this.value5 = { + get [this.value3 = 30]() { return ''; } + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { + cls.value1; + cls.value2; + cls.value3; +} diff --git a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts new file mode 100644 index 0000000000000..b5276abed22b6 --- /dev/null +++ b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts @@ -0,0 +1,33 @@ +// @checkJs: true +// @strict: true +// @emitDeclarationOnly: true +// @declaration: true + +// @filename: staticPropertyAssignmentInherited2.js + +let v = Math.random() ? '' : 0; + +class Base { + static value1 = v; + static value2 = v; + static value3 = v; +} + +class Derived extends Base { + static { + this.value1 = 10; + this.value4 = { + [this.value2 = 20]: '' + } + this.value5 = { + get [this.value3 = 30]() { return ''; } + } + } +} + +/** @param {typeof Derived} cls */ +function test(cls) { + cls.value1; + cls.value2; + cls.value3; +} diff --git a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts new file mode 100644 index 0000000000000..bddf83375ed2a --- /dev/null +++ b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts @@ -0,0 +1,31 @@ +// @checkJs: true +// @strict: true +// @emitDeclarationOnly: true +// @declaration: true + +// @filename: staticPropertyAssignmentInherited3.js + +let v = Math.random() ? '' : 0; + +class Base { + static value1 = v; + static value2 = v; + static value3 = v; +} + +class Derived extends Base {} + +Derived.value1 = 10; +Derived.value4 = { + [Derived.value2 = 20]: '' +} +Derived.value5 = { + get [Derived.value3 = 30]() { return ''; } +} + +/** @param {typeof Derived} cls */ +function test(cls) { + cls.value1; + cls.value2; + cls.value3; +} diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inComputedName.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inComputedName.ts new file mode 100644 index 0000000000000..7aacfea081778 --- /dev/null +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inComputedName.ts @@ -0,0 +1,19 @@ +/// + +//// const name = "foo"; +//// +//// export class C1 { +//// [/*a*/name/*b*/](a: string, b: number) {} +//// } + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Convert parameters to destructured object", + actionName: "Convert parameters to destructured object", + actionDescription: "Convert parameters to destructured object", + newContent: `const name = "foo"; + +export class C1 { + [name]({ a, b }: { a: string; b: number; }) {} +}` +}); \ No newline at end of file From c2594627ca2fbdd9db55abf8e80208eb011707b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 4 Jan 2026 14:06:08 +0100 Subject: [PATCH 2/3] tweak tests --- ...ticPropertyAssignmentInherited1.errors.txt | 39 ---------- .../staticPropertyAssignmentInherited1.js | 10 +-- ...staticPropertyAssignmentInherited1.symbols | 10 ++- .../staticPropertyAssignmentInherited1.types | 62 +++++++++------ ...ticPropertyAssignmentInherited2.errors.txt | 39 ---------- .../staticPropertyAssignmentInherited2.js | 10 +-- ...staticPropertyAssignmentInherited2.symbols | 10 ++- .../staticPropertyAssignmentInherited2.types | 62 +++++++++------ .../staticPropertyAssignmentInherited3.js | 10 +-- ...staticPropertyAssignmentInherited3.symbols | 10 ++- .../staticPropertyAssignmentInherited3.types | 78 +++++++++++-------- .../staticPropertyAssignmentInherited1.ts | 2 +- .../staticPropertyAssignmentInherited2.ts | 2 +- .../staticPropertyAssignmentInherited3.ts | 2 +- 14 files changed, 158 insertions(+), 188 deletions(-) delete mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt delete mode 100644 tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt b/tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt deleted file mode 100644 index 593089bfc7853..0000000000000 --- a/tests/baselines/reference/staticPropertyAssignmentInherited1.errors.txt +++ /dev/null @@ -1,39 +0,0 @@ -staticPropertyAssignmentInherited1.js(9,7): error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. - Types of property 'value1' are incompatible. - Type 'number | undefined' is not assignable to type 'string | number'. - Type 'undefined' is not assignable to type 'string | number'. - - -==== staticPropertyAssignmentInherited1.js (1 errors) ==== - let v = Math.random() ? '' : 0; - - class Base { - static value1 = v; - static value2 = v; - static value3 = v; - } - - class Derived extends Base { - ~~~~~~~ -!!! error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. -!!! error TS2417: Types of property 'value1' are incompatible. -!!! error TS2417: Type 'number | undefined' is not assignable to type 'string | number'. -!!! error TS2417: Type 'undefined' is not assignable to type 'string | number'. - static { - this.value1 = 10; - this.value4 = { - [this.value2 = 20]: '' - } - this.value5 = { - get [this.value3 = 30]() { return ''; } - } - } - } - - /** @param {typeof Derived} cls */ - function test(cls) { - cls.value1; - cls.value2; - cls.value3; - } - \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.js b/tests/baselines/reference/staticPropertyAssignmentInherited1.js index 901c03a45ec8e..840d87a4612f4 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited1.js +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.js @@ -1,7 +1,7 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// //// [staticPropertyAssignmentInherited1.js] -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; class Base { static value1 = v; @@ -34,11 +34,11 @@ function test(cls) { //// [staticPropertyAssignmentInherited1.d.ts] /** @param {typeof Derived} cls */ declare function test(cls: typeof Derived): void; -declare let v: string | number; +declare let v: string | number | undefined; declare class Base { - static value1: string | number; - static value2: string | number; - static value3: string | number; + static value1: string | number | undefined; + static value2: string | number | undefined; + static value3: string | number | undefined; } declare class Derived extends Base { } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols index 9b6678b89c3f2..e14b8af5c2c62 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols @@ -1,14 +1,18 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// === staticPropertyAssignmentInherited1.js === -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; >v : Symbol(v, Decl(staticPropertyAssignmentInherited1.js, 0, 3)) >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>undefined : Symbol(undefined) class Base { ->Base : Symbol(Base, Decl(staticPropertyAssignmentInherited1.js, 0, 31)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited1.js, 0, 59)) static value1 = v; >value1 : Symbol(Base.value1, Decl(staticPropertyAssignmentInherited1.js, 2, 12)) @@ -25,7 +29,7 @@ class Base { class Derived extends Base { >Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) ->Base : Symbol(Base, Decl(staticPropertyAssignmentInherited1.js, 0, 31)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited1.js, 0, 59)) static { this.value1 = 10; diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.types b/tests/baselines/reference/staticPropertyAssignmentInherited1.types index 3af568113baf6..92a386858efb9 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited1.types +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.types @@ -1,11 +1,11 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// === staticPropertyAssignmentInherited1.js === -let v = Math.random() ? '' : 0; ->v : string | number -> : ^^^^^^^^^^^^^^^ ->Math.random() ? '' : 0 : "" | 0 -> : ^^^^^^ +let v = Math.random() ? '' : Math.random() ? 0 : undefined; +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Math.random() ? '' : Math.random() ? 0 : undefined : "" | 0 | undefined +> : ^^^^^^^^^^^^^^^^^^ >Math.random() : number > : ^^^^^^ >Math.random : () => number @@ -16,30 +16,42 @@ let v = Math.random() ? '' : 0; > : ^^^^^^ >'' : "" > : ^^ +>Math.random() ? 0 : undefined : 0 | undefined +> : ^^^^^^^^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ >0 : 0 > : ^ +>undefined : undefined +> : ^^^^^^^^^ class Base { >Base : Base > : ^^^^ static value1 = v; ->value1 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value1 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ static value2 = v; ->value2 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ static value3 = v; ->value3 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } class Derived extends Base { @@ -106,12 +118,12 @@ class Derived extends Base { > : ^^^^^^ >this.value3 = 30 : 30 > : ^^ ->this.value3 : string | number -> : ^^^^^^^^^^^^^^^ +>this.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >this : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >30 : 30 > : ^^ >'' : "" @@ -144,11 +156,11 @@ function test(cls) { > : ^^^^^^^^^^^^^^^^^^ cls.value3; ->cls.value3 : string | number -> : ^^^^^^^^^^^^^^^ +>cls.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >cls : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt b/tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt deleted file mode 100644 index 2efd02a07c570..0000000000000 --- a/tests/baselines/reference/staticPropertyAssignmentInherited2.errors.txt +++ /dev/null @@ -1,39 +0,0 @@ -staticPropertyAssignmentInherited2.js(9,7): error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. - Types of property 'value1' are incompatible. - Type 'number | undefined' is not assignable to type 'string | number'. - Type 'undefined' is not assignable to type 'string | number'. - - -==== staticPropertyAssignmentInherited2.js (1 errors) ==== - let v = Math.random() ? '' : 0; - - class Base { - static value1 = v; - static value2 = v; - static value3 = v; - } - - class Derived extends Base { - ~~~~~~~ -!!! error TS2417: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base'. -!!! error TS2417: Types of property 'value1' are incompatible. -!!! error TS2417: Type 'number | undefined' is not assignable to type 'string | number'. -!!! error TS2417: Type 'undefined' is not assignable to type 'string | number'. - static { - this.value1 = 10; - this.value4 = { - [this.value2 = 20]: '' - } - this.value5 = { - get [this.value3 = 30]() { return ''; } - } - } - } - - /** @param {typeof Derived} cls */ - function test(cls) { - cls.value1; - cls.value2; - cls.value3; - } - \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.js b/tests/baselines/reference/staticPropertyAssignmentInherited2.js index ba0d4ce910fb3..601aa1e52819e 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited2.js +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.js @@ -1,7 +1,7 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// //// [staticPropertyAssignmentInherited2.js] -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; class Base { static value1 = v; @@ -34,11 +34,11 @@ function test(cls) { //// [staticPropertyAssignmentInherited2.d.ts] /** @param {typeof Derived} cls */ declare function test(cls: typeof Derived): void; -declare let v: string | number; +declare let v: string | number | undefined; declare class Base { - static value1: string | number; - static value2: string | number; - static value3: string | number; + static value1: string | number | undefined; + static value2: string | number | undefined; + static value3: string | number | undefined; } declare class Derived extends Base { } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols index d9ab39f7db669..889afdeaefb2a 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols @@ -1,14 +1,18 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// === staticPropertyAssignmentInherited2.js === -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; >v : Symbol(v, Decl(staticPropertyAssignmentInherited2.js, 0, 3)) >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>undefined : Symbol(undefined) class Base { ->Base : Symbol(Base, Decl(staticPropertyAssignmentInherited2.js, 0, 31)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited2.js, 0, 59)) static value1 = v; >value1 : Symbol(Base.value1, Decl(staticPropertyAssignmentInherited2.js, 2, 12)) @@ -25,7 +29,7 @@ class Base { class Derived extends Base { >Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) ->Base : Symbol(Base, Decl(staticPropertyAssignmentInherited2.js, 0, 31)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited2.js, 0, 59)) static { this.value1 = 10; diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.types b/tests/baselines/reference/staticPropertyAssignmentInherited2.types index d2e471f962cb8..5d16205a00d91 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited2.types +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.types @@ -1,11 +1,11 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// === staticPropertyAssignmentInherited2.js === -let v = Math.random() ? '' : 0; ->v : string | number -> : ^^^^^^^^^^^^^^^ ->Math.random() ? '' : 0 : "" | 0 -> : ^^^^^^ +let v = Math.random() ? '' : Math.random() ? 0 : undefined; +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Math.random() ? '' : Math.random() ? 0 : undefined : "" | 0 | undefined +> : ^^^^^^^^^^^^^^^^^^ >Math.random() : number > : ^^^^^^ >Math.random : () => number @@ -16,30 +16,42 @@ let v = Math.random() ? '' : 0; > : ^^^^^^ >'' : "" > : ^^ +>Math.random() ? 0 : undefined : 0 | undefined +> : ^^^^^^^^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ >0 : 0 > : ^ +>undefined : undefined +> : ^^^^^^^^^ class Base { >Base : Base > : ^^^^ static value1 = v; ->value1 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value1 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ static value2 = v; ->value2 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ static value3 = v; ->value3 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } class Derived extends Base { @@ -106,12 +118,12 @@ class Derived extends Base { > : ^^^^^^ >this.value3 = 30 : 30 > : ^^ ->this.value3 : string | number -> : ^^^^^^^^^^^^^^^ +>this.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >this : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >30 : 30 > : ^^ >'' : "" @@ -144,11 +156,11 @@ function test(cls) { > : ^^^^^^^^^^^^^^^^^^ cls.value3; ->cls.value3 : string | number -> : ^^^^^^^^^^^^^^^ +>cls.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >cls : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.js b/tests/baselines/reference/staticPropertyAssignmentInherited3.js index 03472bbe7b3a6..8b8b2cfa82258 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited3.js +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.js @@ -1,7 +1,7 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// //// [staticPropertyAssignmentInherited3.js] -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; class Base { static value1 = v; @@ -32,11 +32,11 @@ function test(cls) { //// [staticPropertyAssignmentInherited3.d.ts] /** @param {typeof Derived} cls */ declare function test(cls: typeof Derived): void; -declare let v: string | number; +declare let v: string | number | undefined; declare class Base { - static value1: string | number; - static value2: string | number; - static value3: string | number; + static value1: string | number | undefined; + static value2: string | number | undefined; + static value3: string | number | undefined; } declare class Derived extends Base { } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols index 69b4990e7ef01..eef9c09eb1d26 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols @@ -1,14 +1,18 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// === staticPropertyAssignmentInherited3.js === -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; >v : Symbol(v, Decl(staticPropertyAssignmentInherited3.js, 0, 3)) >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>undefined : Symbol(undefined) class Base { ->Base : Symbol(Base, Decl(staticPropertyAssignmentInherited3.js, 0, 31)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited3.js, 0, 59)) static value1 = v; >value1 : Symbol(Base.value1, Decl(staticPropertyAssignmentInherited3.js, 2, 12)) @@ -25,7 +29,7 @@ class Base { class Derived extends Base {} >Derived : Symbol(Derived, Decl(staticPropertyAssignmentInherited3.js, 6, 1), Decl(staticPropertyAssignmentInherited3.js, 8, 29), Decl(staticPropertyAssignmentInherited3.js, 10, 20), Decl(staticPropertyAssignmentInherited3.js, 13, 1)) ->Base : Symbol(Base, Decl(staticPropertyAssignmentInherited3.js, 0, 31)) +>Base : Symbol(Base, Decl(staticPropertyAssignmentInherited3.js, 0, 59)) Derived.value1 = 10; >Derived.value1 : Symbol(Derived.value1, Decl(staticPropertyAssignmentInherited3.js, 8, 29)) diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.types b/tests/baselines/reference/staticPropertyAssignmentInherited3.types index 83a990c3ac4a3..6b992adfdabed 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited3.types +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.types @@ -1,11 +1,11 @@ //// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// === staticPropertyAssignmentInherited3.js === -let v = Math.random() ? '' : 0; ->v : string | number -> : ^^^^^^^^^^^^^^^ ->Math.random() ? '' : 0 : "" | 0 -> : ^^^^^^ +let v = Math.random() ? '' : Math.random() ? 0 : undefined; +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Math.random() ? '' : Math.random() ? 0 : undefined : "" | 0 | undefined +> : ^^^^^^^^^^^^^^^^^^ >Math.random() : number > : ^^^^^^ >Math.random : () => number @@ -16,30 +16,42 @@ let v = Math.random() ? '' : 0; > : ^^^^^^ >'' : "" > : ^^ +>Math.random() ? 0 : undefined : 0 | undefined +> : ^^^^^^^^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ >0 : 0 > : ^ +>undefined : undefined +> : ^^^^^^^^^ class Base { >Base : Base > : ^^^^ static value1 = v; ->value1 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value1 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ static value2 = v; ->value2 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ static value3 = v; ->value3 : string | number -> : ^^^^^^^^^^^^^^^ ->v : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } class Derived extends Base {} @@ -77,12 +89,12 @@ Derived.value4 = { > : ^^^^^^ >Derived.value2 = 20 : 20 > : ^^ ->Derived.value2 : string | number -> : ^^^^^^^^^^^^^^^ +>Derived.value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >Derived : typeof Derived > : ^^^^^^^^^^^^^^ ->value2 : string | number -> : ^^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >20 : 20 > : ^^ >'' : "" @@ -105,12 +117,12 @@ Derived.value5 = { > : ^^^^^^ >Derived.value3 = 30 : 30 > : ^^ ->Derived.value3 : string | number -> : ^^^^^^^^^^^^^^^ +>Derived.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >Derived : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >30 : 30 > : ^^ >'' : "" @@ -133,19 +145,19 @@ function test(cls) { > : ^^^^^^ cls.value2; ->cls.value2 : string | number -> : ^^^^^^^^^^^^^^^ +>cls.value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >cls : typeof Derived > : ^^^^^^^^^^^^^^ ->value2 : string | number -> : ^^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cls.value3; ->cls.value3 : string | number -> : ^^^^^^^^^^^^^^^ +>cls.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >cls : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number -> : ^^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } diff --git a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts index 5ee8d88d27b1f..ee18a202fc9b9 100644 --- a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts +++ b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts @@ -5,7 +5,7 @@ // @filename: staticPropertyAssignmentInherited1.js -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; class Base { static value1 = v; diff --git a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts index b5276abed22b6..1ffaad43da651 100644 --- a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts +++ b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts @@ -5,7 +5,7 @@ // @filename: staticPropertyAssignmentInherited2.js -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; class Base { static value1 = v; diff --git a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts index bddf83375ed2a..cfa03760d4d0b 100644 --- a/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts +++ b/tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts @@ -5,7 +5,7 @@ // @filename: staticPropertyAssignmentInherited3.js -let v = Math.random() ? '' : 0; +let v = Math.random() ? '' : Math.random() ? 0 : undefined; class Base { static value1 = v; From 9a6597b6f7afac62462fa33b7a2f7b2073143e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 4 Jan 2026 14:21:03 +0100 Subject: [PATCH 3/3] fix `getContainingClassStaticBlock` too --- src/compiler/checker.ts | 1 - src/compiler/utilities.ts | 17 ++++++++++++----- .../staticPropertyAssignmentInherited1.symbols | 6 +++--- .../staticPropertyAssignmentInherited1.types | 16 ++++++++-------- .../staticPropertyAssignmentInherited2.symbols | 6 +++--- .../staticPropertyAssignmentInherited2.types | 16 ++++++++-------- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d0d53aea61c00..097ca140b5cf1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13676,7 +13676,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { && !getContainingClassStaticBlock(derived.valueDeclaration) ) { symbols.set(base.escapedName, base); - symbols.set(base.escapedName, base); } } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b945db6891734..42e863e36ad95 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3111,12 +3111,19 @@ export function getContainingClass(node: Node): ClassLikeDeclaration | undefined /** @internal */ export function getContainingClassStaticBlock(node: Node): Node | undefined { - return findAncestor(node.parent, n => { - if (isClassLike(n) || isFunctionLike(n)) { - return "quit"; + while (node = node.parent) { + if (node.kind === SyntaxKind.ComputedPropertyName) { + node = node.parent.parent; + continue; } - return isClassStaticBlockDeclaration(n); - }); + if (isClassLike(node) || isFunctionLike(node)) { + return undefined; + } + if (isClassStaticBlockDeclaration(node)) { + return node; + } + } + return undefined; } /** @internal */ diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols index e14b8af5c2c62..1b3d191172091 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols @@ -55,7 +55,7 @@ class Derived extends Base { get [this.value3 = 30]() { return ''; } >[this.value3 = 30] : Symbol([this.value3 = 30], Decl(staticPropertyAssignmentInherited1.js, 14, 19)) ->this.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +>this.value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) >this : Symbol(Derived, Decl(staticPropertyAssignmentInherited1.js, 6, 1)) >value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) } @@ -78,8 +78,8 @@ function test(cls) { >value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited1.js, 12, 7)) cls.value3; ->cls.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +>cls.value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) >cls : Symbol(cls, Decl(staticPropertyAssignmentInherited1.js, 21, 14)) ->value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited1.js, 4, 20)) +>value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.types b/tests/baselines/reference/staticPropertyAssignmentInherited1.types index 92a386858efb9..58f0a394a4d9a 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited1.types +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.types @@ -118,12 +118,12 @@ class Derived extends Base { > : ^^^^^^ >this.value3 = 30 : 30 > : ^^ ->this.value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ >this : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ >30 : 30 > : ^^ >'' : "" @@ -156,11 +156,11 @@ function test(cls) { > : ^^^^^^^^^^^^^^^^^^ cls.value3; ->cls.value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>cls.value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ >cls : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols index 889afdeaefb2a..d11f704bfa960 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols @@ -55,7 +55,7 @@ class Derived extends Base { get [this.value3 = 30]() { return ''; } >[this.value3 = 30] : Symbol([this.value3 = 30], Decl(staticPropertyAssignmentInherited2.js, 14, 19)) ->this.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +>this.value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) >this : Symbol(Derived, Decl(staticPropertyAssignmentInherited2.js, 6, 1)) >value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) } @@ -78,8 +78,8 @@ function test(cls) { >value2 : Symbol(Derived.value2, Decl(staticPropertyAssignmentInherited2.js, 12, 7)) cls.value3; ->cls.value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +>cls.value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) >cls : Symbol(cls, Decl(staticPropertyAssignmentInherited2.js, 21, 14)) ->value3 : Symbol(Base.value3, Decl(staticPropertyAssignmentInherited2.js, 4, 20)) +>value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) } diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.types b/tests/baselines/reference/staticPropertyAssignmentInherited2.types index 5d16205a00d91..d458516fb4e99 100644 --- a/tests/baselines/reference/staticPropertyAssignmentInherited2.types +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.types @@ -118,12 +118,12 @@ class Derived extends Base { > : ^^^^^^ >this.value3 = 30 : 30 > : ^^ ->this.value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ >this : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ >30 : 30 > : ^^ >'' : "" @@ -156,11 +156,11 @@ function test(cls) { > : ^^^^^^^^^^^^^^^^^^ cls.value3; ->cls.value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>cls.value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ >cls : typeof Derived > : ^^^^^^^^^^^^^^ ->value3 : string | number | undefined -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ }