Browse Source

Merge branch 'esmodule' of https://github.com/cameron-martin/rollup into cameron-martin-esmodule

ghi-672
Rich-Harris 9 years ago
parent
commit
dd40bdfec9
  1. 5
      src/finalisers/cjs.js
  2. 4
      src/finalisers/shared/esModuleExport.js
  3. 5
      src/finalisers/umd.js
  4. 4
      test/form/assignment-to-exports-class-declaration/_expected/cjs.js
  5. 4
      test/form/assignment-to-exports-class-declaration/_expected/umd.js
  6. 6
      test/form/computed-properties/_expected/cjs.js
  7. 6
      test/form/computed-properties/_expected/umd.js
  8. 4
      test/form/dedupes-external-imports/_expected/cjs.js
  9. 6
      test/form/dedupes-external-imports/_expected/umd.js
  10. 4
      test/form/export-all-from-internal/_expected/cjs.js
  11. 6
      test/form/export-all-from-internal/_expected/umd.js
  12. 6
      test/form/export-default-import/_expected/cjs.js
  13. 6
      test/form/export-default-import/_expected/umd.js
  14. 4
      test/form/exports-at-end-if-possible/_expected/cjs.js
  15. 6
      test/form/exports-at-end-if-possible/_expected/umd.js
  16. 4
      test/form/multiple-exports/_expected/cjs.js
  17. 6
      test/form/multiple-exports/_expected/umd.js
  18. 6
      test/form/namespaced-named-exports/_expected/cjs.js
  19. 6
      test/form/namespaced-named-exports/_expected/umd.js
  20. 4
      test/form/no-treeshake/_expected/cjs.js
  21. 4
      test/form/no-treeshake/_expected/umd.js
  22. 4
      test/form/preserves-comments-after-imports/_expected/cjs.js
  23. 6
      test/form/preserves-comments-after-imports/_expected/umd.js
  24. 6
      test/form/umd-noconflict/_expected/cjs.js
  25. 4
      test/form/umd-noconflict/_expected/umd.js

5
src/finalisers/cjs.js

@ -1,4 +1,5 @@
import getExportBlock from './shared/getExportBlock.js';
import esModuleExport from './shared/esModuleExport.js';
export default function cjs ( bundle, magicString, { exportMode }, options ) {
let intro = options.useStrict === false ? `` : `'use strict';\n\n`;
@ -34,5 +35,9 @@ export default function cjs ( bundle, magicString, { exportMode }, options ) {
const exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if (exportMode === 'named') {
magicString.append(esModuleExport);
}
return magicString;
}

4
src/finalisers/shared/esModuleExport.js

@ -0,0 +1,4 @@
export default '\n\n' +
'Object.defineProperty(exports, "__esModule", {\n' +
' value: true\n' +
'});\n\n';

5
src/finalisers/umd.js

@ -3,6 +3,7 @@ import { getName, quoteId, req } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
import esModuleExport from './shared/esModuleExport.js';
function setupNamespace ( name ) {
const parts = name.split( '.' );
@ -69,6 +70,10 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if (exportMode === 'named') {
magicString.append(esModuleExport);
}
return magicString
.trim()
.indent( indentString )

4
test/form/assignment-to-exports-class-declaration/_expected/cjs.js

@ -2,3 +2,7 @@
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
Object.defineProperty(exports, "__esModule", {
value: true
});

4
test/form/assignment-to-exports-class-declaration/_expected/umd.js

@ -7,4 +7,8 @@
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

6
test/form/computed-properties/_expected/cjs.js

@ -14,4 +14,8 @@ class X {
}
exports.x = x;
exports.X = X;
exports.X = X;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/computed-properties/_expected/umd.js

@ -20,4 +20,8 @@
exports.x = x;
exports.X = X;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

4
test/form/dedupes-external-imports/_expected/cjs.js

@ -30,3 +30,7 @@ const baz = new Baz();
exports.foo = foo;
exports.bar = bar;
exports.baz = baz;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/dedupes-external-imports/_expected/umd.js

@ -33,4 +33,8 @@
exports.bar = bar;
exports.baz = baz;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

4
test/form/export-all-from-internal/_expected/cjs.js

@ -5,3 +5,7 @@ const b = 2;
exports.a = a;
exports.b = b;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/export-all-from-internal/_expected/umd.js

@ -10,4 +10,8 @@
exports.a = a;
exports.b = b;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

6
test/form/export-default-import/_expected/cjs.js

@ -6,4 +6,8 @@ var x = _interopDefault(require('x'));
exports.x = x;
exports.x = x;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/export-default-import/_expected/umd.js

@ -10,4 +10,8 @@
exports.x = x;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

4
test/form/exports-at-end-if-possible/_expected/cjs.js

@ -7,3 +7,7 @@ console.log( FOO );
console.log( FOO );
exports.FOO = FOO;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/exports-at-end-if-possible/_expected/umd.js

@ -12,4 +12,8 @@
exports.FOO = FOO;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

4
test/form/multiple-exports/_expected/cjs.js

@ -5,3 +5,7 @@ var bar = 2;
exports.foo = foo;
exports.bar = bar;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/multiple-exports/_expected/umd.js

@ -10,4 +10,8 @@
exports.foo = foo;
exports.bar = bar;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

6
test/form/namespaced-named-exports/_expected/cjs.js

@ -2,4 +2,8 @@
var answer = 42;
exports.answer = answer;
exports.answer = answer;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/namespaced-named-exports/_expected/umd.js

@ -8,4 +8,8 @@
exports.answer = answer;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

4
test/form/no-treeshake/_expected/cjs.js

@ -23,3 +23,7 @@ exports.baz = baz;
exports.create = create;
exports.getPrototypeOf = getPrototypeOf;
exports.strange = quux;
Object.defineProperty(exports, "__esModule", {
value: true
});

4
test/form/no-treeshake/_expected/umd.js

@ -26,4 +26,8 @@
exports.getPrototypeOf = getPrototypeOf;
exports.strange = quux;
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

4
test/form/preserves-comments-after-imports/_expected/cjs.js

@ -7,3 +7,7 @@ var number = 5;
var obj = { number };
exports.obj = obj;
Object.defineProperty(exports, "__esModule", {
value: true
});

6
test/form/preserves-comments-after-imports/_expected/umd.js

@ -12,4 +12,8 @@
exports.obj = obj;
}));
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

6
test/form/umd-noconflict/_expected/cjs.js

@ -10,4 +10,8 @@ var setting = 'no';
exports.doThings = doThings;
exports.number = number;
exports.setting = setting;
exports.setting = setting;
Object.defineProperty(exports, "__esModule", {
value: true
});

4
test/form/umd-noconflict/_expected/umd.js

@ -21,4 +21,8 @@
exports.number = number;
exports.setting = setting;
Object.defineProperty(exports, "__esModule", {
value: true
});
}));

Loading…
Cancel
Save