Browse Source

Merge branch 'master' into incremental-transform

ghi-672
Rich-Harris 9 years ago
parent
commit
059ba8c010
  1. 22
      CHANGELOG.md
  2. 2
      package.json
  3. 25
      src/Bundle.js
  4. 4
      src/Declaration.js
  5. 5
      src/ExternalModule.js
  6. 19
      src/Module.js
  7. 3
      src/Statement.js
  8. 5
      src/finalisers/amd.js
  9. 33
      src/finalisers/cjs.js
  10. 14
      src/finalisers/es6.js
  11. 2
      src/finalisers/iife.js
  12. 1
      src/finalisers/shared/esModuleExport.js
  13. 16
      src/finalisers/shared/getInteropBlock.js
  14. 5
      src/finalisers/umd.js
  15. 1
      src/rollup.js
  16. 4
      src/utils/run.js
  17. 2
      test/form/assignment-to-exports-class-declaration/_expected/amd.js
  18. 2
      test/form/assignment-to-exports-class-declaration/_expected/cjs.js
  19. 2
      test/form/assignment-to-exports-class-declaration/_expected/umd.js
  20. 4
      test/form/computed-properties/_expected/amd.js
  21. 4
      test/form/computed-properties/_expected/cjs.js
  22. 4
      test/form/computed-properties/_expected/umd.js
  23. 3
      test/form/conflicting-imports/_config.js
  24. 7
      test/form/conflicting-imports/_expected/amd.js
  25. 8
      test/form/conflicting-imports/_expected/cjs.js
  26. 6
      test/form/conflicting-imports/_expected/es6.js
  27. 8
      test/form/conflicting-imports/_expected/iife.js
  28. 11
      test/form/conflicting-imports/_expected/umd.js
  29. 4
      test/form/conflicting-imports/main.js
  30. 3
      test/form/conflicting-imports/other.js
  31. 2
      test/form/dedupes-external-imports/_expected/amd.js
  32. 2
      test/form/dedupes-external-imports/_expected/cjs.js
  33. 4
      test/form/dedupes-external-imports/_expected/umd.js
  34. 2
      test/form/export-all-from-internal/_expected/amd.js
  35. 2
      test/form/export-all-from-internal/_expected/cjs.js
  36. 4
      test/form/export-all-from-internal/_expected/umd.js
  37. 4
      test/form/export-default-import/_expected/amd.js
  38. 4
      test/form/export-default-import/_expected/cjs.js
  39. 4
      test/form/export-default-import/_expected/umd.js
  40. 2
      test/form/exports-at-end-if-possible/_expected/amd.js
  41. 2
      test/form/exports-at-end-if-possible/_expected/cjs.js
  42. 4
      test/form/exports-at-end-if-possible/_expected/umd.js
  43. 3
      test/form/import-external-namespace-and-default/_config.js
  44. 9
      test/form/import-external-namespace-and-default/_expected/amd.js
  45. 8
      test/form/import-external-namespace-and-default/_expected/cjs.js
  46. 6
      test/form/import-external-namespace-and-default/_expected/es6.js
  47. 10
      test/form/import-external-namespace-and-default/_expected/iife.js
  48. 13
      test/form/import-external-namespace-and-default/_expected/umd.js
  49. 4
      test/form/import-external-namespace-and-default/main.js
  50. 3
      test/form/import-external-namespace-and-default/other.js
  51. 2
      test/form/multiple-exports/_expected/amd.js
  52. 2
      test/form/multiple-exports/_expected/cjs.js
  53. 4
      test/form/multiple-exports/_expected/umd.js
  54. 4
      test/form/namespaced-named-exports/_expected/amd.js
  55. 4
      test/form/namespaced-named-exports/_expected/cjs.js
  56. 4
      test/form/namespaced-named-exports/_expected/umd.js
  57. 2
      test/form/no-treeshake/_expected/amd.js
  58. 2
      test/form/no-treeshake/_expected/cjs.js
  59. 2
      test/form/no-treeshake/_expected/umd.js
  60. 7
      test/form/prefer-const/_config.js
  61. 18
      test/form/prefer-const/_expected/amd.js
  62. 20
      test/form/prefer-const/_expected/cjs.js
  63. 18
      test/form/prefer-const/_expected/es6.js
  64. 19
      test/form/prefer-const/_expected/iife.js
  65. 22
      test/form/prefer-const/_expected/umd.js
  66. 9
      test/form/prefer-const/main.js
  67. 2
      test/form/prefer-const/namespace.js
  68. 3
      test/form/preserve-debugger/_config.js
  69. 7
      test/form/preserve-debugger/_expected/amd.js
  70. 5
      test/form/preserve-debugger/_expected/cjs.js
  71. 3
      test/form/preserve-debugger/_expected/es6.js
  72. 8
      test/form/preserve-debugger/_expected/iife.js
  73. 11
      test/form/preserve-debugger/_expected/umd.js
  74. 3
      test/form/preserve-debugger/main.js
  75. 2
      test/form/preserves-comments-after-imports/_expected/amd.js
  76. 2
      test/form/preserves-comments-after-imports/_expected/cjs.js
  77. 4
      test/form/preserves-comments-after-imports/_expected/umd.js
  78. 4
      test/form/umd-noconflict/_expected/amd.js
  79. 4
      test/form/umd-noconflict/_expected/cjs.js
  80. 2
      test/form/umd-noconflict/_expected/umd.js
  81. 8
      test/function/double-default-export/_config.js
  82. 2
      test/function/double-default-export/foo.js
  83. 2
      test/function/double-default-export/main.js
  84. 8
      test/function/double-named-export/_config.js
  85. 3
      test/function/double-named-export/foo.js
  86. 2
      test/function/double-named-export/main.js
  87. 8
      test/function/double-named-reexport/_config.js
  88. 1
      test/function/double-named-reexport/bar.js
  89. 3
      test/function/double-named-reexport/foo.js
  90. 2
      test/function/double-named-reexport/main.js
  91. 28
      test/function/external-alias/_config.js
  92. 10
      test/function/external-alias/first/main.js
  93. 7
      test/function/external-alias/first/module.js
  94. 14
      test/function/external-function/_config.js
  95. 2
      test/function/external-function/main.js
  96. 18
      test/function/external-normalization/_config.js
  97. 2
      test/function/external-normalization/main.js
  98. 2
      test/function/warn-on-eval/_config.js
  99. 2
      test/test.js

