Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 5, 2020
1 parent bd20782 commit dd4625a
Show file tree
Hide file tree
Showing 27 changed files with 158 additions and 27 deletions.
23 changes: 10 additions & 13 deletions src/Chunk.ts
Expand Up @@ -7,7 +7,6 @@ import FunctionDeclaration from './ast/nodes/FunctionDeclaration';
import { UNDEFINED_EXPRESSION } from './ast/values';
import ExportDefaultVariable from './ast/variables/ExportDefaultVariable';
import ExportShimVariable from './ast/variables/ExportShimVariable';
import GlobalVariable from './ast/variables/GlobalVariable';
import LocalVariable from './ast/variables/LocalVariable';
import NamespaceVariable from './ast/variables/NamespaceVariable';
import Variable from './ast/variables/Variable';
Expand Down Expand Up @@ -367,11 +366,10 @@ export default class Chunk {

getRenderedHash(outputPluginDriver: PluginDriver): string {
if (this.renderedHash) return this.renderedHash;
if (!this.renderedSource) return '';
const hash = createHash();
const hashAugmentation = this.calculateHashAugmentation(outputPluginDriver);
hash.update(hashAugmentation);
hash.update(this.renderedSource.toString());
hash.update(this.renderedSource!.toString());
hash.update(
this.getExportNames()
.map(exportName => {
Expand Down Expand Up @@ -549,7 +547,7 @@ export default class Chunk {
this.facadeModule !== null
) {
for (const dep of this.dependencies) {
if (dep instanceof Chunk) this.inlineChunkDependencies(dep, true);
if (dep instanceof Chunk) this.inlineChunkDependencies(dep);
}
}
const sortedDependencies = [...this.dependencies];
Expand Down Expand Up @@ -1012,16 +1010,12 @@ export default class Chunk {
break;
}
}
} else if (variable instanceof GlobalVariable) {
hoisted = true;
}

const localName = variable.getName();

exports.push({
exported: exportName === '*' ? localName : exportName,
exported: exportName,
hoisted,
local: localName,
local: variable.getName(),
uninitialized
});
}
Expand All @@ -1043,14 +1037,17 @@ export default class Chunk {
return relativePath.startsWith('../') ? relativePath : './' + relativePath;
}

private inlineChunkDependencies(chunk: Chunk, deep: boolean) {
private inlineChunkDependencies(chunk: Chunk) {
for (const dep of chunk.dependencies) {
if (dep instanceof ExternalModule) {
this.dependencies.add(dep);
} else {
if (dep === this) continue;
// At the moment, circular dependencies between chunks are not possible; this will
// change if we ever add logic to ensure correct execution order or open up the
// chunking to plugins
// if (dep === this) continue;
this.dependencies.add(dep);
if (deep) this.inlineChunkDependencies(dep, true);
this.inlineChunkDependencies(dep);
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/Module.ts
Expand Up @@ -587,12 +587,7 @@ export default class Module {

linkDependencies() {
for (const source of this.sources) {
const id = this.resolvedIds[source].id;

if (id) {
const module = this.graph.moduleById.get(id)!;
this.dependencies.add(module);
}
this.dependencies.add(this.graph.moduleById.get(this.resolvedIds[source].id)!);
}
for (const { resolution } of this.dynamicImports) {
if (resolution instanceof Module || resolution instanceof ExternalModule) {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/chunkAssignment.ts
Expand Up @@ -65,11 +65,9 @@ export function getChunkAssignments(
return true;
}

if (manualChunkModules) {
for (const chunkName of Object.keys(manualChunkModules)) {
for (const entry of manualChunkModules[chunkName]) {
assignEntryToStaticDependencies(entry, null, chunkName);
}
for (const chunkName of Object.keys(manualChunkModules)) {
for (const entry of manualChunkModules[chunkName]) {
assignEntryToStaticDependencies(entry, null, chunkName);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/utils/executionOrder.ts
Expand Up @@ -22,8 +22,6 @@ export function analyseModuleExecution(entryModules: Module[]) {
const orderedModules: Module[] = [];

const analyseModule = (module: Module | ExternalModule) => {
if (analysedModules.has(module)) return;

if (module instanceof Module) {
for (const dependency of module.dependencies) {
if (parents.has(dependency)) {
Expand Down Expand Up @@ -74,7 +72,6 @@ function getCyclePath(
while (nextModule !== module) {
path.push(relativeId(nextModule.id));
nextModule = parents.get(nextModule)!;
if (!nextModule) break;
}
path.push(path[0]);
path.reverse();
Expand Down
@@ -0,0 +1,7 @@
module.exports = {
description:
'avoids empty imports if they do not have side-effects when preserving modules (#3359)',
options: {
preserveModules: true
}
};
@@ -0,0 +1,9 @@
define(['exports'], function (exports) { 'use strict';

const a = 1;

exports.a = a;

Object.defineProperty(exports, '__esModule', { value: true });

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

const b = 2;

exports.b = b;

Object.defineProperty(exports, '__esModule', { value: true });

});
@@ -0,0 +1,5 @@
define(['./a', './one'], function (a, one) { 'use strict';

console.log(a.a + one.d);

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

const d = b.b + 4;

exports.d = d;

Object.defineProperty(exports, '__esModule', { value: true });

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

Object.defineProperty(exports, '__esModule', { value: true });

const a = 1;

exports.a = a;
@@ -0,0 +1,7 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const b = 2;

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

var a = require('./a.js');
var one = require('./one.js');

console.log(a.a + one.d);
@@ -0,0 +1,9 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var b = require('./b.js');

const d = b.b + 4;

exports.d = d;
@@ -0,0 +1,3 @@
const a = 1;

export { a };
@@ -0,0 +1,3 @@
const b = 2;

export { b };
@@ -0,0 +1,4 @@
import { a } from './a.js';
import { d } from './one.js';

console.log(a + d);
@@ -0,0 +1,5 @@
import { b } from './b.js';

const d = b + 4;

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

const a = exports('a', 1);

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

const b = exports('b', 2);

}
};
});
@@ -0,0 +1,16 @@
System.register(['./a.js', './one.js'], function () {
'use strict';
var a, d;
return {
setters: [function (module) {
a = module.a;
}, function (module) {
d = module.d;
}],
execute: function () {

console.log(a + d);

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

const d = exports('d', b + 4);

}
};
});
@@ -0,0 +1 @@
export const a = 1;
@@ -0,0 +1 @@
export const b = 2;
@@ -0,0 +1 @@
export const c = 3;
@@ -0,0 +1,3 @@
export { a } from './a';
export { b } from './b';
export { c } from './c';
@@ -0,0 +1,3 @@
import { a } from './index';
import { d } from './one';
console.log(a + d);
@@ -0,0 +1,2 @@
import { b } from './index';
export const d = b + 4;

0 comments on commit dd4625a

Please sign in to comment.