From b5cd46e3e22958ff20e158ba057ec946e58d4a43 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 27 May 2022 06:45:25 +0200 Subject: [PATCH] Improve coverage --- src/ast/nodes/BinaryExpression.ts | 5 +++-- src/ast/nodes/shared/MethodTypes.ts | 12 +----------- .../samples/parameter-side-effects/_config.js | 3 +++ test/function/samples/parameter-side-effects/main.js | 12 ++++++++++++ 4 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 test/function/samples/parameter-side-effects/_config.js create mode 100644 test/function/samples/parameter-side-effects/main.js diff --git a/src/ast/nodes/BinaryExpression.ts b/src/ast/nodes/BinaryExpression.ts index ef04e55d416..4f38da0106b 100644 --- a/src/ast/nodes/BinaryExpression.ts +++ b/src/ast/nodes/BinaryExpression.ts @@ -40,9 +40,10 @@ const binaryOperators: { '>>': (left: any, right: any) => left >> right, '>>>': (left: any, right: any) => left >>> right, '^': (left: any, right: any) => left ^ right, - in: () => UnknownValue, - instanceof: () => UnknownValue, '|': (left: any, right: any) => left | right + // We use the fallback for cases where we return something unknown + // in: () => UnknownValue, + // instanceof: () => UnknownValue, }; export default class BinaryExpression extends NodeBase implements DeoptimizableEntity { diff --git a/src/ast/nodes/shared/MethodTypes.ts b/src/ast/nodes/shared/MethodTypes.ts index 5c1c874a4cb..f2cb1ea95a5 100644 --- a/src/ast/nodes/shared/MethodTypes.ts +++ b/src/ast/nodes/shared/MethodTypes.ts @@ -1,5 +1,5 @@ import { type CallOptions, NO_ARGS } from '../../CallOptions'; -import type { HasEffectsContext, InclusionContext } from '../../ExecutionContext'; +import type { HasEffectsContext } from '../../ExecutionContext'; import { EVENT_CALLED, type NodeEvent } from '../../NodeEvents'; import { EMPTY_PATH, type ObjectPath, UNKNOWN_INTEGER_PATH } from '../../utils/PathTracker'; import { @@ -7,7 +7,6 @@ import { UNKNOWN_LITERAL_NUMBER, UNKNOWN_LITERAL_STRING } from '../../values'; -import type SpreadElement from '../SpreadElement'; import { ExpressionEntity, UNKNOWN_EXPRESSION } from './Expression'; type MethodDescription = { @@ -94,15 +93,6 @@ export class Method extends ExpressionEntity { } return false; } - - includeCallArguments( - context: InclusionContext, - args: readonly (ExpressionEntity | SpreadElement)[] - ): void { - for (const arg of args) { - arg.include(context, false); - } - } } export const METHOD_RETURNS_BOOLEAN = [ diff --git a/test/function/samples/parameter-side-effects/_config.js b/test/function/samples/parameter-side-effects/_config.js new file mode 100644 index 00000000000..a2379c5f5c8 --- /dev/null +++ b/test/function/samples/parameter-side-effects/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'retains calls with parameter side effects' +}; diff --git a/test/function/samples/parameter-side-effects/main.js b/test/function/samples/parameter-side-effects/main.js new file mode 100644 index 00000000000..1ab1f23b307 --- /dev/null +++ b/test/function/samples/parameter-side-effects/main.js @@ -0,0 +1,12 @@ +let effect = false; + +function getPatternValueWithEffect() { + effect = true; + return 'value'; +} + +function test({ [getPatternValueWithEffect()]: value }) {} + +test({ value: 'foo' }); + +assert.ok(effect);