diff options
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 2 | ||||
-rw-r--r-- | src/qml/parser/qqmljslexer.cpp | 37 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmlparser/tst_qqmlparser.cpp | 19 |
4 files changed, 26 insertions, 38 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 0316e54c09..1717fb18f8 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1052,7 +1052,7 @@ QTypeRevision IRBuilder::extractVersion(const QStringRef &string) const int dot = string.indexOf(QLatin1Char('.')); return (dot < 0) - ? QTypeRevision::fromVersion(string.toInt(), 0) + ? QTypeRevision::fromMajorVersion(string.toInt()) : QTypeRevision::fromVersion(string.left(dot).toInt(), string.mid(dot + 1).toInt()); } diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp index 243fc5bd30..4f694447bb 100644 --- a/src/qml/parser/qqmljslexer.cpp +++ b/src/qml/parser/qqmljslexer.cpp @@ -1538,9 +1538,10 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error) setError(QCoreApplication::translate("QQmlParser","Imported file must be a script")); return false; } + lex(); } else if (_tokenKind == T_IDENTIFIER) { - // .import T_IDENTIFIER (. T_IDENTIFIER)* T_VERSION_NUMBER . T_VERSION_NUMBER as T_IDENTIFIER + // .import T_IDENTIFIER (. T_IDENTIFIER)* (T_VERSION_NUMBER (. T_VERSION_NUMBER)?)? as T_IDENTIFIER while (true) { if (!isUriToken(_tokenKind)) { setError(QCoreApplication::translate("QQmlParser","Invalid module URI")); @@ -1566,31 +1567,27 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error) } } - if (_tokenKind != T_VERSION_NUMBER) { - setError(QCoreApplication::translate("QQmlParser","Module import requires a version")); - return false; // expected the module version number - } - - version = tokenText(); - lex(); - if (_tokenKind != T_DOT) { - setError(QCoreApplication::translate( "QQmlParser", "Module import requires a minor version (missing dot)")); - return false; // expected the module version number - } - version += QLatin1Char('.'); - - lex(); - if (_tokenKind != T_VERSION_NUMBER) { - setError(QCoreApplication::translate( "QQmlParser", "Module import requires a minor version (missing number)")); - return false; // expected the module version number + if (_tokenKind == T_VERSION_NUMBER) { + version = tokenText(); + lex(); + if (_tokenKind == T_DOT) { + version += QLatin1Char('.'); + lex(); + if (_tokenKind != T_VERSION_NUMBER) { + setError(QCoreApplication::translate( + "QQmlParser", "Incomplete version number (dot but no minor)")); + return false; // expected the module version number + } + version += tokenText(); + lex(); + } } - version += tokenText(); } // // recognize the mandatory `as' followed by the module name // - if (! (lex() == T_AS && tokenStartLine() == lineNumber)) { + if (! (_tokenKind == T_AS && tokenStartLine() == lineNumber)) { if (fileImport) setError(QCoreApplication::translate("QQmlParser", "File import requires a qualifier")); else diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index a136235f90..b63867ec3d 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -4514,9 +4514,9 @@ void tst_qqmlecmascript::importScripts_data() QTest::newRow("missing module version") << testFileUrl("jsimportfail/missingModuleVersion.qml") - << false /* compilation should succeed */ + << true /* compilation should succeed */ << QString() - << (QStringList() << testFileUrl("jsimportfail/missingModuleVersion.js").toString() + QLatin1String(":1:17: Module import requires a version")) + << QStringList() << QStringList() << QVariantList(); @@ -4524,7 +4524,7 @@ void tst_qqmlecmascript::importScripts_data() << testFileUrl("jsimportfail/malformedModuleVersion.qml") << false /* compilation should succeed */ << QString() - << (QStringList() << testFileUrl("jsimportfail/malformedModuleVersion.js").toString() + QLatin1String(":1:17: Module import requires a version")) + << (QStringList() << testFileUrl("jsimportfail/malformedModuleVersion.js").toString() + QLatin1String(":1:17: Module import requires a qualifier")) << QStringList() << QVariantList(); diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index 8483bd1f95..e4bcfa7796 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -59,7 +59,7 @@ private slots: void templateLiteral(); void leadingSemicolonInClass(); void templatedReadonlyProperty(); - void qmlImportInJSRequiresFullVersion(); + void qmlImportInJS(); void typeAnnotations_data(); void typeAnnotations(); void disallowedTypeAnnotations_data(); @@ -361,37 +361,28 @@ void tst_qqmlparser::templatedReadonlyProperty() QVERIFY(parser.parse()); } -void tst_qqmlparser::qmlImportInJSRequiresFullVersion() +void tst_qqmlparser::qmlImportInJS() { { QQmlJS::Engine engine; QQmlJS::Lexer lexer(&engine); lexer.setCode(QLatin1String(".import Test 1.0 as T"), 0, false); QQmlJS::Parser parser(&engine); - bool b = parser.parseProgram(); - qDebug() << parser.errorMessage(); - QVERIFY(b); + QVERIFY(parser.parseProgram()); } { QQmlJS::Engine engine; QQmlJS::Lexer lexer(&engine); lexer.setCode(QLatin1String(".import Test 1 as T"), 0, false); QQmlJS::Parser parser(&engine); - QVERIFY(!parser.parseProgram()); - } - { - QQmlJS::Engine engine; - QQmlJS::Lexer lexer(&engine); - lexer.setCode(QLatin1String(".import Test 1 as T"), 0, false); - QQmlJS::Parser parser(&engine); - QVERIFY(!parser.parseProgram()); + QVERIFY(parser.parseProgram()); } { QQmlJS::Engine engine; QQmlJS::Lexer lexer(&engine); lexer.setCode(QLatin1String(".import Test as T"), 0, false); QQmlJS::Parser parser(&engine); - QVERIFY(!parser.parseProgram()); + QVERIFY(parser.parseProgram()); } } |