-
Notifications
You must be signed in to change notification settings - Fork 164
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
Parse Polymer 2 template insertion style #6909
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 6 files at r1.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
([\\`|\\'|\\\"])
Should the contents be wrapped in character class ([...]
)? It seems like there is an or
pattern, but that should not work inside of a character class. Same seems to apply to TEMPLATE_PATTERN
.
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 201 at r1 (raw file):
continue; } return templates.get(0);
If the last bits with the continue
s were replaced with something like
Optional<Element> template = domModule.map(module -> {
JsoupUtils.removeCommentsRecursively(domModule.get());
Elements templates = domModule.get()
.getElementsByTag(TEMPLATE_TAG_NAME);
return !templates.isEmpty() ? templates.get(0) : null;
});
if (template.isPresent()) {
return template.get();
}
this could be a normal else if
branch without the while
and double continue
s
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/JsoupUtils.java, line 73 at r1 (raw file):
} }
new line missing
flow-server/src/test/resources/META-INF/VAADIN/config/no-html-template.json, line 13 at r1 (raw file):
], "hash": "foo" }
Missing new line.
Some of the indents are formatted with tabs while others are spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov and @ujoni)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, ujoni (Joni) wrote…
([\\`|\\'|\\\"])
Should the contents be wrapped in character class (
[...]
)? It seems like there is anor
pattern, but that should not work inside of a character class. Same seems to apply toTEMPLATE_PATTERN
.
I'm not sure what you mean......
([\\
|\'|\"])` has
- parenthesis
()
[]
which makesor
between back-tick,'
,"
.
So for me everything looks fine.
What do you mean by character class ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, denis-anisimov (Denis) wrote…
I'm not sure what you mean......
([\\
|\'|\"])` has
- parenthesis
()
[]
which makesor
between back-tick,'
,"
.So for me everything looks fine.
What do you mean by character class ?
Shouldn't it just read (\\`|\\'|\\\")
or [`'\\"]
instead of ([\\`|\\'|\\\"])
. The [
and ]
marks a character group (and could be thought to have an implicit |
between the characters) . I am not actually sure why the quotes (other than ") need to be escaped at all. They aren't special characters, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov and @ujoni)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, ujoni (Joni) wrote…
Shouldn't it just read
(\\`|\\'|\\\")
or[`'\\"]
instead of([\\`|\\'|\\\"])
. The[
and]
marks a character group (and could be thought to have an implicit|
between the characters) . I am not actually sure why the quotes (other than ") need to be escaped at all. They aren't special characters, right?
Hmm.....
I don't think so.
(
is just a marker for group to reuse it later and reference as \\n
(it's referenced later on in regexp as \\1
).
[]
is used for or.
So ([\\
|\'|\"])looks correct for me : it a group which consist of one character ( or , or). back tick quote is used for multiline strings ( I suppose). If you have a short string which is one line then ( I think ) you may use
"or
'` .
But I don't actually know exactly. This is just a modification of the existing pattern/logic.
At least it works....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, denis-anisimov (Denis) wrote…
Hmm.....
I don't think so.
(
is just a marker for group to reuse it later and reference as\\n
(it's referenced later on in regexp as\\1
).
[]
is used for or.So
([\\
|\'|\"])looks correct for me : it a group which consist of one character ( or , or). back tick quote is used for multiline strings ( I suppose). If you have a short string which is one line then ( I think ) you may use
"or
'` .
But I don't actually know exactly. This is just a modification of the existing pattern/logic.
At least it works....
Ah right, we use the () result. So no removing that. But the [\\`|\'|\"]
will match exactly one `, ', ", or | since the | does not have special meaning inside of [ and ].
So I guess someone could break stuff with
return magicTemplateVariable || html`custom template here`;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov and @ujoni)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, ujoni (Joni) wrote…
Ah right, we use the () result. So no removing that. But the
[\\`|\'|\"]
will match exactly one `, ', ", or | since the | does not have special meaning inside of [ and ].So I guess someone could break stuff with
return magicTemplateVariable || html`custom template here`;
Aaaaah.
Alright....
May be you are right.
I have to check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @denis-anisimov)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, denis-anisimov (Denis) wrote…
Aaaaah.
Alright....
May be you are right.
I have to check it.
Though, the above would not actually work in any case since the regex only accepts white space between return
and html
.
Well, anyways, I think the |
is not needed inside the square brackets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissed @vaadin-bot from 2 discussions.
Reviewable status: 3 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @ujoni)
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 88 at r1 (raw file):
Previously, ujoni (Joni) wrote…
Though, the above would not actually work in any case since the regex only accepts white space between
return
andhtml
.
Well, anyways, I think the|
is not needed inside the square brackets.
Done.
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java, line 201 at r1 (raw file):
Previously, ujoni (Joni) wrote…
If the last bits with the
continue
s were replaced with something likeOptional<Element> template = domModule.map(module -> { JsoupUtils.removeCommentsRecursively(domModule.get()); Elements templates = domModule.get() .getElementsByTag(TEMPLATE_TAG_NAME); return !templates.isEmpty() ? templates.get(0) : null; }); if (template.isPresent()) { return template.get(); }this could be a normal
else if
branch without thewhile
and doublecontinue
s
I've extracted the code into a separate method.
May be it can be simplified a bit but I don't see how I can get rid of while
without making another assumption.
There is a test which contain two dom-module
s assignments.
One dom-module
is empty ( kind of invalid , doesn't contain any template) and another
is a valid one.
It's not possible to choose the correct dom-module
without while
.
flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/JsoupUtils.java, line 73 at r1 (raw file):
Previously, ujoni (Joni) wrote…
new line missing
Done.
flow-server/src/test/resources/META-INF/VAADIN/config/no-html-template.json, line 13 at r1 (raw file):
Previously, ujoni (Joni) wrote…
Missing new line.
Some of the indents are formatted with tabs while others are spaces.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 3 files at r2.
Reviewable status: complete! all discussions resolved, 1 of 1 LGTMs obtained (waiting on @ujoni)
"Found Polymer 2 style insertion as a Polymer 3 template content {}", | ||
group); | ||
|
||
templateDocument = Jsoup.parse(group); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.forEach(template::appendChild); | ||
|
||
return template; | ||
} | ||
|
||
private static Element tryParsePolymer2(Document templateDocument, | ||
Matcher noTemplateMatcher) { | ||
while (noTemplateMatcher.find() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissed @vaadin-bot from 2 discussions.
Reviewable status: complete! all discussions resolved, 1 of 1 LGTMs obtained (waiting on @ujoni)
Cherry-picked to |
Fixes #6116
This change is