22
CHANGELOG.md

@ -1,5 +1,27 @@
# rollup changelog
## 0.27.7
* Distinguish between default and namespace imports of external module ([#637](https://github.com/rollup/rollup/issues/637))
* Add `__esModule` property to named exports in AMD, CJS and UMD modes ([#650](https://github.com/rollup/rollup/issues/650))
## 0.26.6
* Deconflict named imports from external modules in ES bundles ([#659](https://github.com/rollup/rollup/issues/659))
* Support `options.preferConst` to generate `const` declarations for exports rather than `var` declarations ([#653](https://github.com/rollup/rollup/issues/653))
## 0.26.5
* Preserve `debugger` statements ([#664](https://github.com/rollup/rollup/issues/664))
* Allow `options.external` to be a function ([#522](https://github.com/rollup/rollup/issues/522))
## 0.26.4
* Prevent plugin-provided external IDs being normalised ([#630](https://github.com/rollup/rollup/issues/630), [#633](https://github.com/rollup/rollup/issues/633))
* Throw if module exports/re-exports the same name twice, or has multiple default exports ([#679](https://github.com/rollup/rollup/issues/679))
* Warn about `eval` security issue ([#675]((https://github.com/rollup/rollup/issues/675)))
## 0.26.3
* Ensure reference is not incorrectly marked as a reassignment ([#648](https://github.com/rollup/rollup/issues/648))

2
package.json

@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "0.26.3",
"version": "0.26.7",
"description": "Next-generation ES6 module bundler",
"main": "dist/rollup.js",
"jsnext:main": "src/rollup.js",

25
src/Bundle.js

@ -15,7 +15,7 @@ import transformBundle from './utils/transformBundle.js';
import collapseSourcemaps from './utils/collapseSourcemaps.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import callIfFunction from './utils/callIfFunction.js';
import { dirname, isRelative, relative, resolve } from './utils/path.js';
import { dirname, isRelative, isAbsolute, relative, resolve } from './utils/path.js';
export default class Bundle {
constructor ( options ) {
@ -41,7 +41,7 @@ export default class Bundle {
this.treeshake = options.treeshake !== false;
this.resolveId = first(
[ id => ~this.external.indexOf( id ) ? false : null ]
[ id => this.isExternal( id ) ? false : null ]
.concat( this.plugins.map( plugin => plugin.resolveId ).filter( Boolean ) )
.concat( resolveId )
);
@ -69,11 +69,19 @@ export default class Bundle {
this.assumedGlobals = blank();
this.external = ensureArray( options.external ).map( id => id.replace( /[\/\\]/g, '/' ) );
if ( typeof options.external === 'function' ) {
this.isExternal = options.external;
} else {
const ids = ensureArray( options.external ).map( id => id.replace( /[\/\\]/g, '/' ) );
this.isExternal = id => ids.indexOf( id ) !== -1;
}
this.onwarn = options.onwarn || makeOnwarn();
// TODO strictly speaking, this only applies with non-ES6, non-default-only bundles
[ 'module', 'exports', '_interopDefault' ].forEach( global => this.assumedGlobals[ global ] = true );
this.varOrConst = options.preferConst ? 'const' : 'var';
}
build () {
@ -220,16 +228,21 @@ export default class Bundle {
// This could be an external, relative dependency, based on the current module's parent dir.
externalName = resolve( module.id, '..', source );
}
const forcedExternal = externalName && ~this.external.indexOf( externalName );
const forcedExternal = externalName && this.isExternal( externalName );
if ( !resolvedId || forcedExternal ) {
let normalizedExternal = source;
if ( !forcedExternal ) {
if ( isRelative( source ) ) throw new Error( `Could not resolve ${source} from ${module.id}` );
if ( !~this.external.indexOf( source ) ) this.onwarn( `Treating '${source}' as external dependency` );
if ( !this.isExternal( source ) ) this.onwarn( `Treating '${source}' as external dependency` );
} else if ( resolvedId ) {
normalizedExternal = this.getPathRelativeToEntryDirname( resolvedId );
if ( isRelative(resolvedId) || isAbsolute(resolvedId) ) {
// Try to deduce relative path from entry dir if resolvedId is defined as a relative path.
normalizedExternal = this.getPathRelativeToEntryDirname( resolvedId );
} else {
normalizedExternal = resolvedId;
}
}
module.resolvedIds[ source ] = normalizedExternal;

4
src/Declaration.js

@ -241,7 +241,7 @@ export class SyntheticNamespaceDeclaration {
return `${indentString}${name}: ${original.render()}`;
});
return `var ${this.render()} = Object.freeze({\n${members.join( ',\n' )}\n});\n\n`;
return `${this.module.bundle.varOrConst} ${this.render()} = Object.freeze({\n${members.join( ',\n' )}\n});\n\n`;
}
render () {
@ -282,7 +282,7 @@ export class ExternalDeclaration {
}
if ( this.name === 'default' ) {
return !es6 && this.module.exportsNames ?
return this.module.exportsNamespace || ( !es6 && this.module.exportsNames ) ?
`${this.module.name}__default` :
this.module.name;
}

5
src/ExternalModule.js

@ -27,9 +27,8 @@ export default class ExternalModule {
}
traceExport ( name ) {
if ( name !== 'default' && name !== '*' ) {
this.exportsNames = true;
}
if ( name !== 'default' && name !== '*' ) this.exportsNames = true;
if ( name === '*' ) this.exportsNamespace = true;
return this.declarations[ name ] || (
this.declarations[ name ] = new ExternalDeclaration( this, name )

19
src/Module.js

@ -77,7 +77,13 @@ export default class Module {
else {
node.specifiers.forEach( specifier => {
this.reexports[ specifier.exported.name ] = {
const name = specifier.exported.name;
if ( this.exports[ name ] || this.reexports[ name ] ) {
throw new Error( `A module cannot have multiple exports with the same name ('${name}')` );
}
this.reexports[ name ] = {
start: specifier.start,
source,
localName: specifier.local.name,
@ -93,6 +99,11 @@ export default class Module {
else if ( node.type === 'ExportDefaultDeclaration' ) {
const identifier = ( node.declaration.id && node.declaration.id.name ) || node.declaration.name;
if ( this.exports.default ) {
// TODO indicate location
throw new Error( 'A module can only have one default export' );
}
this.exports.default = {
localName: 'default',
identifier
@ -129,6 +140,10 @@ export default class Module {
const localName = specifier.local.name;
const exportedName = specifier.exported.name;
if ( this.exports[ exportedName ] || this.reexports[ exportedName ] ) {
throw new Error( `A module cannot have multiple exports with the same name ('${exportedName}')` );
}
this.exports[ exportedName ] = { localName };
});
} else {
@ -577,7 +592,7 @@ export default class Module {
if ( statement.node.declaration.type === 'FunctionExpression' ) {
magicString.overwrite( statement.node.start, statement.node.declaration.start + 8, `function ${defaultName}` );
} else {
magicString.overwrite( statement.node.start, statement.node.declaration.start, `var ${defaultName} = ` );
magicString.overwrite( statement.node.start, statement.node.declaration.start, `${this.bundle.varOrConst} ${defaultName} = ` );
}
}

3
src/Statement.js

@ -47,7 +47,8 @@ export default class Statement {
enter ( node, parent, prop ) {
// warn about eval
if ( node.type === 'CallExpression' && node.callee.name === 'eval' && !scope.contains( 'eval' ) ) {
module.bundle.onwarn( `Use of \`eval\` (in ${module.id}) is discouraged, as it may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details` );
// TODO show location
module.bundle.onwarn( `Use of \`eval\` (in ${module.id}) is strongly discouraged, as it poses security risks and may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details` );
}
// skip re-export declarations

5
src/finalisers/amd.js

@ -1,6 +1,7 @@
import { getName, quoteId } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
import esModuleExport from './shared/esModuleExport.js';
export default function amd ( bundle, magicString, { exportMode, indentString }, options ) {
let deps = bundle.externalModules.map( quoteId );
@ -25,6 +26,10 @@ export default function amd ( bundle, magicString, { exportMode, indentString },
const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if ( exportMode === 'named' ) {
magicString.append( `\n\n${esModuleExport}` );
}
return magicString
.indent( indentString )
.append( '\n\n});' )

33
src/finalisers/cjs.js

@ -1,30 +1,41 @@
import getExportBlock from './shared/getExportBlock.js';
import esModuleExport from './shared/esModuleExport.js';
export default function cjs ( bundle, magicString, { exportMode }, options ) {
let intro = options.useStrict === false ? `` : `'use strict';\n\n`;
let intro = ( options.useStrict === false ? `` : `'use strict';\n\n` ) +
( exportMode === 'named' ? `${esModuleExport}\n\n` : '' );
const hasDefaultImport = bundle.externalModules.some( mod => mod.declarations.default);
let needsInterop = false;
if (hasDefaultImport) {
intro += `function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n`;
}
const varOrConst = bundle.varOrConst;
// TODO handle empty imports, once they're supported
const importBlock = bundle.externalModules
.map( module => {
if ( module.declarations.default ) {
if (module.exportsNames) {
return `var ${module.name} = require('${module.id}');` +
`\nvar ${module.name}__default = _interopDefault(${module.name});`;
} else {
return `var ${module.name} = _interopDefault(require('${module.id}'));`;
if ( module.exportsNamespace ) {
return `${varOrConst} ${module.name} = require('${module.id}');` +
`\n${varOrConst} ${module.name}__default = ${module.name}['default'];`;
}
needsInterop = true;
if ( module.exportsNames ) {
return `${varOrConst} ${module.name} = require('${module.id}');` +
`\n${varOrConst} ${module.name}__default = _interopDefault(${module.name});`;
}
return `${varOrConst} ${module.name} = _interopDefault(require('${module.id}'));`;
} else {
return `var ${module.name} = require('${module.id}');`;
return `${varOrConst} ${module.name} = require('${module.id}');`;
}
})
.join( '\n' );
if ( needsInterop ) {
intro += `function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n`;
}
if ( importBlock ) {
intro += importBlock + '\n\n';
}

14
src/finalisers/es6.js

@ -10,10 +10,20 @@ export default function es6 ( bundle, magicString ) {
const specifiers = [];
const specifiersList = [specifiers];
const importedNames = keys( module.declarations )
.filter( name => name !== '*' && name !== 'default' );
.filter( name => name !== '*' && name !== 'default' )
.map( name => {
const declaration = module.declarations[ name ];
if ( declaration.name === declaration.safeName ) return declaration.name;
return `${declaration.name} as ${declaration.safeName}`;
});
if ( module.declarations.default ) {
specifiers.push( module.name );
if ( module.exportsNamespace ) {
specifiersList.push([ `${module.name}__default` ]);
} else {
specifiers.push( module.name );
}
}
const namespaceSpecifier = module.declarations['*'] ? `* as ${module.name}` : null;

2
src/finalisers/iife.js

@ -41,7 +41,7 @@ export default function iife ( bundle, magicString, { exportMode, indentString }
let outro = `\n\n}(${dependencies}));`;
if ( exportMode === 'default' ) {
intro = ( isNamespaced ? `this.` : `var ` ) + `${name} = ${intro}`;
intro = ( isNamespaced ? `this.` : `${bundle.varOrConst} ` ) + `${name} = ${intro}`;
}
if ( isNamespaced ) {

1
src/finalisers/shared/esModuleExport.js

@ -0,0 +1 @@
export default `Object.defineProperty(exports, '__esModule', { value: true });`;

16
src/finalisers/shared/getInteropBlock.js

@ -1,11 +1,17 @@
export default function getInteropBlock ( bundle ) {
return bundle.externalModules
.map( module => {
return module.declarations.default ?
( module.exportsNames ?
`var ${module.name}__default = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};` :
`${module.name} = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};` ) :
null;
if ( !module.declarations.default ) return null;
if ( module.exportsNamespace ) {
return `${bundle.varOrConst} ${module.name}__default = ${module.name}['default'];`;
}
if ( module.exportsNames ) {
return `${bundle.varOrConst} ${module.name}__default = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};`;
}
return `${module.name} = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};`;
})
.filter( Boolean )
.join( '\n' );

5
src/finalisers/umd.js

@ -3,6 +3,7 @@ import { getName, quoteId, req } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
import esModuleExport from './shared/esModuleExport.js';
function setupNamespace ( name ) {
const parts = name.split( '.' );
@ -69,6 +70,10 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if (exportMode === 'named') {
magicString.append( `\n\n${esModuleExport}` );
}
return magicString
.trim()
.indent( indentString )

1
src/rollup.js

@ -25,6 +25,7 @@ const ALLOWED_KEYS = [
'onwarn',
'outro',
'plugins',
'preferConst',
'sourceMap',
'treeshake',
'useStrict',

4
src/utils/run.js

@ -75,6 +75,10 @@ export default function run ( node, scope, statement, strongDependencies, force
}
}
else if ( node.type === 'DebuggerStatement' ) {
hasSideEffect = true;
}
else if ( node.type === 'ThrowStatement' ) {
// we only care about errors thrown at the top level, otherwise
// any function with error checking gets included if called

2
test/form/assignment-to-exports-class-declaration/_expected/amd.js

@ -3,4 +3,6 @@ define(['exports'], function (exports) { 'use strict';
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/assignment-to-exports-class-declaration/_expected/cjs.js

@ -1,4 +1,6 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );

2
test/form/assignment-to-exports-class-declaration/_expected/umd.js

@ -7,4 +7,6 @@
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
Object.defineProperty(exports, '__esModule', { value: true });
}));

4
test/form/computed-properties/_expected/amd.js

@ -16,4 +16,6 @@ define(['exports'], function (exports) { 'use strict';
exports.x = x;
exports.X = X;
});
Object.defineProperty(exports, '__esModule', { value: true });
});

4
test/form/computed-properties/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var foo = 'foo';
var bar = 'bar';
var baz = 'baz';
@ -14,4 +16,4 @@ class X {
}
exports.x = x;
exports.X = X;
exports.X = X;

4
test/form/computed-properties/_expected/umd.js

@ -20,4 +20,6 @@
exports.x = x;
exports.X = X;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

3
test/form/conflicting-imports/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'ensures bundle imports are deconflicted (#659)'
};

7
test/form/conflicting-imports/_expected/amd.js

@ -0,0 +1,7 @@
define(['foo', 'bar'], function (foo, bar) { 'use strict';
console.log( bar.a );
console.log( foo.a );
});

8
test/form/conflicting-imports/_expected/cjs.js

@ -0,0 +1,8 @@
'use strict';
var foo = require('foo');
var bar = require('bar');
console.log( bar.a );
console.log( foo.a );

6
test/form/conflicting-imports/_expected/es6.js

@ -0,0 +1,6 @@
import { a } from 'foo';
import { a as a$1 } from 'bar';
console.log( a$1 );
console.log( a );

8
test/form/conflicting-imports/_expected/iife.js

@ -0,0 +1,8 @@
(function (foo,bar) {
'use strict';
console.log( bar.a );
console.log( foo.a );
}(foo,bar));

11
test/form/conflicting-imports/_expected/umd.js

@ -0,0 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('foo'), require('bar')) :
typeof define === 'function' && define.amd ? define(['foo', 'bar'], factory) :
(factory(global.foo,global.bar));
}(this, function (foo,bar) { 'use strict';
console.log( bar.a );
console.log( foo.a );
}));

4
test/form/conflicting-imports/main.js

@ -0,0 +1,4 @@
import { a } from 'foo';
import './other.js';
console.log( a );

3
test/form/conflicting-imports/other.js

@ -0,0 +1,3 @@
import { a } from 'bar';
console.log( a );

2
test/form/dedupes-external-imports/_expected/amd.js

@ -29,4 +29,6 @@ define(['exports', 'external'], function (exports, external) { 'use strict';
exports.bar = bar;
exports.baz = baz;
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/dedupes-external-imports/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var external = require('external');
class Foo extends external.Component {

4
test/form/dedupes-external-imports/_expected/umd.js

@ -33,4 +33,6 @@
exports.bar = bar;
exports.baz = baz;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

2
test/form/export-all-from-internal/_expected/amd.js

@ -6,4 +6,6 @@ define(['exports'], function (exports) { 'use strict';
exports.a = a;
exports.b = b;
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/export-all-from-internal/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const a = 1;
const b = 2;

4
test/form/export-all-from-internal/_expected/umd.js

@ -10,4 +10,6 @@
exports.a = a;
exports.b = b;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

4
test/form/export-default-import/_expected/amd.js

@ -6,4 +6,6 @@ define(['exports', 'x'], function (exports, x) { 'use strict';
exports.x = x;
});
Object.defineProperty(exports, '__esModule', { value: true });
});

4
test/form/export-default-import/_expected/cjs.js

@ -1,9 +1,11 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var x = _interopDefault(require('x'));
exports.x = x;
exports.x = x;

4
test/form/export-default-import/_expected/umd.js

@ -10,4 +10,6 @@
exports.x = x;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

2
test/form/exports-at-end-if-possible/_expected/amd.js

@ -8,4 +8,6 @@ define(['exports'], function (exports) { 'use strict';
exports.FOO = FOO;
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/exports-at-end-if-possible/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var FOO = 'foo';
console.log( FOO );

4
test/form/exports-at-end-if-possible/_expected/umd.js

@ -12,4 +12,6 @@
exports.FOO = FOO;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

3
test/form/import-external-namespace-and-default/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'disinguishes between external default and namespace (#637)'
};

9
test/form/import-external-namespace-and-default/_expected/amd.js

@ -0,0 +1,9 @@
define(['foo'], function (foo) { 'use strict';
var foo__default = foo['default'];
console.log( foo.bar );
console.log( foo__default );
});

8
test/form/import-external-namespace-and-default/_expected/cjs.js

@ -0,0 +1,8 @@
'use strict';
var foo = require('foo');
var foo__default = foo['default'];
console.log( foo.bar );
console.log( foo__default );

6
test/form/import-external-namespace-and-default/_expected/es6.js

@ -0,0 +1,6 @@
import * as foo from 'foo';
import foo__default from 'foo';
console.log( foo.bar );
console.log( foo__default );

10
test/form/import-external-namespace-and-default/_expected/iife.js

@ -0,0 +1,10 @@
(function (foo) {
'use strict';
var foo__default = foo['default'];
console.log( foo.bar );
console.log( foo__default );
}(foo));

13
test/form/import-external-namespace-and-default/_expected/umd.js

@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('foo')) :
typeof define === 'function' && define.amd ? define(['foo'], factory) :
(factory(global.foo));
}(this, function (foo) { 'use strict';
var foo__default = foo['default'];
console.log( foo.bar );
console.log( foo__default );
}));

4
test/form/import-external-namespace-and-default/main.js

@ -0,0 +1,4 @@
import foo from 'foo';
import './other.js';
console.log( foo );

3
test/form/import-external-namespace-and-default/other.js

@ -0,0 +1,3 @@
import * as foo from 'foo';
console.log( foo.bar );

2
test/form/multiple-exports/_expected/amd.js

@ -6,4 +6,6 @@ define(['exports'], function (exports) { 'use strict';
exports.foo = foo;
exports.bar = bar;
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/multiple-exports/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var foo = 1;
var bar = 2;

4
test/form/multiple-exports/_expected/umd.js

@ -10,4 +10,6 @@
exports.foo = foo;
exports.bar = bar;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

4
test/form/namespaced-named-exports/_expected/amd.js

@ -4,4 +4,6 @@ define(['exports'], function (exports) { 'use strict';
exports.answer = answer;
});
Object.defineProperty(exports, '__esModule', { value: true });
});

4
test/form/namespaced-named-exports/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var answer = 42;
exports.answer = answer;
exports.answer = answer;

4
test/form/namespaced-named-exports/_expected/umd.js

@ -8,4 +8,6 @@
exports.answer = answer;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

2
test/form/no-treeshake/_expected/amd.js

@ -22,4 +22,6 @@ define(['exports', 'external'], function (exports, external) { 'use strict';
exports.getPrototypeOf = getPrototypeOf;
exports.strange = quux;
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/no-treeshake/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var external = require('external');
var foo = 'unused';

2
test/form/no-treeshake/_expected/umd.js

@ -26,4 +26,6 @@
exports.getPrototypeOf = getPrototypeOf;
exports.strange = quux;
Object.defineProperty(exports, '__esModule', { value: true });
}));

7
test/form/prefer-const/_config.js

@ -0,0 +1,7 @@
module.exports = {
description: 'uses const instead of var if specified (#653)',
options: {
preferConst: true,
moduleName: 'myBundle'
}
};

18
test/form/prefer-const/_expected/amd.js

@ -0,0 +1,18 @@
define(['external', 'other', 'another'], function (external, other, another) { 'use strict';
const a = 1;
const b = 2;
const namespace = Object.freeze({
a: a,
b: b
});
console.log( Object.keys( namespace ) );
const main = 42;
return main;
});

20
test/form/prefer-const/_expected/cjs.js

@ -0,0 +1,20 @@
'use strict';
const external = require('external');
const other = require('other');
const another = require('another');
const a = 1;
const b = 2;
const namespace = Object.freeze({
a: a,
b: b
});
console.log( Object.keys( namespace ) );
const main = 42;
module.exports = main;

18
test/form/prefer-const/_expected/es6.js

@ -0,0 +1,18 @@
import 'external';
import 'other';
import 'another';
const a = 1;
const b = 2;
const namespace = Object.freeze({
a: a,
b: b
});
console.log( Object.keys( namespace ) );
const main = 42;
export default main;

19
test/form/prefer-const/_expected/iife.js

@ -0,0 +1,19 @@
const myBundle = (function (external,other,another) {
'use strict';
const a = 1;
const b = 2;
const namespace = Object.freeze({
a: a,
b: b
});
console.log( Object.keys( namespace ) );
const main = 42;
return main;
}(external,other,another));

22
test/form/prefer-const/_expected/umd.js

@ -0,0 +1,22 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('external'), require('other'), require('another')) :
typeof define === 'function' && define.amd ? define(['external', 'other', 'another'], factory) :
(global.myBundle = factory(global.external,global.other,global.another));
}(this, function (external,other,another) { 'use strict';
const a = 1;
const b = 2;
const namespace = Object.freeze({
a: a,
b: b
});
console.log( Object.keys( namespace ) );
const main = 42;
return main;
}));

9
test/form/prefer-const/main.js

@ -0,0 +1,9 @@
import external from 'external';
import a from 'other';
import { b } from 'other';
import { another } from 'another';
import * as namespace from './namespace.js';
console.log( Object.keys( namespace ) );
export default 42;

2
test/form/prefer-const/namespace.js

@ -0,0 +1,2 @@
export const a = 1;
export const b = 2;

3
test/form/preserve-debugger/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'debugger statements are preserved (#664)'
};

7
test/form/preserve-debugger/_expected/amd.js

@ -0,0 +1,7 @@
define(function () { 'use strict';
before();
debugger;
after();
});

5
test/form/preserve-debugger/_expected/cjs.js

@ -0,0 +1,5 @@
'use strict';
before();
debugger;
after();

3
test/form/preserve-debugger/_expected/es6.js

@ -0,0 +1,3 @@
before();
debugger;
after();

8
test/form/preserve-debugger/_expected/iife.js

@ -0,0 +1,8 @@
(function () {
'use strict';
before();
debugger;
after();
}());

11
test/form/preserve-debugger/_expected/umd.js

@ -0,0 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, function () { 'use strict';
before();
debugger;
after();
}));

3
test/form/preserve-debugger/main.js

@ -0,0 +1,3 @@
before();
debugger;
after();

2
test/form/preserves-comments-after-imports/_expected/amd.js

@ -8,4 +8,6 @@ define(['exports'], function (exports) { 'use strict';
exports.obj = obj;
Object.defineProperty(exports, '__esModule', { value: true });
});

2
test/form/preserves-comments-after-imports/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/** A comment for a number */
var number = 5;

4
test/form/preserves-comments-after-imports/_expected/umd.js

@ -12,4 +12,6 @@
exports.obj = obj;
}));
Object.defineProperty(exports, '__esModule', { value: true });
}));

4
test/form/umd-noconflict/_expected/amd.js

@ -12,4 +12,6 @@ define(['exports'], function (exports) { 'use strict';
exports.number = number;
exports.setting = setting;
});
Object.defineProperty(exports, '__esModule', { value: true });
});

4
test/form/umd-noconflict/_expected/cjs.js

@ -1,5 +1,7 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function doThings() {
console.log( 'doing things...' );
}
@ -10,4 +12,4 @@ var setting = 'no';
exports.doThings = doThings;
exports.number = number;
exports.setting = setting;
exports.setting = setting;

2
test/form/umd-noconflict/_expected/umd.js

@ -21,4 +21,6 @@
exports.number = number;
exports.setting = setting;
Object.defineProperty(exports, '__esModule', { value: true });
}));

8
test/function/double-default-export/_config.js

@ -0,0 +1,8 @@
const assert = require( 'assert' );
module.exports = {
description: 'throws on double default exports',
error: err => {
assert.equal( err.message, 'A module can only have one default export' );
}
};

2
test/function/double-default-export/foo.js

@ -0,0 +1,2 @@
export default 1;
export default 2;

2
test/function/double-default-export/main.js

@ -0,0 +1,2 @@
import foo from './foo.js';
console.log( foo );

8
test/function/double-named-export/_config.js

@ -0,0 +1,8 @@
const assert = require( 'assert' );
module.exports = {
description: 'throws on duplicate named exports',
error: err => {
assert.equal( err.message, `A module cannot have multiple exports with the same name ('foo')` );
}
};

3
test/function/double-named-export/foo.js

@ -0,0 +1,3 @@
var foo = 1;
export { foo };
export { foo };

2
test/function/double-named-export/main.js

@ -0,0 +1,2 @@
import { foo } from './foo.js';
console.log( foo );

8
test/function/double-named-reexport/_config.js

@ -0,0 +1,8 @@
const assert = require( 'assert' );
module.exports = {
description: 'throws on duplicate named exports',
error: err => {
assert.equal( err.message, `A module cannot have multiple exports with the same name ('foo')` );
}
};

1
test/function/double-named-reexport/bar.js

@ -0,0 +1 @@
export var foo = 2;

3
test/function/double-named-reexport/foo.js

@ -0,0 +1,3 @@
var foo = 1;
export { foo };
export { foo } from './bar.js';

2
test/function/double-named-reexport/main.js

@ -0,0 +1,2 @@
import { foo } from './foo.js';
console.log( foo );

28
test/function/external-alias/_config.js

@ -0,0 +1,28 @@
var assert = require( 'assert' );
var path = require( 'path' );
module.exports = {
description: 'includes an external module included dynamically by an alias',
options: {
entry: path.join( __dirname, 'first', 'main.js' ),
external: [ 'lodash' ],
// Define a simple alias plugin for underscore
plugins: [
{
resolveId: function ( id ) {
if ( id === 'underscore' ) {
return 'lodash';
}
}
}
]
},
context: {
require: function ( required ) {
assert.equal( required, 'lodash' );
return 1;
}
}
};

10
test/function/external-alias/first/main.js

@ -0,0 +1,10 @@
import _ from 'underscore';
import first from './module';
export default function ( inputs ) {
if ( !_.isArray( inputs ) ) {
return inputs;
}
return first.square( inputs );
};

7
test/function/external-alias/first/module.js

@ -0,0 +1,7 @@
import _ from 'underscore';
export default function square ( inputs ) {
return _.map( inputs, function ( x ) {
return x * x;
});
};

14
test/function/external-function/_config.js

@ -0,0 +1,14 @@
module.exports = {
description: 'allows external option to be a function (#522)',
options: {
external: id => {
return id === 'external';
}
},
context: {
require: id => {
if ( id === 'external' ) return 42;
return require( id );
}
}
};

2
test/function/external-function/main.js

@ -0,0 +1,2 @@
import ext from 'external';
assert.equal( ext, 42 );

18
test/function/external-normalization/_config.js

@ -0,0 +1,18 @@
var path = require( 'path' );
var assert = require( 'assert' );
module.exports = {
description: 'external paths from custom resolver remain external (#633)',
options: {
external: [ 'path' ],
plugins: [{
resolveId: ( id ) => {
if ( id == './dep.js' ) return 'path';
return id;
}
}]
},
exports: exports => {
assert.equal( exports, path.resolve );
}
};

2
test/function/external-normalization/main.js

@ -0,0 +1,2 @@
import { resolve } from './dep.js';
export default resolve;

2
test/function/warn-on-eval/_config.js

@ -8,7 +8,7 @@ module.exports = {
options: {
onwarn: function ( message ) {
warned = true;
assert.ok( /Use of `eval` \(in .+?main\.js\) is discouraged, as it may cause issues with minification\. See https:\/\/github.com\/rollup\/rollup\/wiki\/Troubleshooting#avoiding-eval for more details/.test( message ) );
assert.ok( /Use of `eval` \(in .+?main\.js\) is strongly discouraged, as it poses security risks and may cause issues with minification\. See https:\/\/github.com\/rollup\/rollup\/wiki\/Troubleshooting#avoiding-eval for more details/.test( message ) );
}
},
exports: function () {

2
test/test.js

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

Loading…
Cancel
Save