mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
77 lines
1.6 KiB
TypeScript
77 lines
1.6 KiB
TypeScript
//// [tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts] ////
|
|
|
|
//// [constLocalsInFunctionExpressions.ts]
|
|
declare function getStringOrNumber(): string | number;
|
|
|
|
function f1() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x === "string") {
|
|
const f = () => x.length;
|
|
}
|
|
}
|
|
|
|
function f2() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x !== "string") {
|
|
return;
|
|
}
|
|
const f = () => x.length;
|
|
}
|
|
|
|
function f3() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x === "string") {
|
|
const f = function() { return x.length; };
|
|
}
|
|
}
|
|
|
|
function f4() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x !== "string") {
|
|
return;
|
|
}
|
|
const f = function() { return x.length; };
|
|
}
|
|
|
|
function f5() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x === "string") {
|
|
const f = () => () => x.length;
|
|
}
|
|
}
|
|
|
|
//// [constLocalsInFunctionExpressions.js]
|
|
"use strict";
|
|
function f1() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x === "string") {
|
|
const f = () => x.length;
|
|
}
|
|
}
|
|
function f2() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x !== "string") {
|
|
return;
|
|
}
|
|
const f = () => x.length;
|
|
}
|
|
function f3() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x === "string") {
|
|
const f = function () { return x.length; };
|
|
}
|
|
}
|
|
function f4() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x !== "string") {
|
|
return;
|
|
}
|
|
const f = function () { return x.length; };
|
|
}
|
|
function f5() {
|
|
const x = getStringOrNumber();
|
|
if (typeof x === "string") {
|
|
const f = () => () => x.length;
|
|
}
|
|
}
|