Fix location information for programs

There appears to be a bug in our use of jison causing the parent location information to be reported to programs. I wasn’t able to work through what might be causing this so instead using the location information of the statements collection to generate the proper location information.

This is a bit of a hack but we are very far behind on the Jison release train and upgrading will likely be a less than pleasant task that doesn’t provide us much benefit.

Fixes #1024
This commit is contained in:
kpdecker
2015-06-26 14:30:34 -05:00
parent d2fb3a4906
commit 93faffa549
4 changed files with 74 additions and 6 deletions
+25
View File
@@ -121,3 +121,28 @@ export function prepareBlock(openBlock, program, inverseAndProgram, close, inver
openBlock.strip, inverseStrip, close && close.strip,
this.locInfo(locInfo));
}
export function prepareProgram(statements, loc) {
if (!loc && statements.length) {
const first = statements[0].loc,
last = statements[statements.length - 1].loc;
if (first && last) {
loc = {
source: first.source,
start: {
line: first.start.line,
column: first.start.column
},
end: {
line: last.end.line,
column: last.end.column
}
};
}
}
return new this.Program(statements, null, {}, loc);
}