Browse Source

add: interop option

gh-953
Emil Ajdyna 8 years ago
parent
commit
211fa097a9
  1. 2
      LICENSE.md
  2. 2
      src/finalisers/amd.js
  3. 2
      src/finalisers/iife.js
  4. 4
      src/finalisers/shared/getInteropBlock.js
  5. 2
      src/finalisers/umd.js
  6. 1
      src/rollup.js
  7. 7
      test/form/interop-false/_config.js
  8. 8
      test/form/interop-false/_expected/amd.js
  9. 10
      test/form/interop-false/_expected/cjs.js
  10. 6
      test/form/interop-false/_expected/es.js
  11. 9
      test/form/interop-false/_expected/iife.js
  12. 12
      test/form/interop-false/_expected/umd.js
  13. 3
      test/form/interop-false/main.js
  14. 2
      test/test.js

2
LICENSE.md

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 [these people](https://github.com/rollup/rollup/graphs/contributors)
Copyright (c) 2016 [these people](https://github.com/rollup/rollup/graphs/contributors)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

2
src/finalisers/amd.js

@ -20,7 +20,7 @@ export default function amd ( bundle, magicString, { exportMode, indentString, i
const wrapperStart = `define(${params}function (${args.join( ', ' )}) {${useStrict}\n\n`;
// var foo__default = 'default' in foo ? foo['default'] : foo;
const interopBlock = getInteropBlock( bundle );
const interopBlock = getInteropBlock( bundle, options );
if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
if ( intro ) magicString.prepend( intro );

2
src/finalisers/iife.js

@ -49,7 +49,7 @@ export default function iife ( bundle, magicString, { exportMode, indentString,
}
// var foo__default = 'default' in foo ? foo['default'] : foo;
const interopBlock = getInteropBlock( bundle );
const interopBlock = getInteropBlock( bundle, options );
if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
if ( intro ) magicString.prepend( intro );

4
src/finalisers/shared/getInteropBlock.js

@ -1,7 +1,7 @@
export default function getInteropBlock ( bundle ) {
export default function getInteropBlock ( bundle, options ) {
return bundle.externalModules
.map( module => {
if ( !module.declarations.default ) return null;
if ( !module.declarations.default || options.interop === false ) return null;
if ( module.exportsNamespace ) {
return `${bundle.varOrConst} ${module.name}__default = ${module.name}['default'];`;

2
src/finalisers/umd.js

@ -66,7 +66,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString, i
`.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() );
// var foo__default = 'default' in foo ? foo['default'] : foo;
const interopBlock = getInteropBlock( bundle );
const interopBlock = getInteropBlock( bundle, options );
if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
if ( intro ) magicString.prepend( intro );

1
src/rollup.js

@ -22,6 +22,7 @@ const ALLOWED_KEYS = [
'format',
'globals',
'indent',
'interop',
'intro',
'moduleId',
'moduleName',

7
test/form/interop-false/_config.js

@ -0,0 +1,7 @@
module.exports = {
description: 'getInterop with interop: false',
options: {
moduleName: 'foo',
interop: false
}
};

8
test/form/interop-false/_expected/amd.js

@ -0,0 +1,8 @@
define(['core/view'], function (View) { 'use strict';
/*eslint import/no-unresolved: 0*/
var main = View.extend({});
return main;
});

10
test/form/interop-false/_expected/cjs.js

@ -0,0 +1,10 @@
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var View = _interopDefault(require('core/view'));
/*eslint import/no-unresolved: 0*/
var main = View.extend({});
module.exports = main;

6
test/form/interop-false/_expected/es.js

@ -0,0 +1,6 @@
import View from 'core/view';
/*eslint import/no-unresolved: 0*/
var main = View.extend({});
export default main;

9
test/form/interop-false/_expected/iife.js

@ -0,0 +1,9 @@
var foo = (function (View) {
'use strict';
/*eslint import/no-unresolved: 0*/
var main = View.extend({});
return main;
}(View));

12
test/form/interop-false/_expected/umd.js

@ -0,0 +1,12 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('core/view')) :
typeof define === 'function' && define.amd ? define(['core/view'], factory) :
(global.foo = factory(global.View));
}(this, (function (View) { 'use strict';
/*eslint import/no-unresolved: 0*/
var main = View.extend({});
return main;
})));

3
test/form/interop-false/main.js

@ -0,0 +1,3 @@
/*eslint import/no-unresolved: 0*/
import View from 'core/view';
export default View.extend({});

2
test/test.js

@ -90,7 +90,7 @@ describe( 'rollup', function () {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( () => {
throw new Error( 'Missing expected error' );
}, err => {
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, context, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, paths, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict' );
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, context, dest, entry, exports, external, footer, format, globals, indent, interop, intro, moduleId, moduleName, noConflict, onwarn, outro, paths, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict' );
});
});

Loading…
Cancel
Save