[Pkg-javascript-commits] [less.js] 23/25: better error message when import missing a semi-colon or malformed.

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v1.7.4
in repository less.js.

commit 1e04f3364d578539d41ff86895268d3af4862db9
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sun Jul 27 20:47:19 2014 +0100

    better error message when import missing a semi-colon or malformed.
---
 lib/less/parser.js                  | 27 ++++++++++++++++-----------
 test/less/errors/import-no-semi.txt |  2 +-
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/lib/less/parser.js b/lib/less/parser.js
index 3775b8f..6abe053 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -225,7 +225,7 @@ less.Parser = function Parser(env) {
         return oldi !== i || oldj !== j;
     }
 
-    function expect(arg, msg) {
+    function expect(arg, msg, index) {
         // some older browsers return typeof 'function' for RegExp
         var result = (Object.prototype.toString.call(arg) === '[object Function]') ? arg.call(parsers) : $(arg);
         if (result) {
@@ -1611,7 +1611,7 @@ less.Parser = function Parser(env) {
             //
             //     @import "lib";
             //
-            // Depending on our environemnt, importing is done differently:
+            // Depending on our environment, importing is done differently:
             // In the browser, it's an XHR request, in Node, it would be a
             // file-system operation. The function used for importing is
             // stored in `import`, which we pass to the Import constructor.
@@ -1619,22 +1619,27 @@ less.Parser = function Parser(env) {
             "import": function () {
                 var path, features, index = i;
 
-                save();
-
                 var dir = $re(/^@import?\s+/);
 
-                var options = (dir ? this.importOptions() : null) || {};
+                if (dir) {
+                    var options = (dir ? this.importOptions() : null) || {};
 
-                if (dir && (path = this.entities.quoted() || this.entities.url())) {
-                    features = this.mediaFeatures();
-                    if ($char(';')) {
-                        forget();
+                    if ((path = this.entities.quoted() || this.entities.url())) {
+                        features = this.mediaFeatures();
+
+                        if (!$(';')) {
+                            i = index;
+                            error("missing semi-colon or unrecognised media features on import");
+                        }
                         features = features && new(tree.Value)(features);
                         return new(tree.Import)(path, features, options, index, env.currentFileInfo);
                     }
+                    else
+                    {
+                        i = index;
+                        error("malformed import statement");
+                    }
                 }
-
-                restore();
             },
 
             importOptions: function() {
diff --git a/test/less/errors/import-no-semi.txt b/test/less/errors/import-no-semi.txt
index 8b3f795..aaa4ac5 100644
--- a/test/less/errors/import-no-semi.txt
+++ b/test/less/errors/import-no-semi.txt
@@ -1,2 +1,2 @@
-ParseError: Unrecognised input in {path}import-no-semi.less on line 1, column 1:
+SyntaxError: missing semi-colon or unrecognised media features on import in {path}import-no-semi.less on line 1, column 1:
 1 @import "this-statement-is-invalid.less"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list