-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle path access and calls in conditional expressions
- Loading branch information
1 parent
983c089
commit 96d48b3
Showing
15 changed files
with
262 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'only retain branches with side-effects' | ||
}; |
22 changes: 22 additions & 0 deletions
22
test/form/samples/conditional-expression-paths/_expected/amd.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,22 @@ | ||
define(function () { 'use strict'; | ||
|
||
var unknownValue = globalFunction(); | ||
|
||
// unknown branch with side-effect | ||
var foo2 = { x: () => {} }; | ||
var bar2 = { x: () => console.log( 'effect' ) }; | ||
var a2 = (unknownValue ? foo2 : bar2).x.y.z; | ||
var b2 = (unknownValue ? foo2 : bar2).x(); | ||
var c2 = (unknownValue ? foo2 : bar2).x = () => console.log( 'effect' ); | ||
foo2.x(); | ||
bar2.x(); | ||
|
||
var bar4 = { x: () => console.log( 'effect' ) }; | ||
var a4 = (bar4).y.z; | ||
var b4 = (bar4).y.z; | ||
var c4 = (bar4).x(); | ||
var d4 = (bar4).x(); | ||
var e4 = (bar4).y.z = 1; | ||
var f4 = (bar4).y.z = 1; | ||
|
||
}); |
20 changes: 20 additions & 0 deletions
20
test/form/samples/conditional-expression-paths/_expected/cjs.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,20 @@ | ||
'use strict'; | ||
|
||
var unknownValue = globalFunction(); | ||
|
||
// unknown branch with side-effect | ||
var foo2 = { x: () => {} }; | ||
var bar2 = { x: () => console.log( 'effect' ) }; | ||
var a2 = (unknownValue ? foo2 : bar2).x.y.z; | ||
var b2 = (unknownValue ? foo2 : bar2).x(); | ||
var c2 = (unknownValue ? foo2 : bar2).x = () => console.log( 'effect' ); | ||
foo2.x(); | ||
bar2.x(); | ||
|
||
var bar4 = { x: () => console.log( 'effect' ) }; | ||
var a4 = (bar4).y.z; | ||
var b4 = (bar4).y.z; | ||
var c4 = (bar4).x(); | ||
var d4 = (bar4).x(); | ||
var e4 = (bar4).y.z = 1; | ||
var f4 = (bar4).y.z = 1; |
18 changes: 18 additions & 0 deletions
18
test/form/samples/conditional-expression-paths/_expected/es.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,18 @@ | ||
var unknownValue = globalFunction(); | ||
|
||
// unknown branch with side-effect | ||
var foo2 = { x: () => {} }; | ||
var bar2 = { x: () => console.log( 'effect' ) }; | ||
var a2 = (unknownValue ? foo2 : bar2).x.y.z; | ||
var b2 = (unknownValue ? foo2 : bar2).x(); | ||
var c2 = (unknownValue ? foo2 : bar2).x = () => console.log( 'effect' ); | ||
foo2.x(); | ||
bar2.x(); | ||
|
||
var bar4 = { x: () => console.log( 'effect' ) }; | ||
var a4 = (bar4).y.z; | ||
var b4 = (bar4).y.z; | ||
var c4 = (bar4).x(); | ||
var d4 = (bar4).x(); | ||
var e4 = (bar4).y.z = 1; | ||
var f4 = (bar4).y.z = 1; |
23 changes: 23 additions & 0 deletions
23
test/form/samples/conditional-expression-paths/_expected/iife.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,23 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var unknownValue = globalFunction(); | ||
|
||
// unknown branch with side-effect | ||
var foo2 = { x: () => {} }; | ||
var bar2 = { x: () => console.log( 'effect' ) }; | ||
var a2 = (unknownValue ? foo2 : bar2).x.y.z; | ||
var b2 = (unknownValue ? foo2 : bar2).x(); | ||
var c2 = (unknownValue ? foo2 : bar2).x = () => console.log( 'effect' ); | ||
foo2.x(); | ||
bar2.x(); | ||
|
||
var bar4 = { x: () => console.log( 'effect' ) }; | ||
var a4 = (bar4).y.z; | ||
var b4 = (bar4).y.z; | ||
var c4 = (bar4).x(); | ||
var d4 = (bar4).x(); | ||
var e4 = (bar4).y.z = 1; | ||
var f4 = (bar4).y.z = 1; | ||
|
||
}()); |
26 changes: 26 additions & 0 deletions
26
test/form/samples/conditional-expression-paths/_expected/umd.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,26 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
|
||
var unknownValue = globalFunction(); | ||
|
||
// unknown branch with side-effect | ||
var foo2 = { x: () => {} }; | ||
var bar2 = { x: () => console.log( 'effect' ) }; | ||
var a2 = (unknownValue ? foo2 : bar2).x.y.z; | ||
var b2 = (unknownValue ? foo2 : bar2).x(); | ||
var c2 = (unknownValue ? foo2 : bar2).x = () => console.log( 'effect' ); | ||
foo2.x(); | ||
bar2.x(); | ||
|
||
var bar4 = { x: () => console.log( 'effect' ) }; | ||
var a4 = (bar4).y.z; | ||
var b4 = (bar4).y.z; | ||
var c4 = (bar4).x(); | ||
var d4 = (bar4).x(); | ||
var e4 = (bar4).y.z = 1; | ||
var f4 = (bar4).y.z = 1; | ||
|
||
}))); |
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,39 @@ | ||
var unknownValue = globalFunction(); | ||
|
||
// unknown branch without side-effects | ||
var foo1 = { x: () => {} }; | ||
var bar1 = { x: () => {} }; | ||
var a1 = (unknownValue ? foo1 : bar1).x.y; | ||
var b1 = (unknownValue ? foo1 : bar1).x(); | ||
var c1 = (unknownValue ? foo1 : bar1).x = () => {}; | ||
foo1.x(); | ||
bar1.x(); | ||
|
||
// unknown branch with side-effect | ||
var foo2 = { x: () => {} }; | ||
var bar2 = { x: () => console.log( 'effect' ) }; | ||
var a2 = (unknownValue ? foo2 : bar2).x.y.z; | ||
var b2 = (unknownValue ? foo2 : bar2).x(); | ||
var c2 = (unknownValue ? foo2 : bar2).x = () => console.log( 'effect' ); | ||
foo2.x(); | ||
bar2.x(); | ||
|
||
// no side-effects | ||
var foo3 = { x: () => {}, y: {} }; | ||
var bar3 = { x: () => console.log( 'effect' ) }; | ||
var a3 = (true ? foo3 : bar3).y.z; | ||
var b3 = (false ? bar3 : foo3).y.z; | ||
var c3 = (true ? foo3 : bar3).x(); | ||
var d3 = (false ? bar3 : foo3).x(); | ||
var e3 = (true ? foo3 : bar3).y.z = 1; | ||
var f3 = (false ? bar3 : foo3).y.z = 1; | ||
|
||
// known side-effect | ||
var foo4 = { x: () => {}, y: {} }; | ||
var bar4 = { x: () => console.log( 'effect' ) }; | ||
var a4 = (true ? bar4 : foo4).y.z; | ||
var b4 = (false ? foo4 : bar4).y.z; | ||
var c4 = (true ? bar4 : foo4).x(); | ||
var d4 = (false ? foo4 : bar4).x(); | ||
var e4 = (true ? bar4 : foo4).y.z = 1; | ||
var f4 = (false ? foo4 : bar4).y.z = 1; |
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
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