Permalink
Browse files

add: interop option

  • Loading branch information...
1 parent 5d5eb24 commit 211fa097a929a049584a520196d182a3128316a6 @emilos emilos committed Sep 16, 2016
View
@@ -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
@@ -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 );
@@ -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 );
@@ -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'];`;
@@ -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 );
View
@@ -22,6 +22,7 @@ const ALLOWED_KEYS = [
'format',
'globals',
'indent',
+ 'interop',
'intro',
'moduleId',
'moduleName',
@@ -0,0 +1,7 @@
+module.exports = {
+ description: 'getInterop with interop: false',
+ options: {
+ moduleName: 'foo',
+ interop: false
+ }
+};
@@ -0,0 +1,8 @@
+define(['core/view'], function (View) { 'use strict';
+
+ /*eslint import/no-unresolved: 0*/
+ var main = View.extend({});
+
+ return main;
+
+});
@@ -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;
@@ -0,0 +1,6 @@
+import View from 'core/view';
+
+/*eslint import/no-unresolved: 0*/
+var main = View.extend({});
+
+export default main;
@@ -0,0 +1,9 @@
+var foo = (function (View) {
+ 'use strict';
+
+ /*eslint import/no-unresolved: 0*/
+ var main = View.extend({});
+
+ return main;
+
+}(View));
@@ -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;
+
+})));
@@ -0,0 +1,3 @@
+/*eslint import/no-unresolved: 0*/
+import View from 'core/view';
+export default View.extend({});
View
@@ -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' );
});
});

0 comments on commit 211fa09

Please sign in to comment.