From 75f36d15024a9fa0c8edfeb5217527836ebd818e Mon Sep 17 00:00:00 2001 From: Lukas Taegert Date: Sat, 4 Nov 2017 22:28:35 +0100 Subject: [PATCH] Remove parameter binding logic as it has abysmal performance in its current form. This also makes bindCallAtPath obsolete again. Instead we always assume that parameters have unknown values when determining side effects. The hack that calling a member of an included variable is always a side effect also needs to stay in place until we find a way to determine with absolute certainty it was not overridden e.g. by assuming unknown function calls always mutate their parameters. --- src/ast/Node.js | 9 --- src/ast/nodes/ArrowFunctionExpression.js | 10 +--- src/ast/nodes/CallExpression.js | 7 --- src/ast/nodes/ClassBody.js | 6 -- src/ast/nodes/ConditionalExpression.js | 4 -- src/ast/nodes/Identifier.js | 6 -- src/ast/nodes/LogicalExpression.js | 4 -- src/ast/nodes/MemberExpression.js | 9 --- src/ast/nodes/MethodDefinition.js | 5 -- src/ast/nodes/NewExpression.js | 4 -- src/ast/nodes/ObjectExpression.js | 8 --- src/ast/nodes/Property.js | 17 +----- src/ast/nodes/shared/ClassNode.js | 5 -- src/ast/nodes/shared/FunctionNode.js | 6 -- src/ast/scopes/FunctionScope.js | 4 +- src/ast/scopes/ParameterScope.js | 14 ----- src/ast/scopes/ReturnValueScope.js | 6 +- src/ast/values.js | 1 - src/ast/variables/LocalVariable.js | 12 +--- src/ast/variables/Variable.js | 9 --- .../_expected/amd.js | 36 +++++------ .../_expected/cjs.js | 36 +++++------ .../_expected/es.js | 36 +++++------ .../_expected/iife.js | 36 +++++------ .../_expected/umd.js | 36 +++++------ .../arrow-function-call-parameters/main.js | 60 +++++-------------- .../function-call-parameters/_expected/amd.js | 1 - .../function-call-parameters/_expected/cjs.js | 1 - .../function-call-parameters/_expected/es.js | 1 - .../_expected/iife.js | 1 - .../function-call-parameters/_expected/umd.js | 1 - .../samples/function-call-parameters/main.js | 22 ------- 32 files changed, 113 insertions(+), 300 deletions(-) diff --git a/src/ast/Node.js b/src/ast/Node.js index 6a87b511032..caf3fbead86 100644 --- a/src/ast/Node.js +++ b/src/ast/Node.js @@ -31,15 +31,6 @@ export default class Node { */ bindAssignmentAtPath ( path, expression, options ) {} - /** - * Binds the arguments a node is called with to this node and possibly its parameters. - * Should usually be overridden together with hasEffectsWhenCalled. - * @param {String[]} path - * @param {CallOptions} callOptions - * @param {ExecutionPathOptions} options - */ - bindCallAtPath ( path, callOptions, options ) {} - /** * Override to control on which children "bind" is called. */ diff --git a/src/ast/nodes/ArrowFunctionExpression.js b/src/ast/nodes/ArrowFunctionExpression.js index 43f77b5174a..f7c1c2ff6df 100644 --- a/src/ast/nodes/ArrowFunctionExpression.js +++ b/src/ast/nodes/ArrowFunctionExpression.js @@ -3,11 +3,6 @@ import Scope from '../scopes/Scope'; import ReturnValueScope from '../scopes/ReturnValueScope'; export default class ArrowFunctionExpression extends Node { - bindCallAtPath ( path, { args } ) { - path.length === 0 - && this.scope.bindCallArguments( args ); - } - bindNode () { this.body.bindImplicitReturnExpressionToScope ? this.body.bindImplicitReturnExpressionToScope() @@ -35,9 +30,8 @@ export default class ArrowFunctionExpression extends Node { if ( path.length > 0 ) { return true; } - const innerOptions = this.scope.getOptionsWithReplacedParameters( callOptions.args, options ); - return this.params.some( param => param.hasEffects( innerOptions ) ) - || this.body.hasEffects( innerOptions ); + return this.params.some( param => param.hasEffects( options ) ) + || this.body.hasEffects( options ); } initialiseChildren () { diff --git a/src/ast/nodes/CallExpression.js b/src/ast/nodes/CallExpression.js index 189c5f7dde7..e51257b4e0c 100644 --- a/src/ast/nodes/CallExpression.js +++ b/src/ast/nodes/CallExpression.js @@ -9,12 +9,6 @@ export default class CallExpression extends Node { node.bindAssignmentAtPath( path, expression, innerOptions.addAssignedReturnExpressionAtPath( path, this ) ), options ); } - bindCallAtPath ( path, callOptions, options ) { - !options.hasReturnExpressionBeenCalledAtPath( path, this ) - && this.callee.forEachReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node => - node.bindCallAtPath( path, callOptions, innerOptions.addCalledReturnExpressionAtPath( path, this ) ), options ); - } - bindNode () { if ( this.callee.type === 'Identifier' ) { const variable = this.scope.findVariable( this.callee.name ); @@ -34,7 +28,6 @@ export default class CallExpression extends Node { }, this.start ); } } - this.callee.bindCallAtPath( [], this._callOptions, ExecutionPathOptions.create() ); } forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { diff --git a/src/ast/nodes/ClassBody.js b/src/ast/nodes/ClassBody.js index 6ece0dd9644..1bce2c0aec6 100644 --- a/src/ast/nodes/ClassBody.js +++ b/src/ast/nodes/ClassBody.js @@ -1,12 +1,6 @@ import Node from '../Node'; export default class ClassBody extends Node { - bindCallAtPath ( path, callOptions, options ) { - path.length === 0 - && this.classConstructor - && this.classConstructor.bindCallAtPath( path, callOptions, options ); - } - hasEffectsWhenCalledAtPath ( path, callOptions, options ) { if ( path.length > 0 ) { return true; diff --git a/src/ast/nodes/ConditionalExpression.js b/src/ast/nodes/ConditionalExpression.js index 1dc2b3af395..178f4bc655e 100644 --- a/src/ast/nodes/ConditionalExpression.js +++ b/src/ast/nodes/ConditionalExpression.js @@ -7,10 +7,6 @@ export default class ConditionalExpression extends Node { && this._forEachRelevantBranch( node => node.bindAssignmentAtPath( path, expression, options ) ); } - bindCallAtPath ( path, callOptions, options ) { - this._forEachRelevantBranch( node => node.bindCallAtPath( path, callOptions, options ) ); - } - forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { this._forEachRelevantBranch( node => node.forEachReturnExpressionWhenCalledAtPath( path, callOptions, callback, options ) ); } diff --git a/src/ast/nodes/Identifier.js b/src/ast/nodes/Identifier.js index b256d56ba6f..153b4c0e3f4 100644 --- a/src/ast/nodes/Identifier.js +++ b/src/ast/nodes/Identifier.js @@ -9,12 +9,6 @@ export default class Identifier extends Node { && this.variable.bindAssignmentAtPath( path, expression, options ); } - bindCallAtPath ( path, callOptions, options ) { - this._bindVariableIfMissing(); - this.variable - && this.variable.bindCallAtPath( path, callOptions, options ); - } - bindNode () { this._bindVariableIfMissing(); } diff --git a/src/ast/nodes/LogicalExpression.js b/src/ast/nodes/LogicalExpression.js index fd66e15e6de..3048df12d88 100644 --- a/src/ast/nodes/LogicalExpression.js +++ b/src/ast/nodes/LogicalExpression.js @@ -7,10 +7,6 @@ export default class LogicalExpression extends Node { && this._forEachRelevantBranch( node => node.bindAssignmentAtPath( path, expression, options ) ); } - bindCallAtPath ( path, callOptions, options ) { - this._forEachRelevantBranch( node => node.bindCallAtPath( path, callOptions, options ) ); - } - forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { this._forEachRelevantBranch( node => node.forEachReturnExpressionWhenCalledAtPath( path, callOptions, callback, options ) ); } diff --git a/src/ast/nodes/MemberExpression.js b/src/ast/nodes/MemberExpression.js index a781f75f60a..c417dcd3fdf 100644 --- a/src/ast/nodes/MemberExpression.js +++ b/src/ast/nodes/MemberExpression.js @@ -85,15 +85,6 @@ export default class MemberExpression extends Node { } } - bindCallAtPath ( path, callOptions, options ) { - if ( !this._bound ) this.bind(); - if ( this.variable ) { - this.variable.bindCallAtPath( path, callOptions, options ); - } else { - this.object.bindCallAtPath( [ this._getPathSegment(), ...path ], callOptions, options ); - } - } - forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { if ( !this._bound ) this.bind(); if ( this.variable ) { diff --git a/src/ast/nodes/MethodDefinition.js b/src/ast/nodes/MethodDefinition.js index f192f1f1b66..2e64d5e5f92 100644 --- a/src/ast/nodes/MethodDefinition.js +++ b/src/ast/nodes/MethodDefinition.js @@ -1,11 +1,6 @@ import Node from '../Node'; export default class MethodDefinition extends Node { - bindCallAtPath ( path, callOptions, options ) { - path.length === 0 - && this.value.bindCallAtPath( path, callOptions, options ); - } - hasEffects ( options ) { return this.key.hasEffects( options ); } diff --git a/src/ast/nodes/NewExpression.js b/src/ast/nodes/NewExpression.js index 4717bca4213..e19781c6e6a 100644 --- a/src/ast/nodes/NewExpression.js +++ b/src/ast/nodes/NewExpression.js @@ -3,10 +3,6 @@ import CallOptions from '../CallOptions'; import ExecutionPathOptions from '../ExecutionPathOptions'; export default class NewExpression extends Node { - bindNode () { - this.callee.bindCallAtPath( [], this._callOptions, ExecutionPathOptions.create() ); - } - hasEffects ( options ) { return this.arguments.some( child => child.hasEffects( options ) ) || this.callee.hasEffectsWhenCalledAtPath( [], this._callOptions, options.getHasEffectsWhenCalledOptions() ); diff --git a/src/ast/nodes/ObjectExpression.js b/src/ast/nodes/ObjectExpression.js index 901b307b011..a4c33728bf8 100644 --- a/src/ast/nodes/ObjectExpression.js +++ b/src/ast/nodes/ObjectExpression.js @@ -15,14 +15,6 @@ export default class ObjectExpression extends Node { && property.bindAssignmentAtPath( path.slice( 1 ), expression, options ) ); } - bindCallAtPath ( path, callOptions, options ) { - if ( path.length === 0 ) return; - - const { properties, hasCertainHit } = this._getPossiblePropertiesWithName( path[ 0 ], PROPERTY_KINDS_READ ); - hasCertainHit && properties.forEach( property => - property.bindCallAtPath( path.slice( 1 ), callOptions, options ) ); - } - forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { if ( path.length === 0 ) return; diff --git a/src/ast/nodes/Property.js b/src/ast/nodes/Property.js index af37a8c341e..d71b688e8c0 100644 --- a/src/ast/nodes/Property.js +++ b/src/ast/nodes/Property.js @@ -8,28 +8,13 @@ export default class Property extends Node { path.length > 0 && this.value.forEachReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node => node.bindAssignmentAtPath( path, expression, innerOptions.addAssignedReturnExpressionAtPath( path, this ) ), options ); - } else if ( this.kind === 'set' ) { - path.length === 0 - && this.value.bindCallAtPath( [], CallOptions.create( { withNew: false, args: [ expression ], caller: this } ), options ); - } else { + } else if ( this.kind !== 'set' ) { this.value.bindAssignmentAtPath( path, expression, options ); } } - bindCallAtPath ( path, callOptions, options ) { - if ( this.kind === 'get' ) { - this.value.bindCallAtPath( [], this._accessorCallOptions, options ); - !options.hasReturnExpressionBeenCalledAtPath( path, this ) - && this.value.forEachReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node => - node.bindCallAtPath( path, callOptions, innerOptions.addCalledReturnExpressionAtPath( path, this ) ), options ); - } else { - this.value.bindCallAtPath( path, callOptions, options ); - } - } - forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { if ( this.kind === 'get' ) { - this.value.bindCallAtPath( [], this._accessorCallOptions, options ); this.value.forEachReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node => node.forEachReturnExpressionWhenCalledAtPath( path, callOptions, callback, innerOptions ), options ); } else { diff --git a/src/ast/nodes/shared/ClassNode.js b/src/ast/nodes/shared/ClassNode.js index e61848ad841..c7fe7773d2f 100644 --- a/src/ast/nodes/shared/ClassNode.js +++ b/src/ast/nodes/shared/ClassNode.js @@ -2,11 +2,6 @@ import Node from '../../Node.js'; import Scope from '../../scopes/Scope'; export default class ClassNode extends Node { - bindCallAtPath ( path, callOptions, options ) { - this.body.bindCallAtPath( path, callOptions, options ); - this.superClass && this.superClass.bindCallAtPath( path, callOptions, options ); - } - hasEffectsWhenAccessedAtPath ( path ) { return path.length > 1; } diff --git a/src/ast/nodes/shared/FunctionNode.js b/src/ast/nodes/shared/FunctionNode.js index 3a7d1a16470..4ff27a3d3a4 100644 --- a/src/ast/nodes/shared/FunctionNode.js +++ b/src/ast/nodes/shared/FunctionNode.js @@ -3,12 +3,6 @@ import FunctionScope from '../../scopes/FunctionScope'; import VirtualObjectExpression from './VirtualObjectExpression'; export default class FunctionNode extends Node { - bindCallAtPath ( path, { args } ) { - if ( path.length === 0 ) { - this.scope.bindCallArguments( args ); - } - } - bindNode () { this.body.bindImplicitReturnExpressionToScope(); } diff --git a/src/ast/scopes/FunctionScope.js b/src/ast/scopes/FunctionScope.js index 5ebd5726771..f97abb261ec 100644 --- a/src/ast/scopes/FunctionScope.js +++ b/src/ast/scopes/FunctionScope.js @@ -16,8 +16,8 @@ export default class FunctionScope extends ReturnValueScope { } getOptionsWhenCalledWith ( { args, withNew }, options ) { - return super.getOptionsWithReplacedParameters( args, options ) + return options .replaceVariableInit( this.variables.this, withNew ? new VirtualObjectExpression() : UNKNOWN_ASSIGNMENT ) - .setArgumentsVariables( args.map( ( parameter, index ) => super.getParameterVariables()[index] || parameter) ); + .setArgumentsVariables( args.map( ( parameter, index ) => super.getParameterVariables()[ index ] || parameter ) ); } } diff --git a/src/ast/scopes/ParameterScope.js b/src/ast/scopes/ParameterScope.js index e0cf6d6a98d..247a0875863 100644 --- a/src/ast/scopes/ParameterScope.js +++ b/src/ast/scopes/ParameterScope.js @@ -1,6 +1,5 @@ import Scope from './Scope'; import ParameterVariable from '../variables/ParameterVariable'; -import { UNKNOWN_ASSIGNMENT } from '../values'; export default class ParameterScope extends Scope { constructor ( options = {} ) { @@ -21,19 +20,6 @@ export default class ParameterScope extends Scope { return variable; } - bindCallArguments ( args ) { - this._parameters.forEach( ( parameter, index ) => - parameter.bindInitialization( args[ index ] || UNKNOWN_ASSIGNMENT ) ); - } - - getOptionsWithReplacedParameters ( args, options ) { - let newOptions = options; - this._parameters.forEach( ( parameter, index ) => - newOptions = newOptions.replaceVariableInit( parameter, args[ index ] || UNKNOWN_ASSIGNMENT ) - ); - return newOptions; - } - getParameterVariables () { return this._parameters; } diff --git a/src/ast/scopes/ReturnValueScope.js b/src/ast/scopes/ReturnValueScope.js index b628c063e3b..497ff7fc895 100644 --- a/src/ast/scopes/ReturnValueScope.js +++ b/src/ast/scopes/ReturnValueScope.js @@ -11,12 +11,10 @@ export default class ReturnValueScope extends ParameterScope { } forEachReturnExpressionWhenCalled ( callOptions, callback, options ) { - const innerOptions = this.getOptionsWithReplacedParameters( callOptions.args, options ); - this._returnExpressions.forEach( callback( innerOptions ) ); + this._returnExpressions.forEach( callback( options ) ); } someReturnExpressionWhenCalled ( callOptions, predicateFunction, options ) { - const innerOptions = this.getOptionsWithReplacedParameters( callOptions.args, options ); - return Array.from( this._returnExpressions ).some( predicateFunction( innerOptions ) ); + return Array.from( this._returnExpressions ).some( predicateFunction( options ) ); } } diff --git a/src/ast/values.js b/src/ast/values.js index 8d97af1d64f..41207c9cfee 100644 --- a/src/ast/values.js +++ b/src/ast/values.js @@ -3,7 +3,6 @@ export const UNKNOWN_VALUE = { toString: () => '[[UNKNOWN]]' }; export const UNKNOWN_ASSIGNMENT = { type: 'UNKNOWN', bindAssignmentAtPath: () => {}, - bindCallAtPath: () => {}, forEachReturnExpressionWhenCalledAtPath: () => {}, hasEffectsWhenAccessedAtPath: path => path.length > 0, hasEffectsWhenAssignedAtPath: path => path.length > 0, diff --git a/src/ast/variables/LocalVariable.js b/src/ast/variables/LocalVariable.js index ceda4c8a3c9..8142f18f112 100644 --- a/src/ast/variables/LocalVariable.js +++ b/src/ast/variables/LocalVariable.js @@ -2,7 +2,7 @@ import Variable from './Variable'; import StructuredAssignmentTracker from './StructuredAssignmentTracker'; // To avoid infinite recursions -const MAX_PATH_LENGTH = 8; +const MAX_PATH_LENGTH = 6; export default class LocalVariable extends Variable { constructor ( name, declarator, init ) { @@ -12,7 +12,6 @@ export default class LocalVariable extends Variable { this.declarations = new Set( declarator ? [ declarator ] : null ); this.boundExpressions = new StructuredAssignmentTracker(); init && this.boundExpressions.addAtPath( [], init ); - this.boundCalls = new StructuredAssignmentTracker(); } addDeclaration ( identifier ) { @@ -32,15 +31,6 @@ export default class LocalVariable extends Variable { } else { this.isReassigned = true; } - this.boundCalls.forEachAtPath( path, ( relativePath, callOptions ) => - expression.bindCallAtPath( relativePath, callOptions, options ) ); - } - - bindCallAtPath ( path, callOptions, options ) { - if ( path.length > MAX_PATH_LENGTH || this.boundCalls.hasAtPath( path, callOptions ) ) return; - this.boundCalls.addAtPath( path, callOptions ); - this.boundExpressions.forEachAtPath( path, ( relativePath, node ) => - node.bindCallAtPath( relativePath, callOptions, options ) ); } forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) { diff --git a/src/ast/variables/Variable.js b/src/ast/variables/Variable.js index 27f98d89b0a..1c443a494eb 100644 --- a/src/ast/variables/Variable.js +++ b/src/ast/variables/Variable.js @@ -23,15 +23,6 @@ export default class Variable { */ bindAssignmentAtPath ( path, expression, options ) {} - /** - * Binds a call to this node. Necessary to be able to bind arguments - * to parameters. - * @param {String[]} path - * @param {CallOptions} callOptions - * @param {ExecutionPathOptions} options - */ - bindCallAtPath ( path, callOptions, options ) {} - /** * @param {String[]} path * @param {CallOptions} callOptions diff --git a/test/form/samples/arrow-function-call-parameters/_expected/amd.js b/test/form/samples/arrow-function-call-parameters/_expected/amd.js index 3e609d33362..3e20fc5fe5f 100644 --- a/test/form/samples/arrow-function-call-parameters/_expected/amd.js +++ b/test/form/samples/arrow-function-call-parameters/_expected/amd.js @@ -1,33 +1,33 @@ define(function () { 'use strict'; - const callArg2 = arg => arg(); - callArg2( () => console.log( 'effect' ) ); + const callArg = arg => arg(); + callArg( () => console.log( 'effect' ) ); - const assignArg2 = arg => arg.foo.bar = 1; - assignArg2( {} ); + const assignArg = arg => arg.foo.bar = 1; + assignArg( {} ); + + const returnArg = arg => arg; + returnArg( () => console.log( 'effect' ) )(); const returnArg2 = arg => arg; - returnArg2( () => console.log( 'effect' ) )(); + returnArg2( {} ).foo.bar = 1; - const returnArg4 = arg => arg; - returnArg4( {} ).foo.bar = 1; + const returnArg3 = arg => arg; + returnArg3( () => () => console.log( 'effect' ) )()(); - const returnArg6 = arg => arg; - returnArg6( () => () => console.log( 'effect' ) )()(); + const returnArgReturn = arg => arg(); + returnArgReturn( () => () => console.log( 'effect' ) )(); const returnArgReturn2 = arg => arg(); - returnArgReturn2( () => () => console.log( 'effect' ) )(); + returnArgReturn2( () => ({}) ).foo.bar = 1; - const returnArgReturn4 = arg => arg(); - returnArgReturn4( () => ({}) ).foo.bar = 1; + const returnArgReturn3 = arg => arg(); + returnArgReturn3( () => () => () => console.log( 'effect' ) )()(); - const returnArgReturn6 = arg => arg(); - returnArgReturn6( () => () => () => console.log( 'effect' ) )()(); + const multiArgument = ( func, obj ) => func( obj ); + multiArgument( obj => obj(), () => console.log( 'effect' ) ); const multiArgument2 = ( func, obj ) => func( obj ); - multiArgument2( obj => obj(), () => console.log( 'effect' ) ); - - const multiArgument4 = ( func, obj ) => func( obj ); - multiArgument4( obj => obj.foo.bar = 1, {} ); + multiArgument2( obj => obj.foo.bar = 1, {} ); }); diff --git a/test/form/samples/arrow-function-call-parameters/_expected/cjs.js b/test/form/samples/arrow-function-call-parameters/_expected/cjs.js index 02a5835d466..afc702f801c 100644 --- a/test/form/samples/arrow-function-call-parameters/_expected/cjs.js +++ b/test/form/samples/arrow-function-call-parameters/_expected/cjs.js @@ -1,31 +1,31 @@ 'use strict'; -const callArg2 = arg => arg(); -callArg2( () => console.log( 'effect' ) ); +const callArg = arg => arg(); +callArg( () => console.log( 'effect' ) ); -const assignArg2 = arg => arg.foo.bar = 1; -assignArg2( {} ); +const assignArg = arg => arg.foo.bar = 1; +assignArg( {} ); + +const returnArg = arg => arg; +returnArg( () => console.log( 'effect' ) )(); const returnArg2 = arg => arg; -returnArg2( () => console.log( 'effect' ) )(); +returnArg2( {} ).foo.bar = 1; -const returnArg4 = arg => arg; -returnArg4( {} ).foo.bar = 1; +const returnArg3 = arg => arg; +returnArg3( () => () => console.log( 'effect' ) )()(); -const returnArg6 = arg => arg; -returnArg6( () => () => console.log( 'effect' ) )()(); +const returnArgReturn = arg => arg(); +returnArgReturn( () => () => console.log( 'effect' ) )(); const returnArgReturn2 = arg => arg(); -returnArgReturn2( () => () => console.log( 'effect' ) )(); +returnArgReturn2( () => ({}) ).foo.bar = 1; -const returnArgReturn4 = arg => arg(); -returnArgReturn4( () => ({}) ).foo.bar = 1; +const returnArgReturn3 = arg => arg(); +returnArgReturn3( () => () => () => console.log( 'effect' ) )()(); -const returnArgReturn6 = arg => arg(); -returnArgReturn6( () => () => () => console.log( 'effect' ) )()(); +const multiArgument = ( func, obj ) => func( obj ); +multiArgument( obj => obj(), () => console.log( 'effect' ) ); const multiArgument2 = ( func, obj ) => func( obj ); -multiArgument2( obj => obj(), () => console.log( 'effect' ) ); - -const multiArgument4 = ( func, obj ) => func( obj ); -multiArgument4( obj => obj.foo.bar = 1, {} ); +multiArgument2( obj => obj.foo.bar = 1, {} ); diff --git a/test/form/samples/arrow-function-call-parameters/_expected/es.js b/test/form/samples/arrow-function-call-parameters/_expected/es.js index 3f1479c5d0d..02f05c52ae2 100644 --- a/test/form/samples/arrow-function-call-parameters/_expected/es.js +++ b/test/form/samples/arrow-function-call-parameters/_expected/es.js @@ -1,29 +1,29 @@ -const callArg2 = arg => arg(); -callArg2( () => console.log( 'effect' ) ); +const callArg = arg => arg(); +callArg( () => console.log( 'effect' ) ); -const assignArg2 = arg => arg.foo.bar = 1; -assignArg2( {} ); +const assignArg = arg => arg.foo.bar = 1; +assignArg( {} ); + +const returnArg = arg => arg; +returnArg( () => console.log( 'effect' ) )(); const returnArg2 = arg => arg; -returnArg2( () => console.log( 'effect' ) )(); +returnArg2( {} ).foo.bar = 1; -const returnArg4 = arg => arg; -returnArg4( {} ).foo.bar = 1; +const returnArg3 = arg => arg; +returnArg3( () => () => console.log( 'effect' ) )()(); -const returnArg6 = arg => arg; -returnArg6( () => () => console.log( 'effect' ) )()(); +const returnArgReturn = arg => arg(); +returnArgReturn( () => () => console.log( 'effect' ) )(); const returnArgReturn2 = arg => arg(); -returnArgReturn2( () => () => console.log( 'effect' ) )(); +returnArgReturn2( () => ({}) ).foo.bar = 1; -const returnArgReturn4 = arg => arg(); -returnArgReturn4( () => ({}) ).foo.bar = 1; +const returnArgReturn3 = arg => arg(); +returnArgReturn3( () => () => () => console.log( 'effect' ) )()(); -const returnArgReturn6 = arg => arg(); -returnArgReturn6( () => () => () => console.log( 'effect' ) )()(); +const multiArgument = ( func, obj ) => func( obj ); +multiArgument( obj => obj(), () => console.log( 'effect' ) ); const multiArgument2 = ( func, obj ) => func( obj ); -multiArgument2( obj => obj(), () => console.log( 'effect' ) ); - -const multiArgument4 = ( func, obj ) => func( obj ); -multiArgument4( obj => obj.foo.bar = 1, {} ); +multiArgument2( obj => obj.foo.bar = 1, {} ); diff --git a/test/form/samples/arrow-function-call-parameters/_expected/iife.js b/test/form/samples/arrow-function-call-parameters/_expected/iife.js index 923053db68a..bf1dab98c27 100644 --- a/test/form/samples/arrow-function-call-parameters/_expected/iife.js +++ b/test/form/samples/arrow-function-call-parameters/_expected/iife.js @@ -1,34 +1,34 @@ (function () { 'use strict'; - const callArg2 = arg => arg(); - callArg2( () => console.log( 'effect' ) ); + const callArg = arg => arg(); + callArg( () => console.log( 'effect' ) ); - const assignArg2 = arg => arg.foo.bar = 1; - assignArg2( {} ); + const assignArg = arg => arg.foo.bar = 1; + assignArg( {} ); + + const returnArg = arg => arg; + returnArg( () => console.log( 'effect' ) )(); const returnArg2 = arg => arg; - returnArg2( () => console.log( 'effect' ) )(); + returnArg2( {} ).foo.bar = 1; - const returnArg4 = arg => arg; - returnArg4( {} ).foo.bar = 1; + const returnArg3 = arg => arg; + returnArg3( () => () => console.log( 'effect' ) )()(); - const returnArg6 = arg => arg; - returnArg6( () => () => console.log( 'effect' ) )()(); + const returnArgReturn = arg => arg(); + returnArgReturn( () => () => console.log( 'effect' ) )(); const returnArgReturn2 = arg => arg(); - returnArgReturn2( () => () => console.log( 'effect' ) )(); + returnArgReturn2( () => ({}) ).foo.bar = 1; - const returnArgReturn4 = arg => arg(); - returnArgReturn4( () => ({}) ).foo.bar = 1; + const returnArgReturn3 = arg => arg(); + returnArgReturn3( () => () => () => console.log( 'effect' ) )()(); - const returnArgReturn6 = arg => arg(); - returnArgReturn6( () => () => () => console.log( 'effect' ) )()(); + const multiArgument = ( func, obj ) => func( obj ); + multiArgument( obj => obj(), () => console.log( 'effect' ) ); const multiArgument2 = ( func, obj ) => func( obj ); - multiArgument2( obj => obj(), () => console.log( 'effect' ) ); - - const multiArgument4 = ( func, obj ) => func( obj ); - multiArgument4( obj => obj.foo.bar = 1, {} ); + multiArgument2( obj => obj.foo.bar = 1, {} ); }()); diff --git a/test/form/samples/arrow-function-call-parameters/_expected/umd.js b/test/form/samples/arrow-function-call-parameters/_expected/umd.js index 5f39801aad8..039cd740cdf 100644 --- a/test/form/samples/arrow-function-call-parameters/_expected/umd.js +++ b/test/form/samples/arrow-function-call-parameters/_expected/umd.js @@ -4,34 +4,34 @@ (factory()); }(this, (function () { 'use strict'; - const callArg2 = arg => arg(); - callArg2( () => console.log( 'effect' ) ); + const callArg = arg => arg(); + callArg( () => console.log( 'effect' ) ); - const assignArg2 = arg => arg.foo.bar = 1; - assignArg2( {} ); + const assignArg = arg => arg.foo.bar = 1; + assignArg( {} ); + + const returnArg = arg => arg; + returnArg( () => console.log( 'effect' ) )(); const returnArg2 = arg => arg; - returnArg2( () => console.log( 'effect' ) )(); + returnArg2( {} ).foo.bar = 1; - const returnArg4 = arg => arg; - returnArg4( {} ).foo.bar = 1; + const returnArg3 = arg => arg; + returnArg3( () => () => console.log( 'effect' ) )()(); - const returnArg6 = arg => arg; - returnArg6( () => () => console.log( 'effect' ) )()(); + const returnArgReturn = arg => arg(); + returnArgReturn( () => () => console.log( 'effect' ) )(); const returnArgReturn2 = arg => arg(); - returnArgReturn2( () => () => console.log( 'effect' ) )(); + returnArgReturn2( () => ({}) ).foo.bar = 1; - const returnArgReturn4 = arg => arg(); - returnArgReturn4( () => ({}) ).foo.bar = 1; + const returnArgReturn3 = arg => arg(); + returnArgReturn3( () => () => () => console.log( 'effect' ) )()(); - const returnArgReturn6 = arg => arg(); - returnArgReturn6( () => () => () => console.log( 'effect' ) )()(); + const multiArgument = ( func, obj ) => func( obj ); + multiArgument( obj => obj(), () => console.log( 'effect' ) ); const multiArgument2 = ( func, obj ) => func( obj ); - multiArgument2( obj => obj(), () => console.log( 'effect' ) ); - - const multiArgument4 = ( func, obj ) => func( obj ); - multiArgument4( obj => obj.foo.bar = 1, {} ); + multiArgument2( obj => obj.foo.bar = 1, {} ); }))); diff --git a/test/form/samples/arrow-function-call-parameters/main.js b/test/form/samples/arrow-function-call-parameters/main.js index 4334ee1bcad..02f05c52ae2 100644 --- a/test/form/samples/arrow-function-call-parameters/main.js +++ b/test/form/samples/arrow-function-call-parameters/main.js @@ -1,59 +1,29 @@ -const callArg1 = arg => arg(); -callArg1( () => {} ); +const callArg = arg => arg(); +callArg( () => console.log( 'effect' ) ); -const callArg2 = arg => arg(); -callArg2( () => console.log( 'effect' ) ); +const assignArg = arg => arg.foo.bar = 1; +assignArg( {} ); -const assignArg1 = arg => arg.foo.bar = 1; -assignArg1( { foo: {} } ); - -const assignArg2 = arg => arg.foo.bar = 1; -assignArg2( {} ); - -const returnArg1 = arg => arg; -returnArg1( () => {} )(); +const returnArg = arg => arg; +returnArg( () => console.log( 'effect' ) )(); const returnArg2 = arg => arg; -returnArg2( () => console.log( 'effect' ) )(); +returnArg2( {} ).foo.bar = 1; const returnArg3 = arg => arg; -returnArg3( { foo: {} } ).foo.bar = 1; - -const returnArg4 = arg => arg; -returnArg4( {} ).foo.bar = 1; - -const returnArg5 = arg => arg; -returnArg5( () => () => {} )()(); - -const returnArg6 = arg => arg; -returnArg6( () => () => console.log( 'effect' ) )()(); +returnArg3( () => () => console.log( 'effect' ) )()(); -const returnArgReturn1 = arg => arg(); -returnArgReturn1( () => () => {} )(); +const returnArgReturn = arg => arg(); +returnArgReturn( () => () => console.log( 'effect' ) )(); const returnArgReturn2 = arg => arg(); -returnArgReturn2( () => () => console.log( 'effect' ) )(); +returnArgReturn2( () => ({}) ).foo.bar = 1; const returnArgReturn3 = arg => arg(); -returnArgReturn3( () => ({ foo: {} }) ).foo.bar = 1; +returnArgReturn3( () => () => () => console.log( 'effect' ) )()(); -const returnArgReturn4 = arg => arg(); -returnArgReturn4( () => ({}) ).foo.bar = 1; - -const returnArgReturn5 = arg => arg(); -returnArgReturn5( () => () => () => {} )()(); - -const returnArgReturn6 = arg => arg(); -returnArgReturn6( () => () => () => console.log( 'effect' ) )()(); - -const multiArgument1 = ( func, obj ) => func( obj ); -multiArgument1( obj => obj(), () => {} ); +const multiArgument = ( func, obj ) => func( obj ); +multiArgument( obj => obj(), () => console.log( 'effect' ) ); const multiArgument2 = ( func, obj ) => func( obj ); -multiArgument2( obj => obj(), () => console.log( 'effect' ) ); - -const multiArgument3 = ( func, obj ) => func( obj ); -multiArgument3( obj => obj.foo.bar = 1, { foo: {} } ); - -const multiArgument4 = ( func, obj ) => func( obj ); -multiArgument4( obj => obj.foo.bar = 1, {} ); +multiArgument2( obj => obj.foo.bar = 1, {} ); diff --git a/test/form/samples/function-call-parameters/_expected/amd.js b/test/form/samples/function-call-parameters/_expected/amd.js index 5358a209cfc..d864d70c3c9 100644 --- a/test/form/samples/function-call-parameters/_expected/amd.js +++ b/test/form/samples/function-call-parameters/_expected/amd.js @@ -1,6 +1,5 @@ define(function () { 'use strict'; - // parameters are associated correctly // parameters are associated correctly const retained1 = function ( func, obj ) { return func( obj ); }; retained1( obj => obj(), () => () => console.log( 'effect' ) )(); diff --git a/test/form/samples/function-call-parameters/_expected/cjs.js b/test/form/samples/function-call-parameters/_expected/cjs.js index 1870904f6ed..69e2e8f7186 100644 --- a/test/form/samples/function-call-parameters/_expected/cjs.js +++ b/test/form/samples/function-call-parameters/_expected/cjs.js @@ -1,6 +1,5 @@ 'use strict'; -// parameters are associated correctly // parameters are associated correctly const retained1 = function ( func, obj ) { return func( obj ); }; retained1( obj => obj(), () => () => console.log( 'effect' ) )(); diff --git a/test/form/samples/function-call-parameters/_expected/es.js b/test/form/samples/function-call-parameters/_expected/es.js index d6770b8be4f..1ab81a10219 100644 --- a/test/form/samples/function-call-parameters/_expected/es.js +++ b/test/form/samples/function-call-parameters/_expected/es.js @@ -1,5 +1,4 @@ // parameters are associated correctly -// parameters are associated correctly const retained1 = function ( func, obj ) { return func( obj ); }; retained1( obj => obj(), () => () => console.log( 'effect' ) )(); diff --git a/test/form/samples/function-call-parameters/_expected/iife.js b/test/form/samples/function-call-parameters/_expected/iife.js index 8199579ce3d..4c7db0eab57 100644 --- a/test/form/samples/function-call-parameters/_expected/iife.js +++ b/test/form/samples/function-call-parameters/_expected/iife.js @@ -1,7 +1,6 @@ (function () { 'use strict'; - // parameters are associated correctly // parameters are associated correctly const retained1 = function ( func, obj ) { return func( obj ); }; retained1( obj => obj(), () => () => console.log( 'effect' ) )(); diff --git a/test/form/samples/function-call-parameters/_expected/umd.js b/test/form/samples/function-call-parameters/_expected/umd.js index 274b18fe6c9..dc1acdbfe00 100644 --- a/test/form/samples/function-call-parameters/_expected/umd.js +++ b/test/form/samples/function-call-parameters/_expected/umd.js @@ -4,7 +4,6 @@ (factory()); }(this, (function () { 'use strict'; - // parameters are associated correctly // parameters are associated correctly const retained1 = function ( func, obj ) { return func( obj ); }; retained1( obj => obj(), () => () => console.log( 'effect' ) )(); diff --git a/test/form/samples/function-call-parameters/main.js b/test/form/samples/function-call-parameters/main.js index 2e0e35da1ad..1ab81a10219 100644 --- a/test/form/samples/function-call-parameters/main.js +++ b/test/form/samples/function-call-parameters/main.js @@ -1,25 +1,3 @@ -// parameters are associated correctly -const removed1 = function ( func, obj ) { return func( obj ); }; -removed1( obj => obj(), () => () => {} )(); - -const removed2 = function ( func, obj ) { return func( obj ); }; -removed2( obj => ({ foo: obj }), { bar: {} } ).foo.bar.baz = 1; - -// parameters and arguments have the same values -function removed3 ( x ) { - x.foo.bar = 1; - arguments[ 0 ].foo.bar = 1; -} - -removed3( { foo: {} } ); - -// the number of arguments does not depend on the number of parameters -function removed4 ( x ) { - arguments[ 1 ].foo.bar = 1; -} - -removed4( {}, { foo: {} } ); - // parameters are associated correctly const retained1 = function ( func, obj ) { return func( obj ); }; retained1( obj => obj(), () => () => console.log( 'effect' ) )();