Browse Source

Merge branch 'master' into gh-813

semi-dynamic-namespace-imports
Bogdan Chadkin 9 years ago
parent
commit
bd6b12bf3a
  1. 8
      .eslintrc
  2. 4
      CHANGELOG.md
  3. 2
      package.json
  4. 14
      src/Bundle.js
  5. 10
      src/Module.js
  6. 2
      src/ast/flatten.js
  7. 4
      src/finalisers/amd.js
  8. 8
      src/finalisers/iife.js
  9. 8
      src/finalisers/umd.js
  10. 4
      src/rollup.js
  11. 8
      src/utils/collapseSourcemaps.js
  12. 2
      src/utils/defaults.js
  13. 2
      src/utils/makeLegalIdentifier.js
  14. 2
      src/utils/object.js
  15. 2
      src/utils/promise.js
  16. 4
      src/utils/pureFunctions.js
  17. 4
      src/utils/transform.js
  18. 10
      test/test.js

8
.eslintrc

@ -7,15 +7,19 @@
"space-before-blocks": [ 2, "always" ], "space-before-blocks": [ 2, "always" ],
"space-before-function-paren": [ 2, "always" ], "space-before-function-paren": [ 2, "always" ],
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
"no-cond-assign": [ 0 ], "no-cond-assign": 0,
"object-shorthand": [2, "always" ], "no-unused-vars": 2,
"object-shorthand": [ 2, "always" ],
"no-const-assign": 2, "no-const-assign": 2,
"no-class-assign": 2, "no-class-assign": 2,
"no-this-before-super": 2, "no-this-before-super": 2,
"no-var": 2, "no-var": 2,
"no-unreachable": 2,
"valid-typeof": 2,
"quote-props": [ 2, "as-needed" ], "quote-props": [ 2, "as-needed" ],
"one-var": [ 2, "never" ], "one-var": [ 2, "never" ],
"prefer-arrow-callback": 2, "prefer-arrow-callback": 2,
"prefer-const": [ 2, { "destructuring": "all" } ],
"arrow-spacing": 2 "arrow-spacing": 2
}, },
"env": { "env": {

4
CHANGELOG.md

@ -1,5 +1,9 @@
# rollup changelog # rollup changelog
## 0.34.4
* Module render performance tweak ([#823](https://github.com/rollup/rollup/pull/823))
## 0.34.3 ## 0.34.3
* Avoid infinite recursion in `Bundle.sort()` ([#800](https://github.com/rollup/rollup/pull/800)) * Avoid infinite recursion in `Bundle.sort()` ([#800](https://github.com/rollup/rollup/pull/800))

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "rollup", "name": "rollup",
"version": "0.34.3", "version": "0.34.4",
"description": "Next-generation ES6 module bundler", "description": "Next-generation ES6 module bundler",
"main": "dist/rollup.js", "main": "dist/rollup.js",
"module": "dist/rollup.es.js", "module": "dist/rollup.es.js",

14
src/Bundle.js

@ -130,7 +130,7 @@ export default class Bundle {
} }
deconflict () { deconflict () {
let used = blank(); const used = blank();
// ensure no conflicts with globals // ensure no conflicts with globals
keys( this.assumedGlobals ).forEach( name => used[ name ] = 1 ); keys( this.assumedGlobals ).forEach( name => used[ name ] = 1 );
@ -299,7 +299,7 @@ export default class Bundle {
const exportMode = getExportMode( this, options.exports, options.moduleName ); const exportMode = getExportMode( this, options.exports, options.moduleName );
let magicString = new MagicStringBundle({ separator: '\n\n' }); let magicString = new MagicStringBundle({ separator: '\n\n' });
let usedModules = []; const usedModules = [];
this.orderedModules.forEach( module => { this.orderedModules.forEach( module => {
const source = module.render( format === 'es' ); const source = module.render( format === 'es' );
@ -343,7 +343,7 @@ export default class Bundle {
let code = magicString.toString(); let code = magicString.toString();
let map = null; let map = null;
let bundleSourcemapChain = []; const bundleSourcemapChain = [];
code = transformBundle( code, this.plugins, bundleSourcemapChain ) code = transformBundle( code, this.plugins, bundleSourcemapChain )
.replace( new RegExp( `\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'g' ), '' ); .replace( new RegExp( `\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'g' ), '' );
@ -366,12 +366,12 @@ export default class Bundle {
} }
sort () { sort () {
let seen = {};
let hasCycles; let hasCycles;
let ordered = []; const seen = {};
const ordered = [];
let stronglyDependsOn = blank(); const stronglyDependsOn = blank();
let dependsOn = blank(); const dependsOn = blank();
this.modules.forEach( module => { this.modules.forEach( module => {
stronglyDependsOn[ module.id ] = blank(); stronglyDependsOn[ module.id ] = blank();

10
src/Module.js

@ -122,7 +122,7 @@ export default class Module {
// export var a = 1, b = 2, c = 3; // export var a = 1, b = 2, c = 3;
// export function foo () {} // export function foo () {}
else if ( node.declaration ) { else if ( node.declaration ) {
let declaration = node.declaration; const declaration = node.declaration;
if ( declaration.type === 'VariableDeclaration' ) { if ( declaration.type === 'VariableDeclaration' ) {
declaration.declarations.forEach( decl => { declaration.declarations.forEach( decl => {
@ -275,7 +275,7 @@ export default class Module {
} }
getExports () { getExports () {
let exports = blank(); const exports = blank();
keys( this.exports ).forEach( name => { keys( this.exports ).forEach( name => {
exports[ name ] = true; exports[ name ] = true;
@ -354,7 +354,7 @@ export default class Module {
} }
}); });
let statements = []; const statements = [];
let lastChar = 0; let lastChar = 0;
let commentIndex = 0; let commentIndex = 0;
@ -448,7 +448,7 @@ export default class Module {
} }
render ( es ) { render ( es ) {
let magicString = this.magicString.clone(); const magicString = this.magicString;
this.statements.forEach( statement => { this.statements.forEach( statement => {
if ( !statement.isIncluded ) { if ( !statement.isIncluded ) {
@ -504,7 +504,7 @@ export default class Module {
} }
} }
let toDeshadow = blank(); const toDeshadow = blank();
statement.references.forEach( reference => { statement.references.forEach( reference => {
const { start, end } = reference; const { start, end } = reference;

2
src/ast/flatten.js

@ -1,5 +1,5 @@
export default function flatten ( node ) { export default function flatten ( node ) {
let parts = []; const parts = [];
while ( node.type === 'MemberExpression' ) { while ( node.type === 'MemberExpression' ) {
if ( node.computed ) return null; if ( node.computed ) return null;
parts.unshift( node.property.name ); parts.unshift( node.property.name );

4
src/finalisers/amd.js

@ -4,8 +4,8 @@ import getExportBlock from './shared/getExportBlock.js';
import esModuleExport from './shared/esModuleExport.js'; import esModuleExport from './shared/esModuleExport.js';
export default function amd ( bundle, magicString, { exportMode, indentString }, options ) { export default function amd ( bundle, magicString, { exportMode, indentString }, options ) {
let deps = bundle.externalModules.map( quotePath ); const deps = bundle.externalModules.map( quotePath );
let args = bundle.externalModules.map( getName ); const args = bundle.externalModules.map( getName );
if ( exportMode === 'named' ) { if ( exportMode === 'named' ) {
args.unshift( `exports` ); args.unshift( `exports` );

8
src/finalisers/iife.js

@ -5,7 +5,7 @@ import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js'; import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
function setupNamespace ( keypath ) { function setupNamespace ( keypath ) {
let parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`? const parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`?
parts.pop(); parts.pop();
@ -22,9 +22,9 @@ export default function iife ( bundle, magicString, { exportMode, indentString }
const name = options.moduleName; const name = options.moduleName;
const isNamespaced = name && ~name.indexOf( '.' ); const isNamespaced = name && ~name.indexOf( '.' );
let dependencies = bundle.externalModules.map( globalNameMaker ); const dependencies = bundle.externalModules.map( globalNameMaker );
let args = bundle.externalModules.map( getName ); const args = bundle.externalModules.map( getName );
if ( exportMode !== 'none' && !name ) { if ( exportMode !== 'none' && !name ) {
throw new Error( 'You must supply options.moduleName for IIFE bundles' ); throw new Error( 'You must supply options.moduleName for IIFE bundles' );
@ -38,7 +38,7 @@ export default function iife ( bundle, magicString, { exportMode, indentString }
const useStrict = options.useStrict !== false ? `'use strict';` : ``; const useStrict = options.useStrict !== false ? `'use strict';` : ``;
let intro = `(function (${args}) {\n`; let intro = `(function (${args}) {\n`;
let outro = `\n\n}(${dependencies}));`; const outro = `\n\n}(${dependencies}));`;
if ( exportMode === 'default' ) { if ( exportMode === 'default' ) {
intro = ( isNamespaced ? `this.` : `${bundle.varOrConst} ` ) + `${name} = ${intro}`; intro = ( isNamespaced ? `this.` : `${bundle.varOrConst} ` ) + `${name} = ${intro}`;

8
src/finalisers/umd.js

@ -23,11 +23,11 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn ); const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
let amdDeps = bundle.externalModules.map( quotePath ); const amdDeps = bundle.externalModules.map( quotePath );
let cjsDeps = bundle.externalModules.map( req ); const cjsDeps = bundle.externalModules.map( req );
let globalDeps = bundle.externalModules.map( module => `global.${globalNameMaker( module )}` ); const globalDeps = bundle.externalModules.map( module => `global.${globalNameMaker( module )}` );
let args = bundle.externalModules.map( getName ); const args = bundle.externalModules.map( getName );
if ( exportMode === 'named' ) { if ( exportMode === 'named' ) {
amdDeps.unshift( `'exports'` ); amdDeps.unshift( `'exports'` );

4
src/rollup.js

@ -80,10 +80,10 @@ export function rollup ( options ) {
} }
const dest = options.dest; const dest = options.dest;
let output = generate( options ); const output = generate( options );
let { code, map } = output; let { code, map } = output;
let promises = []; const promises = [];
if ( options.sourceMap ) { if ( options.sourceMap ) {
let url; let url;

8
src/utils/collapseSourcemaps.js

@ -21,12 +21,12 @@ class Link {
} }
traceMappings () { traceMappings () {
let sources = []; const sources = [];
let sourcesContent = []; const sourcesContent = [];
let names = []; const names = [];
const mappings = this.mappings.map( line => { const mappings = this.mappings.map( line => {
let tracedLine = []; const tracedLine = [];
line.forEach( segment => { line.forEach( segment => {
const source = this.sources[ segment[1] ]; const source = this.sources[ segment[1] ];

2
src/utils/defaults.js

@ -32,7 +32,7 @@ export function resolveId ( importee, importer ) {
export function makeOnwarn () { export function makeOnwarn () {
let warned = blank(); const warned = blank();
return msg => { return msg => {
if ( msg in warned ) return; if ( msg in warned ) return;

2
src/utils/makeLegalIdentifier.js

@ -3,7 +3,7 @@ import { blank } from './object.js';
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' ); const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' ); const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );
let blacklisted = blank(); const blacklisted = blank();
reservedWords.concat( builtins ).forEach( word => blacklisted[ word ] = true ); reservedWords.concat( builtins ).forEach( word => blacklisted[ word ] = true );

2
src/utils/object.js

@ -10,7 +10,7 @@ export function forOwn ( object, func ) {
export function assign ( target, ...sources ) { export function assign ( target, ...sources ) {
sources.forEach( source => { sources.forEach( source => {
for ( let key in source ) { for ( const key in source ) {
if ( source.hasOwnProperty( key ) ) target[ key ] = source[ key ]; if ( source.hasOwnProperty( key ) ) target[ key ] = source[ key ];
} }
}); });

2
src/utils/promise.js

@ -1,5 +1,5 @@
export function mapSequence ( array, fn ) { export function mapSequence ( array, fn ) {
let results = []; const results = [];
let promise = Promise.resolve(); let promise = Promise.resolve();
function next ( member, i ) { function next ( member, i ) {

4
src/utils/pureFunctions.js

@ -1,9 +1,9 @@
let pureFunctions = {}; const pureFunctions = {};
const arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' ); const arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' );
const simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split( ' ' ); const simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split( ' ' );
const simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( ' ' ); const simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( ' ' );
let allSimdMethods = []; const allSimdMethods = [];
simdTypes.forEach( t => { simdTypes.forEach( t => {
simdMethods.forEach( m => { simdMethods.forEach( m => {
allSimdMethods.push( `SIMD.${t}.${m}` ); allSimdMethods.push( `SIMD.${t}.${m}` );

4
src/utils/transform.js

@ -1,9 +1,9 @@
export default function transform ( source, id, plugins ) { export default function transform ( source, id, plugins ) {
let sourceMapChain = []; const sourceMapChain = [];
const originalSourceMap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map; const originalSourceMap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map;
let originalCode = source.code; const originalCode = source.code;
let ast = source.ast; let ast = source.ast;
return plugins.reduce( ( promise, plugin ) => { return plugins.reduce( ( promise, plugin ) => {

10
test/test.js

@ -166,7 +166,7 @@ describe( 'rollup', function () {
const config = loadConfig( FUNCTION + '/' + dir + '/_config.js' ); const config = loadConfig( FUNCTION + '/' + dir + '/_config.js' );
( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => { ( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => {
let warnings = []; const warnings = [];
const captureWarning = msg => warnings.push( msg ); const captureWarning = msg => warnings.push( msg );
const options = extend( { const options = extend( {
@ -216,7 +216,7 @@ describe( 'rollup', function () {
if ( config.code ) config.code( code ); if ( config.code ) config.code( code );
let module = { const module = {
exports: {} exports: {}
}; };
@ -475,7 +475,7 @@ describe( 'rollup', function () {
const cjs = bundle.generate({ format: 'cjs' }); const cjs = bundle.generate({ format: 'cjs' });
const m = new Function( 'module', 'exports', cjs.code ); const m = new Function( 'module', 'exports', cjs.code );
let module = { exports: {} }; const module = { exports: {} };
m( module, module.exports ); m( module, module.exports );
return module.exports; return module.exports;
@ -608,7 +608,7 @@ describe( 'rollup', function () {
}); });
it( 'calls ongenerate hooks in sequence', () => { it( 'calls ongenerate hooks in sequence', () => {
let result = []; const result = [];
return rollup.rollup({ return rollup.rollup({
entry: 'entry', entry: 'entry',
@ -636,7 +636,7 @@ describe( 'rollup', function () {
}); });
it( 'calls onwrite hooks in sequence', () => { it( 'calls onwrite hooks in sequence', () => {
let result = []; const result = [];
const dest = path.join( __dirname, 'tmp/bundle.js' ); const dest = path.join( __dirname, 'tmp/bundle.js' );
return rollup.rollup({ return rollup.rollup({

Loading…
Cancel
Save