diff --git a/lib/core_dom/css_shim.dart b/lib/core_dom/css_shim.dart index ca3adf2d9..8f5d5536d 100644 --- a/lib/core_dom/css_shim.dart +++ b/lib/core_dom/css_shim.dart @@ -52,6 +52,10 @@ String shimCssText(String css, String tag) => class _CssShim { static final List SELECTOR_SPLITS = const [' ', '>', '+', '~']; + static final RegExp COMMENTS = new RegExp( + // Taken from http://www.w3.org/TR/CSS2/grammar.html#scanner. + r"\/\*[^*]*\*+([^/*][^*]*\*+)*\/"); + static final RegExp CONTENT = new RegExp( r"[^}]*" r"content:\s*" @@ -92,11 +96,14 @@ class _CssShim { : tag = tag, attr = "[$tag]"; String shimCssText(String css) { - final preprocessed = convertColonHost(css); + final preprocessed = convertColonHost(stripComments(css)); final rules = cssToRules(preprocessed); return scopeRules(rules); } + String stripComments(String css) => + css.replaceAll(COMMENTS, ""); + String convertColonHost(String css) { css = css.replaceAll(":host", HOST_TOKEN); diff --git a/test/core_dom/css_shim_spec.dart b/test/core_dom/css_shim_spec.dart index db73a76fc..6a675520c 100644 --- a/test/core_dom/css_shim_spec.dart +++ b/test/core_dom/css_shim_spec.dart @@ -116,5 +116,10 @@ main() { var css = s("polyfill-non-strict {} x /deep/ y {}", "a"); expect(css).toEqual('a x y {}'); }); + + it("should handle comments", () { + var css = s("/*a*/ polyfill-non-strict {} x /deep/ y {}", "a"); + expect(css).toEqual('a x y {}'); + }); }); }