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

The template engine doesn't compile template with negative number without dev mode #40

Open
vovieque opened this issue Jan 28, 2015 · 2 comments
Assignees

Comments

@vovieque
Copy link

The template engine doesn't compile the next template without dev mode:

attrs()({
    tabindex: -1
}),
Error: Only literal or function is allowed in template's body at 674:9
    attrs()({
         ^
    at Compiler.assert (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/node_modules/xjst/lib/xjst/compiler/base.js:180:9)
    at Compiler.transformTemplates (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/node_modules/xjst/lib/xjst/compiler/base.js:648:8)
    at Array.map (native)
    at Compiler.translate (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/node_modules/xjst/lib/xjst/compiler/base.js:201:41)
    at Object.translate (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/node_modules/xjst/lib/xjst/api.js:16:40)
    at Compiler.translate (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/lib/bemhtml/compiler.js:121:35)
    at Compiler.generate (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/lib/bemhtml/compiler.js:707:14)
    at Object.generate (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/bem-xjst/lib/bemhtml/api.js:16:40)
    at require.declare.process (/home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/techs/bem-xjst.js:7:28)
    at /home/rakchaev/job/makeup/bem/node_modules/enb-bemxjst/node_modules/sibling/lib/runner.js:22:48

This template body doesn't pass condition utils.isLiteral.
Because negative number is detected as UnaryExpression:

{ type: 'ObjectExpression',
  properties: 
   [ { type: 'Property',
       key: 
        { type: 'Identifier',
          name: 'tabindex',
          loc: { start: [Object], end: [Object] } },
       value: 
        { type: 'UnaryExpression',
          operator: '-',
          argument: { type: 'Literal', value: 1, raw: '1', loc: [Object] },
          prefix: true,
          loc: { start: [Object], end: [Object] } },
       kind: 'init',
       loc: 
        { start: { line: 675, column: 2 },
          end: { line: 675, column: 14 } } } ],
  loc: 
   { start: { line: 674, column: 9 },
     end: { line: 676, column: 2 } } }

But positive number is detected as Literal:

{ type: 'ObjectExpression',
  properties: 
   [ { type: 'Property',
       key: 
        { type: 'Identifier',
          name: 'tabindex',
          loc: { start: [Object], end: [Object] } },
       value: 
        { type: 'Literal',
          value: 1,
          raw: '1',
          loc: { start: [Object], end: [Object] } },
       kind: 'init',
       loc: 
        { start: { line: 675, column: 2 },
          end: { line: 675, column: 13 } } } ],
  loc: 
   { start: { line: 674, column: 9 },
     end: { line: 676, column: 2 } } }
@vovieque
Copy link
Author

vovieque commented Feb 6, 2015

We can use strings for attributes.
But for js and content modes number can be useful.

block('rating').js()({
    rating: -5.5
})
content()({
    block: 'rating',
    rating: -5.5
})

@indutny
Copy link
Collaborator

indutny commented Feb 7, 2015

Will look into it very soon.

@vovieque vovieque changed the title Template with negative number doesn't compile without dev mode The template engine doesn't compile template with negative number without dev mode Feb 9, 2015
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