;;; js2-mode.el --- Improved JavaScript editing mode
-;; Copyright (C) 2009, 2011-2014 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2011-2015 Free Software Foundation, Inc.
;; Author: Steve Yegge <steve.yegge@gmail.com>
;; mooz <stillpedant@gmail.com>
;; Dmitry Gutov <dgutov@yandex.ru>
;; URL: https://github.com/mooz/js2-mode/
;; http://code.google.com/p/js2-mode/
-;; Version: 20141118
+;; Version: 20150202
;; Keywords: languages, javascript
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
(defmacro js2-time (form)
"Evaluate FORM, discard result, and return elapsed time in sec."
(declare (debug t))
- (let ((beg (make-symbol "--js2-time-beg--"))
- (delta (make-symbol "--js2-time-end--")))
- `(let ((,beg (current-time))
- ,delta)
+ (let ((beg (make-symbol "--js2-time-beg--")))
+ `(let ((,beg (current-time)))
,form
(/ (truncate (* (- (float-time (current-time))
(float-time ,beg))
"Skip to end of line."
(while (not (memq (js2-get-char) js2-eol-chars)))
(js2-unget-char)
- (setf (js2-token-end (js2-current-token)) js2-ts-cursor)
- (setq js2-token-end js2-ts-cursor))
+ (setf (js2-token-end (js2-current-token)) js2-ts-cursor))
(defun js2-init-scanner (&optional buf line)
"Create token stream for BUF starting on LINE.
During operation, creates an instance of `js2-token' struct, sets
its relevant fields and puts it into `js2-ti-tokens'."
(let (identifier-start
- is-unicode-escape-start c c1
+ is-unicode-escape-start c
contains-escape escape-val str result base
- quote-char val look-for-slash continue tt
+ quote-char look-for-slash continue tt
(token (js2-new-token 0)))
(setq
tt
;; building it out of a string buffer.
(let ((c (js2-get-char))
js2-ts-string-buffer
- nc)
+ nc c1 val escape-val)
(catch 'break
(while (/= c quote-char)
(catch 'continue
(defun js2-parse-paren-expr-or-generator-comp ()
(let ((px-pos (js2-current-token-beg)))
- (if (and (>= js2-language-version 200)
- (js2-match-token js2-FOR))
- (js2-parse-generator-comp px-pos)
+ (cond
+ ((and (>= js2-language-version 200)
+ (js2-match-token js2-FOR))
+ (js2-parse-generator-comp px-pos))
+ ((and (>= js2-language-version 200)
+ (js2-match-token js2-RP))
+ ;; Not valid expression syntax, but this is valid in an arrow
+ ;; function with no params: () => body.
+ (if (eq (js2-peek-token) js2-ARROW)
+ ;; Return whatever, it will hopefully be rewinded and
+ ;; reparsed when we reach the =>.
+ (make-js2-keyword-node :type js2-NULL)
+ (js2-report-error "msg.syntax")
+ (make-js2-error-node)))
+ (t
(let* ((js2-in-for-init nil)
(expr (js2-parse-expr))
(pn (make-js2-paren-node :pos px-pos
px-pos))))
(js2-node-add-children pn (js2-paren-node-expr pn))
(js2-must-match js2-RP "msg.no.paren")
- pn))))
+ pn)))))
(defun js2-parse-expr (&optional oneshot)
(let* ((pn (js2-parse-assign-expr))
(= tt js2-FALSE)
(= tt js2-TRUE))
(make-js2-keyword-node :type tt))
- ((= tt js2-RP)
- ;; Not valid expression syntax, but this is valid in an arrow
- ;; function with no params: () => body.
- (if (eq (js2-peek-token) js2-ARROW)
- (progn
- (js2-unget-token) ; Put back the right paren.
- ;; Return whatever, it will hopefully be rewinded and
- ;; reparsed when we reach the =>.
- (make-js2-keyword-node :type js2-NULL))
- (js2-report-error "msg.syntax")
- (make-js2-error-node)))
((= tt js2-TRIPLEDOT)
;; Likewise, only valid in an arrow function with a rest param.
(if (and (js2-match-token js2-NAME)
pn))
(defun js2-parse-class-stmt ()
- (let ((pos (js2-current-token-beg)))
- (js2-must-match-name "msg.unnamed.class.stmt")
- (js2-parse-class pos 'CLASS_STATEMENT (js2-create-name-node t))))
+ (let ((pos (js2-current-token-beg))
+ (_ (js2-must-match-name "msg.unnamed.class.stmt"))
+ (name (js2-create-name-node t)))
+ (js2-set-face (js2-node-pos name) (js2-node-end name)
+ 'font-lock-function-name-face 'record)
+ (let ((node (js2-parse-class pos 'CLASS_STATEMENT name)))
+ (js2-define-symbol js2-FUNCTION
+ (js2-name-node-name name)
+ node)
+ node)))
(defun js2-parse-class-expr ()
(let ((pos (js2-current-token-beg))
(defun js2-parse-class (pos form name)
;; class X [extends ...] {
(let (pn elems extends)
- (when name
- (js2-set-face (js2-node-pos name) (js2-node-end name)
- 'font-lock-function-name-face 'record))
(if (js2-match-token js2-EXTENDS)
(if (= (js2-peek-token) js2-LC)
(js2-report-error "msg.missing.extends")