Browse Source

merge master -> gh-344

gh-438-b
Rich-Harris 9 years ago
parent
commit
295b6723cb
  1. 24
      CHANGELOG.md
  2. 15
      bin/help.md
  3. 26
      bin/runRollup.js
  4. 7
      package.json
  5. 23
      src/Bundle.js
  6. 25
      src/Module.js
  7. 34
      src/ast/Scope.js
  8. 31
      src/ast/extractNames.js
  9. 5
      src/ast/isReference.js
  10. 8
      src/finalisers/iife.js
  11. 11
      src/finalisers/shared/getGlobalNameMaker.js
  12. 9
      src/finalisers/umd.js
  13. 134
      src/utils/collapseSourcemaps.js
  14. 19
      src/utils/transformBundle.js
  15. 4
      test/cli/banner-intro-outro-footer/_config.js
  16. 9
      test/cli/banner-intro-outro-footer/_expected.js
  17. 1
      test/cli/banner-intro-outro-footer/main.js
  18. 5
      test/cli/config-env/_config.js
  19. 2
      test/cli/config-env/main.js
  20. 12
      test/cli/config-env/rollup.config.js
  21. 2
      test/cli/indent-none/_expected.js
  22. 2
      test/cli/module-name/_expected.js
  23. 4
      test/form/banner-and-footer-plugin/_expected/umd.js
  24. 4
      test/form/banner-and-footer/_expected/umd.js
  25. 4
      test/form/block-comments/_expected/umd.js
  26. 4
      test/form/dedupes-external-imports/_expected/umd.js
  27. 4
      test/form/exclude-unnecessary-modifications/_expected/umd.js
  28. 4
      test/form/export-all-from-internal/_expected/umd.js
  29. 4
      test/form/export-default-2/_expected/umd.js
  30. 4
      test/form/export-default-3/_expected/umd.js
  31. 4
      test/form/export-default/_expected/umd.js
  32. 4
      test/form/export-multiple-vars/_expected/umd.js
  33. 4
      test/form/exports-at-end-if-possible/_expected/umd.js
  34. 8
      test/form/external-imports-custom-names-function/_config.js
  35. 5
      test/form/external-imports-custom-names-function/_expected/amd.js
  36. 5
      test/form/external-imports-custom-names-function/_expected/cjs.js
  37. 3
      test/form/external-imports-custom-names-function/_expected/es6.js
  38. 5
      test/form/external-imports-custom-names-function/_expected/iife.js
  39. 9
      test/form/external-imports-custom-names-function/_expected/umd.js
  40. 2
      test/form/external-imports-custom-names-function/main.js
  41. 4
      test/form/external-imports-custom-names/_expected/umd.js
  42. 4
      test/form/external-imports/_expected/umd.js
  43. 4
      test/form/indent-false/_expected/umd.js
  44. 4
      test/form/indent-true-spaces/_expected/umd.js
  45. 4
      test/form/indent-true/_expected/umd.js
  46. 4
      test/form/internal-conflict-resolution/_expected/umd.js
  47. 4
      test/form/intro-and-outro/_expected/umd.js
  48. 4
      test/form/multiple-exports/_expected/umd.js
  49. 2
      test/form/namespace-optimization-b/_expected/umd.js
  50. 4
      test/form/namespace-optimization/_expected/umd.js
  51. 4
      test/form/namespaced-default-exports/_expected/umd.js
  52. 4
      test/form/namespaced-named-exports/_expected/umd.js
  53. 4
      test/form/no-imports-or-exports/_expected/umd.js
  54. 2
      test/form/object-destructuring-default-values/_expected/umd.js
  55. 4
      test/form/preserves-comments-after-imports/_expected/umd.js
  56. 4
      test/form/removes-existing-sourcemap-comments/_expected/umd.js
  57. 4
      test/form/self-contained-bundle/_expected/umd.js
  58. 4
      test/form/shorthand-properties/_expected/umd.js
  59. 2
      test/form/side-effect-b/_expected/umd.js
  60. 2
      test/form/side-effect-c/_expected/umd.js
  61. 4
      test/form/side-effect-d/_expected/umd.js
  62. 4
      test/form/side-effect-e/_expected/umd.js
  63. 4
      test/form/side-effect-f/_expected/umd.js
  64. 4
      test/form/side-effect-g/_expected/umd.js
  65. 4
      test/form/side-effect-h/_expected/umd.js
  66. 4
      test/form/side-effect-i/_expected/umd.js
  67. 2
      test/form/side-effect-j/_expected/umd.js
  68. 2
      test/form/side-effect-k/_expected/umd.js
  69. 4
      test/form/side-effect-l/_expected/umd.js
  70. 4
      test/form/side-effect/_expected/umd.js
  71. 2
      test/form/sourcemaps-inline/_expected/umd.js
  72. 2
      test/form/sourcemaps/_expected/umd.js
  73. 4
      test/form/spacing-after-function-with-semicolon/_expected/umd.js
  74. 2
      test/form/string-indentation-b/_expected/umd.js
  75. 4
      test/form/string-indentation/_expected/umd.js
  76. 17
      test/form/transform-bundle-plugin/_config.js
  77. 2
      test/form/transform-bundle-plugin/_expected/amd.js
  78. 2
      test/form/transform-bundle-plugin/_expected/cjs.js
  79. 2
      test/form/transform-bundle-plugin/_expected/es6.js
  80. 2
      test/form/transform-bundle-plugin/_expected/iife.js
  81. 2
      test/form/transform-bundle-plugin/_expected/umd.js
  82. 1
      test/form/transform-bundle-plugin/main.js
  83. 4
      test/form/unmodified-default-exports-function-argument/_expected/umd.js
  84. 4
      test/form/unmodified-default-exports/_expected/umd.js
  85. 4
      test/form/unused-default-exports/_expected/umd.js
  86. 12
      test/function/export-destruction/_config.js
  87. 5
      test/function/export-destruction/main.js
  88. 4
      test/function/top-level-arrow-function/_config.js
  89. 2
      test/function/top-level-arrow-function/main.js
  90. 3
      test/function/vars-not-removed/_config.js
  91. 3
      test/function/vars-not-removed/bar.js
  92. 3
      test/function/vars-not-removed/foo.js
  93. 2
      test/function/vars-not-removed/main.js
  94. 58
      test/sourcemaps/names-transformed/_config.js
  95. 4
      test/sourcemaps/names-transformed/a.js
  96. 4
      test/sourcemaps/names-transformed/b.js
  97. 5
      test/sourcemaps/names-transformed/main.js
  98. 38
      test/sourcemaps/transform-bundle/_config.js
  99. 1
      test/sourcemaps/transform-bundle/main.js

