commit
dc26688731
|
@ -1593,7 +1593,14 @@ class Parser extends Tapable {
|
|||
walkFunctionExpression(expression) {
|
||||
const wasTopLevel = this.scope.topLevelScope;
|
||||
this.scope.topLevelScope = false;
|
||||
this.inScope(expression.params, () => {
|
||||
const scopeParams = expression.params;
|
||||
|
||||
// Add function name in scope for recursive calls
|
||||
if (expression.id) {
|
||||
scopeParams.push(expression.id.name);
|
||||
}
|
||||
|
||||
this.inScope(scopeParams, () => {
|
||||
for (const param of expression.params) {
|
||||
this.walkPattern(param);
|
||||
}
|
||||
|
@ -1777,7 +1784,14 @@ class Parser extends Tapable {
|
|||
const args = options.map(renameArgOrThis);
|
||||
const wasTopLevel = this.scope.topLevelScope;
|
||||
this.scope.topLevelScope = false;
|
||||
this.inScope(params.filter((identifier, idx) => !args[idx]), () => {
|
||||
const scopeParams = params.filter((identifier, idx) => !args[idx]);
|
||||
|
||||
// Add function name in scope for recursive calls
|
||||
if (functionExpression.id) {
|
||||
scopeParams.push(functionExpression.id.name);
|
||||
}
|
||||
|
||||
this.inScope(scopeParams, () => {
|
||||
if (renameThis) {
|
||||
this.scope.renames.set("this", renameThis);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import myFunction from './module';
|
||||
import myFunctionDefaultParameter from './moduleDefaultParameter';
|
||||
import myFunctionExportedFunctionExpression from './moduleExportedFunctionExpression';
|
||||
import myFunctionExportedFunctionExpressionDefaultParameter from './moduleExportedFunctionExpressionDefaultParameter';
|
||||
|
||||
it('should execute IIFE twice', () => {
|
||||
expect(myFunction()).toBe(2);
|
||||
});
|
||||
|
||||
it('should execute IIFE twice when using IIFE function name as default parameter', () => {
|
||||
expect(myFunctionDefaultParameter()).toBe(2);
|
||||
});
|
||||
|
||||
it('should execute Function Expression twice', () => {
|
||||
expect(myFunctionExportedFunctionExpression()).toBe(2);
|
||||
});
|
||||
|
||||
it('should execute Function Expression twice when using IIFE function name as default parameter', () => {
|
||||
expect(myFunctionExportedFunctionExpressionDefaultParameter()).toBe(2);
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
import someFunction from './someFunction';
|
||||
|
||||
export default function myFunction() {
|
||||
let iifeExecutionCount = 0;
|
||||
|
||||
(function someFunction (recurse) {
|
||||
iifeExecutionCount++;
|
||||
|
||||
if (recurse) {
|
||||
someFunction(false);
|
||||
}
|
||||
})(true);
|
||||
|
||||
return iifeExecutionCount;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
export default function myFunction() {
|
||||
let iifeExecutionCount = 0;
|
||||
|
||||
(function someFunction (recurse, recurseFunction = someFunction) {
|
||||
iifeExecutionCount++;
|
||||
|
||||
if (recurse) {
|
||||
recurseFunction(false);
|
||||
}
|
||||
})(true);
|
||||
|
||||
return iifeExecutionCount;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
import someFunction from './someFunction';
|
||||
|
||||
export default (function someFunction (recurse = true) {
|
||||
if (recurse) {
|
||||
return 1 + someFunction(false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
import someFunction from './someFunction';
|
||||
|
||||
export default (function someFunction (recurse = true, recurseFunction = someFunction) {
|
||||
if (recurse) {
|
||||
return 1 + recurseFunction(false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
export default function someFunction () {
|
||||
return -1;
|
||||
}
|
Loading…
Reference in New Issue