Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize low-resolution sourcemap handling and add tests
- Loading branch information
1 parent
eeca9a7
commit a25b540
Showing
6 changed files
with
114 additions
and
49 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
37 changes: 37 additions & 0 deletions
37
test/function/samples/warning-low-resolution-location/_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,37 @@ | ||
const path = require('path'); | ||
const { encode } = require('sourcemap-codec'); | ||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
|
||
module.exports = { | ||
description: 'handles when a low resolution sourcemap is used to report an error', | ||
options: { | ||
plugins: { | ||
name: 'test-plugin', | ||
transform() { | ||
// each entry of each line consist of | ||
// [generatedColumn, sourceIndex, sourceLine, sourceColumn]; | ||
// this mapping only maps the first line to itself | ||
const decodedMap = [[[0, 0, 0, 0]]]; | ||
return { code: 'export default this', map: { mappings: encode(decodedMap), sources: [] } }; | ||
} | ||
} | ||
}, | ||
warnings: [ | ||
{ | ||
code: 'THIS_IS_UNDEFINED', | ||
frame: ` | ||
1: console.log('original source'); | ||
^`, | ||
id: ID_MAIN, | ||
loc: { | ||
column: 0, | ||
file: ID_MAIN, | ||
line: 1 | ||
}, | ||
message: | ||
"The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", | ||
pos: 15, | ||
url: 'https://rollupjs.org/guide/en/#error-this-is-undefined' | ||
} | ||
] | ||
}; |
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('original source'); |
47 changes: 47 additions & 0 deletions
47
test/sourcemaps/samples/transform-low-resolution/_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,47 @@ | ||
const assert = require('assert'); | ||
const MagicString = require('magic-string'); | ||
const { SourceMapConsumer } = require('source-map'); | ||
const { encode } = require('sourcemap-codec'); | ||
const getLocation = require('../../getLocation'); | ||
|
||
module.exports = { | ||
description: 'handles combining low-resolution and high-resolution source-maps when transforming', | ||
options: { | ||
output: { name: 'bundle' }, | ||
plugins: [ | ||
{ | ||
transform(code) { | ||
// each entry of each line consist of | ||
// [generatedColumn, sourceIndex, sourceLine, sourceColumn]; | ||
// this mapping only maps the second line to the first with no column | ||
// details | ||
const decodedMap = [[], [[0, 0, 0, 0]]]; | ||
return { | ||
code: `console.log('added');\n${code}`, | ||
map: { mappings: encode(decodedMap) } | ||
}; | ||
} | ||
}, | ||
{ | ||
transform(code) { | ||
const s = new MagicString(code); | ||
s.prepend("console.log('second');\n"); | ||
|
||
return { | ||
code: s.toString(), | ||
map: s.generateMap({ hires: true }) | ||
}; | ||
} | ||
} | ||
] | ||
}, | ||
async test(code, map) { | ||
const smc = await new SourceMapConsumer(map); | ||
|
||
const generatedLoc = getLocation(code, code.indexOf("'baz'")); | ||
const originalLoc = smc.originalPositionFor(generatedLoc); | ||
|
||
assert.strictEqual(originalLoc.line, 1); | ||
assert.strictEqual(originalLoc.column, 0); | ||
} | ||
}; |
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 @@ | ||
export let foo = 'bar'; foo += 'baz'; |