Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Strips comments from css before applying css shim. #1738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/core_dom/css_shim.dart
Original file line number Diff line number Diff line change
@@ -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);

5 changes: 5 additions & 0 deletions test/core_dom/css_shim_spec.dart
Original file line number Diff line number Diff line change
@@ -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 {}');
});
});
}