diff --git a/src/libs/qmljs/qmljsscanner.cpp b/src/libs/qmljs/qmljsscanner.cpp
index c916f1aa234f236b954322af7b6fea0edb80842e..8567bf60026d3c91184c4e9705d2d5f76c9d8a48 100644
--- a/src/libs/qmljs/qmljsscanner.cpp
+++ b/src/libs/qmljs/qmljsscanner.cpp
@@ -77,7 +77,8 @@ const _Tp *end(const _Tp (&a)[N])
 }
 
 QmlJSScanner::QmlJSScanner()
-    : m_state(0)
+    : _state(0),
+      _scanComments(true)
 {
 }
 
@@ -85,6 +86,16 @@ QmlJSScanner::~QmlJSScanner()
 {
 }
 
+bool QmlJSScanner::scanComments() const
+{
+    return _scanComments;
+}
+
+void QmlJSScanner::setScanComments(bool scanComments)
+{
+    _scanComments = scanComments;
+}
+
 static bool isIdentifierChar(QChar ch)
 {
     switch (ch.unicode()) {
@@ -116,14 +127,14 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
         MultiLineComment = 1
     };
 
-    m_state = startState;
+    _state = startState;
     QList<Token> tokens;
 
     // ### handle multi line comment state.
 
     int index = 0;
 
-    if (m_state == MultiLineComment) {
+    if (_state == MultiLineComment) {
         const int start = index;
         while (index < text.length()) {
             const QChar ch = text.at(index);
@@ -132,7 +143,7 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
                 la = text.at(index + 1);
 
             if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
-                m_state = Normal;
+                _state = Normal;
                 index += 2;
                 break;
             } else {
@@ -140,7 +151,8 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
             }
         }
 
-        tokens.append(Token(start, index - start, Token::Comment));
+        if (_scanComments)
+            tokens.append(Token(start, index - start, Token::Comment));
     }
 
     while (index < text.length()) {
@@ -153,12 +165,13 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
         switch (ch.unicode()) {
         case '/':
             if (la == QLatin1Char('/')) {
-                tokens.append(Token(index, text.length() - index, Token::Comment));
+                if (_scanComments)
+                    tokens.append(Token(index, text.length() - index, Token::Comment));
                 index = text.length();
             } else if (la == QLatin1Char('*')) {
                 const int start = index;
                 index += 2;
-                m_state = MultiLineComment;
+                _state = MultiLineComment;
                 while (index < text.length()) {
                     const QChar ch = text.at(index);
                     QChar la;
@@ -166,14 +179,15 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
                         la = text.at(index + 1);
 
                     if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
-                        m_state = Normal;
+                        _state = Normal;
                         index += 2;
                         break;
                     } else {
                         ++index;
                     }
                 }
-                tokens.append(Token(start, index - start, Token::Comment));
+                if (_scanComments)
+                    tokens.append(Token(start, index - start, Token::Comment));
             } else {
                 tokens.append(Token(index++, 1, Token::Delimiter));
             }
@@ -285,7 +299,7 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
 
 int QmlJSScanner::state() const
 {
-    return m_state;
+    return _state;
 }
 
 bool QmlJSScanner::isKeyword(const QString &text) const
diff --git a/src/libs/qmljs/qmljsscanner.h b/src/libs/qmljs/qmljsscanner.h
index ae2485a52bcd8577cbcb1376c65e86f583048f29..3c3c12b360fb2555e18628af34835edac0086229 100644
--- a/src/libs/qmljs/qmljsscanner.h
+++ b/src/libs/qmljs/qmljsscanner.h
@@ -80,13 +80,17 @@ public:
     QmlJSScanner();
     virtual ~QmlJSScanner();
 
+    bool scanComments() const;
+    void setScanComments(bool scanComments);
+
     QList<Token> operator()(const QString &text, int startState = 0);
     int state() const;
 
     bool isKeyword(const QString &text) const;
 
 private:
-    int m_state;
+    int _state;
+    bool _scanComments: 1;
 };
 
 } // namespace QmlJS