pveyes / naskah

Bahasa pemrograman dengan sintaks Bahasa Indonesia (Programming language with Indonesian syntax) 🇮🇩
https://naskah.vercel.app
MIT License
176 stars 11 forks source link

Guard identifier on compiled JS #9

Open pveyes opened 5 years ago

pveyes commented 5 years ago

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) {
}
andraantariksa commented 3 years ago

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.