]> code.delx.au - gnu-emacs-elpa/commitdiff
(Hopefully) fix #117 and capitaomorte/autopair#21
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 13 Oct 2013 01:21:51 +0000 (04:21 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 13 Oct 2013 01:21:51 +0000 (04:21 +0300)
js2-mode.el
tests/parser.el

index 4bd3af00abd86b9361e07a8bfd0aa5f3b089341e..03be86b5048b582c9d242d8502a7f7be6af9f7e1 100644 (file)
@@ -5434,6 +5434,7 @@ its relevant fields and puts it into `js2-ti-tokens'."
           (setq c (js2-get-char))
           (cond
            ((eq c js2-EOF_CHAR)
+            (js2-unget-char)
             (js2-ts-set-char-token-bounds token)
             (throw 'return js2-EOF))
            ((eq c ?\n)
@@ -7407,7 +7408,8 @@ Last token scanned is the close-curly for the function body."
               (js2-function-node-member-expr pn) member-expr)
         pn)
        (t
-        (js2-report-error "msg.no.paren.parms"))))))
+        (js2-report-error "msg.no.paren.parms")
+        (make-js2-error-node))))))
 
 (defun js2-parse-function-expr ()
   (let ((pos (js2-current-token-beg))
@@ -8189,7 +8191,7 @@ Current token type is `js2-SEMI' or `js2-ERROR'."
     (if (eq tt js2-SEMI)
         (make-js2-empty-expr-node :len 1)
       (setq pos (js2-current-token-beg)
-            len (- (js2-current-token-beg) pos))
+            len (- (js2-current-token-end) pos))
       (js2-report-error "msg.syntax" nil pos len)
       (make-js2-error-node :pos pos :len len))))
 
@@ -9189,7 +9191,7 @@ array-literals, array comprehensions and regular expressions."
       (setq px-pos (point-at-bol)
             len (- js2-ts-cursor px-pos))
       (js2-report-error "msg.unexpected.eof" nil px-pos len)
-      (make-js2-error-node :pos px-pos :len len))
+      (make-js2-error-node :pos (1- js2-ts-cursor)))
      (t
       (js2-report-error "msg.syntax")
       (make-js2-error-node)))))
index 0a076e12d3c1a0f966b41cddb8bf453231d6d29b..b84265ebe4fcf1196182910e32d736df6d90f135 100644 (file)
@@ -85,7 +85,7 @@ the test."
 (js2-deftest-parse named-function-expression\r
   "a = function b() {};")\r
 \r
-;;; Callers of `js2-valid-prop-name-token'.\r
+;;; Callers of `js2-valid-prop-name-token'\r
 \r
 (js2-deftest-parse parse-property-access-when-not-keyword\r
   "A.foo = 3;")\r
@@ -106,7 +106,7 @@ the test."
   "a = {in: 1};"\r
   :bind ((js2-allow-keywords-as-property-names t)))\r
 \r
-;;; 'of' contextual keyword.\r
+;;; 'of' contextual keyword\r
 \r
 (js2-deftest-parse parse-array-comp-loop-with-of\r
   "[a for (a of [])];")\r
@@ -120,7 +120,7 @@ the test."
 (js2-deftest-parse of-can-be-function-name\r
   "function of() {\n}")\r
 \r
-;;; Destructuring binding.\r
+;;; Destructuring binding\r
 \r
 (js2-deftest-parse destruct-in-declaration\r
   "var {a, b} = {a: 1, b: 2};")\r
@@ -134,7 +134,7 @@ the test."
 (js2-deftest-parse destruct-in-catch-clause\r
   "try {\n} catch ({a, b}) {\n  a + b;\n}")\r
 \r
-;;; Function parameters.\r
+;;; Function parameters\r
 \r
 (js2-deftest-parse function-with-default-parameters\r
   "function foo(a = 1, b = a + 1) {\n}")\r
@@ -161,7 +161,7 @@ the test."
 (js2-deftest-parse function-with-rest-after-default-parameter\r
   "function foo(a = 1, ...rest) {\n}")\r
 \r
-;;; Arrow functions.\r
+;;; Arrow functions\r
 \r
 (js2-deftest-parse arrow-function-with-empty-args-and-no-curlies\r
   "() => false;" :reference "() => {false};")\r
@@ -175,7 +175,7 @@ the test."
 (js2-deftest-parse parenless-arrow-function-prohibits-destructuring\r
   "[a, b] => {a + b;};" :syntax-error "]" :errors-count 5)\r
 \r
-;;; Automatic semicolon insertion.\r
+;;; Automatic semicolon insertion\r
 \r
 (js2-deftest-parse no-auto-semi-insertion-after-if\r
   "if (true) {\n}")\r
@@ -243,3 +243,14 @@ the test."
     (should (eq js2-NUMBER (js2-next-token)))\r
     (should (eq 1 (js2-token-number\r
                    (js2-current-token))))))\r
+\r
+;;; Error handling\r
+\r
+(js2-deftest for-node-with-error-len "for "\r
+  (js2-mode)\r
+  (let ((node (js2-node-at-point (point-min))))\r
+    (should (= (js2-node-len (js2-node-parent node)) 4))))\r
+\r
+(js2-deftest function-without-parens-error "function b {}"\r
+  ;; Should finish the parse.\r
+  (js2-mode))\r