24
CHANGELOG.md

@ -1,5 +1,29 @@
# rollup changelog
## 0.23.1
* Reinstate missing fix from ([#392](https://github.com/rollup/rollup/pull/392))
## 0.23.0
* Add `bundleTransform` plugin hook and option ([#387](https://github.com/rollup/rollup/pull/387))
* Correctly store names in sourcemaps, regardless of transformers
* Add `--environment` option to CLI ([#388](https://github.com/rollup/rollup/pull/388))
* Handle destructuring in exports ([#374](https://github.com/rollup/rollup/issues/374))
* Fix UMD global exports bug introduced in 0.22.1 ([#392](https://github.com/rollup/rollup/pull/392))
## 0.22.2
* Prevent lost `var` keywords ([#390](https://github.com/rollup/rollup/issues/390))
## 0.22.1
* Update expected option keys ([#379](https://github.com/rollup/rollup/issues/379))
* Handle transformers that return stringified sourcemaps ([#377](https://github.com/rollup/rollup/issues/377))
* Automatically create missing namespaces if `moduleName` contains dots ([#378](https://github.com/rollup/rollup/issues/378))
* Ignore external dependency warnings coming from config file ([#333](https://github.com/rollup/rollup/issues/333))
* Update to latest magic-string for performance boost
## 0.22.0
* Duplicate warnings are squelched ([#362](https://github.com/rollup/rollup/issues/362))

15
bin/help.md

@ -20,14 +20,27 @@ Basic options:
-m, --sourcemap Generate sourcemap (`-m inline` for inline map)
--no-strict Don't emit a `"use strict";` in the generated modules.
--no-indent Don't indent result
--environment <values> Settings passed to config file (see example)
--intro Content to insert at top of bundle (inside wrapper)
--outro Content to insert at end of bundle (inside wrapper)
--banner Content to insert at top of bundle (outside wrapper)
--footer Content to insert at end of bundle (outside wrapper)
Examples:
# use settings in config file
rollup -c
# in config file, process.env.INCLUDE_DEPS === 'true'
# and process.env.BUILD === 'production'
rollup -c --environment INCLUDE_DEPS,BUILD:production
# create CommonJS bundle.js from src/main.js
rollup --format=cjs --output=bundle.js -- src/main.js
rollup -f iife --globals jquery:jQuery,angular:ng \
# create self-executing IIFE using `window.jQuery`
# and `window._` as external globals
rollup -f iife --globals jquery:jQuery,lodash:_ \
-i src/app.js -o build/app.js -m build/app.js.map
Notes:

26
bin/runRollup.js

@ -20,6 +20,17 @@ module.exports = function ( command ) {
command.input = command._[0];
}
if ( command.environment ) {
command.environment.split( ',' ).forEach( function ( pair ) {
var index = pair.indexOf( ':' );
if ( ~index ) {
process.env[ pair.slice( 0, index ) ] = pair.slice( index + 1 );
} else {
process.env[ pair ] = true;
}
});
}
var config = command.config === true ? 'rollup.config.js' : command.config;
if ( config ) {
@ -27,7 +38,10 @@ module.exports = function ( command ) {
rollup.rollup({
entry: config,
onwarn: log
onwarn: function ( message ) {
if ( /Treating .+ as external dependency/.test( message ) ) return;
log( message );
}
}).then( function ( bundle ) {
var code = bundle.generate({
format: 'cjs'
@ -60,12 +74,16 @@ module.exports = function ( command ) {
};
var equivalents = {
input: 'entry',
output: 'dest',
name: 'moduleName',
banner: 'banner',
footer: 'footer',
format: 'format',
globals: 'globals',
id: 'moduleId',
input: 'entry',
intro: 'intro',
name: 'moduleName',
output: 'dest',
outro: 'outro',
sourcemap: 'sourceMap'
};

7
package.json

@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "0.22.0",
"version": "0.23.1",
"description": "Next-generation ES6 module bundler",
"main": "dist/rollup.js",
"jsnext:main": "src/rollup.js",
@ -48,7 +48,7 @@
"eslint": "^1.7.1",
"estree-walker": "^0.2.0",
"istanbul": "^0.4.0",
"magic-string": "^0.10.0",
"magic-string": "^0.10.1",
"mocha": "^2.3.3",
"remap-istanbul": "^0.4.0",
"rollup": "^0.20.2",
@ -57,7 +57,8 @@
"rollup-plugin-replace": "^1.0.1",
"sander": "^0.4.0",
"source-map": "^0.5.3",
"sourcemap-codec": "^1.2.1"
"sourcemap-codec": "^1.2.1",
"uglify-js": "^2.6.1"
},
"dependencies": {
"chalk": "^1.1.1",

23
src/Bundle.js

@ -11,7 +11,9 @@ import getExportMode from './utils/getExportMode.js';
import getIndentString from './utils/getIndentString.js';
import { unixizePath } from './utils/normalizePlatform.js';
import transform from './utils/transform.js';
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 { isRelative, resolve } from './utils/path.js';
@ -46,6 +48,10 @@ export default class Bundle {
.map( plugin => plugin.transform )
.filter( Boolean );
this.bundleTransformers = this.plugins
.map( plugin => plugin.transformBundle )
.filter( Boolean );
this.moduleById = blank();
this.modules = [];
@ -242,20 +248,23 @@ export default class Bundle {
if ( banner ) magicString.prepend( banner + '\n' );
if ( footer ) magicString.append( '\n' + footer );
const code = magicString.toString();
let code = magicString.toString();
let map = null;
let bundleSourcemapChain = [];
code = transformBundle( code, this.bundleTransformers, bundleSourcemapChain )
.replace( new RegExp( `\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'g' ), '' );
if ( options.sourceMap ) {
let file = options.sourceMapFile || options.dest;
if ( file ) file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file );
map = magicString.generateMap({
includeContent: true,
file
// TODO
});
map = magicString.generateMap({ file, includeContent: true });
if ( this.transformers.length ) map = collapseSourcemaps( map, usedModules );
if ( this.transformers.length || this.bundleTransformers.length ) {
map = collapseSourcemaps( map, usedModules, bundleSourcemapChain );
}
map.sources = map.sources.map( unixizePath );
}

25
src/Module.js

@ -10,6 +10,7 @@ import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import { SyntheticDefaultDeclaration, SyntheticNamespaceDeclaration } from './Declaration.js';
import { isFalsy, isTruthy } from './ast/conditions.js';
import { emptyBlockStatement } from './ast/create.js';
import extractNames from './ast/extractNames.js';
export default class Module {
constructor ({ id, code, originalCode, ast, sourceMapChain, bundle }) {
@ -97,6 +98,7 @@ export default class Module {
}
// export { foo, bar, baz }
// export var { foo, bar } = ...
// export var foo = 42;
// export var a = 1, b = 2, c = 3;
// export function foo () {}
@ -114,17 +116,18 @@ export default class Module {
else {
let declaration = node.declaration;
let name;
if ( declaration.type === 'VariableDeclaration' ) {
// export var foo = 42
name = declaration.declarations[0].id.name;
} else {
declaration.declarations.forEach( decl => {
extractNames( decl.id ).forEach( localName => {
this.exports[ localName ] = { localName };
});
});
}
else {
// export function foo () {}
name = declaration.id.name;
const localName = declaration.id.name;
this.exports[ localName ] = { localName };
}
this.exports[ name ] = { localName: name };
}
}
}
@ -497,10 +500,14 @@ export default class Module {
// modify exports as necessary
if ( statement.isExportDeclaration ) {
// remove `export` from `export var foo = 42`
// TODO: can we do something simpler here?
// we just want to remove `export`, right?
if ( statement.node.type === 'ExportNamedDeclaration' && statement.node.declaration.type === 'VariableDeclaration' ) {
const name = statement.node.declaration.declarations[0].id.name;
const name = extractNames( statement.node.declaration.declarations[ 0 ].id )[ 0 ];
const declaration = this.declarations[ name ];
if ( !declaration ) throw new Error( `Missing declaration for ${name}!` );
const end = declaration.isExported && declaration.isReassigned ?
statement.node.declaration.declarations[0].start :
statement.node.declaration.start;

34
src/ast/Scope.js

@ -1,38 +1,6 @@
import { blank, keys } from '../utils/object.js';
import Declaration from '../Declaration.js';
const extractors = {
Identifier ( names, param ) {
names.push( param.name );
},
ObjectPattern ( names, param ) {
param.properties.forEach( prop => {
extractors[ prop.key.type ]( names, prop.key );
});
},
ArrayPattern ( names, param ) {
param.elements.forEach( element => {
if ( element ) extractors[ element.type ]( names, element );
});
},
RestElement ( names, param ) {
extractors[ param.argument.type ]( names, param.argument );
},
AssignmentPattern ( names, param ) {
return extractors[ param.left.type ]( names, param.left );
}
};
function extractNames ( param ) {
let names = [];
extractors[ param.type ]( names, param );
return names;
}
import extractNames from './extractNames.js';
export default class Scope {
constructor ( options ) {

31
src/ast/extractNames.js

@ -0,0 +1,31 @@
export default function extractNames ( param ) {
const names = [];
extractors[ param.type ]( names, param );
return names;
}
const extractors = {
Identifier ( names, param ) {
names.push( param.name );
},
ObjectPattern ( names, param ) {
param.properties.forEach( prop => {
extractors[ prop.value.type ]( names, prop.value );
});
},
ArrayPattern ( names, param ) {
param.elements.forEach( element => {
if ( element ) extractors[ element.type ]( names, element );
});
},
RestElement ( names, param ) {
extractors[ param.argument.type ]( names, param.argument );
},
AssignmentPattern ( names, param ) {
extractors[ param.left.type ]( names, param.left );
}
};

5
src/ast/isReference.js

@ -4,6 +4,11 @@ export default function isReference ( node, parent ) {
}
if ( node.type === 'Identifier' ) {
// the only time we could have an identifier node without a parent is
// if it's the entire body of a function without a block statement –
// i.e. an arrow function expression like `a => a`
if ( !parent ) return true;
// TODO is this right?
if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object;

8
src/finalisers/iife.js

@ -2,6 +2,7 @@ import { blank } from '../utils/object.js';
import { getName } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
function setupNamespace ( keypath ) {
let parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`?
@ -16,13 +17,12 @@ function setupNamespace ( keypath ) {
}
export default function iife ( bundle, magicString, { exportMode, indentString }, options ) {
const globalNames = options.globals || blank();
const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
const name = options.moduleName;
const isNamespaced = name && ~name.indexOf( '.' );
let dependencies = bundle.externalModules.map( module => {
return globalNames[ module.id ] || module.name;
});
let dependencies = bundle.externalModules.map( globalNameMaker );
let args = bundle.externalModules.map( getName );

11
src/finalisers/shared/getGlobalNameMaker.js

@ -0,0 +1,11 @@
export default function getGlobalNameMaker ( globals, onwarn ) {
const fn = typeof globals === 'function' ? globals : id => globals[ id ];
return function ( module ) {
const name = fn( module.id );
if ( name ) return name;
onwarn( `No name was provided for external module '${module.id}' in options.globals – guessing '${module.name}'` );
return module.name;
};
}

9
src/finalisers/umd.js

@ -2,6 +2,7 @@ import { blank } from '../utils/object.js';
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';
function setupNamespace ( name ) {
const parts = name.split( '.' );
@ -19,13 +20,11 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
throw new Error( 'You must supply options.moduleName for UMD bundles' );
}
const globalNames = options.globals || blank();
const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
let amdDeps = bundle.externalModules.map( quoteId );
let cjsDeps = bundle.externalModules.map( req );
let globalDeps = bundle.externalModules.map( module => {
return 'global.' + (globalNames[ module.id ] || module.name);
});
let globalDeps = bundle.externalModules.map( module => `global.${globalNameMaker( module )}` );
let args = bundle.externalModules.map( getName );
@ -50,7 +49,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
`(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? ${cjsExport}factory(${cjsDeps.join( ', ' )}) :
typeof define === 'function' && define.amd ? define(${amdParams}factory) :
${defaultExport}factory(${globalDeps});
(${defaultExport}factory(${globalDeps}));
}(this, function (${args}) {${useStrict}
`.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() );

134
src/utils/collapseSourcemaps.js

@ -1,72 +1,108 @@
import { encode, decode } from 'sourcemap-codec';
function traceSegment ( loc, mappings ) {
const line = loc[0];
const column = loc[1];
function Source ( map, sources ) {
if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' );
const segments = mappings[ line ];
this.sources = sources;
this.names = map.names;
this.mappings = decode( map.mappings );
}
if ( !segments ) return null;
Source.prototype = { // TODO bring into line with others post-https://github.com/rollup/rollup/pull/386
traceMappings () {
let names = [];
const mappings = this.mappings.map( line => {
let tracedLine = [];
line.forEach( segment => {
const source = this.sources[ segment[1] ];
const traced = source.traceSegment( segment[2], segment[3], this.names[ segment[4] ] );
if ( traced ) {
let nameIndex = null;
segment = [
segment[0],
traced.index,
traced.line,
traced.column
];
if ( traced.name ) {
nameIndex = names.indexOf( traced.name );
if ( nameIndex === -1 ) {
nameIndex = names.length;
names.push( traced.name );
}
segment[4] = nameIndex;
}
tracedLine.push( segment );
}
});
return tracedLine;
});
for ( let i = 0; i < segments.length; i += 1 ) {
const segment = segments[i];
return { names, mappings };
},
if ( segment[0] > column ) return null;
traceSegment ( line, column, name ) {
const segments = this.mappings[ line ];
if ( segment[0] === column ) {
if ( segment[1] !== 0 ) {
throw new Error( 'Bad sourcemap' );
}
return [ segment[2], segment[3] ];
}
}
if ( !segments ) return null;
return null;
}
for ( let i = 0; i < segments.length; i += 1 ) {
const segment = segments[i];
export default function collapseSourcemaps ( map, modules ) {
const chains = modules.map( module => {
return module.sourceMapChain.map( map => {
if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' );
return decode( map.mappings );
});
});
if ( segment[0] > column ) return null;
const decodedMappings = decode( map.mappings );
if ( segment[0] === column ) {
const source = this.sources[ segment[1] ];
const tracedMappings = decodedMappings.map( line => {
let tracedLine = [];
if ( !source ) throw new Error( 'Bad sourcemap' );
line.forEach( segment => {
const sourceIndex = segment[1];
const sourceCodeLine = segment[2];
const sourceCodeColumn = segment[3];
if ( source.isOriginal ) {
return {
index: source.index,
line: segment[2],
column: segment[3],
name: this.names[ segment[4] ] || name
};
}
const chain = chains[ sourceIndex ];
return source.traceSegment( segment[2], segment[3], name );
}
}
let i = chain.length;
let traced = [ sourceCodeLine, sourceCodeColumn ];
return null;
}
};
while ( i-- && traced ) {
traced = traceSegment( traced, chain[i] );
}
export default function collapseSourcemaps ( map, modules, bundleSourcemapChain ) {
const sources = modules.map( ( module, i ) => {
let source = { isOriginal: true, index: i };
if ( traced ) {
tracedLine.push([
segment[0],
segment[1],
traced[0],
traced[1]
// TODO name?
]);
}
module.sourceMapChain.forEach( map => {
source = new Source( map, [ source ]);
});
return tracedLine;
return source;
});
let source = new Source( map, sources );
bundleSourcemapChain.forEach( map => {
source = new Source( map, [ source ] );
});
const { names, mappings } = source.traceMappings();
// we re-use the `map` object because it has convenient toString/toURL methods
map.sourcesContent = modules.map( module => module.originalCode );
map.mappings = encode( tracedMappings );
map.mappings = encode( mappings );
map.names = names;
return map;
}

19
src/utils/transformBundle.js

@ -0,0 +1,19 @@
export default function transformBundle ( code, transformers, sourceMapChain ) {
return transformers.reduce( ( code, transformer ) => {
let result = transformer( code );
if ( result == null ) return code;
if ( typeof result === 'string' ) {
result = {
code: result,
map: null
};
}
const map = typeof result.map === 'string' ? JSON.parse( result.map ) : map;
sourceMapChain.push( map );
return result.code;
}, code );
}

4
test/cli/banner-intro-outro-footer/_config.js

@ -0,0 +1,4 @@
module.exports = {
description: 'adds banner/intro/outro/footer',
command: 'rollup -i main.js -f iife --banner "// banner" --intro "// intro" --outro "// outro" --footer "// footer"'
};

9
test/cli/banner-intro-outro-footer/_expected.js

@ -0,0 +1,9 @@
// banner
(function () { 'use strict';
// intro
console.log( 42 );
// outro
})();
// footer

1
test/cli/banner-intro-outro-footer/main.js

@ -0,0 +1 @@
console.log( 42 );

5
test/cli/config-env/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'passes environment variables to config file',
command: 'rollup --config --environment PRODUCTION,FOO:bar',
execute: true
};

2
test/cli/config-env/main.js

@ -0,0 +1,2 @@
assert.equal( '__ENVIRONMENT__', 'production' );
assert.equal( '__FOO__', 'bar' );

12
test/cli/config-env/rollup.config.js

@ -0,0 +1,12 @@
var replace = require( 'rollup-plugin-replace' );
module.exports = {
entry: 'main.js',
format: 'cjs',
plugins: [
replace({
__ENVIRONMENT__: process.env.PRODUCTION ? 'production' : 'development',
__FOO__: process.env.FOO
})
]
};

2
test/cli/indent-none/_expected.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
assert.equal( 1 + 1, 2 );

2
test/cli/module-name/_expected.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;

4
test/form/banner-and-footer-plugin/_expected/umd.js

@ -3,11 +3,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
console.log( 1 + 1 );
}));
/* first footer */
/* second footer */
/* second footer */

4
test/form/banner-and-footer/_expected/umd.js

@ -2,10 +2,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
console.log( 'hello world' );
}));
/* this is a footer */
/* this is a footer */

4
test/form/block-comments/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
function foo () {
@ -20,4 +20,4 @@
alert( foo() );
}));
}));

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) :
typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) :
factory((global.myBundle = {}),global.external);
(factory((global.myBundle = {}),global.external));
}(this, function (exports,external) { 'use strict';
class Foo extends external.Component {
@ -33,4 +33,4 @@
exports.bar = bar;
exports.baz = baz;
}));
}));

4
test/form/exclude-unnecessary-modifications/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var foo = {};
@ -29,4 +29,4 @@
console.log( foo );
}));
}));

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.exposedInternals = {}));
(factory((global.exposedInternals = {})));
}(this, function (exports) { 'use strict';
const a = 1;
@ -10,4 +10,4 @@
exports.a = a;
exports.b = b;
}));
}));

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

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var bar = 1;
return bar;
}));
}));

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

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var bar = 1;
return bar;
}));
}));

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

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;
return main;
}));
}));

