Function: web-mode-javascript-statement-beginning-position
web-mode-javascript-statement-beginning-position is a natively
compiled function defined in web-mode.el.
Signature
(web-mode-javascript-statement-beginning-position POS REG-BEG IS-TERNARY)
Source Code
;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
;; TODO: reg-beg : jsx-beg
;; TODO: skipper les expr dont la depth est superieure
;; NOTE: blockside is useful for ejs
(defun web-mode-javascript-statement-beginning-position (pos reg-beg is-ternary)
(unless pos (setq pos (point)))
(setq pos (1- pos))
(let ((char nil)
(blockside (get-text-property pos 'block-side))
(i 0)
(is-jsx (string= web-mode-content-type "jsx"))
(depth-o nil) (depth-l nil)
(continue (not (null pos)))
(regexp "[\]\[}{)(=:]\\|\\(return\\)"))
(when is-ternary
(setq regexp (concat regexp "\\|[><]")))
(setq depth-o (get-text-property pos 'jsx-depth))
(unless reg-beg
(cond
(blockside
(setq reg-beg (web-mode-block-beginning-position pos)))
(is-jsx
(setq reg-beg (web-mode-jsx-depth-beginning-position pos)))
(t
(setq reg-beg (web-mode-part-beginning-position pos)))
) ;cond
) ;unless
(while continue
(setq char (char-after pos))
(cond
((> (setq i (1+ i)) 20000)
(message "javascript-statement-beginning-position ** warning (%S) **" pos)
(setq continue nil
pos nil))
((null pos)
(message "javascript-statement-beginning-position ** invalid pos **")
(setq continue nil))
((< pos reg-beg)
(when (not is-jsx)
(message "javascript-statement-beginning-position ** failure **"))
(setq continue nil
pos reg-beg))
((and is-jsx
(progn (setq depth-l (get-text-property pos 'jsx-depth)) t)
(not (eq depth-l depth-o)))
;;(message "%S > depth-o(%S) depth-l(%S)" pos depth-o depth-l)
(setq pos (previous-single-property-change pos 'jsx-depth))
(setq pos (1- pos))
;;(message "--> %S %S" pos (get-text-property pos 'jsx-depth))
)
((and blockside
(member (get-text-property pos 'block-token) '(string comment))
(eq (get-text-property pos 'block-token) (get-text-property (1- pos) 'block-token)))
(setq pos (web-mode-block-token-beginning-position pos)))
((and (not blockside)
(member (get-text-property pos 'part-token) '(string comment))
(eq (get-text-property pos 'part-token) (get-text-property (1- pos) 'part-token)))
(setq pos (web-mode-part-token-beginning-position pos)))
((and (not blockside)
(get-text-property pos 'block-side))
(when (setq pos (web-mode-block-beginning-position pos))
(setq pos (1- pos))))
((member char '(?\) ?\] ?\}))
(setq pos (web-mode-part-opening-paren-position pos reg-beg))
(setq pos (1- pos)))
((and (eq char ?\=)
(web-mode-looking-back "[<>!=]+" pos reg-beg t))
(setq pos (- pos 1 (length (match-string-no-properties 0)))))
((member char '(?\( ?\{ ?\[ ?\= ?\< ?\>))
(web-mode-looking-at ".[ \t\n]*" pos)
(setq continue nil
pos (+ pos (length (match-string-no-properties 0)))))
((web-mode-looking-at "\\(return\\)[ \n]" pos)
(setq continue nil
pos (+ pos (length (match-string-no-properties 0)))))
((and (eq char ?\:)
(web-mode-looking-back "[{,][ \t\n]*[[:alnum:]_]+[ ]*" pos))
(web-mode-looking-at ".[ \t\n]*" pos)
(setq continue nil
pos (+ pos (length (match-string-no-properties 0)))))
(t
(setq pos (web-mode-rsb-position pos regexp reg-beg))
(when (not pos)
(cond
(is-jsx
(when (web-mode-looking-at "[ \n]*" reg-beg)
(setq pos (+ reg-beg (length (match-string-no-properties 0)))))
(setq continue nil))
(t
(message "javascript-statement-beginning-position ** search failure **")
(setq continue nil
pos reg-beg))
) ;cond
)
) ;t
) ;cond
) ;while
;;(message "%S -------" pos)
pos))