-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8849 from Microsoft/outerControlFlows
Improve control flow analysis in function expressions
- Loading branch information
Showing
16 changed files
with
970 additions
and
222 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/baselines/reference/constLocalsInFunctionExpressions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//// [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] | ||
function f1() { | ||
var x = getStringOrNumber(); | ||
if (typeof x === "string") { | ||
var f = function () { return x.length; }; | ||
} | ||
} | ||
function f2() { | ||
var x = getStringOrNumber(); | ||
if (typeof x !== "string") { | ||
return; | ||
} | ||
var f = function () { return x.length; }; | ||
} | ||
function f3() { | ||
var x = getStringOrNumber(); | ||
if (typeof x === "string") { | ||
var f = function () { return x.length; }; | ||
} | ||
} | ||
function f4() { | ||
var x = getStringOrNumber(); | ||
if (typeof x !== "string") { | ||
return; | ||
} | ||
var f = function () { return x.length; }; | ||
} | ||
function f5() { | ||
var x = getStringOrNumber(); | ||
if (typeof x === "string") { | ||
var f = function () { return function () { return x.length; }; }; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
tests/baselines/reference/constLocalsInFunctionExpressions.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
=== tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts === | ||
declare function getStringOrNumber(): string | number; | ||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) | ||
|
||
function f1() { | ||
>f1 : Symbol(f1, Decl(constLocalsInFunctionExpressions.ts, 0, 54)) | ||
|
||
const x = getStringOrNumber(); | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9)) | ||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) | ||
|
||
if (typeof x === "string") { | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9)) | ||
|
||
const f = () => x.length; | ||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 5, 13)) | ||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9)) | ||
>length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
} | ||
} | ||
|
||
function f2() { | ||
>f2 : Symbol(f2, Decl(constLocalsInFunctionExpressions.ts, 7, 1)) | ||
|
||
const x = getStringOrNumber(); | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9)) | ||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) | ||
|
||
if (typeof x !== "string") { | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9)) | ||
|
||
return; | ||
} | ||
const f = () => x.length; | ||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 14, 9)) | ||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9)) | ||
>length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
} | ||
|
||
function f3() { | ||
>f3 : Symbol(f3, Decl(constLocalsInFunctionExpressions.ts, 15, 1)) | ||
|
||
const x = getStringOrNumber(); | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9)) | ||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) | ||
|
||
if (typeof x === "string") { | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9)) | ||
|
||
const f = function() { return x.length; }; | ||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 20, 13)) | ||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9)) | ||
>length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
} | ||
} | ||
|
||
function f4() { | ||
>f4 : Symbol(f4, Decl(constLocalsInFunctionExpressions.ts, 22, 1)) | ||
|
||
const x = getStringOrNumber(); | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9)) | ||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) | ||
|
||
if (typeof x !== "string") { | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9)) | ||
|
||
return; | ||
} | ||
const f = function() { return x.length; }; | ||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 29, 9)) | ||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9)) | ||
>length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
} | ||
|
||
function f5() { | ||
>f5 : Symbol(f5, Decl(constLocalsInFunctionExpressions.ts, 30, 1)) | ||
|
||
const x = getStringOrNumber(); | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9)) | ||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) | ||
|
||
if (typeof x === "string") { | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9)) | ||
|
||
const f = () => () => x.length; | ||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 35, 13)) | ||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9)) | ||
>length : Symbol(String.length, Decl(lib.d.ts, --, --)) | ||
} | ||
} |
Oops, something went wrong.