mirror of https://github.com/lukechilds/rollup.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
59 lines
1.4 KiB
9 years ago
|
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'
|
||
|
});
|
||
|
}
|
||
|
};
|