Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renderChunk to follow all transformBundle tests, type definition
- Loading branch information
1 parent
8fa0895
commit 87b4e49
Showing
26 changed files
with
285 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
description: 'allows plugins to hook render chunk', | ||
options: { | ||
plugins: [ | ||
{ | ||
renderChunk(code) { | ||
return '/* first plugin */'; | ||
} | ||
}, | ||
{ | ||
renderChunk(code) { | ||
return code + '\n/* second plugin */'; | ||
} | ||
} | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* first plugin */ | ||
/* second plugin */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* first plugin */ | ||
/* second plugin */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* first plugin */ | ||
/* second plugin */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* first plugin */ | ||
/* second plugin */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* first plugin */ | ||
/* second plugin */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* first plugin */ | ||
/* second plugin */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log( 1 + 1 ); |
25 changes: 25 additions & 0 deletions
25
test/function/samples/plugin-error-only-first-render-chunk/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
description: 'throws error only with first plugin renderChunk', | ||
options: { | ||
plugins: [ | ||
{ | ||
name: 'plugin1', | ||
renderChunk() { | ||
throw Error('Something happened 1'); | ||
} | ||
}, | ||
{ | ||
name: 'plugin2', | ||
renderChunk() { | ||
throw Error('Something happened 2'); | ||
} | ||
} | ||
] | ||
}, | ||
generateError: { | ||
code: 'PLUGIN_ERROR', | ||
plugin: 'plugin1', | ||
hook: 'renderChunk', | ||
message: `Something happened 1` | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
test/function/samples/plugin-error-only-first-render-chunk/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
description: 'bundle transformers can be asynchronous', | ||
options: { | ||
plugins: [ | ||
{ | ||
renderChunk(code) { | ||
return Promise.resolve(code.replace('x', 1)); | ||
} | ||
}, | ||
{ | ||
renderChunk(code) { | ||
return code.replace('1', 2); | ||
} | ||
}, | ||
{ | ||
renderChunk(code) { | ||
return Promise.resolve(code.replace('2', 3)); | ||
} | ||
} | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assert.equal( x, 3 ); |
62 changes: 62 additions & 0 deletions
62
test/sourcemaps/samples/names-transformed-render-chunk/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const assert = require('assert'); | ||
const uglify = require('uglify-js'); | ||
const MagicString = require('magic-string'); | ||
const getLocation = require('../../getLocation'); | ||
const SourceMapConsumer = require('source-map').SourceMapConsumer; | ||
|
||
module.exports = { | ||
description: 'names are recovered if transforms are used', | ||
options: { | ||
plugins: [ | ||
{ | ||
transform(code) { | ||
const s = new MagicString(code); | ||
const pattern = /mangleMe/g; | ||
let match; | ||
|
||
while ((match = pattern.exec(code))) { | ||
s.overwrite(match.index, match.index + match[0].length, 'mangleMePlease', { | ||
storeName: true, | ||
contentOnly: false | ||
}); | ||
} | ||
|
||
return { | ||
code: s.toString(), | ||
map: s.generateMap({ hires: true }) | ||
}; | ||
}, | ||
renderChunk(code) { | ||
return uglify.minify(code, { | ||
sourceMap: { | ||
filename: 'x' | ||
} | ||
}); | ||
} | ||
} | ||
] | ||
}, | ||
test(code, map) { | ||
const smc = new SourceMapConsumer(map); | ||
|
||
let generatedLoc = getLocation(code, /\w+=["']this/.exec(code).index); | ||
let originalLoc = smc.originalPositionFor(generatedLoc); | ||
|
||
assert.deepEqual(originalLoc, { | ||
source: '../a.js', | ||
line: 1, | ||
column: 4, | ||
name: 'mangleMe' | ||
}); | ||
|
||
generatedLoc = getLocation(code, /\w+=["']nor/.exec(code).index); | ||
originalLoc = smc.originalPositionFor(generatedLoc); | ||
|
||
assert.deepEqual(originalLoc, { | ||
source: '../b.js', | ||
line: 1, | ||
column: 4, | ||
name: 'mangleMe' | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var mangleMe = "this string should not be inlined".toLowerCase(); | ||
export default function () { | ||
assert.equal( mangleMe, 1 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var mangleMe = "nor should this one".toLowerCase(); | ||
export default function () { | ||
assert.equal( mangleMe, 2 ); | ||
} |
5 changes: 5 additions & 0 deletions
5
test/sourcemaps/samples/names-transformed-render-chunk/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import a from './a.js'; | ||
import b from './b.js'; | ||
|
||
a(); | ||
b(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const babiliResults = require('./babili-results'); | ||
const assert = require('assert'); | ||
const getLocation = require('../../getLocation'); | ||
const SourceMapConsumer = require('source-map').SourceMapConsumer; | ||
|
||
module.exports = { | ||
description: 'generates valid sourcemap when source could not be determined', | ||
options: { | ||
plugins: [ | ||
{ | ||
renderChunk(code, chunk, options) { | ||
const format = options.format; | ||
|
||
return babiliResults[format]; | ||
} | ||
} | ||
], | ||
output: { indent: false } | ||
}, | ||
test(code, map) { | ||
const smc = new SourceMapConsumer(map); | ||
|
||
let generatedLoc = getLocation(code, code.indexOf('42')); | ||
let 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); | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/sourcemaps/samples/render-chunk-babili/babili-results.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log( 42 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const uglify = require('uglify-js'); | ||
const assert = require('assert'); | ||
const getLocation = require('../../getLocation'); | ||
const SourceMapConsumer = require('source-map').SourceMapConsumer; | ||
|
||
module.exports = { | ||
description: 'preserves sourcemap chains when transforming', | ||
options: { | ||
plugins: [ | ||
{ | ||
renderChunk(code) { | ||
const options = { | ||
sourceMap: { | ||
filename: 'x' // trigger sourcemap generation | ||
} | ||
}; | ||
|
||
return uglify.minify(code, options); | ||
} | ||
} | ||
] | ||
}, | ||
test(code, map) { | ||
const smc = new SourceMapConsumer(map); | ||
|
||
let generatedLoc = getLocation(code, code.indexOf('42')); | ||
let 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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log( 42 ); |
30 changes: 30 additions & 0 deletions
30
test/sourcemaps/samples/transform-without-sourcemap-render-chunk/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = { | ||
description: 'preserves sourcemap chains when transforming', | ||
options: { | ||
plugins: [ | ||
{ | ||
name: 'fake plugin 1', | ||
transform(code) { | ||
return code; | ||
} | ||
}, | ||
{ | ||
name: 'fake plugin 2', | ||
transform(code) { | ||
return { code, map: null }; | ||
}, | ||
renderChunk(code) { | ||
return { code, map: null }; | ||
} | ||
} | ||
] | ||
}, | ||
warnings: [ | ||
{ | ||
code: `SOURCEMAP_BROKEN`, | ||
plugin: 'fake plugin 1', | ||
message: `Sourcemap is likely to be incorrect: a plugin ('fake plugin 1') was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, | ||
url: `https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect` | ||
} | ||
] | ||
}; |
1 change: 1 addition & 0 deletions
1
test/sourcemaps/samples/transform-without-sourcemap-render-chunk/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log( 42 ); |