diff --git a/LICENSE.md b/LICENSE.md index ae037ce..ec3180a 100644 --- a/LICENSE.md +++ b/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 diff --git a/src/finalisers/amd.js b/src/finalisers/amd.js index 456dd86..96626e2 100644 --- a/src/finalisers/amd.js +++ b/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 ); diff --git a/src/finalisers/iife.js b/src/finalisers/iife.js index 612f70f..8120594 100644 --- a/src/finalisers/iife.js +++ b/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 ); diff --git a/src/finalisers/shared/getInteropBlock.js b/src/finalisers/shared/getInteropBlock.js index 67a26d7..6ecdba0 100644 --- a/src/finalisers/shared/getInteropBlock.js +++ b/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'];`; diff --git a/src/finalisers/umd.js b/src/finalisers/umd.js index a36db02..f2be2a2 100644 --- a/src/finalisers/umd.js +++ b/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 ); diff --git a/src/rollup.js b/src/rollup.js index 2ab5b51..be39d0b 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -22,6 +22,7 @@ const ALLOWED_KEYS = [ 'format', 'globals', 'indent', + 'interop', 'intro', 'moduleId', 'moduleName', diff --git a/test/form/interop-false/_config.js b/test/form/interop-false/_config.js new file mode 100644 index 0000000..0076e3a --- /dev/null +++ b/test/form/interop-false/_config.js @@ -0,0 +1,7 @@ +module.exports = { + description: 'getInterop with interop: false', + options: { + moduleName: 'foo', + interop: false + } +}; diff --git a/test/form/interop-false/_expected/amd.js b/test/form/interop-false/_expected/amd.js new file mode 100644 index 0000000..3ee81e0 --- /dev/null +++ b/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; + +}); \ No newline at end of file diff --git a/test/form/interop-false/_expected/cjs.js b/test/form/interop-false/_expected/cjs.js new file mode 100644 index 0000000..4813a5d --- /dev/null +++ b/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; \ No newline at end of file diff --git a/test/form/interop-false/_expected/es.js b/test/form/interop-false/_expected/es.js new file mode 100644 index 0000000..d404c44 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/test/form/interop-false/_expected/iife.js b/test/form/interop-false/_expected/iife.js new file mode 100644 index 0000000..fe0202b --- /dev/null +++ b/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)); \ No newline at end of file diff --git a/test/form/interop-false/_expected/umd.js b/test/form/interop-false/_expected/umd.js new file mode 100644 index 0000000..2f376e3 --- /dev/null +++ b/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; + +}))); \ No newline at end of file diff --git a/test/form/interop-false/main.js b/test/form/interop-false/main.js new file mode 100644 index 0000000..8d67d61 --- /dev/null +++ b/test/form/interop-false/main.js @@ -0,0 +1,3 @@ +/*eslint import/no-unresolved: 0*/ +import View from 'core/view'; +export default View.extend({}); \ No newline at end of file diff --git a/test/test.js b/test/test.js index ca11679..5876435 100644 --- a/test/test.js +++ b/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' ); }); });