nfx icon indicating copy to clipboard operation
nfx copied to clipboard

JS Compiler: fix interaction with NHT code

Open vlapchenko opened this issue 8 years ago • 6 comments

Please, fix JS Compiler to correctly parse NHT code insertions like as:

div {
  span="?[:SomeVariable]" {}
}

vlapchenko avatar Apr 05 '17 10:04 vlapchenko

Change precedence tpl then js would not work

You have practical example?

itadapter avatar Apr 05 '17 13:04 itadapter

If I write such construction:

div {
  span="?[:SomeVariable]" {}
}

then I get output:

var Ø5=WAVE.ce('span');Ø5.innerText=[:SomeVariable];

which contains invalid NHT code [:SomeVariable].

vlapchenko avatar Apr 05 '17 20:04 vlapchenko

Also, how exactly I should write laconf code in this case:

@[if (m_IsOwner) {]
  <a class='uiSmallButton' href='?[order.Link]'>Order</a>
@[}]

?

vlapchenko avatar Apr 05 '17 22:04 vlapchenko

I guess the NHT compilation model is such that NHT generates C# template class. The LJS comilation phase is taking place before NHT/C#, so there is no way you can eval NHTC# syntax before LJS (laconinc js). In your case I would use the (ctx ) passed into the js function and use pure js IF. Another way it to compile LJS under NTC ifs

itadapter avatar Apr 06 '17 01:04 itadapter

Fixed. Use double question marks

div {
  span="??[:SomeVariable]" {}
}

panagushin avatar Apr 11 '17 17:04 panagushin

There is some inconvenience to use the offered decision. To parse my statement correctly I have to wrap it with additional quotes every time:

div {
  span="?'?[:SomeVariable]'" {}
}

vlapchenko avatar Apr 13 '17 18:04 vlapchenko