4
test/form/export-multiple-vars/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var a = 1;
@ -14,4 +14,4 @@
assert.equal( e, 5 );
assert.equal( i, 9 );
}));
}));

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.myBundle = {}));
(factory((global.myBundle = {})));
}(this, function (exports) { 'use strict';
var FOO = 'foo';
@ -12,4 +12,4 @@
exports.FOO = FOO;
}));
}));

8
test/form/external-imports-custom-names-function/_config.js

@ -0,0 +1,8 @@
module.exports = {
description: 'allows globals to be specified as a function',
options: {
globals: function ( id ) {
return id.replace( /-/g, '_' );
}
}
};

5
test/form/external-imports-custom-names-function/_expected/amd.js

@ -0,0 +1,5 @@
define(['a-b-c'], function (aBC) { 'use strict';
aBC.foo();
});

5
test/form/external-imports-custom-names-function/_expected/cjs.js

@ -0,0 +1,5 @@
'use strict';
var aBC = require('a-b-c');
aBC.foo();

3
test/form/external-imports-custom-names-function/_expected/es6.js

@ -0,0 +1,3 @@
import { foo } from 'a-b-c';
foo();

5
test/form/external-imports-custom-names-function/_expected/iife.js

@ -0,0 +1,5 @@
(function (aBC) { 'use strict';
aBC.foo();
})(a_b_c);

