Skip to content

Commit 90d3f8b

Browse files
authored
Only report expando use-before-def for identical control flow containers (#27199)
1 parent 089b86a commit 90d3f8b

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18487,7 +18487,10 @@ namespace ts {
1848718487
}
1848818488
}
1848918489
}
18490-
else if (strictNullChecks && prop && prop.valueDeclaration && isPropertyAccessExpression(prop.valueDeclaration) && getAssignmentDeclarationPropertyAccessKind(prop.valueDeclaration)) {
18490+
else if (strictNullChecks && prop && prop.valueDeclaration &&
18491+
isPropertyAccessExpression(prop.valueDeclaration) &&
18492+
getAssignmentDeclarationPropertyAccessKind(prop.valueDeclaration) &&
18493+
getControlFlowContainer(node) === getControlFlowContainer(prop.valueDeclaration)) {
1849118494
assumeUninitialized = true;
1849218495
}
1849318496
const flowType = getFlowTypeOfReference(node, propType, assumeUninitialized ? getOptionalType(propType) : propType);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/conformance/salsa/use.js ===
2+
const util = require('./mod')
3+
>util : Symbol(util, Decl(use.js, 0, 5))
4+
>require : Symbol(require)
5+
>'./mod' : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
6+
7+
function n() {
8+
>n : Symbol(n, Decl(use.js, 0, 29))
9+
10+
util.existy // no error
11+
>util.existy : Symbol(existy, Decl(mod.js, 1, 14))
12+
>util : Symbol(util, Decl(use.js, 0, 5))
13+
>existy : Symbol(existy, Decl(mod.js, 1, 14))
14+
}
15+
util.existy // no error
16+
>util.existy : Symbol(existy, Decl(mod.js, 1, 14))
17+
>util : Symbol(util, Decl(use.js, 0, 5))
18+
>existy : Symbol(existy, Decl(mod.js, 1, 14))
19+
20+
=== tests/cases/conformance/salsa/mod.js ===
21+
const util = exports = module.exports = {}
22+
>util : Symbol(util, Decl(mod.js, 0, 5))
23+
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
24+
>module.exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
25+
>module : Symbol(module, Decl(mod.js, 0, 22))
26+
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
27+
28+
if (!!false) {
29+
util.existy = function () { }
30+
>util.existy : Symbol(existy, Decl(mod.js, 1, 14))
31+
>util : Symbol(util, Decl(mod.js, 0, 5))
32+
>existy : Symbol(existy, Decl(mod.js, 1, 14))
33+
}
34+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/conformance/salsa/use.js ===
2+
const util = require('./mod')
3+
>util : typeof import("tests/cases/conformance/salsa/mod")
4+
>require('./mod') : typeof import("tests/cases/conformance/salsa/mod")
5+
>require : any
6+
>'./mod' : "./mod"
7+
8+
function n() {
9+
>n : () => void
10+
11+
util.existy // no error
12+
>util.existy : () => void
13+
>util : typeof import("tests/cases/conformance/salsa/mod")
14+
>existy : () => void
15+
}
16+
util.existy // no error
17+
>util.existy : () => void
18+
>util : typeof import("tests/cases/conformance/salsa/mod")
19+
>existy : () => void
20+
21+
=== tests/cases/conformance/salsa/mod.js ===
22+
const util = exports = module.exports = {}
23+
>util : typeof import("tests/cases/conformance/salsa/mod")
24+
>exports = module.exports = {} : typeof import("tests/cases/conformance/salsa/mod")
25+
>exports : typeof import("tests/cases/conformance/salsa/mod")
26+
>module.exports = {} : typeof import("tests/cases/conformance/salsa/mod")
27+
>module.exports : typeof import("tests/cases/conformance/salsa/mod")
28+
>module : { "tests/cases/conformance/salsa/mod": typeof import("tests/cases/conformance/salsa/mod"); }
29+
>exports : typeof import("tests/cases/conformance/salsa/mod")
30+
>{} : {}
31+
32+
if (!!false) {
33+
>!!false : boolean
34+
>!false : true
35+
>false : false
36+
37+
util.existy = function () { }
38+
>util.existy = function () { } : () => void
39+
>util.existy : () => void
40+
>util : typeof import("tests/cases/conformance/salsa/mod")
41+
>existy : () => void
42+
>function () { } : () => void
43+
}
44+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: mod.js
5+
const util = exports = module.exports = {}
6+
if (!!false) {
7+
util.existy = function () { }
8+
}
9+
10+
// @Filename: use.js
11+
const util = require('./mod')
12+
function n() {
13+
util.existy // no error
14+
}
15+
util.existy // no error

0 commit comments

Comments
 (0)