naskah icon indicating copy to clipboard operation
naskah copied to clipboard

Guard identifier on compiled JS

Open pveyes opened this issue 6 years ago • 1 comments

Currently we can use any reserved word/token (such as var, if, etc) as identifier in naskah which won't be valid JS. The simplest thing we can do is add underscore before printing the identifier if it's a reserved word in JS

So that:

misal x = 3;
misal var = 2;

jika while benar {
} 

should be compiled to

var x = 3;
var _var = 2;

if (_while == true) {
}

pveyes avatar Oct 21 '18 17:10 pveyes

I think the solution depends on the goal itself. If the transpiler goal is to create an optimized javascript code, it is better to create a shorter identifier to reduce the parsing time (?). For another case, why don't make all of the javascript keyword a reserved keyword? Adding something to the identifier is more counter-intuitive for me and it will be a special case that people might have to remember if they wants to interact with the generated code.

andraantariksa avatar Oct 30 '20 11:10 andraantariksa