9
test/form/external-imports-custom-names-function/_expected/umd.js

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

2
test/form/external-imports-custom-names-function/main.js

@ -0,0 +1,2 @@
import { foo } from 'a-b-c';
foo();

4
test/form/external-imports-custom-names/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(global.jQuery);
(factory(global.jQuery));
}(this, function ($) { 'use strict';
$ = 'default' in $ ? $['default'] : $;
@ -10,4 +10,4 @@
$( 'body' ).html( '<h1>hello world!</h1>' );
});
}));
}));

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('factory'), require('baz'), require('shipping-port'), require('alphabet')) :
typeof define === 'function' && define.amd ? define(['factory', 'baz', 'shipping-port', 'alphabet'], factory) :
factory(global.factory,global.baz,global.containers,global.alphabet);
(factory(global.factory,global.baz,global.containers,global.alphabet));
}(this, function (factory,baz,containers,alphabet) { 'use strict';
factory = 'default' in factory ? factory['default'] : factory;
@ -13,4 +13,4 @@
console.log( alphabet.a );
console.log( alphabet__default.length );
}));
}));

4
test/form/indent-false/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.foo = factory();
(global.foo = factory());
}(this, function () { 'use strict';
function foo () {
@ -10,4 +10,4 @@ function foo () {
return foo;
}));
}));

