[Development] Using semicolons in JS (QML)

Olivier Goffart olivier at woboq.com
Fri Sep 30 16:48:20 CEST 2016


On Freitag, 30. September 2016 12:19:09 CEST Kai Koehne wrote:
> Hi,
> 
> It’s Friday, so time for some bikeshedding ;)
> 
> 
> As you might know, the semicolon as a statement separator in JavaScript is
> optional.

Technicly, that's more complicated than that.  The semicolons are mandatory. 
But in case of parse error, the parser should try to recover by inserting them 
using complex rules.

Quoting the ECMAScript spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-7.9

| Certain ECMAScript statements [...] must be terminated with semicolons. Such
| semicolons may always appear explicitly in the source text. For convenience,
| however, such semicolons may be omitted from the source text in certain
| situations. These situations are described by saying that semicolons are
| automatically inserted into the source code token stream in those
| situations.

| When, as the program is parsed from left to right, a token (called the
| offending token) is encountered that is not allowed by any production of the
| grammar, then a semicolon is automatically inserted before the offending
| token if one or more of the following conditions is true:
|   - The offending token is separated from the previous token by at least one
|     LineTerminator.
|   - The offending token is }.
| [...]


 
> [...]
> To make a proposal: Let’s use semicolons in imperative JS parts of QML in
> our examples and documentation. Apart from being on the safe side
> regarding some pathological cases, it also makes the difference between
> declarative QML bindings  and imperative JS code more explicit.
> 
> Now I do realize that the right side of QML bindings is actually JavaScript.
> But no, I do not want to propose that now every binding ends with a ‘;’. A
> good rule of thumb might be that semicolons should be used inside either
> function X() {} or OnSignalHandler: {} blocks, or in .js files. 
> Thoughts?

Personally, I like to use semicolon everywhere when I write QML; including at 
the end of the bindings.
I'm used to semi colon from writing C++ anyway.

-- 
Olivier

Woboq - Qt services and support - https://woboq.com - https://code.woboq.org



More information about the Development mailing list