Socket
Socket
Sign inDemoInstall

rollup

Package Overview
Dependencies
Maintainers
1
Versions
818
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

src/utils/getExportMode.js

6

CHANGELOG.md
# rollup changelog
## 0.7.1
* Named functions can be used as default exports from a bundle
* Method calls are assumed to mutate the owner (i.e. `foo.bar()` mutates `foo`) ([#13](https://github.com/rollup/rollup/issues/13))
* `options.indent` can be used to control indentation of resulting bundle. `options.true` (default) means 'auto', `options.false` means empty string. Alternatively specify whitespace e.g. `' '` or `'\t'` ([#5](https://github.com/rollup/rollup/issues/5))
## 0.7.0

@@ -4,0 +10,0 @@

156

dist/rollup.js

@@ -404,2 +404,7 @@ 'use strict';

});
// `foo.bar()` is assumed to mutate foo
if (node.callee.type === 'MemberExpression') {
addNode(node.callee);
}
}

@@ -751,2 +756,3 @@ };

var isDeclaration = /Declaration$/.test(node.declaration.type);
var declaredName = isDeclaration && node.declaration.id.name;

@@ -756,3 +762,4 @@ _this2.exports.default = {

name: 'default',
localName: isDeclaration ? node.declaration.id.name : 'default',
localName: declaredName || 'default',
declaredName: declaredName,
isDeclaration: isDeclaration

@@ -1102,3 +1109,6 @@ };