4
test/form/indent-true-spaces/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.foo = factory();
(global.foo = factory());
}(this, function () { 'use strict';
function foo () {
@ -10,4 +10,4 @@
return foo;
}));
}));

4
test/form/indent-true/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.foo = factory();
(global.foo = factory());
}(this, function () { 'use strict';
function foo () {
@ -10,4 +10,4 @@
return foo;
}));
}));

4
test/form/internal-conflict-resolution/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var bar$1 = 42;
@ -16,4 +16,4 @@
bar();
}));
}));

4
test/form/intro-and-outro/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
/* this is an intro */
console.log( 'hello world' );
/* this is an outro */
}));
}));

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.myBundle = {}));
(factory((global.myBundle = {})));
}(this, function (exports) { 'use strict';
var foo = 1;
@ -10,4 +10,4 @@
exports.foo = foo;
exports.bar = bar;
}));
}));

2
test/form/namespace-optimization-b/_expected/umd.js

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

4
test/form/namespace-optimization/_expected/umd.js

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

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

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = factory();
(global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = factory());
}(this, function () { 'use strict';
var main = 42;
return main;
}));
}));

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

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = {}));
(factory((global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = {})));
}(this, function (exports) { 'use strict';
var answer = 42;
exports.answer = answer;
}));
}));

