20 using namespace QQmlJS::AST;
21 const QFileInfo info { m_file };
22 const QString baseName = info.baseName();
23 scope->setInternalName(baseName.endsWith(QStringLiteral(
".ui")) ? baseName.chopped(3)
26 QQmlJS::Engine engine;
27 QQmlJS::Lexer lexer(&engine);
29 const QString lowerSuffix = info.suffix().toLower();
30 const bool isESModule = lowerSuffix == QLatin1String(
"mjs");
31 const bool isJavaScript = isESModule || lowerSuffix == QLatin1String(
"js");
35 if (!file.open(QFile::ReadOnly))
38 QString code = QString::fromUtf8(file.readAll());
41 lexer.setCode(code, 1, !isJavaScript);
42 QQmlJS::Parser parser(&engine);
44 const bool success = isJavaScript ? (isESModule ? parser.parseModule()
45 : parser.parseProgram())
48 QQmlJS::AST::Node *rootNode = parser.rootNode();
51 logger.setFilePath(m_file);
53 logger.setSilent(
true);
55 m_importer->runImportVisitor(rootNode,
58 QQmlJSImportVisitor::implicitImportDirectory(
59 m_file, m_importer->resourceFileMapper()),
61 return success && rootNode;