Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for emit of a computed property based on an aliased symbol #47978

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/baselines/reference/symbolProperty61.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//// [symbolProperty61.ts]
declare global {
interface SymbolConstructor {
readonly obs: symbol
}
}

const observable: typeof Symbol.obs = Symbol.obs

export class MyObservable<T> {
constructor(private _val: T) {}

subscribe(next: (val: T) => void) {
next(this._val)
}

[observable]() {
return this
}
}

type InteropObservable<T> = {
[Symbol.obs]: () => { subscribe(next: (val: T) => void): void }
}

function from<T>(obs: InteropObservable<T>) {
return obs[Symbol.obs]()
}

from(new MyObservable(42))


//// [symbolProperty61.js]
const observable = Symbol.obs;
export class MyObservable {
constructor(_val) {
this._val = _val;
}
subscribe(next) {
next(this._val);
}
[observable]() {
return this;
}
}
function from(obs) {
return obs[Symbol.obs]();
}
from(new MyObservable(42));


//// [symbolProperty61.d.ts]
declare global {
interface SymbolConstructor {
readonly obs: symbol;
}
}
declare const observable: typeof Symbol.obs;
export declare class MyObservable<T> {
private _val;
constructor(_val: T);
subscribe(next: (val: T) => void): void;
[observable](): this;
}
export {};
84 changes: 84 additions & 0 deletions tests/baselines/reference/symbolProperty61.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
=== tests/cases/conformance/es6/Symbols/symbolProperty61.ts ===
declare global {
>global : Symbol(global, Decl(symbolProperty61.ts, 0, 0))

interface SymbolConstructor {
>SymbolConstructor : Symbol(SymbolConstructor, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(symbolProperty61.ts, 0, 16))

readonly obs: symbol
>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
}
}

const observable: typeof Symbol.obs = Symbol.obs
>observable : Symbol(observable, Decl(symbolProperty61.ts, 6, 5))
>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))

export class MyObservable<T> {
>MyObservable : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48))
>T : Symbol(T, Decl(symbolProperty61.ts, 8, 26))

constructor(private _val: T) {}
>_val : Symbol(MyObservable._val, Decl(symbolProperty61.ts, 9, 16))
>T : Symbol(T, Decl(symbolProperty61.ts, 8, 26))

subscribe(next: (val: T) => void) {
>subscribe : Symbol(MyObservable.subscribe, Decl(symbolProperty61.ts, 9, 35))
>next : Symbol(next, Decl(symbolProperty61.ts, 11, 14))
>val : Symbol(val, Decl(symbolProperty61.ts, 11, 21))
>T : Symbol(T, Decl(symbolProperty61.ts, 8, 26))

next(this._val)
>next : Symbol(next, Decl(symbolProperty61.ts, 11, 14))
>this._val : Symbol(MyObservable._val, Decl(symbolProperty61.ts, 9, 16))
>this : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48))
>_val : Symbol(MyObservable._val, Decl(symbolProperty61.ts, 9, 16))
}

[observable]() {
>[observable] : Symbol(MyObservable[observable], Decl(symbolProperty61.ts, 13, 5))
>observable : Symbol(observable, Decl(symbolProperty61.ts, 6, 5))

return this
>this : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48))
}
}

type InteropObservable<T> = {
>InteropObservable : Symbol(InteropObservable, Decl(symbolProperty61.ts, 18, 1))
>T : Symbol(T, Decl(symbolProperty61.ts, 20, 23))

[Symbol.obs]: () => { subscribe(next: (val: T) => void): void }
>[Symbol.obs] : Symbol([Symbol.obs], Decl(symbolProperty61.ts, 20, 29))
>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
>subscribe : Symbol(subscribe, Decl(symbolProperty61.ts, 21, 25))
>next : Symbol(next, Decl(symbolProperty61.ts, 21, 36))
>val : Symbol(val, Decl(symbolProperty61.ts, 21, 43))
>T : Symbol(T, Decl(symbolProperty61.ts, 20, 23))
}

function from<T>(obs: InteropObservable<T>) {
>from : Symbol(from, Decl(symbolProperty61.ts, 22, 1))
>T : Symbol(T, Decl(symbolProperty61.ts, 24, 14))
>obs : Symbol(obs, Decl(symbolProperty61.ts, 24, 17))
>InteropObservable : Symbol(InteropObservable, Decl(symbolProperty61.ts, 18, 1))
>T : Symbol(T, Decl(symbolProperty61.ts, 24, 14))

return obs[Symbol.obs]()
>obs : Symbol(obs, Decl(symbolProperty61.ts, 24, 17))
>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31))
}

from(new MyObservable(42))
>from : Symbol(from, Decl(symbolProperty61.ts, 22, 1))
>MyObservable : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48))

80 changes: 80 additions & 0 deletions tests/baselines/reference/symbolProperty61.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
=== tests/cases/conformance/es6/Symbols/symbolProperty61.ts ===
declare global {
>global : any

interface SymbolConstructor {
readonly obs: symbol
>obs : unique symbol
}
}

const observable: typeof Symbol.obs = Symbol.obs
>observable : unique symbol
>Symbol.obs : unique symbol
>Symbol : SymbolConstructor
>obs : unique symbol
>Symbol.obs : unique symbol
>Symbol : SymbolConstructor
>obs : unique symbol

export class MyObservable<T> {
>MyObservable : MyObservable<T>

constructor(private _val: T) {}
>_val : T

subscribe(next: (val: T) => void) {
>subscribe : (next: (val: T) => void) => void
>next : (val: T) => void
>val : T

next(this._val)
>next(this._val) : void
>next : (val: T) => void
>this._val : T
>this : this
>_val : T
}

[observable]() {
>[observable] : () => this
>observable : unique symbol

return this
>this : this
}
}

type InteropObservable<T> = {
>InteropObservable : InteropObservable<T>

[Symbol.obs]: () => { subscribe(next: (val: T) => void): void }
>[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; }
>Symbol.obs : unique symbol
>Symbol : SymbolConstructor
>obs : unique symbol
>subscribe : (next: (val: T) => void) => void
>next : (val: T) => void
>val : T
}

function from<T>(obs: InteropObservable<T>) {
>from : <T>(obs: InteropObservable<T>) => { subscribe(next: (val: T) => void): void; }
>obs : InteropObservable<T>

return obs[Symbol.obs]()
>obs[Symbol.obs]() : { subscribe(next: (val: T) => void): void; }
>obs[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; }
>obs : InteropObservable<T>
>Symbol.obs : unique symbol
>Symbol : SymbolConstructor
>obs : unique symbol
}

from(new MyObservable(42))
>from(new MyObservable(42)) : { subscribe(next: (val: number) => void): void; }
>from : <T>(obs: InteropObservable<T>) => { subscribe(next: (val: T) => void): void; }
>new MyObservable(42) : MyObservable<number>
>MyObservable : typeof MyObservable
>42 : 42

32 changes: 32 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty61.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @target: ES6
// @declaration: true

declare global {
interface SymbolConstructor {
readonly obs: symbol
}
}

const observable: typeof Symbol.obs = Symbol.obs

export class MyObservable<T> {
constructor(private _val: T) {}

subscribe(next: (val: T) => void) {
next(this._val)
}

[observable]() {
return this
}
}

type InteropObservable<T> = {
[Symbol.obs]: () => { subscribe(next: (val: T) => void): void }
}

function from<T>(obs: InteropObservable<T>) {
return obs[Symbol.obs]()
}

from(new MyObservable(42))