Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix side effect and self-reference handling
- Loading branch information
1 parent
ab63d0d
commit 505331c
Showing
15 changed files
with
117 additions
and
41 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
console.log('retained'); | ||
|
||
console.log('retained'); | ||
|
||
class Used1 {} | ||
const Intermediate = Used1; | ||
const used1 = new Used1(); | ||
|
||
if (used1 instanceof Intermediate) console.log('retained'); | ||
else console.log('does not matter'); | ||
|
||
class Used2 {} | ||
|
||
if (new Used2() instanceof Intermediate) console.log('retained'); | ||
else console.log('does not matter'); |
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 |
---|---|---|
@@ -1,17 +1,21 @@ | ||
class Unused1 {} | ||
class Used1 {} | ||
const Intermediate = Used1; | ||
|
||
if (new Intermediate() instanceof Unused1) console.log('removed'); | ||
if ({} instanceof Unused1) console.log('removed'); | ||
else console.log('retained'); | ||
|
||
class Unused2 {} | ||
class WithEffect { | ||
constructor() { | ||
console.log('effect'); | ||
} | ||
} | ||
function Unused2() {} | ||
|
||
if (new WithEffect() instanceof Unused2) | ||
console.log('does not matter, but effect should be retained'); | ||
if ({} instanceof Unused2) console.log('removed'); | ||
else console.log('retained'); | ||
|
||
class Used1 {} | ||
const Intermediate = Used1; | ||
const used1 = new Used1(); | ||
|
||
if (used1 instanceof Intermediate) console.log('retained'); | ||
else console.log('does not matter'); | ||
|
||
class Used2 {} | ||
|
||
if (new Used2() instanceof Intermediate) console.log('retained'); | ||
else console.log('does not matter'); |
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: 'retains side effects in the left hand side of instanceof' | ||
}; |
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,14 @@ | ||
let effect = false; | ||
|
||
class Bar {} | ||
class Foo { | ||
constructor() { | ||
effect = true; | ||
} | ||
} | ||
|
||
if (new Foo() instanceof Bar) { | ||
assert.fail('Wrong instance relation'); | ||
} | ||
|
||
assert.ok(effect); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/instanceof/right-hand-effect/_config.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,3 @@ | ||
module.exports = { | ||
description: 'retains side effects in the right hand side of instanceof' | ||
}; |
14 changes: 14 additions & 0 deletions
14
test/function/samples/instanceof/right-hand-effect/main.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,14 @@ | ||
let effect = false; | ||
|
||
class Foo {} | ||
|
||
if ( | ||
new Foo() instanceof | ||
class { | ||
[(effect = true)]() {} | ||
} | ||
) { | ||
assert.fail('Wrong instance relation'); | ||
} | ||
|
||
assert.ok(effect); |
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: 'retains instanceof if it is true' | ||
}; |
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,5 @@ | ||
class Foo {} | ||
|
||
if (!(new Foo() instanceof Foo)) { | ||
assert.fail('instanceof not resolved correctly'); | ||
} |