From 9d7b27f5bf44a46707e6d50ebf51ecf73f91dd1b Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 5 Dec 2014 16:32:56 +0100 Subject: Clean up JS .import/.pragma directive scanning There's a scanner in QQmlJS::Lexer::scanDirectives that can parse those, so let's get rid of extra parser that operates on a string. Instead this way we can do the scanning all in one shot, avoid detaching a copy of the source code string and (most importantly) bring the parser closer to the copy in Qt Creator, which uses the directives approach to extract imports and pragma. Change-Id: Iff6eb8d91a45d8a70f383f953115692be48259de Reviewed-by: Fawzi Mohamed --- tools/qmlmin/main.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tools/qmlmin') diff --git a/tools/qmlmin/main.cpp b/tools/qmlmin/main.cpp index aa3adf053d..aa99b242a7 100644 --- a/tools/qmlmin/main.cpp +++ b/tools/qmlmin/main.cpp @@ -93,7 +93,7 @@ public: _directives += QLatin1String(".pragma library\n"); } - virtual void importFile(const QString &jsfile, const QString &module) + virtual void importFile(const QString &jsfile, const QString &module, int line, int column) { _directives += QLatin1String(".import"); _directives += QLatin1Char('"'); @@ -102,9 +102,11 @@ public: _directives += QLatin1String("as "); _directives += module; _directives += QLatin1Char('\n'); + Q_UNUSED(line); + Q_UNUSED(column); } - virtual void importModule(const QString &uri, const QString &version, const QString &module) + virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column) { _directives += QLatin1String(".import "); _directives += uri; @@ -113,6 +115,8 @@ public: _directives += QLatin1String(" as "); _directives += module; _directives += QLatin1Char('\n'); + Q_UNUSED(line); + Q_UNUSED(column); } protected: @@ -262,7 +266,8 @@ bool Minify::parse(int startToken) if (startToken == T_FEED_JS_PROGRAM) { // parse optional pragma directive - if (scanDirectives(this)) { + DiagnosticMessage error; + if (scanDirectives(this, &error)) { // append the scanned directives to the minifier code. append(directives()); @@ -433,7 +438,8 @@ bool Tokenize::parse(int startToken) if (startToken == T_FEED_JS_PROGRAM) { // parse optional pragma directive - if (scanDirectives(this)) { + DiagnosticMessage error; + if (scanDirectives(this, &error)) { // append the scanned directives as one token to // the token stream. _minifiedCode.append(directives()); -- cgit v1.2.3