[Development] Proposed syntax change for pragmas and imports in QtQuick .js files

Mike Verdone mike.verdone at ableton.com
Mon Feb 16 14:34:40 CET 2015


Hi all,

This is my first post to the Qt dev list. Apologies if I say something
dumb.

I’d like to propose some changes to the “meta” syntax in QtQuick .js
files. I propose this in order to support JavaScript tools such as linters
and “transpilers”. Specifically I’d like to change:

.pragma singleton

to

“pragma singleton”;

and

.import “foo.js” as Foo

to

var Foo = Qt.import(“foo.js”);


In the first example, the pragma is changed to something that standard
JavaScript can parse and ignore. It matches nicely with the ECMAScript
“use strict”; syntax.

For the import statement, I could also apply the same string-like syntax
trick, but building an actual Qt.import function allows programs to detect
that the new variable is available in the global scope.

The “.” meta syntax should be preserved for backwards compatibility.

Making these changes opens QtQuick’s JS to a whole new world of JavaScript
libraries and tools. For instance, .js files can be validated with ESLint
for correctness. Tools like the 6to5 allow one to write ES6 JavaScript
right now, and transpile it to QtQuick-compatible ES5 JavaScript.

I’m not expecting any of you busy Qt developers to take on this work. I’m
just curious if these changes might be accepted if I manage to implement
them, or if you have other ideas for how to enable tools like linters to
process QtQuick JS.

Thanks,

Mike.

—
Mike Verdone
Ableton AG
Schoenhauser Allee 6-7
10119 Berlin, Germany

Vorstand: Gerhard Behles, Jan Bohl, Bernd Roggendorf
Aufsichtsrat: Uwe Struck (Vorsitzender)
Sitz: Amtsgericht Berlin-Charlottenburg HRB 72838
Umsatzsteueridentifikationsnummer: DE204128565



More information about the Development mailing list