4
test/form/no-imports-or-exports/_expected/umd.js

@ -1,9 +1,9 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
console.log( 'this is it' );
}));
}));

2
test/form/object-destructuring-default-values/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
const a = 1;

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.myBundle = {}));
(factory((global.myBundle = {})));
}(this, function (exports) { 'use strict';
/** A comment for a number */
@ -12,4 +12,4 @@
exports.obj = obj;
}));
}));

4
test/form/removes-existing-sourcemap-comments/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
function foo () {
@ -10,4 +10,4 @@
console.log( foo() );
}));
}));

4
test/form/self-contained-bundle/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
function foo () {
@ -19,4 +19,4 @@
foo();
console.log( 3 );
}));
}));

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

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
function x () {
@ -26,4 +26,4 @@
assert.equal( bar.x(), 'bar' );
assert.equal( baz.x(), 'baz' );
}));
}));

2
test/form/side-effect-b/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;

2
test/form/side-effect-c/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;

4
test/form/side-effect-d/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;
return main;
}));
}));

4
test/form/side-effect-e/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
function foo () {
@ -21,4 +21,4 @@
return main;
}));
}));

4
test/form/side-effect-f/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;
return main;
}));
}));

4
test/form/side-effect-g/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;
return main;
}));
}));

4
test/form/side-effect-h/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var main = 42;
return main;
}));
}));

