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

interpolate block params in AST? #1198

Closed
stevenvachon opened this issue Mar 13, 2016 · 1 comment
Closed

interpolate block params in AST? #1198

stevenvachon opened this issue Mar 13, 2016 · 1 comment

Comments

@stevenvachon
Copy link

{{#path 1 "2" path.path as |param0 param1 param2|}} text {{param0}} {{param1}} {{param2}} {{/path}}

currently parses into something very similar to:

{ type: 'Program',
  body: 
   [ { type: 'BlockStatement',
       path: { type: 'PathExpression', parts: ['path'] },
       params: 
        [ { type: 'NumberLiteral', value: 1 },
          { type: 'StringLiteral', value: '2' },
          { type: 'PathExpression', parts: ['path', 'path'] } ],
       program: 
        { type: 'Program',
          body: 
           [ { type: 'ContentStatement', value: ' text ' },
             { type: 'MustacheStatement', path: { type: 'PathExpression', parts: ['param0'] } },
             { type: 'MustacheStatement', path: { type: 'PathExpression', parts: ['param1'] } },
             { type: 'MustacheStatement', path: { type: 'PathExpression', parts: ['param2'] } } ],
          blockParams: ['param0', 'param1', 'param2'] },
       } ] }

which relies on the compiler to interpolate the block parameters. Why not do that in the parser to simplify both the compiler and the AST? It could instead parse to something like:

{ type: 'Program',
  body: 
   [ { type: 'BlockStatement',
       path: { type: 'PathExpression', parts: ['path'] },
       params: 
        [ { type: 'NumberLiteral', value: 1 },
          { type: 'StringLiteral', value: '2' },
          { type: 'PathExpression', parts: ['path', 'path'] } ],
       program: 
        { type: 'Program',
          body: 
           [ { type: 'ContentStatement', value: ' text ' } },
             { type: 'MustacheStatement', path: { type: 'NumberLiteral', value: 1 } },
             { type: 'MustacheStatement', path: { type: 'StringLiteral', value: '2' } },
             { type: 'MustacheStatement', path: { type: 'PathExpression', parts: ['path', 'path'] } } ] },
       } ] }
@kpdecker
Copy link
Collaborator

This is not how block parameters work. They can only be resolved at runtime after the block helper runs, not at parse time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants