Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure property mutations on function arguments are not lost
- Loading branch information
1 parent
4bb67cb
commit 0f9b30e
Showing
6 changed files
with
50 additions
and
3 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
8 changes: 8 additions & 0 deletions
8
test/function/samples/associate-function-return-values-5/_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,8 @@ | ||
var assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'Associates value mutations across return values', | ||
exports: function(exports) { | ||
assert.equal(exports.bar, 'present'); | ||
} | ||
}; |
14 changes: 14 additions & 0 deletions
14
test/function/samples/associate-function-return-values-5/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 @@ | ||
const foo = {value: false}; | ||
const exported = {}; | ||
|
||
function getFoo() { | ||
return foo; | ||
} | ||
|
||
getFoo().value = true; | ||
|
||
if (foo.value) { | ||
exported.bar = 'present' | ||
} | ||
|
||
export default exported; |
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: 'track reassignments of properties of 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,17 @@ | ||
const obj = { | ||
flag: false | ||
}; | ||
|
||
function reassign(x) { | ||
x.flag = true; | ||
} | ||
|
||
reassign(obj); | ||
|
||
let hasBeenReassigned = false; | ||
|
||
if (obj.flag) { | ||
hasBeenReassigned = true; | ||
} | ||
|
||
assert.ok(hasBeenReassigned); |