aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2021-02-03 09:06:09 +0100
committerFawzi Mohamed <fawzi.mohamed@qt.io>2021-02-15 18:22:27 +0100
commit6d51f997df14f2b22c265c5b2fda679ece9edef3 (patch)
tree551889cb0b96998d87c234c6cce657242c4ce954 /src
parenta8685fdb4d57c0ba36d80c395c2ae878595f04da (diff)
Uniformly support shebang
The "qml" tool was the only way of loading QML files that would respect a shebang line. This is problematic as this way you cannot load such files programatically using QQmlComponent, limiting their re-use. Common tools like Qt Creator, but also qmllint, qmlformat, qmlcachegen, etc would not recognize files with shebangs. By moving she-bang support directly in the lexer all tools implicitly support it. Note that we could just as easily support '#' as extra comment character along with //, but here we narrowly add support for in the first line only, as node does (this means that javascript files using she-bang accepted by node, are now accepted also by qml). The only tool needing some adjustments is qmlformat, that has to emit the she-bang again as she-bang and as first line. Add tests for qmlformat, and sprinkle some she-bangs in the other tests just to be sure it doesn't affect anything. Change-Id: I1f6d881c7438bdb23163b5dbe829d59a35d11132 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/parser/qqmljslexer.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp
index 0c4b2ef32f..0e355c54e6 100644
--- a/src/qml/parser/qqmljslexer.cpp
+++ b/src/qml/parser/qqmljslexer.cpp
@@ -768,6 +768,20 @@ again:
else
return scanNumber(ch);
+ case '#':
+ if (_currentLineNumber == 1 && _currentColumnNumber == 2) {
+ // shebang support
+ while (_codePtr <= _endPtr && !isLineTerminator()) {
+ scanChar();
+ }
+ if (_engine) {
+ _engine->addComment(tokenOffset(), _codePtr - _tokenStartPtr - 1,
+ tokenStartLine(), tokenStartColumn());
+ }
+ goto again;
+ }
+ Q_FALLTHROUGH();
+
default: {
uint c = ch.unicode();
bool identifierWithEscapeChars = false;