function amd(bundle, magicString, exportMode, options) {
function amd(bundle, magicString, _ref, options) {
var exportMode = _ref.exportMode;
var indentString = _ref.indentString;
var deps = bundle.externalModules.map(quoteId);

@@ -1132,6 +1142,8 @@ var args = bundle.externalModules.map(getName);

return magicString.trim().indent().append('\n\n});').prepend(intro);
return magicString.indent(indentString).append('\n\n});').prepend(intro);
}
function cjs(bundle, magicString, exportMode) {
function cjs(bundle, magicString, _ref) {
var exportMode = _ref.exportMode;
var intro = '\'use strict\';\n\n';

@@ -1175,3 +1187,5 @@

function es6(bundle, magicString, exportMode, options) {
function es6(bundle, magicString, _ref, options) {
var exportMode = _ref.exportMode;
var introBlock = ''; // TODO...

@@ -1199,3 +1213,6 @@

function iife(bundle, magicString, exportMode, options) {
function iife(bundle, magicString, _ref, options) {
var exportMode = _ref.exportMode;
var indentString = _ref.indentString;
var globalNames = options.globals || blank();

@@ -1228,6 +1245,9 @@

return magicString.indent().prepend(intro).append(outro);
return magicString.indent(indentString).prepend(intro).append(outro);
}
function umd(bundle, magicString, exportMode, options) {
function umd(bundle, magicString, _ref, options) {
var exportMode = _ref.exportMode;
var indentString = _ref.indentString;
if (exportMode !== 'none' && !options.moduleName) {

@@ -1262,3 +1282,3 @@ throw new Error('You must supply options.moduleName for UMD bundles');

var intro = ('(function (global, factory) {\n\t\t\ttypeof exports === \'object\' && typeof module !== \'undefined\' ? ' + cjsExport + 'factory(' + cjsDeps.join(', ') + ') :\n\t\t\ttypeof define === \'function\' && define.amd ? define(' + amdParams + 'factory) :\n\t\t\t' + defaultExport + 'factory(' + globalDeps + ');\n\t\t}(this, function (' + args + ') { \'use strict\';\n\n\t\t').replace(/^\t\t/gm, '').replace(/^\t/gm, indentStr);
var intro = ('(function (global, factory) {\n\t\t\ttypeof exports === \'object\' && typeof module !== \'undefined\' ? ' + cjsExport + 'factory(' + cjsDeps.join(', ') + ') :\n\t\t\ttypeof define === \'function\' && define.amd ? define(' + amdParams + 'factory) :\n\t\t\t' + defaultExport + 'factory(' + globalDeps + ');\n\t\t}(this, function (' + args + ') { \'use strict\';\n\n\t\t').replace(/^\t\t/gm, '').replace(/^\t/gm, magicString.getIndentString());

@@ -1283,3 +1303,3 @@ var exports = bundle.entryModule.exports;

return magicString.trim().indent().append('\n\n}));').prepend(intro);
return magicString.trim().indent(indentString).append('\n\n}));').prepend(intro);
}

@@ -1358,8 +1378,43 @@

function Bundle___classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function badExports(option, keys) {
throw new Error('\'' + option + '\' was specified for options.exports, but entry module has following exports: ' + keys.join(', '));
}
function getExportMode(bundle, exportMode) {
var exportKeys = keys(bundle.entryModule.exports);
if (exportMode === 'default') {
if (exportKeys.length !== 1 || exportKeys[0] !== 'default') {
badExports('default', exportKeys);
}
} else if (exportMode === 'none' && exportKeys.length) {
badExports('none', exportKeys);
}
if (!exportMode || exportMode === 'auto') {
if (exportKeys.length === 0) {
exportMode = 'none';
} else if (exportKeys.length === 1 && exportKeys[0] === 'default') {
exportMode = 'default';
} else {
exportMode = 'named';
}
}
if (!/(?:default|named|none)/.test(exportMode)) {
throw new Error('options.exports must be \'default\', \'named\', \'none\', \'auto\', or left unspecified (defaults to \'auto\')');
}
return exportMode;
}
function getIndentString(magicString, options) {
if (!('indent' in options) || options.indent === true) {
return magicString.getIndentString();
}
return options.indent || '';
}
function Bundle___classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Bundle = (function () {

@@ -1431,21 +1486,34 @@ function Bundle(options) {

return this.fetchModule(this.entryPath, null).then(function (entryModule) {
var defaultExport = entryModule.exports.default;
_this2.entryModule = entryModule;
if (entryModule.exports.default) {
(function () {
var defaultExportName = makeLegalIdentifier(_path.basename(_this2.entryPath).slice(0, -_path.extname(_this2.entryPath).length));
if (defaultExport) {
// `export default function foo () {...}` -
// use the declared name for the export
if (defaultExport.declaredName) {
entryModule.suggestName('default', defaultExport.declaredName);
}
var topLevelNames = [];
entryModule.statements.forEach(function (statement) {
keys(statement.defines).forEach(function (name) {
return topLevelNames.push(name);
// `export default a + b` - generate an export name
// based on the filename of the entry module
else {
(function () {
var defaultExportName = makeLegalIdentifier(_path.basename(_this2.entryPath).slice(0, -_path.extname(_this2.entryPath).length));
// deconflict
var topLevelNames = [];
entryModule.statements.forEach(function (statement) {
keys(statement.defines).forEach(function (name) {
return topLevelNames.push(name);
});
});
});
while (~topLevelNames.indexOf(defaultExportName)) {
defaultExportName = '_' + defaultExportName;
}
while (~topLevelNames.indexOf(defaultExportName)) {
defaultExportName = '_' + defaultExportName;
}
entryModule.suggestName('default', defaultExportName);
})();
entryModule.suggestName('default', defaultExportName);
})();
}
}

@@ -1540,4 +1608,2 @@

// Determine export mode - 'default', 'named', 'none'
var exportMode = this.getExportMode(options.exports);
var format = options.format || 'es6';

@@ -1681,4 +1747,10 @@

magicString = finalise(this, magicString.trim(), exportMode, options);
magicString = finalise(this, magicString.trim(), {
// Determine export mode - 'default', 'named', 'none'
exportMode: getExportMode(this, options.exports),
// Determine indentation
indentString: getIndentString(magicString, options)
}, options);
var code = magicString.toString();

@@ -1706,30 +1778,2 @@ var map = null;

Bundle.prototype.getExportMode = function getExportMode(exportMode) {
var exportKeys = keys(this.entryModule.exports);
if (exportMode === 'default') {
if (exportKeys.length !== 1 || exportKeys[0] !== 'default') {
badExports('default', exportKeys);
}
} else if (exportMode === 'none' && exportKeys.length) {
badExports('none', exportKeys);
}
if (!exportMode || exportMode === 'auto') {
if (exportKeys.length === 0) {
exportMode = 'none';
} else if (exportKeys.length === 1 && exportKeys[0] === 'default') {
exportMode = 'default';
} else {
exportMode = 'named';
}
}
if (!/(?:default|named|none)/.test(exportMode)) {
throw new Error('options.exports must be \'default\', \'named\', \'none\', \'auto\', or left unspecified (defaults to \'auto\')');
}
return exportMode;
};
return Bundle;

@@ -1736,0 +1780,0 @@ })();

{
"name": "rollup",
"version": "0.7.0",
"version": "0.7.1",
"description": "Next-generation ES6 module bundler",

@@ -48,3 +48,3 @@ "main": "dist/rollup.js",

"chalk": "^1.0.0",
"magic-string": "^0.5.3",
"magic-string": "^0.6.2",
"minimist": "^1.1.1",

@@ -51,0 +51,0 @@ "sander": "^0.3.3"

@@ -12,7 +12,5 @@ import { basename, dirname, extname, relative, resolve } from 'path';

import { defaultLoader } from './utils/load';
import getExportMode from './utils/getExportMode';
import getIndentString from './utils/getIndentString';
function badExports ( option, keys ) {
throw new Error( `'${option}' was specified for options.exports, but entry module has following exports: ${keys.join(', ')}` );
}
export default class Bundle {

@@ -81,17 +79,30 @@ constructor ( options ) {

.then( entryModule => {
const defaultExport = entryModule.exports.default;
this.entryModule = entryModule;
if ( entryModule.exports.default ) {
let defaultExportName = makeLegalIdentifier( basename( this.entryPath ).slice( 0, -extname( this.entryPath ).length ) );
if ( defaultExport ) {
// `export default function foo () {...}` -
// use the declared name for the export
if ( defaultExport.declaredName ) {
entryModule.suggestName( 'default', defaultExport.declaredName );
}
let topLevelNames = [];
entryModule.statements.forEach( statement => {
keys( statement.defines ).forEach( name => topLevelNames.push( name ) );
});
// `export default a + b` - generate an export name
// based on the filename of the entry module
else {
let defaultExportName = makeLegalIdentifier( basename( this.entryPath ).slice( 0, -extname( this.entryPath ).length ) );
while ( ~topLevelNames.indexOf( defaultExportName ) ) {
defaultExportName = `_${defaultExportName}`;
// deconflict
let topLevelNames = [];
entryModule.statements.forEach( statement => {
keys( statement.defines ).forEach( name => topLevelNames.push( name ) );
});
while ( ~topLevelNames.indexOf( defaultExportName ) ) {
defaultExportName = `_${defaultExportName}`;
}
entryModule.suggestName( 'default', defaultExportName );
}
entryModule.suggestName( 'default', defaultExportName );
}

@@ -183,4 +194,2 @@

// Determine export mode - 'default', 'named', 'none'
let exportMode = this.getExportMode( options.exports );
const format = options.format || 'es6';

@@ -333,4 +342,10 @@

magicString = finalise( this, magicString.trim(), exportMode, options );
magicString = finalise( this, magicString.trim(), {
// Determine export mode - 'default', 'named', 'none'
exportMode: getExportMode( this, options.exports ),
// Determine indentation
indentString: getIndentString( magicString, options )
}, options );
const code = magicString.toString();

@@ -355,30 +370,2 @@ let map = null;

}
getExportMode ( exportMode ) {
const exportKeys = keys( this.entryModule.exports );
if ( exportMode === 'default' ) {
if ( exportKeys.length !== 1 || exportKeys[0] !== 'default' ) {
badExports( 'default', exportKeys );
}
} else if ( exportMode === 'none' && exportKeys.length ) {
badExports( 'none', exportKeys );
}
if ( !exportMode || exportMode === 'auto' ) {
if ( exportKeys.length === 0 ) {
exportMode = 'none';
} else if ( exportKeys.length === 1 && exportKeys[0] === 'default' ) {
exportMode = 'default';
} else {
exportMode = 'named';
}
}
if ( !/(?:default|named|none)/.test( exportMode ) ) {
throw new Error( `options.exports must be 'default', 'named', 'none', 'auto', or left unspecified (defaults to 'auto')` );
}
return exportMode;
}
}
import { getName, quoteId } from '../utils/map-helpers';
export default function amd ( bundle, magicString, exportMode, options ) {
export default function amd ( bundle, magicString, { exportMode, indentString }, options ) {
let deps = bundle.externalModules.map( quoteId );

@@ -35,6 +35,5 @@ let args = bundle.externalModules.map( getName );

return magicString
.trim()
.indent()
.indent( indentString )
.append( '\n\n});' )
.prepend( intro );
}
import { keys } from '../utils/object';
export default function cjs ( bundle, magicString, exportMode ) {
export default function cjs ( bundle, magicString, { exportMode }) {
let intro = `'use strict';\n\n`;

@@ -5,0 +5,0 @@

import { keys } from '../utils/object';
export default function es6 ( bundle, magicString, exportMode, options ) {
export default function es6 ( bundle, magicString, { exportMode }, options ) {
const introBlock = ''; // TODO...

@@ -5,0 +5,0 @@

import { blank } from '../utils/object';
import { getName } from '../utils/map-helpers';
export default function iife ( bundle, magicString, exportMode, options ) {
export default function iife ( bundle, magicString, { exportMode, indentString }, options ) {
const globalNames = options.globals || blank();

@@ -33,5 +33,5 @@

return magicString
.indent()
.indent( indentString )
.prepend( intro )
.append( outro );
}
import { blank } from '../utils/object';
import { getName, quoteId, req } from '../utils/map-helpers';
export default function umd ( bundle, magicString, exportMode, options ) {
export default function umd ( bundle, magicString, { exportMode, indentString }, options ) {
if ( exportMode !== 'none' && !options.moduleName ) {

@@ -43,3 +43,3 @@ throw new Error( 'You must supply options.moduleName for UMD bundles' );

`.replace( /^\t\t/gm, '' ).replace( /^\t/gm, indentStr );
`.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() );

@@ -66,5 +66,5 @@ const exports = bundle.entryModule.exports;

.trim()
.indent()
.indent( indentString )
.append( '\n\n}));' )
.prepend( intro );
}

@@ -101,2 +101,3 @@ import { Promise } from 'sander';

const isDeclaration = /Declaration$/.test( node.declaration.type );
const declaredName = isDeclaration && node.declaration.id.name;

@@ -106,3 +107,4 @@ this.exports.default = {

name: 'default',
localName: isDeclaration ? node.declaration.id.name : 'default',
localName: declaredName || 'default',
declaredName,
isDeclaration

@@ -109,0 +111,0 @@ };

@@ -191,2 +191,7 @@ import { blank, keys } from './utils/object';

node.arguments.forEach( arg => addNode( arg, false ) );
// `foo.bar()` is assumed to mutate foo
if ( node.callee.type === 'MemberExpression' ) {
addNode( node.callee );
}
}

@@ -193,0 +198,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc