mirror of
https://github.com/swc-project/swc.git
synced 2024-12-18 19:21:33 +03:00
b887b30092
**Description:** This is required for https://github.com/swc-project/swc/pull/6981 and https://github.com/swc-project/swc/pull/6950
91 lines
1.8 KiB
TypeScript
91 lines
1.8 KiB
TypeScript
// @strictNullChecks: true
|
|
// @allowUnreachableCode: false
|
|
{
|
|
const data = { param: 'value' };
|
|
|
|
const {
|
|
param = (() => { throw new Error('param is not defined') })(),
|
|
} = data;
|
|
|
|
console.log(param); // should not trigger 'Unreachable code detected.'
|
|
}
|
|
|
|
|
|
{
|
|
const data = { param: 'value' };
|
|
|
|
let foo: string | undefined = "";
|
|
const {
|
|
param = (() => { throw new Error('param is not defined') })(),
|
|
} = data;
|
|
|
|
foo; // should be string
|
|
}
|
|
|
|
{
|
|
const data = { param: 'value' };
|
|
|
|
let foo: string | undefined = "";
|
|
const {
|
|
param = (() => { foo = undefined })(),
|
|
} = data;
|
|
|
|
foo; // should be string | undefined
|
|
}
|
|
|
|
{
|
|
const data = { param: 'value' };
|
|
|
|
let foo: string | undefined = "";
|
|
const {
|
|
param = (() => { return "" + 1 })(),
|
|
} = data;
|
|
|
|
foo; // should be string
|
|
}
|
|
|
|
{
|
|
interface Window {
|
|
window: Window;
|
|
}
|
|
|
|
let foo: string | undefined;
|
|
let window = {} as Window;
|
|
window.window = window;
|
|
|
|
const { [(() => { foo = ""; return 'window' as const })()]:
|
|
{ [(() => { return 'window' as const })()]: bar } } = window;
|
|
|
|
foo; // should be string
|
|
}
|
|
|
|
{
|
|
interface Window {
|
|
window: Window;
|
|
}
|
|
|
|
let foo: string | undefined;
|
|
let window = {} as Window;
|
|
window.window = window;
|
|
|
|
const { [(() => { return 'window' as const })()]:
|
|
{ [(() => { foo = ""; return 'window' as const })()]: bar } } = window;
|
|
|
|
foo; // should be string
|
|
}
|
|
|
|
{
|
|
interface Window {
|
|
window: Window;
|
|
}
|
|
|
|
let foo: string | undefined;
|
|
let window = {} as Window;
|
|
window.window = window;
|
|
|
|
const { [(() => { return 'window' as const })()]:
|
|
{ [(() => { return 'window' as const })()]: bar = (() => { foo = ""; return window; })() } } = window;
|
|
|
|
foo; // should be string | undefined
|
|
}
|