4
test/form/side-effect-i/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
if ( !ok ) {
@ -12,4 +12,4 @@
return main;
}));
}));

2
test/form/side-effect-j/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
var augment;

2
test/form/side-effect-k/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
(global.myBundle = factory());
}(this, function () { 'use strict';
function augment ( x ) {

4
test/form/side-effect-l/_expected/umd.js

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

4
test/form/side-effect/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var foo = 42;
assert.equal( foo, 42 );
}));
}));

2
test/form/sourcemaps-inline/_expected/umd.js

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

2
test/form/sourcemaps/_expected/umd.js

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

4
test/form/spacing-after-function-with-semicolon/_expected/umd.js

@ -1,11 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
function x () { return 'x' };
assert.equal( x(), 'x' );
}));
}));

2
test/form/string-indentation-b/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var a = 'a';

4
test/form/string-indentation/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var a = '1\
@ -21,4 +21,4 @@
assert.equal( c, '1\n 2' );
assert.equal( d, '1\n\t2' );
}));
}));

17
test/form/transform-bundle-plugin/_config.js

@ -0,0 +1,17 @@
module.exports = {
description: 'allows plugins to transform bundle',
options: {
plugins: [
{
transformBundle: function (code) {
return '/* first plugin */';
}
},
{
transformBundle: function (code) {
return code + '\n/* second plugin */';
}
}
]
}
}

2
test/form/transform-bundle-plugin/_expected/amd.js

@ -0,0 +1,2 @@
/* first plugin */
/* second plugin */

2
test/form/transform-bundle-plugin/_expected/cjs.js

@ -0,0 +1,2 @@
/* first plugin */
/* second plugin */

2
test/form/transform-bundle-plugin/_expected/es6.js

@ -0,0 +1,2 @@
/* first plugin */
/* second plugin */

2
test/form/transform-bundle-plugin/_expected/iife.js

@ -0,0 +1,2 @@
/* first plugin */
/* second plugin */

2
test/form/transform-bundle-plugin/_expected/umd.js

@ -0,0 +1,2 @@
/* first plugin */
/* second plugin */

1
test/form/transform-bundle-plugin/main.js

@ -0,0 +1 @@
console.log( 1 + 1 );

4
test/form/unmodified-default-exports-function-argument/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var foo = function () {
@ -17,4 +17,4 @@
console.log( answer );
}));
}));

4
test/form/unmodified-default-exports/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var Foo = function () {
@ -16,4 +16,4 @@
var foo = new Foo();
}));
}));

4
test/form/unused-default-exports/_expected/umd.js

@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
(factory());
}(this, function () { 'use strict';
var foo = { value: 1 };
@ -15,4 +15,4 @@
assert.equal( foo.value, 2 );
}));
}));

