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 ba6b6d253a31c..42e863e36ad95 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 */ @@ -3093,17 +3111,33 @@ 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 */ 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.js b/tests/baselines/reference/staticPropertyAssignmentInherited1.js new file mode 100644 index 0000000000000..840d87a4612f4 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// + +//// [staticPropertyAssignmentInherited1.js] +let v = Math.random() ? '' : Math.random() ? 0 : undefined; + +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 | undefined; +declare class Base { + 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 new file mode 100644 index 0000000000000..1b3d191172091 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.symbols @@ -0,0 +1,85 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// + +=== staticPropertyAssignmentInherited1.js === +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, 59)) + + 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, 59)) + + 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(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) +>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(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited1.js, 21, 14)) +>value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited1.js, 15, 11)) +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited1.types b/tests/baselines/reference/staticPropertyAssignmentInherited1.types new file mode 100644 index 0000000000000..58f0a394a4d9a --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited1.types @@ -0,0 +1,166 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited1.ts] //// + +=== staticPropertyAssignmentInherited1.js === +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 +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +>'' : "" +> : ^^ +>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 | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + static value2 = v; +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + static value3 = v; +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +} + +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 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>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 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.js b/tests/baselines/reference/staticPropertyAssignmentInherited2.js new file mode 100644 index 0000000000000..601aa1e52819e --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// + +//// [staticPropertyAssignmentInherited2.js] +let v = Math.random() ? '' : Math.random() ? 0 : undefined; + +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 | undefined; +declare class Base { + 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 new file mode 100644 index 0000000000000..d11f704bfa960 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.symbols @@ -0,0 +1,85 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// + +=== staticPropertyAssignmentInherited2.js === +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, 59)) + + 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, 59)) + + 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(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) +>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(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) +>cls : Symbol(cls, Decl(staticPropertyAssignmentInherited2.js, 21, 14)) +>value3 : Symbol(Derived.value3, Decl(staticPropertyAssignmentInherited2.js, 15, 11)) +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited2.types b/tests/baselines/reference/staticPropertyAssignmentInherited2.types new file mode 100644 index 0000000000000..d458516fb4e99 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited2.types @@ -0,0 +1,166 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited2.ts] //// + +=== staticPropertyAssignmentInherited2.js === +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 +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +>'' : "" +> : ^^ +>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 | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + static value2 = v; +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + static value3 = v; +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +} + +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 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>this : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>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 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : number | undefined +> : ^^^^^^^^^^^^^^^^^^ +} + diff --git a/tests/baselines/reference/staticPropertyAssignmentInherited3.js b/tests/baselines/reference/staticPropertyAssignmentInherited3.js new file mode 100644 index 0000000000000..8b8b2cfa82258 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// + +//// [staticPropertyAssignmentInherited3.js] +let v = Math.random() ? '' : Math.random() ? 0 : undefined; + +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 | undefined; +declare class Base { + static value1: string | number | undefined; + static value2: string | number | undefined; + static value3: string | number | undefined; +} +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..eef9c09eb1d26 --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// + +=== staticPropertyAssignmentInherited3.js === +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, 59)) + + 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, 59)) + +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..6b992adfdabed --- /dev/null +++ b/tests/baselines/reference/staticPropertyAssignmentInherited3.types @@ -0,0 +1,163 @@ +//// [tests/cases/conformance/salsa/staticPropertyAssignmentInherited3.ts] //// + +=== staticPropertyAssignmentInherited3.js === +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 +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +>'' : "" +> : ^^ +>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 | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + static value2 = v; +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + static value3 = v; +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +} + +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 | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>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 | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Derived : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>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 | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value2 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + cls.value3; +>cls.value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>cls : typeof Derived +> : ^^^^^^^^^^^^^^ +>value3 : string | number | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +} + 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..ee18a202fc9b9 --- /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() ? '' : Math.random() ? 0 : undefined; + +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..1ffaad43da651 --- /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() ? '' : Math.random() ? 0 : undefined; + +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..cfa03760d4d0b --- /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() ? '' : Math.random() ? 0 : undefined; + +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