fix(42678): detect access to uninitialized variable in IIFE (#42776)

* fix(42678): detect access to uninitialized variable in IIFE

* improve performance

* Add missing space to match coding guidelines

* simplify the implementation

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
Zzzen
2021-12-07 02:42:20 +08:00
committed by GitHub
parent 1f275d705d
commit 7a1687de26
7 changed files with 201 additions and 3 deletions

View File

@@ -2536,10 +2536,12 @@ namespace ts {
/* Starting from 'initial' node walk up the parent chain until 'stopAt' node is reached.
* If at any point current node is equal to 'parent' node - return true.
* If current node is an IIFE, continue walking up.
* Return false if 'stopAt' node is reached or isFunctionLike(current) === true.
*/
function isSameScopeDescendentOf(initial: Node, parent: Node | undefined, stopAt: Node): boolean {
return !!parent && !!findAncestor(initial, n => n === stopAt || isFunctionLike(n) ? "quit" : n === parent);
return !!parent && !!findAncestor(initial, n => n === parent
|| (n === stopAt || isFunctionLike(n) && !getImmediatelyInvokedFunctionExpression(n) ? "quit" : false));
}
function getAnyImportSyntax(node: Node): AnyImportSyntax | undefined {