From 9d8f4d341d583fe49ceae4bd193c552d7a7587f6 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 13 Aug 2017 14:04:59 -0400 Subject: [PATCH 1/2] preserve space before non-parenthesized media query expression - fixes #759 --- src/css/Stylesheet.ts | 3 ++- test/css/samples/media-query-word/expected.css | 1 + test/css/samples/media-query-word/input.html | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/css/samples/media-query-word/expected.css create mode 100644 test/css/samples/media-query-word/input.html diff --git a/src/css/Stylesheet.ts b/src/css/Stylesheet.ts index 5680ec4551..03f3d4ec06 100644 --- a/src/css/Stylesheet.ts +++ b/src/css/Stylesheet.ts @@ -144,7 +144,8 @@ class Atrule { minify(code: MagicString, cascade: boolean) { if (this.node.name === 'media') { - let c = this.node.start + 6; + const expressionChar = code.original[this.node.expression.start]; + let c = this.node.start + (expressionChar === '(' ? 6 : 7); if (this.node.expression.start > c) code.remove(c, this.node.expression.start); this.node.expression.children.forEach((query: Node) => { diff --git a/test/css/samples/media-query-word/expected.css b/test/css/samples/media-query-word/expected.css new file mode 100644 index 0000000000..5f15d2fdc0 --- /dev/null +++ b/test/css/samples/media-query-word/expected.css @@ -0,0 +1 @@ +@media only screen and (min-width: 400px){[svelte-xyz].large-screen,[svelte-xyz] .large-screen{display:block}} \ No newline at end of file diff --git a/test/css/samples/media-query-word/input.html b/test/css/samples/media-query-word/input.html new file mode 100644 index 0000000000..dcd42b5413 --- /dev/null +++ b/test/css/samples/media-query-word/input.html @@ -0,0 +1,9 @@ +
animated
+ + \ No newline at end of file From 1f7349c5bedc0d81640178c43b8d461671335f8f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 13 Aug 2017 14:07:19 -0400 Subject: [PATCH 2/2] simplify adapted example --- test/css/samples/media-query-word/expected.css | 2 +- test/css/samples/media-query-word/input.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/css/samples/media-query-word/expected.css b/test/css/samples/media-query-word/expected.css index 5f15d2fdc0..3975992f2a 100644 --- a/test/css/samples/media-query-word/expected.css +++ b/test/css/samples/media-query-word/expected.css @@ -1 +1 @@ -@media only screen and (min-width: 400px){[svelte-xyz].large-screen,[svelte-xyz] .large-screen{display:block}} \ No newline at end of file +@media only screen and (min-width: 400px){div[svelte-xyz],[svelte-xyz] div{color:red}} \ No newline at end of file diff --git a/test/css/samples/media-query-word/input.html b/test/css/samples/media-query-word/input.html index dcd42b5413..342b003b62 100644 --- a/test/css/samples/media-query-word/input.html +++ b/test/css/samples/media-query-word/input.html @@ -1,9 +1,9 @@ -
animated
+
hello
\ No newline at end of file