Skip to content

Commit

Permalink
fix: get line numbers to be proper again
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 1, 2020
1 parent dc3bc65 commit 8c31701
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/bundle-source/demo/circular/b.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import { foo } from './a';
* --------->
* <!-- foo as bar -->
*/
console.error('here am I');
export { foo as bar };
13 changes: 7 additions & 6 deletions packages/bundle-source/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,21 @@ export default async function bundleSource(
// eslint-disable-next-line no-await-in-loop
const consumer = await new SourceMapConsumer(chunk.map);
const unmapped = new WeakSet();
let lastPos = ast.loc.start;
let lastPos = { ...ast.loc.start };
unmapLoc = loc => {
if (!loc || unmapped.has(loc)) {
return;
}
// Ensure we start in the right position... doesn't matter where we end.
loc.end = loc.start;
// Make sure things start at least at the right place.
loc.end = { ...loc.start };
for (const pos of ['start', 'end']) {
if (loc[pos]) {
const newPos = consumer.originalPositionFor(loc[pos]);
if (newPos.source !== null) {
lastPos = loc[pos];
lastPos.line = newPos.line;
lastPos.column = newPos.column;
lastPos = {
line: newPos.line,
column: newPos.column,
};
}
loc[pos] = lastPos;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/bundle-source/test/circular.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function evaluate(src, endowments) {

test('circular export', async t => {
try {
const { source: src1 } = await bundleSource(
const { source: src1, sourceMap: map1 } = await bundleSource(
`${__dirname}/../demo/circular/a.js`,
'nestedEvaluate',
);
Expand All @@ -22,7 +22,7 @@ test('circular export', async t => {
return evaluate(src, { require, nestedEvaluate });
};
// console.log(src1);
const srcMap1 = `(${src1})`;
const srcMap1 = `(${src1})\n${map1}`;
const ex1 = nestedEvaluate(srcMap1)();

// console.log(err.stack);
Expand Down

0 comments on commit 8c31701

Please sign in to comment.