felipeochoa / rjsx-mode

A JSX major mode for Emacs
https://github.com/felipeochoa/rjsx-mode
MIT License
641 stars 32 forks source link

rjsx-delete-creates-full-tag errors with "rjsx-node does not define visitor-traversal function" #39

Closed aaronjensen closed 7 years ago

aaronjensen commented 7 years ago

My C-d has stopped working recently. Has something in rjsx-mode changed or should I be looking into my own config? Thanks!

To repro:

  1. Open a new scratch buffer
  2. M-x rjsx-mode
  3. Type:

    const foo = <div
  4. That should insert the />, press C-d
Debugger entered--Lisp error: (error "rjsx-node does not define a visitor-traversal function")
  signal(error ("rjsx-node does not define a visitor-traversal function"))
  error("%s does not define a visitor-traversal function" rjsx-node)
  js2-visit-ast(#s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#4) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #2 :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #3) :kids (#2) :decl-type 153) :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #2 :name "foo" :scope nil) :initializer #1) :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #1 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil) js2-node-at-point-visitor)
  js2-visit-var-init-node(#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#3) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #1 :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #2) :kids (#1) :decl-type 153) :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #1 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #1 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #2 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) js2-node-at-point-visitor)
  js2-visit-ast(#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#3) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #1 :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #2) :kids (#1) :decl-type 153) :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #1 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #1 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #2 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) js2-node-at-point-visitor)
  js2-visit-var-decl(#s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#2) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #1 :target #7 :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #8 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #9 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #1) :kids (#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #1 :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #3 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #3 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #4 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil))) :decl-type 153) js2-node-at-point-visitor)
  js2-visit-ast(#s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#2) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #1 :target #7 :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #8 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #9 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #1) :kids (#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #1 :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #3 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #3 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #4 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil))) :decl-type 153) js2-node-at-point-visitor)
  js2-visit-expr-stmt-node(#s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#1) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #1 :kids (#7) :decl-type 153) :target #6 :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #7 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #8 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #1 :kids (#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #2 :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #4 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #4 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #5 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil))) :decl-type 153)) js2-node-at-point-visitor)
  js2-visit-ast(#s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#1) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #1 :kids (#7) :decl-type 153) :target #6 :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #7 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #8 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) :expr #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #1 :kids (#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #2 :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #4 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #4 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #5 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil))) :decl-type 153)) js2-node-at-point-visitor)
  js2-visit-ast-root(#s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #1 :expr #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #3 :kids (#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #4 :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #6 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #6 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #7 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil))) :decl-type 153))) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #1 :expr #7) :kids (#6) :decl-type 153) :target #5 :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #6 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #7 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) js2-node-at-point-visitor)
  js2-visit-ast(#s(js2-ast-root :type 135 :pos 1 :len 18 :props nil :parent nil :kids (#s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #1 :expr #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #3 :kids (#s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #4 :target #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #6 :name "foo" :scope nil) :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #6 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #7 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil))) :decl-type 153))) :symbol-table ((foo . #s(js2-symbol :decl-type 153 :name "foo" :ast-node #s(js2-name-node :type 39 :pos 0 :len 3 :props nil :parent #s(js2-var-init-node :type 153 :pos 6 :len 12 :props nil :parent #s(js2-var-decl-node :type 121 :pos 0 :len 18 :props nil :parent #s(js2-expr-stmt-node :type 132 :pos 0 :len 18 :props nil :parent #1 :expr #7) :kids (#6) :decl-type 153) :target #5 :initializer #s(rjsx-node :type 58 :pos 6 :len 6 :props nil :parent #6 :name #s(rjsx-member :type 61 :pos 1 :len 3 :props nil :parent #7 :dots-pos nil :idents (#s(rjsx-identifier :type 60 :pos 14 :len 3 :props nil :parent nil :namespace nil :name #s(js2-name-node :type 39 :pos 14 :len 3 :props nil :parent nil :name "div" :scope nil)))) :rjsx-props nil :kids nil :closing-tag nil)) :name "foo" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :buffer "*scratch*" :comments nil :errors nil :warnings nil :node-count nil) js2-node-at-point-visitor)
  js2-node-at-point(17 t)
  rjsx--tag-at-point()
  rjsx-delete-creates-full-tag(1)
  funcall-interactively(rjsx-delete-creates-full-tag 1)
  call-interactively(rjsx-delete-creates-full-tag nil nil)
  command-execute(rjsx-delete-creates-full-tag)
felipeochoa commented 7 years ago

@aaronjensen There haven't been any major changes in rjsx-mode, and I just checked js2 and didn't see anything in the ast-walking code there. I'm unable to reproduce this issue with the latest versions from MELPA, so it may be about your configuration.

aaronjensen commented 7 years ago

Maybe it's an emacs 26 issue? I can reproduce w/ emacs -Q.

aaronjensen commented 7 years ago

Confirmed, it does not repro on 25.2, it seems specific to 26

felipeochoa commented 7 years ago

Ok that's useful info. I don't have emacs 26 installed to test this, but I think it's related to cl-defstruct changing to use records instead of vectors for instances (emacs-mirror/emacs@056548283884d61b1b9637c3e56855ce3a17274d). Then js2-visit-ast does:

(let ((vfunc (get (aref node 0) 'js2-visitor))) 
 ;; ...
)

which assumes that node is a vector with its tag in the 0th slot.

felipeochoa commented 7 years ago

I think the latest release should fix this issue, but please let me know if it doesn't work for you. I'll leave the issue open until you've confirmed, since I haven't personally tested the changes (but Travis did)

aaronjensen commented 7 years ago

This fixed it for me! Thank you for the quick fix, much appreciated.