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

Hausmann Simon Simon.Hausmann at theqtcompany.com
Mon Feb 16 14:54:41 CET 2015


Hi,

In principle I think that's a very good direction. However .pragma singleton does not exist for .js files :). Qt.import as a substitute for .pragma import would be great. In an ideal world we'd support es6 modules.


Simon

  Original Message
From: Mike Verdone
Sent: Monday, February 16, 2015 21:34
To: development at qt-project.org
Subject: [Development] Proposed syntax change for pragmas and imports in        QtQuick .js files


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

_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list