Skip to content
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

Better recovery from malformed attribute expressions #11

Open
felipeochoa opened this issue Nov 3, 2016 · 0 comments
Open

Better recovery from malformed attribute expressions #11

felipeochoa opened this issue Nov 3, 2016 · 0 comments

Comments

@felipeochoa
Copy link
Owner

There are three possibilities for recovering from a missing RC:

  1. Do nothing This works best for attributes in the middle when they have a value (e.g., a={123 b="...") since the js2 expression parser won't consume extra tokens, letting additional attributes be tokenized properly. In contrast, when the attribute is the last one in the tag the parser will happily give us a greater-than expression using the closing GT from the tag, messing everything up. There's not much we can do to distinguish between correct and incorrect parsing there. In self-closing tags js2 would parse the / as division, then > as an error primary expression, and then who knows.

  2. Un-parse the expression This works best for attributes where there's not even a value If we're a middle attribute, js2 will try to parse the next attribute as an assignment of an object literal or string. It can be a valid assignment (a={ b={abc}, a={ b="str"), an error due to a spread op (a={ {...abc}), or an error due to an invalid object literal body (a={ b={a > b}. When the assignment is valid, js2 may keep going if we're at the end of the tag, using the / or > to form expressions.

    If we're at the end of a tag, js2 will parse either a regex (for self-closing tags) or anything goes for an expression starting with > (which is de facto treated as its own primary expression).

  3. Consume up to the next RC. This fixes malformed/partially formed expressions inside the curlies. E.g., a={pred ? b}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant