-
Notifications
You must be signed in to change notification settings - Fork 49
rework parsing to use substitutions #169
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
base: master
Are you sure you want to change the base?
Conversation
@43081j one option here is to use the tokenization algorithm that lit-html itself uses which detects syntax position. Then you can insert the correct marker in all cases. |
i actually now realised i think the substitution is pointless in fact, it could just be a constant value! like we can infer from those placeholders where the expressions were, so we don't actually care what each one is individually... ill have a re-read through lit's parsing though too as that sounds useful here |
82dd6cc
to
620cdec
Compare
@43081j these are placeholders inserted before parsing with parse5, yeah? If so, we do care about what the markers are because they have to be valid for the syntax position of the expression. The main thing is that you want comment makers for child expressions so that you avoid any "adoption agency" side effects (that's the algorithm that moves disallowed nodes out of I think the best thing might be to copy the |
Yes exactly. In master it is already wrong, as the placeholder is I'll have a look at copying that function over, i almost did but wasn't sure if we needed it yet. would be a lot nicer than a constant placeholder i think |
Oh, and I bet the |
It is but i already fixed the positioning so it can be variable length now (the placeholder). We just calculate the correct offsets on the way out based on the placeholder length. Thats constant for now but if it wasn't, we'd just keep a map of expressions to placeholders for the same reason. It should work fine this way unless im missing something |
@43081j looking at how we could add element binding support, I do think we will need to use the HTML tokenization code from lit-html to determine which marker to insert. |
I'm working on this today. |
sure, feel free to close this if you open another PR for it. would be nice i think to use the same logic as lit itself like you mentioned |
I have a feeling we're going to need this when we want to start detecting things like:
It is very delicate right now in master because it depends entirely on length of the parsed HTML matching length of the input JS, which means we're limited on what we can use as placeholders.
If we want to detect tag bindings and other things, we need the placeholder to be a valid tag name (so parse5 is happy), too.
This is one option i think, where we track a set of substitutions instead of arbitrary
____
placeholders.Feedback would be appreciated, if this is the wrong way to go then we can close it
Depends on #168 to fix the vscode CI error