Skip to content

Commit

Permalink
Allow to disable __esModule (#2287)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound authored and lukastaegert committed Jun 20, 2018
1 parent 9de98ce commit d4aed73
Show file tree
Hide file tree
Showing 16 changed files with 1,220 additions and 1,144 deletions.
2,282 changes: 1,141 additions & 1,141 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Chunk.ts
Expand Up @@ -763,6 +763,7 @@ export default class Chunk {
const renderOptions: RenderOptions = {
compact: options.compact,
freeze: options.freeze !== false,
esModule: options.esModule !== false,
namespaceToStringTag: options.namespaceToStringTag === true,
indent: this.indentString,
format: options.format
Expand Down
2 changes: 1 addition & 1 deletion src/finalisers/amd.ts
Expand Up @@ -71,7 +71,7 @@ export default function amd(
options.compact
);
if (exportBlock) magicString.append(n + n + exportBlock);
if (namedExportsMode && hasExports && isEntryModuleFacade)
if (namedExportsMode && hasExports && isEntryModuleFacade && options.esModule)
magicString.append(`${n}${n}${options.compact ? compactEsModuleExport : esModuleExport}`);
if (outro) magicString.append(outro);

Expand Down
2 changes: 1 addition & 1 deletion src/finalisers/cjs.ts
Expand Up @@ -23,7 +23,7 @@ export default function cjs(

intro =
(options.strict === false ? intro : `'use strict';${n}${n}${intro}`) +
(namedExportsMode && hasExports && isEntryModuleFacade
(namedExportsMode && hasExports && isEntryModuleFacade && options.esModule
? `${options.compact ? compactEsModuleExport : esModuleExport}${n}${n}`
: '');

Expand Down
2 changes: 1 addition & 1 deletion src/finalisers/umd.ts
Expand Up @@ -131,7 +131,7 @@ export default function umd(
options.compact
);
if (exportBlock) magicString.append(n + n + exportBlock);
if (namedExportsMode && hasExports)
if (namedExportsMode && hasExports && options.esModule)
magicString.append(n + n + (options.compact ? compactEsModuleExport : esModuleExport));
if (outro) magicString.append(outro);

Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Expand Up @@ -254,6 +254,7 @@ export interface OutputOptions {
indent?: boolean;
strict?: boolean;
freeze?: boolean;
esModule?: boolean;
namespaceToStringTag?: boolean;
compact?: boolean;

Expand Down
1 change: 1 addition & 0 deletions src/utils/mergeOptions.ts
Expand Up @@ -254,6 +254,7 @@ function getOutputOptions(
footer: getOption('footer'),
format: format === 'esm' ? 'es' : format,
freeze: getOption('freeze'),
esModule: getOption('esModule'),
globals: getOption('globals'),
indent: getOption('indent', true),
interop: getOption('interop', true),
Expand Down
1 change: 1 addition & 0 deletions src/utils/renderHelpers.ts
Expand Up @@ -4,6 +4,7 @@ import { Node, StatementNode } from '../ast/nodes/shared/Node';
export interface RenderOptions {
compact: boolean;
freeze: boolean;
esModule: boolean;
namespaceToStringTag: boolean;
indent: string;
format: string;
Expand Down
7 changes: 7 additions & 0 deletions test/form/samples/define-es-modules-false/_config.js
@@ -0,0 +1,7 @@
module.exports = {
solo: true,
description: 'Not add __esModule property to exports with esModule: false',
options: {
output: { name: 'foo', esModule: false },
}
};
10 changes: 10 additions & 0 deletions test/form/samples/define-es-modules-false/_expected/amd.js
@@ -0,0 +1,10 @@
define(['exports'], function (exports) { 'use strict';

const make1 = () => {};

const make2 = () => {};

exports.make1 = make1;
exports.make2 = make2;

});
8 changes: 8 additions & 0 deletions test/form/samples/define-es-modules-false/_expected/cjs.js
@@ -0,0 +1,8 @@
'use strict';

const make1 = () => {};

const make2 = () => {};

exports.make1 = make1;
exports.make2 = make2;
5 changes: 5 additions & 0 deletions test/form/samples/define-es-modules-false/_expected/es.js
@@ -0,0 +1,5 @@
const make1 = () => {};

const make2 = () => {};

export { make1, make2 };
13 changes: 13 additions & 0 deletions test/form/samples/define-es-modules-false/_expected/iife.js
@@ -0,0 +1,13 @@
var foo = (function (exports) {
'use strict';

const make1 = () => {};

const make2 = () => {};

exports.make1 = make1;
exports.make2 = make2;

return exports;

}({}));
12 changes: 12 additions & 0 deletions test/form/samples/define-es-modules-false/_expected/system.js
@@ -0,0 +1,12 @@
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {

const make1 = exports('make1', () => {});

const make2 = exports('make2', () => {});

}
};
});
14 changes: 14 additions & 0 deletions test/form/samples/define-es-modules-false/_expected/umd.js
@@ -0,0 +1,14 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.foo = {})));
}(this, (function (exports) { 'use strict';

const make1 = () => {};

const make2 = () => {};

exports.make1 = make1;
exports.make2 = make2;

})));
3 changes: 3 additions & 0 deletions test/form/samples/define-es-modules-false/main.js
@@ -0,0 +1,3 @@
export const make1 = () => {};

export const make2 = () => {};

0 comments on commit d4aed73

Please sign in to comment.