(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)
(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))
(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))))
(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)))))
(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
"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
(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
(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
(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
(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
(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