-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(instrumentor): Do not run the arithmetic operator mutator on obvious string concatenations #2648
fix(instrumentor): Do not run the arithmetic operator mutator on obvious string concatenations #2648
Conversation
…ous string concatenations
return false; | ||
} | ||
|
||
const stringTypes = ['StringLiteral', 'TemplateLiteral']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further thought, this should probably be a whitelist not a blacklist. It's a bit weird, but something like:
const log = (thingToLog) => console.log(thingToLog);
const concat = 1 + log;
console.log(concat)
Will result in "1(thingToLog) => console.log(thingToLog)"
. What do you think @nicojs, should we do a whitelist of things that actually make sense for an ArithmeticOperator, or keep it simple and only make exceptions for strings and template strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a whitelist can become big and hard(er) to maintain. I personally think this is fine to start with. It's better than what we have now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Don't mutate `"a" + "b"` into `"a" - "b"`. This only works for 'obvious' string concats.
As discussed in #2646, this is a shallow "Best-effort" approach to not mutating obvious string concatenations