Version 0.2.5 is now released. A notable new feature is automatic semicolon insertion. This is one of the most controversial features of JavaScript syntax, so I decided to make it optional.
There is two parts to it. The first part is that a semicolon is not necessary at the end of a block or at the end of a program. Example:
function f(){
var x = 1;
var y = 2 <- semicolon optional
}
This is a nice and uncontroversial feature.
The controversial part is that semicolons are also sometimes optional at the end of individual lines:
var x = 1 <- semicolon also optional!
var y = 2
This is controversial because the rules for determining when a statement is finished are not immediately obvious. A line-break does not always terminate a statement - only if the syntax would be illegal without the semicolon, is a semicolon inserted by the parser.
Most of the time this works as you would expect, but in some cases the result may be surprising and may lead to obscure bugs. Eric Lippert has some examples.
Because of these problems, many believe that automatic semicolon insertion was a mistake in JavaScript. However ES4 cannot change the rules, because that would break backwards compatibility.
I had some doubt if I wanted to support semicolon insertion in Mascara, because the purpose of Mascara is to help you make less bugs, not to create more bugs. On the other hand, Mascara should follow the ES4 spec as close as possible, and play nice with legacy JavaScript. So I decided that:
1) Semicolon at the end of a block is always optional. This should not cause any problems.
2) Automatic semicolon insertion at the end of individual lines are disabled per default, but a compiler option is available to enable it.
In the online demo, there is now a "compiler options"-area, where semicolon insertion can be enabled.
In the 0.2.5 download, semicolon insertion can be enabled in the file config.py in the root, by changing "semicolonInsertion":False to "semicolonInsertion":True for the compiler_settings line.
Hope you think this decision makes sense, otherwise let me know!
tirsdag den 8. juli 2008
Abonner på:
Kommentarer til indlægget (Atom)
This blog has moved to http://blog.mascaraengine.com. See you!
This blog is (was) for news, announcements and questions regarding the
Mascara ECMAScript 6 -> JavaScript translator.
This blog is (was) for news, announcements and questions regarding the
Mascara ECMAScript 6 -> JavaScript translator.
Ingen kommentarer:
Send en kommentar