diff options
author | kpdecker <kpdecker@gmail.com> | 2015-06-26 14:30:34 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-06-26 16:58:34 -0500 |
commit | 93faffa549166c492267cc96d3e6848923760d90 (patch) | |
tree | 77233e09591a29459e42f7b6b34de6791404f973 /lib | |
parent | d2fb3a49062d4914007152b9fcd55369d978c497 (diff) | |
download | handlebars.js-93faffa549166c492267cc96d3e6848923760d90.zip handlebars.js-93faffa549166c492267cc96d3e6848923760d90.tar.gz handlebars.js-93faffa549166c492267cc96d3e6848923760d90.tar.bz2 |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/handlebars/compiler/helpers.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js index fc0120c..e3eb786 100644 --- a/lib/handlebars/compiler/helpers.js +++ b/lib/handlebars/compiler/helpers.js @@ -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); +} + + |