Skip to content

Commit

Permalink
Merge branch 'master' of github.com:webpack/webpack into issue-8833
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning committed Apr 5, 2019
2 parents b59e0d1 + dc26688 commit a061d0f
Show file tree
Hide file tree
Showing 9 changed files with 1,042 additions and 805 deletions.
8 changes: 5 additions & 3 deletions lib/FunctionModuleTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class FunctionModuleTemplatePlugin {
const req = module.readableIdentifier(
moduleTemplate.runtimeTemplate.requestShortener
);
source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n");
source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n");
source.add(" \\****" + req.replace(/./g, "*") + "****/\n");
const reqStr = req.replace(/\*\//g, "*_/");
const reqStrStar = "*".repeat(reqStr.length);
source.add("/*!****" + reqStrStar + "****!*\\\n");
source.add(" !*** " + reqStr + " ***!\n");
source.add(" \\****" + reqStrStar + "****/\n");
if (
Array.isArray(module.buildMeta.providedExports) &&
module.buildMeta.providedExports.length === 0
Expand Down
18 changes: 16 additions & 2 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions test/cases/parsing/issue-8874/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
15 changes: 15 additions & 0 deletions test/cases/parsing/issue-8874/module.js
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions test/cases/parsing/issue-8874/moduleDefaultParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function myFunction() {
let iifeExecutionCount = 0;

(function someFunction (recurse, recurseFunction = someFunction) {
iifeExecutionCount++;

if (recurse) {
recurseFunction(false);
}
})(true);

return iifeExecutionCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import someFunction from './someFunction';

export default (function someFunction (recurse = true) {
if (recurse) {
return 1 + someFunction(false);
}

return 1;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import someFunction from './someFunction';

export default (function someFunction (recurse = true, recurseFunction = someFunction) {
if (recurse) {
return 1 + recurseFunction(false);
}

return 1;
});
3 changes: 3 additions & 0 deletions test/cases/parsing/issue-8874/someFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function someFunction () {
return -1;
}

0 comments on commit a061d0f

Please sign in to comment.