Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljstypereader.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
7
8#include <QtQml/private/qqmljsast_p.h>
9#include <QtQml/private/qqmljsengine_p.h>
10#include <QtQml/private/qqmljslexer_p.h>
11#include <QtQml/private/qqmljsparser_p.h>
12#include <QtQml/private/qqmlimportresolver_p.h>
13
14#include <QtCore/qfileinfo.h>
15#include <QtCore/qdebug.h>
16
18
19namespace QQmlJS {
20void defaultTypeReader(QQmlJSImporter *importer, const QString &filePath,
21 const QSharedPointer<QQmlJSScope> &scope)
22{
23 using namespace QQmlJS::AST;
24 const QFileInfo info{ filePath };
25
26 QQmlJS::Engine engine;
27
28 const QString lowerSuffix = info.suffix().toLower();
29 const bool isESModule = lowerSuffix == QLatin1String("mjs");
30 const bool isJavaScript = isESModule || lowerSuffix == QLatin1String("js");
31
32 QFile file(filePath);
33 if (!file.open(QFile::ReadOnly))
34 return;
35
36 QString code = QString::fromUtf8(file.readAll());
37 file.close();
38
39 const QQmlJS::Parser::Goal goal = !isJavaScript ? QQmlJS::Parser::Goal::QmlDocument
40 : isESModule ? QQmlJS::Parser::Goal::Module
41 : QQmlJS::Parser::Goal::Script;
42 QQmlJS::AST::Node *rootNode = QQmlJS::Parser::parseCode(&engine, code, goal).rootNode;
43
44 QQmlJSLogger logger;
45 logger.setFilePath(filePath);
46 logger.setCode(code);
47 logger.setSilent(true);
48 logger.setIsDisabled(true);
49
50 importer->runImportVisitor(rootNode,
51 { scope,
52 &logger,
53 QQmlJSImportVisitor::implicitImportDirectory(
54 filePath, importer->resourceFileMapper()),
55 { } });
56}
57} // namespace QQmlJS
58
59QT_END_NAMESPACE
void defaultTypeReader(QQmlJSImporter *importer, const QString &filePath, const QSharedPointer< QQmlJSScope > &scope)
Combined button and popup list for selecting options.