mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
9 years ago
6 changed files with 105 additions and 14 deletions
@ -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(); |
Loading…
Reference in new issue