Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program location info slightly off #1024

Closed
mmun opened this issue May 9, 2015 · 6 comments
Closed

Program location info slightly off #1024

mmun opened this issue May 9, 2015 · 6 comments
Labels
Milestone

Comments

@mmun
Copy link
Contributor

mmun commented May 9, 2015

The location info of a program that belongs to a block is slightly off. Specifically, the loc.start for both the main and inverse are set to the beginning of the block's mustache rather than the end.

Here's a JSBin illustrating it for 3.0.3: http://jsbin.com/yemadanida/1/edit?html,js,console

I also think loc.source should be set to null instead of undefined because it's JSONifyable and it's what's documented anyways.

@kpdecker kpdecker added the bug label May 22, 2015
@kpdecker
Copy link
Collaborator

Re: loc, it sounds like we should change that.

Re: source, null vs. undefined is a pet peeve of mine (See the fun with express handlebars defaults in the last release). Everyone has their own definition and nuances of what the things mean. Generally I prefer the route that creates the least amount of code, i.e. implicit undefineds vs. explicit nulls. Should we change the docs to | undefined | null to make it clear that code should safely handle both?

@kpdecker kpdecker added this to the Next milestone May 22, 2015
@mmun
Copy link
Contributor Author

mmun commented May 22, 2015

@kpdecker Re: source, yeah that's fine, though I'd hoped it the AST would be valid JSON (undefined isn't a valid value in JSON).

@kpdecker
Copy link
Collaborator

Undefined is perfectly valid json. {} has every field name as undefined ;)

On Fri, May 22, 2015 at 1:56 PM Martin Muñoz notifications@github.com
wrote:

@kpdecker https://github.com/kpdecker Re: source, yeah that's fine,
though I'd hoped it the AST would be valid JSON (undefined isn't a valid
value in JSON).


Reply to this email directly or view it on GitHub
#1024 (comment)
.

@kpdecker
Copy link
Collaborator

Test case:

  it('GH1024 - should track program location properly', function() {
    var p = Handlebars.parse('\n'
      + '  {{#if foo}}\n'
      + '    {{bar}}\n'
      + '       {{else}}    {{baz}}\n'
      + '\n'
      + '     {{/if}}\n'
      + '    ');

    console.log(JSON.stringify(p));

    // We really need a deep equals but for now this should be stable...
    equals(JSON.stringify(p.loc), JSON.stringify({
      start: { line: 1, column: 0 },
      end: { line: 7, column: 4 }
    }));
    equals(JSON.stringify(p.body[1].program.loc), JSON.stringify({
      start: { line: 2, column: 13 },
      end: { line: 4, column: 7 }
    }));
    equals(JSON.stringify(p.body[1].inverse.loc), JSON.stringify({
      start: { line: 4, column: 15 },
      end: { line: 6, column: 5 }
    }));
  });

@kpdecker
Copy link
Collaborator

@mmun would you argue that this test case is incorrect now? eee2c4d#diff-162dcff9d8009bd8efba3ccd7ee514d9R240

@mmun
Copy link
Contributor Author

mmun commented Jun 26, 2015

@kpdecker Yes, I would argue they are incorrect.

The block helper program node test should be testColumns(program, 3, 5, 31, 5);.
The block helper inverse node test should be testColumns(inverse, 5, 7, 13, 0);.
The block helper node test itself is 👍.

flenter pushed a commit to flenter/handlebars.js that referenced this issue Aug 27, 2015
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 handlebars-lang#1024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants