Skip to content

Commit

Permalink
Try to fix end-of-region mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
markw65 committed Jun 3, 2022
1 parent 4637045 commit febd2e9
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions lib/compiler/passes/generate-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ function generateJS(ast, options) {
const sourceMapStack = [];
let value;

function sourceMapPop() {
const [
index,
location,
] = sourceMapStack.pop();
const chunks = parts.splice(index).map(
chunk => chunk instanceof SourceNode
? chunk
: chunk + "\n"
);
if (chunks.length) {
parts.push(new SourceNode(
location.start.line,
location.start.column - 1,
location.source,
chunks
));
}
return location;
}
function compileCondition(cond, argCount) {
const baseLength = argCount + 3;
const thenLength = bc[ip + baseLength - 2];
Expand Down Expand Up @@ -587,27 +607,17 @@ function generateJS(ast, options) {
break;

case op.SOURCE_MAP_POP: {
const [
index,
location,
] = sourceMapStack.pop();
const chunks = parts.splice(index).map(
chunk => chunk instanceof SourceNode
? chunk
: chunk + "\n"
);
chunks.push(new SourceNode(
location.end.line,
location.end.column - 1,
location.source,
""
));
parts.push(new SourceNode(
location.start.line,
location.start.column - 1,
location.source,
chunks
));
const location = sourceMapPop();
if (sourceMapStack.length
&& location.end.offset
< sourceMapStack[sourceMapStack.length - 1][1].end.offset) {
const outer = sourceMapPop();
outer.start = location.end;
sourceMapStack.push([
parts.length,
outer,
]);
}
ip++;
break;
}
Expand Down

0 comments on commit febd2e9

Please sign in to comment.