mirror of https://github.com/lukechilds/rollup.git
99 changed files with 589 additions and 206 deletions
@ -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 ); |
||||
|
} |
||||
|
}; |
@ -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; |
||||
|
}; |
||||
|
} |
@ -1,72 +1,108 @@ |
|||||
import { encode, decode } from 'sourcemap-codec'; |
import { encode, decode } from 'sourcemap-codec'; |
||||
|
|
||||
function traceSegment ( loc, mappings ) { |
function Source ( map, sources ) { |
||||
const line = loc[0]; |
if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' ); |
||||
const column = loc[1]; |
|
||||
|
|
||||
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 ) { |
return { names, mappings }; |
||||
const segment = segments[i]; |
}, |
||||
|
|
||||
if ( segment[0] > column ) return null; |
traceSegment ( line, column, name ) { |
||||
|
const segments = this.mappings[ line ]; |
||||
|
|
||||
if ( segment[0] === column ) { |
if ( !segments ) return null; |
||||
if ( segment[1] !== 0 ) { |
|
||||
throw new Error( 'Bad sourcemap' ); |
|
||||
} |
|
||||
|
|
||||
return [ segment[2], segment[3] ]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return null; |
for ( let i = 0; i < segments.length; i += 1 ) { |
||||
} |
const segment = segments[i]; |
||||
|
|
||||
export default function collapseSourcemaps ( map, modules ) { |
if ( segment[0] > column ) return null; |
||||
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 ); |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
const decodedMappings = decode( map.mappings ); |
if ( segment[0] === column ) { |
||||
|
const source = this.sources[ segment[1] ]; |
||||
|
|
||||
const tracedMappings = decodedMappings.map( line => { |
if ( !source ) throw new Error( 'Bad sourcemap' ); |
||||
let tracedLine = []; |
|
||||
|
|
||||
line.forEach( segment => { |
if ( source.isOriginal ) { |
||||
const sourceIndex = segment[1]; |
return { |
||||
const sourceCodeLine = segment[2]; |
index: source.index, |
||||
const sourceCodeColumn = segment[3]; |
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; |
return null; |
||||
let traced = [ sourceCodeLine, sourceCodeColumn ]; |
} |
||||
|
}; |
||||
|
|
||||
while ( i-- && traced ) { |
export default function collapseSourcemaps ( map, modules, bundleSourcemapChain ) { |
||||
traced = traceSegment( traced, chain[i] ); |
const sources = modules.map( ( module, i ) => { |
||||
} |
let source = { isOriginal: true, index: i }; |
||||
|
|
||||
if ( traced ) { |
module.sourceMapChain.forEach( map => { |
||||
tracedLine.push([ |
source = new Source( map, [ source ]); |
||||
segment[0], |
|
||||
segment[1], |
|
||||
traced[0], |
|
||||
traced[1] |
|
||||
// TODO name?
|
|
||||
]); |
|
||||
} |
|
||||
}); |
}); |
||||
|
|
||||
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.sourcesContent = modules.map( module => module.originalCode ); |
||||
map.mappings = encode( tracedMappings ); |
map.mappings = encode( mappings ); |
||||
|
map.names = names; |
||||
|
|
||||
return map; |
return map; |
||||
} |
} |
||||
|
@ -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 ); |
||||
|
} |
@ -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"' |
||||
|
}; |
@ -0,0 +1,9 @@ |
|||||
|
// banner
|
||||
|
(function () { 'use strict'; |
||||
|
|
||||
|
// intro
|
||||
|
console.log( 42 ); |
||||
|
// outro
|
||||
|
|
||||
|
})(); |
||||
|
// footer
|
@ -0,0 +1 @@ |
|||||
|
console.log( 42 ); |
@ -0,0 +1,5 @@ |
|||||
|
module.exports = { |
||||
|
description: 'passes environment variables to config file', |
||||
|
command: 'rollup --config --environment PRODUCTION,FOO:bar', |
||||
|
execute: true |
||||
|
}; |
@ -0,0 +1,2 @@ |
|||||
|
assert.equal( '__ENVIRONMENT__', 'production' ); |
||||
|
assert.equal( '__FOO__', 'bar' ); |
@ -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 |
||||
|
}) |
||||
|
] |
||||
|
}; |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var bar = 1; |
var bar = 1; |
||||
|
|
||||
return bar; |
return bar; |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var bar = 1; |
var bar = 1; |
||||
|
|
||||
return bar; |
return bar; |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var main = 42; |
var main = 42; |
||||
|
|
||||
return main; |
return main; |
||||
|
|
||||
})); |
})); |
@ -0,0 +1,8 @@ |
|||||
|
module.exports = { |
||||
|
description: 'allows globals to be specified as a function', |
||||
|
options: { |
||||
|
globals: function ( id ) { |
||||
|
return id.replace( /-/g, '_' ); |
||||
|
} |
||||
|
} |
||||
|
}; |
@ -0,0 +1,5 @@ |
|||||
|
define(['a-b-c'], function (aBC) { 'use strict'; |
||||
|
|
||||
|
aBC.foo(); |
||||
|
|
||||
|
}); |
@ -0,0 +1,5 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
var aBC = require('a-b-c'); |
||||
|
|
||||
|
aBC.foo(); |
@ -0,0 +1,3 @@ |
|||||
|
import { foo } from 'a-b-c'; |
||||
|
|
||||
|
foo(); |
@ -0,0 +1,5 @@ |
|||||
|
(function (aBC) { 'use strict'; |
||||
|
|
||||
|
aBC.foo(); |
||||
|
|
||||
|
})(a_b_c); |
@ -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(); |
||||
|
|
||||
|
})); |
@ -0,0 +1,2 @@ |
|||||
|
import { foo } from 'a-b-c'; |
||||
|
foo(); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
factory(); |
(factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
/* this is an intro */ |
/* this is an intro */ |
||||
console.log( 'hello world' ); |
console.log( 'hello world' ); |
||||
/* this is an outro */ |
/* this is an outro */ |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
factory(); |
(factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
function a () {} |
function a () {} |
||||
|
|
||||
a(); |
a(); |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(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'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var main = 42; |
var main = 42; |
||||
|
|
||||
return main; |
return main; |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) : |
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'; |
}(this, function (exports) { 'use strict'; |
||||
|
|
||||
var answer = 42; |
var answer = 42; |
||||
|
|
||||
exports.answer = answer; |
exports.answer = answer; |
||||
|
|
||||
})); |
})); |
@ -1,9 +1,9 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
factory(); |
(factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
console.log( 'this is it' ); |
console.log( 'this is it' ); |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var main = 42; |
var main = 42; |
||||
|
|
||||
return main; |
return main; |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var main = 42; |
var main = 42; |
||||
|
|
||||
return main; |
return main; |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var main = 42; |
var main = 42; |
||||
|
|
||||
return main; |
return main; |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
global.myBundle = factory(); |
(global.myBundle = factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var main = 42; |
var main = 42; |
||||
|
|
||||
return main; |
return main; |
||||
|
|
||||
})); |
})); |
@ -1,9 +1,9 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
factory(); |
(factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
|
|
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
factory(); |
(factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
var foo = 42; |
var foo = 42; |
||||
|
|
||||
assert.equal( foo, 42 ); |
assert.equal( foo, 42 ); |
||||
|
|
||||
})); |
})); |
@ -1,11 +1,11 @@ |
|||||
(function (global, factory) { |
(function (global, factory) { |
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
typeof define === 'function' && define.amd ? define(factory) : |
typeof define === 'function' && define.amd ? define(factory) : |
||||
factory(); |
(factory()); |
||||
}(this, function () { 'use strict'; |
}(this, function () { 'use strict'; |
||||
|
|
||||
function x () { return 'x' }; |
function x () { return 'x' }; |
||||
|
|
||||
assert.equal( x(), 'x' ); |
assert.equal( x(), 'x' ); |
||||
|
|
||||
})); |
})); |
@ -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 */'; |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
/* first plugin */ |
||||
|
/* second plugin */ |
@ -0,0 +1,2 @@ |
|||||
|
/* first plugin */ |
||||
|
/* second plugin */ |
@ -0,0 +1,2 @@ |
|||||
|
/* first plugin */ |
||||
|
/* second plugin */ |
@ -0,0 +1,2 @@ |
|||||
|
/* first plugin */ |
||||
|
/* second plugin */ |
@ -0,0 +1,2 @@ |
|||||
|
/* first plugin */ |
||||
|
/* second plugin */ |
@ -0,0 +1 @@ |
|||||
|
console.log( 1 + 1 ); |
@ -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 ); |
||||
|
} |
||||
|
}; |
@ -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; |
@ -0,0 +1,4 @@ |
|||||
|
module.exports = { |
||||
|
description: 'handles naked return value from top-level arrow function expression (#403)', |
||||
|
babel: true |
||||
|
}; |
@ -0,0 +1,2 @@ |
|||||
|
const f = a => a; |
||||
|
assert.equal( f( 42 ), 42 ); |
@ -0,0 +1,3 @@ |
|||||
|
module.exports = { |
||||
|
description: 'does not erroneously remove var/let/const keywords (#390)' |
||||
|
}; |
@ -0,0 +1,3 @@ |
|||||
|
var a = 2, b = 3; |
||||
|
|
||||
|
assert.equal( a + b, 5 ); |
@ -0,0 +1,3 @@ |
|||||
|
var a = 1, b = 2; |
||||
|
|
||||
|
assert.equal( a + b, 3 ); |
@ -0,0 +1,2 @@ |
|||||
|
import './foo.js'; |
||||
|
import './bar.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' |
||||
|
}); |
||||
|
} |
||||
|
}; |
@ -0,0 +1,4 @@ |
|||||
|
var mangleMe = 1; |
||||
|
export default function () { |
||||
|
assert.equal( mangleMe, 1 ); |
||||
|
} |
@ -0,0 +1,4 @@ |
|||||
|
var mangleMe = 2; |
||||
|
export default function () { |
||||
|
assert.equal( mangleMe, 2 ); |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
import a from './a.js'; |
||||
|
import b from './b.js'; |
||||
|
|
||||
|
a(); |
||||
|
b(); |
@ -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 ); |
||||
|
} |
||||
|
}; |
@ -0,0 +1 @@ |
|||||
|
console.log( 42 ); |
Loading…
Reference in new issue