Skip to content

Commit

Permalink
fix: allow spaces between html function call and back tick (#10523)
Browse files Browse the repository at this point in the history
fixes #8881
  • Loading branch information
Denis committed Mar 31, 2021
1 parent 8c299c8 commit ee7aa70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Expand Up @@ -15,12 +15,6 @@
*/
package com.vaadin.flow.component.polymertemplate;

import static com.vaadin.flow.server.frontend.FrontendUtils.DEAULT_FLOW_RESOURCES_FOLDER;
import static com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME;
import static elemental.json.JsonType.ARRAY;
import static elemental.json.JsonType.OBJECT;
import static elemental.json.JsonType.STRING;

import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -39,6 +33,12 @@
import elemental.json.JsonObject;
import elemental.json.JsonType;

import static com.vaadin.flow.server.frontend.FrontendUtils.DEAULT_FLOW_RESOURCES_FOLDER;
import static com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME;
import static elemental.json.JsonType.ARRAY;
import static elemental.json.JsonType.OBJECT;
import static elemental.json.JsonType.STRING;

/**
* Parse statistics data provided by webpack.
*
Expand Down Expand Up @@ -90,7 +90,7 @@ public final class BundleParser {
* end character with <code>;}</code> e.g. <code>';}</code>
*/
private static final Pattern POLYMER_TEMPLATE_PATTERN = Pattern.compile(
"get[\\s]*template\\(\\)[\\s]*\\{[\\s]*return[\\s]*html([\\`\\'\\\"])([\\s\\S]*)\\1;[\\s]*\\}");
"get[\\s]*template\\(\\)[\\s]*\\{[\\s]*return[\\s]*html[\\s]*([\\`\\'\\\"])([\\s\\S]*)\\1;[\\s]*\\}");

private static final Pattern NO_TEMPLATE_PATTERN = Pattern.compile(
"innerHTML[\\s]*=[\\s]*([\\`\\'\\\"])([\\s]*<dom-module\\s+[\\s\\S]*)\\1;");
Expand Down
Expand Up @@ -12,6 +12,7 @@

import elemental.json.Json;
import elemental.json.JsonObject;

import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;

public class BundleParserTest {
Expand Down Expand Up @@ -93,4 +94,12 @@ public void parseTemplateElement_stringContentNotSeenAsComment() {
"nats://server:port", natsElement.attr("placeholder"));

}

@Test
public void parseTemplateElement_spacesBetweenHtmlAndTick() {
String source = "static get template() { return html `<div id='bar'></div>`;}";
Element element = BundleParser.parseTemplateElement("foo.js", source);

Assert.assertNotNull(element.getElementById("bar"));
}
}

0 comments on commit ee7aa70

Please sign in to comment.