Skip to content

Commit

Permalink
WIP: test case for import namespace when only rendering systemjs (#3731)
Browse files Browse the repository at this point in the history
* test case for import namespace when only rendering systemjs

* Deconflict external namespace variables for SystemJS

Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
  • Loading branch information
sastan and lukastaegert committed Aug 16, 2020
1 parent f0f8c47 commit 18df9a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,20 +980,20 @@ export default class Chunk {
}

private getDependenciesToBeDeconflicted(
addDependencies: boolean,
addNonNamespaces: boolean,
interop: GetInterop,
addDependenciesWithoutBindings: boolean
addNonNamespacesAndInteropHelpers: boolean,
addInternalDependencies: boolean,
addDependenciesWithoutBindings: boolean,
interop: GetInterop
): DependenciesToBeDeconflicted {
const dependencies = new Set<Chunk | ExternalModule>();
const deconflictedDefault = new Set<ExternalModule>();
const deconflictedNamespace = new Set<ExternalModule>();
if (addDependencies) {
for (const variable of [...this.exportNamesByVariable.keys(), ...this.imports]) {
if (addNonNamespaces || variable.isNamespace) {
const module = variable.module!;
if (module instanceof ExternalModule) {
dependencies.add(module);
for (const variable of [...this.exportNamesByVariable.keys(), ...this.imports]) {
if (addNonNamespacesAndInteropHelpers || variable.isNamespace) {
const module = variable.module!;
if (module instanceof ExternalModule) {
dependencies.add(module);
if (addNonNamespacesAndInteropHelpers) {
if (variable.name === 'default') {
if (defaultInteropHelpersByInteropType[String(interop(module.id))]) {
deconflictedDefault.add(module);
Expand All @@ -1003,11 +1003,11 @@ export default class Chunk {
deconflictedNamespace.add(module);
}
}
} else {
const chunk = this.chunkByModule.get(module)!;
if (chunk !== this) {
dependencies.add(chunk);
}
}
} else if (addInternalDependencies) {
const chunk = this.chunkByModule.get(module)!;
if (chunk !== this) {
dependencies.add(chunk);
}
}
}
Expand Down Expand Up @@ -1238,10 +1238,10 @@ export default class Chunk {
deconflictChunk(
this.orderedModules,
this.getDependenciesToBeDeconflicted(
format !== 'system',
format !== 'es' && format !== 'system',
interop,
format === 'amd' || format === 'umd' || format === 'iife'
format !== 'system',
format === 'amd' || format === 'umd' || format === 'iife',
interop
),
this.imports,
usedNames,
Expand Down
9 changes: 9 additions & 0 deletions test/form/samples/import-namespace-systemjs/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
description: 'imports namespace (systemjs only)',
options: {
external: ['dependency'],
output: {
format: 'system'
}
}
};
14 changes: 14 additions & 0 deletions test/form/samples/import-namespace-systemjs/_expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
System.register(['dependency'], function () {
'use strict';
var dependency;
return {
setters: [function (module) {
dependency = module;
}],
execute: function () {

console.log(dependency);

}
};
});
2 changes: 2 additions & 0 deletions test/form/samples/import-namespace-systemjs/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as dependency from 'dependency';
console.log(dependency);

0 comments on commit 18df9a6

Please sign in to comment.