12
test/function/export-destruction/_config.js

@ -0,0 +1,12 @@
var assert = require( 'assert' );
module.exports = {
description: 'handle destruction patterns in export declarations',
babel: true,
exports: function ( exports ) {
assert.deepEqual( Object.keys( exports ), [ 'baz', 'quux' ] );
assert.equal( exports.baz, 5 );
assert.equal( exports.quux, 17 );
}
};

5
test/function/export-destruction/main.js

@ -0,0 +1,5 @@
var foo = { bar: { baz: 5 } };
var arr = [ { quux: 'wrong' }, { quux: 17 } ];
export var { bar: { baz } } = foo;
export var [ /* skip */, { quux } ] = arr;

4
test/function/top-level-arrow-function/_config.js

@ -0,0 +1,4 @@
module.exports = {
description: 'handles naked return value from top-level arrow function expression (#403)',
babel: true
};

2
test/function/top-level-arrow-function/main.js

@ -0,0 +1,2 @@
const f = a => a;
assert.equal( f( 42 ), 42 );

3
test/function/vars-not-removed/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'does not erroneously remove var/let/const keywords (#390)'
};

3
test/function/vars-not-removed/bar.js

@ -0,0 +1,3 @@
var a = 2, b = 3;
assert.equal( a + b, 5 );

3
test/function/vars-not-removed/foo.js

@ -0,0 +1,3 @@
var a = 1, b = 2;
assert.equal( a + b, 3 );

2
test/function/vars-not-removed/main.js

@ -0,0 +1,2 @@
import './foo.js';
import './bar.js';

58
test/sourcemaps/names-transformed/_config.js

@ -0,0 +1,58 @@
var assert = require( 'assert' );
var uglify = require( 'uglify-js' );
var MagicString = require( 'magic-string' );
var getLocation = require( '../../utils/getLocation' );
var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;
module.exports = {
description: 'names are recovered if transforms are used',
options: {
plugins: [
{
transform: function ( code ) {
var s = new MagicString( code );
var pattern = /mangleMe/g;
var match;
while ( match = pattern.exec( code ) ) {
s.overwrite( match.index, match.index + match[0].length, 'mangleMePlease', true );
}
return {
code: s.toString(),
map: s.generateMap({ hires: true })
};
},
transformBundle: function ( code ) {
return uglify.minify( code, {
fromString: true,
outSourceMap: 'x'
});
}
}
]
},
test: function ( code, map ) {
var smc = new SourceMapConsumer( map );
var generatedLoc = getLocation( code, /\w+=1/.exec( code ).index );
var originalLoc = smc.originalPositionFor( generatedLoc );
assert.deepEqual( originalLoc, {
source: '../a.js',
line: 1,
column: 4,
name: 'mangleMe'
});
generatedLoc = getLocation( code, /\w+=2/.exec( code ).index );
originalLoc = smc.originalPositionFor( generatedLoc );
assert.deepEqual( originalLoc, {
source: '../b.js',
line: 1,
column: 4,
name: 'mangleMe'
});
}
};

4
test/sourcemaps/names-transformed/a.js

@ -0,0 +1,4 @@
var mangleMe = 1;
export default function () {
assert.equal( mangleMe, 1 );
}

4
test/sourcemaps/names-transformed/b.js

@ -0,0 +1,4 @@
var mangleMe = 2;
export default function () {
assert.equal( mangleMe, 2 );
}

5
test/sourcemaps/names-transformed/main.js

@ -0,0 +1,5 @@
import a from './a.js';
import b from './b.js';
a();
b();

38
test/sourcemaps/transform-bundle/_config.js

@ -0,0 +1,38 @@
var uglify = require( 'uglify-js' );
var assert = require( 'assert' );
var getLocation = require( '../../utils/getLocation' );
var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;
module.exports = {
description: 'preserves sourcemap chains when transforming',
options: {
plugins: [
{
transformBundle: function ( code ) {
var options = {
fromString: true,
outSourceMap: 'x' // trigger sourcemap generation
};
return uglify.minify( code, options );
}
}
]
},
test: function ( code, map ) {
var smc = new SourceMapConsumer( map );
var generatedLoc = getLocation( code, code.indexOf( '42' ) );
var originalLoc = smc.originalPositionFor( generatedLoc );
assert.ok( /main/.test( originalLoc.source ) );
assert.equal( originalLoc.line, 1 );
assert.equal( originalLoc.column, 13 );
generatedLoc = getLocation( code, code.indexOf( 'log' ) );
originalLoc = smc.originalPositionFor( generatedLoc );
assert.equal( originalLoc.line, 1 );
assert.equal( originalLoc.column, 8 );
}
};

1
test/sourcemaps/transform-bundle/main.js

@ -0,0 +1 @@
console.log( 42 );
Loading…
Cancel
Save