-
-
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.
Add regression tests for instanceof (#4525)
* Treeshake instanceof * Fix side effect and self-reference handling * Remove feature and add regression test
- Loading branch information
1 parent
30735b4
commit 1792cdf
Showing
10 changed files
with
90 additions
and
9 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: '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 for function parameters' | ||
}; |
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,12 @@ | ||
let effect = false; | ||
|
||
class Foo {} | ||
|
||
function checkInstance(instance) { | ||
if (instance instanceof Foo) { | ||
effect = true; | ||
} | ||
} | ||
|
||
checkInstance(new Foo()); | ||
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'); | ||
} |