diff --git a/tests/baselines/reference/computedPropertiesWithSetterAssignment.js b/tests/baselines/reference/computedPropertiesWithSetterAssignment.js new file mode 100644 index 0000000000000..6c61698aa026e --- /dev/null +++ b/tests/baselines/reference/computedPropertiesWithSetterAssignment.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] //// + +//// [a.ts] +const k = Symbol(); + +const enum Props { + k = 'k', +} + +interface Foo { + get k(): Set; + set k(v: Iterable); + + get [k](): Set; + set [k](v: Iterable); +} + +declare const foo: Foo; + +foo.k = ['foo']; +foo['k'] = ['foo']; +foo[Props.k] = ['foo']; +foo[k] = ['foo']; + + +//// [a.js] +"use strict"; +const k = Symbol(); +foo.k = ['foo']; +foo['k'] = ['foo']; +foo["k" /* Props.k */] = ['foo']; +foo[k] = ['foo']; diff --git a/tests/baselines/reference/computedPropertiesWithSetterAssignment.symbols b/tests/baselines/reference/computedPropertiesWithSetterAssignment.symbols new file mode 100644 index 0000000000000..cc82a9dc99a58 --- /dev/null +++ b/tests/baselines/reference/computedPropertiesWithSetterAssignment.symbols @@ -0,0 +1,61 @@ +//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] //// + +=== /a.ts === +const k = Symbol(); +>k : Symbol(k, Decl(a.ts, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +const enum Props { +>Props : Symbol(Props, Decl(a.ts, 0, 19)) + + k = 'k', +>k : Symbol(Props.k, Decl(a.ts, 2, 18)) +} + +interface Foo { +>Foo : Symbol(Foo, Decl(a.ts, 4, 1)) + + get k(): Set; +>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25)) +>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) + + set k(v: Iterable); +>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25)) +>v : Symbol(v, Decl(a.ts, 8, 10)) +>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) + + get [k](): Set; +>[k] : Symbol(Foo[k], Decl(a.ts, 8, 31), Decl(a.ts, 10, 27)) +>k : Symbol(k, Decl(a.ts, 0, 5)) +>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) + + set [k](v: Iterable); +>[k] : Symbol(Foo[k], Decl(a.ts, 8, 31), Decl(a.ts, 10, 27)) +>k : Symbol(k, Decl(a.ts, 0, 5)) +>v : Symbol(v, Decl(a.ts, 11, 12)) +>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) +} + +declare const foo: Foo; +>foo : Symbol(foo, Decl(a.ts, 14, 13)) +>Foo : Symbol(Foo, Decl(a.ts, 4, 1)) + +foo.k = ['foo']; +>foo.k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25)) +>foo : Symbol(foo, Decl(a.ts, 14, 13)) +>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25)) + +foo['k'] = ['foo']; +>foo : Symbol(foo, Decl(a.ts, 14, 13)) +>'k' : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25)) + +foo[Props.k] = ['foo']; +>foo : Symbol(foo, Decl(a.ts, 14, 13)) +>Props.k : Symbol(Props.k, Decl(a.ts, 2, 18)) +>Props : Symbol(Props, Decl(a.ts, 0, 19)) +>k : Symbol(Props.k, Decl(a.ts, 2, 18)) + +foo[k] = ['foo']; +>foo : Symbol(foo, Decl(a.ts, 14, 13)) +>k : Symbol(k, Decl(a.ts, 0, 5)) + diff --git a/tests/baselines/reference/computedPropertiesWithSetterAssignment.types b/tests/baselines/reference/computedPropertiesWithSetterAssignment.types new file mode 100644 index 0000000000000..92c0df4cfc46d --- /dev/null +++ b/tests/baselines/reference/computedPropertiesWithSetterAssignment.types @@ -0,0 +1,112 @@ +//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] //// + +=== /a.ts === +const k = Symbol(); +>k : unique symbol +> : ^^^^^^^^^^^^^ +>Symbol() : unique symbol +> : ^^^^^^^^^^^^^ +>Symbol : SymbolConstructor +> : ^^^^^^^^^^^^^^^^^ + +const enum Props { +>Props : Props +> : ^^^^^ + + k = 'k', +>k : Props.k +> : ^^^^^^^ +>'k' : "k" +> : ^^^ +} + +interface Foo { + get k(): Set; +>k : Set +> : ^^^^^^^^^^^ + + set k(v: Iterable); +>k : Set +> : ^^^^^^^^^^^ +>v : Iterable +> : ^^^^^^^^^^^^^^^^ + + get [k](): Set; +>[k] : Set +> : ^^^^^^^^^^^ +>k : unique symbol +> : ^^^^^^^^^^^^^ + + set [k](v: Iterable); +>[k] : Set +> : ^^^^^^^^^^^ +>k : unique symbol +> : ^^^^^^^^^^^^^ +>v : Iterable +> : ^^^^^^^^^^^^^^^^ +} + +declare const foo: Foo; +>foo : Foo +> : ^^^ + +foo.k = ['foo']; +>foo.k = ['foo'] : string[] +> : ^^^^^^^^ +>foo.k : Iterable +> : ^^^^^^^^^^^^^^^^ +>foo : Foo +> : ^^^ +>k : Iterable +> : ^^^^^^^^^^^^^^^^ +>['foo'] : string[] +> : ^^^^^^^^ +>'foo' : "foo" +> : ^^^^^ + +foo['k'] = ['foo']; +>foo['k'] = ['foo'] : string[] +> : ^^^^^^^^ +>foo['k'] : Iterable +> : ^^^^^^^^^^^^^^^^ +>foo : Foo +> : ^^^ +>'k' : "k" +> : ^^^ +>['foo'] : string[] +> : ^^^^^^^^ +>'foo' : "foo" +> : ^^^^^ + +foo[Props.k] = ['foo']; +>foo[Props.k] = ['foo'] : string[] +> : ^^^^^^^^ +>foo[Props.k] : Iterable +> : ^^^^^^^^^^^^^^^^ +>foo : Foo +> : ^^^ +>Props.k : Props +> : ^^^^^ +>Props : typeof Props +> : ^^^^^^^^^^^^ +>k : Props +> : ^^^^^ +>['foo'] : string[] +> : ^^^^^^^^ +>'foo' : "foo" +> : ^^^^^ + +foo[k] = ['foo']; +>foo[k] = ['foo'] : string[] +> : ^^^^^^^^ +>foo[k] : Iterable +> : ^^^^^^^^^^^^^^^^ +>foo : Foo +> : ^^^ +>k : unique symbol +> : ^^^^^^^^^^^^^ +>['foo'] : string[] +> : ^^^^^^^^ +>'foo' : "foo" +> : ^^^^^ + diff --git a/tests/cases/compiler/computedPropertiesWithSetterAssignment.ts b/tests/cases/compiler/computedPropertiesWithSetterAssignment.ts new file mode 100644 index 0000000000000..c1fd1623a2bfa --- /dev/null +++ b/tests/cases/compiler/computedPropertiesWithSetterAssignment.ts @@ -0,0 +1,24 @@ +// @target: esnext +// @strict: true +// @filename: /a.ts + +const k = Symbol(); + +const enum Props { + k = 'k', +} + +interface Foo { + get k(): Set; + set k(v: Iterable); + + get [k](): Set; + set [k](v: Iterable); +} + +declare const foo: Foo; + +foo.k = ['foo']; +foo['k'] = ['foo']; +foo[Props.k] = ['foo']; +foo[k] = ['foo'];