Skip to content

Commit

Permalink
Detect side-effects in method arguments of unknown strings (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Oct 3, 2018
1 parent 7f4b543 commit 177b95e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ast/values.ts
Expand Up @@ -254,10 +254,9 @@ const UNKNOWN_LITERAL_STRING: ExpressionEntity = {
},
hasEffectsWhenAccessedAtPath: path => path.length > 1,
hasEffectsWhenAssignedAtPath: path => path.length > 0,
hasEffectsWhenCalledAtPath: path => {
hasEffectsWhenCalledAtPath: (path, callOptions, options) => {
if (path.length === 1) {
const subPath = path[0];
return typeof subPath !== 'string' || !literalStringMembers[subPath];
return hasMemberEffectWhenCalled(literalStringMembers, path[0], true, callOptions, options);
}
return true;
},
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
description: 'detects side-effects in chained string method arguments'
};
@@ -0,0 +1,11 @@
function getData() {
var data = [];

'abc'.trim().replace('b', function() {
data.push('replaced');
});

return data;
}

assert.deepEqual(getData(), ['replaced']);

0 comments on commit 177b95e

Please sign in to comment.