diff --git a/src/ast/values.ts b/src/ast/values.ts index a0944120665..768687c799c 100644 --- a/src/ast/values.ts +++ b/src/ast/values.ts @@ -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; }, diff --git a/test/function/samples/builtin-prototypes/argument-side-effects/_config.js b/test/function/samples/builtin-prototypes/argument-side-effects/_config.js new file mode 100644 index 00000000000..5e77f83b5cc --- /dev/null +++ b/test/function/samples/builtin-prototypes/argument-side-effects/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'detects side-effects in chained string method arguments' +}; diff --git a/test/function/samples/builtin-prototypes/argument-side-effects/main.js b/test/function/samples/builtin-prototypes/argument-side-effects/main.js new file mode 100644 index 00000000000..91c7d0398e9 --- /dev/null +++ b/test/function/samples/builtin-prototypes/argument-side-effects/main.js @@ -0,0 +1,11 @@ +function getData() { + var data = []; + + 'abc'.trim().replace('b', function() { + data.push('replaced'); + }); + + return data; +} + +assert.deepEqual(getData(), ['replaced']);