Skip to content

Commit

Permalink
fix: get right sideEffectModules (#5029)
Browse files Browse the repository at this point in the history
* fix: get right SideEffectModules

* chore: remove field solo in tests

* add conditions

Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>

---------

Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
TrickyPi and lukastaegert committed Jun 10, 2023
1 parent abd289d commit be39a57
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Module.ts
Expand Up @@ -1277,10 +1277,14 @@ export default class Module {
}

private includeVariable(variable: Variable): void {
if (!variable.included) {
const variableModule = variable.module;
if (variable.included) {
if (variableModule instanceof Module && variableModule !== this) {
getAndExtendSideEffectModules(variable, this);
}
} else {
variable.include();
this.graph.needsTreeshakingPass = true;
const variableModule = variable.module;
if (variableModule instanceof Module) {
if (!variableModule.isExecuted) {
markModuleAndImpureDependenciesAsExecuted(variableModule);
Expand Down
21 changes: 21 additions & 0 deletions test/chunking-form/samples/chunk-assigment-in-dynamic/_config.js
@@ -0,0 +1,21 @@
const path = require('node:path');
const commonjs = require('@rollup/plugin-commonjs');

module.exports = defineTest({
description: 'the content of c.js is complete',
options: {
plugins: [
commonjs(),
{
resolveId(id) {
if (id === './c.js') {
return {
id: path.resolve('./c.js'),
moduleSideEffects: false
};
}
}
}
]
}
});
@@ -0,0 +1,9 @@
define(['exports', './generated-c'], (function (exports, c) { 'use strict';

function A() {
return { icon: c.c.faPrint };
}

exports.A = A;

}));
@@ -0,0 +1,9 @@
define(['exports', './generated-c'], (function (exports, c) { 'use strict';

function B() {
return { icon: c.c.faPrint };
}

exports.B = B;

}));
@@ -0,0 +1,15 @@
define(['exports'], (function (exports) { 'use strict';

var c = {};

(function (exports) {
exports.preFaPrint = {
foo: 1
};

exports.faPrint = exports.preFaPrint;
} (c));

exports.c = c;

}));
@@ -0,0 +1,8 @@
define(['require'], (function (require) { 'use strict';

const importA = () => new Promise(function (resolve, reject) { require(['./generated-a'], resolve, reject); });
const importB = () => new Promise(function (resolve, reject) { require(['./generated-b'], resolve, reject); });

console.log(importA, importB);

}));
@@ -0,0 +1,9 @@
'use strict';

var c = require('./generated-c.js');

function A() {
return { icon: c.c.faPrint };
}

exports.A = A;
@@ -0,0 +1,9 @@
'use strict';

var c = require('./generated-c.js');

function B() {
return { icon: c.c.faPrint };
}

exports.B = B;
@@ -0,0 +1,13 @@
'use strict';

var c = {};

(function (exports) {
exports.preFaPrint = {
foo: 1
};

exports.faPrint = exports.preFaPrint;
} (c));

exports.c = c;
@@ -0,0 +1,6 @@
'use strict';

const importA = () => Promise.resolve().then(function () { return require('./generated-a.js'); });
const importB = () => Promise.resolve().then(function () { return require('./generated-b.js'); });

console.log(importA, importB);
@@ -0,0 +1,7 @@
import { c } from './generated-c.js';

function A() {
return { icon: c.faPrint };
}

export { A };
@@ -0,0 +1,7 @@
import { c } from './generated-c.js';

function B() {
return { icon: c.faPrint };
}

export { B };
@@ -0,0 +1,11 @@
var c = {};

(function (exports) {
exports.preFaPrint = {
foo: 1
};

exports.faPrint = exports.preFaPrint;
} (c));

export { c };
@@ -0,0 +1,4 @@
const importA = () => import('./generated-a.js');
const importB = () => import('./generated-b.js');

console.log(importA, importB);
@@ -0,0 +1,18 @@
System.register(['./generated-c.js'], (function (exports) {
'use strict';
var c;
return {
setters: [function (module) {
c = module.c;
}],
execute: (function () {

exports('A', A);

function A() {
return { icon: c.faPrint };
}

})
};
}));
@@ -0,0 +1,18 @@
System.register(['./generated-c.js'], (function (exports) {
'use strict';
var c;
return {
setters: [function (module) {
c = module.c;
}],
execute: (function () {

exports('B', B);

function B() {
return { icon: c.faPrint };
}

})
};
}));
@@ -0,0 +1,18 @@
System.register([], (function (exports) {
'use strict';
return {
execute: (function () {

var c = exports('c', {});

(function (exports) {
exports.preFaPrint = {
foo: 1
};

exports.faPrint = exports.preFaPrint;
} (c));

})
};
}));
@@ -0,0 +1,13 @@
System.register([], (function (exports, module) {
'use strict';
return {
execute: (function () {

const importA = () => module.import('./generated-a.js');
const importB = () => module.import('./generated-b.js');

console.log(importA, importB);

})
};
}));
5 changes: 5 additions & 0 deletions test/chunking-form/samples/chunk-assigment-in-dynamic/a.js
@@ -0,0 +1,5 @@
import { faPrint } from './c.js';

export function A() {
return { icon: faPrint };
}
5 changes: 5 additions & 0 deletions test/chunking-form/samples/chunk-assigment-in-dynamic/b.js
@@ -0,0 +1,5 @@
import { faPrint } from './c.js';

export function B() {
return { icon: faPrint };
}
5 changes: 5 additions & 0 deletions test/chunking-form/samples/chunk-assigment-in-dynamic/c.js
@@ -0,0 +1,5 @@
exports.preFaPrint = {
foo: 1
};

exports.faPrint = exports.preFaPrint;
4 changes: 4 additions & 0 deletions test/chunking-form/samples/chunk-assigment-in-dynamic/main.js
@@ -0,0 +1,4 @@
const importA = () => import('./a.js');
const importB = () => import('./b.js');

console.log(importA, importB);

0 comments on commit be39a57

Please sign in to comment.