Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: "export *" before named export #2893

Merged
merged 3 commits into from Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Module.ts
Expand Up @@ -429,8 +429,7 @@ export default class Module {
}

if (name !== 'default') {
for (let i = 0; i < this.exportAllModules.length; i += 1) {
const module = this.exportAllModules[i];
for (const module of this.exportAllModules) {
const declaration = module.getVariableForExportName(name, true);

if (declaration) return declaration;
Expand Down Expand Up @@ -504,10 +503,16 @@ export default class Module {
this.addModulesToSpecifiers(this.importDescriptions);
this.addModulesToSpecifiers(this.reexports);

this.exportAllModules = this.exportAllSources.map(source => {
const id = this.resolvedIds[source].id;
return this.graph.moduleById.get(id) as any;
});
this.exportAllModules = this.exportAllSources
.map(source => {
const id = this.resolvedIds[source].id;
return this.graph.moduleById.get(id) as Module | ExternalModule;
})
.sort((moduleA, moduleB) => {
const aExternal = moduleA instanceof ExternalModule;
const bExternal = moduleB instanceof ExternalModule;
return aExternal === bExternal ? 0 : aExternal ? 1 : -1;
});
}

render(options: RenderOptions): MagicString {
Expand Down
7 changes: 7 additions & 0 deletions test/form/samples/export-all-before-named/_config.js
@@ -0,0 +1,7 @@
module.exports = {
description: 'external `export *` must not interfere with internal exports',
options: {
output: { name: 'exposedInternals' },
external: ['external']
}
};
19 changes: 19 additions & 0 deletions test/form/samples/export-all-before-named/_expected/amd.js
@@ -0,0 +1,19 @@
define(['exports', 'external'], function (exports, external) { 'use strict';

function internalFn(path) {
return path[0] === '.';
}

Object.keys(external).forEach(function (key) {
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return external[key];
}
});
});
exports.internalFn = internalFn;

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

});
19 changes: 19 additions & 0 deletions test/form/samples/export-all-before-named/_expected/cjs.js
@@ -0,0 +1,19 @@
'use strict';

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

var external = require('external');

function internalFn(path) {
return path[0] === '.';
}

Object.keys(external).forEach(function (key) {
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return external[key];
}
});
});
exports.internalFn = internalFn;
7 changes: 7 additions & 0 deletions test/form/samples/export-all-before-named/_expected/es.js
@@ -0,0 +1,7 @@
export * from 'external';

function internalFn(path) {
return path[0] === '.';
}

export { internalFn };
20 changes: 20 additions & 0 deletions test/form/samples/export-all-before-named/_expected/iife.js
@@ -0,0 +1,20 @@
var exposedInternals = (function (exports, external) {
'use strict';

function internalFn(path) {
return path[0] === '.';
}

Object.keys(external).forEach(function (key) {
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return external[key];
}
});
});
exports.internalFn = internalFn;

return exports;

}({}, external));
22 changes: 22 additions & 0 deletions test/form/samples/export-all-before-named/_expected/system.js
@@ -0,0 +1,22 @@
System.register('exposedInternals', ['external'], function (exports) {
'use strict';
var _starExcludes = { internalFn: 1, default: 1 };
return {
setters: [function (module) {
var _setter = {};
for (var _$p in module) {
if (!_starExcludes[_$p]) _setter[_$p] = module[_$p];
}
exports(_setter);
}],
execute: function () {

exports('internalFn', internalFn);

function internalFn(path) {
return path[0] === '.';
}

}
};
});
23 changes: 23 additions & 0 deletions test/form/samples/export-all-before-named/_expected/umd.js
@@ -0,0 +1,23 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) :
typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) :
(global = global || self, factory(global.exposedInternals = {}, global.external));
}(this, function (exports, external) { 'use strict';

function internalFn(path) {
return path[0] === '.';
}

Object.keys(external).forEach(function (key) {
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return external[key];
}
});
});
exports.internalFn = internalFn;

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

}));
3 changes: 3 additions & 0 deletions test/form/samples/export-all-before-named/internal.js
@@ -0,0 +1,3 @@
export function internalFn(path) {
return path[0] === '.';
}
2 changes: 2 additions & 0 deletions test/form/samples/export-all-before-named/main.js
@@ -0,0 +1,2 @@
export * from 'external';
export * from './internal.js';