Merge pull request #8926 from noelebrun/bugfix/8874

fixes #8874
This commit is contained in:
Tobias Koppers 2019-03-25 19:54:03 +01:00 committed by GitHub
commit dc26688731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 86 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);
});

View File

@ -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;
}

View File

@ -0,0 +1,13 @@
export default function myFunction() {
let iifeExecutionCount = 0;
(function someFunction (recurse, recurseFunction = someFunction) {
iifeExecutionCount++;
if (recurse) {
recurseFunction(false);
}
})(true);
return iifeExecutionCount;
}

View File

@ -0,0 +1,9 @@
import someFunction from './someFunction';
export default (function someFunction (recurse = true) {
if (recurse) {
return 1 + someFunction(false);
}
return 1;
});

View File

@ -0,0 +1,10 @@
import someFunction from './someFunction';
export default (function someFunction (recurse = true, recurseFunction = someFunction) {
if (recurse) {
return 1 + recurseFunction(false);
}
return 1;
});

View File

@ -0,0 +1,3 @@
export default function someFunction () {
return -1;
}