-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reserved keywords as attributes produce error #62
Comments
I just gave this a try, but the problem is most reserved keywords are not parsed as |
I've tried hacking on that and got it to parse |
I was thinking maybe it would be easy just adding Something like this: (defun rjsx-match-token (match &optional dont-unget)
"Get next token and return t if it matches MATCH, a bytecode.
Returns nil and consumes nothing if MATCH is not the next token."
(setf js2-ti-lookahead 0)
(if (/= (js2-get-token 'KEYWORD_IS_NAME) match)
(ignore (unless dont-unget (js2-unget-token)))
t))
(defun rjsx-must-match-name (msg-id)
(if (rjsx-match-token js2-NAME nil)
t
(if (eq (js2-current-token-type) js2-RESERVED)
(js2-report-error "msg.reserved.id" (js2-current-token-string))
(js2-report-error msg-id)
(js2-unget-token))
nil))
(cl-defun rjsx-parse-identifier (&optional face &key (allow-ns t))
"Parse a possibly namespaced identifier and fontify with FACE if given.
Returns a `js2-error-node' if unable to parse. If the &key
argument ALLOW-NS is nil, does not allow namespaced names."
(if (rjsx-must-match-name "msg.bad.jsx.ident")
(let ((pn (make-rjsx-identifier))
But there is too many things going on that I don't understand. And this did not help much. |
If there is anything I could try out, give me some hints. |
IIRC, the (cl-defun rjsx-parse-identifier (&optional face &key (allow-ns t))
;; snip
(if (rjsx-must-match-name "msg.bad.jsx.ident")
(if (js2-match-token js2-NAME)
;; snip
(if (js2-match-token js2-NAME)
(if (eq prev-token-end (js2-current-token-beg))
(progn (push (js2-current-token-string) name-parts)
(setq prev-token-end (js2-current-token-end)
name-start (or name-start (js2-current-token-beg))))
(js2-unget-token)
(setq continue nil))
;; snip The complexity elsewhere comes from checking for namespaces and allowing dashes in names. (So it's stitching one token out of several Does that help? |
How about not using js2 to parse the attribute name, and force js2 somehow to skip forward as much as we parse. Just check for {...var} and make js2 parse that for us? |
I mean, since html/xml is not javascript maybe not use javascript parser to parse it. |
The issue is not the parser but the lexer. But either way, yes, that's probably right. We already manipulate the lexer internals to handle |
So it's js2 that has to be fixed or improved? |
I use babel to translate jsx syntax into my own custom components not React (you can do this by including a pragma such as
/** @jsx generate */
at the top of the file,generate
is then the method fed the translated data).I have this code
I get a parse error on
class
because it is reserved js word. Quick peak intorjsx-parse-identifier
andjs2-must-match-name
shows that it tests for keywords and produces an error. Maybe we should be more permissive here?The text was updated successfully, but these errors were encountered: