From 9c598b184657be59e718fec6d6df8f76e0443e40 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Thu, 14 Sep 2017 14:04:04 +0200 Subject: [PATCH] Adjust quotes in some more cases of `@import` in CSS (#2818) Fixes #2817. --- src/clean-ast.js | 2 ++ src/printer-postcss.js | 4 +-- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 28 +++++++++++++++++++ tests/css_quotes/quotes.css | 7 +++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/clean-ast.js b/src/clean-ast.js index 489c7696..eeecf92d 100644 --- a/src/clean-ast.js +++ b/src/clean-ast.js @@ -102,8 +102,10 @@ function massageAST(ast, parent) { if ( (ast.type === "media-feature" || + ast.type === "media-keyword" || ast.type === "media-type" || ast.type === "media-unknown" || + ast.type === "media-url" || ast.type === "media-value" || ast.type === "selector-root-invalid" || ast.type === "selector-attribute" || diff --git a/src/printer-postcss.js b/src/printer-postcss.js index f2b2d695..ffb712db 100644 --- a/src/printer-postcss.js +++ b/src/printer-postcss.js @@ -194,10 +194,10 @@ function genericPrint(path, options, print) { return adjustNumbers(adjustStrings(n.value, options)); } case "media-keyword": { - return n.value; + return adjustStrings(n.value, options); } case "media-url": { - return n.value; + return adjustStrings(n.value, options); } case "media-unknown": { return adjustStrings(n.value, options); diff --git a/tests/css_import/__snapshots__/jsfmt.spec.js.snap b/tests/css_import/__snapshots__/jsfmt.spec.js.snap index 70892396..a349f949 100644 --- a/tests/css_import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/css_import/__snapshots__/jsfmt.spec.js.snap @@ -40,7 +40,7 @@ exports[`url.css 1`] = ` @import url('foo'); $dir: 'fonts'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@import url('foo'); +@import url("foo"); $dir: "fonts"; `; diff --git a/tests/css_quotes/__snapshots__/jsfmt.spec.js.snap b/tests/css_quotes/__snapshots__/jsfmt.spec.js.snap index e6149b54..c648791d 100644 --- a/tests/css_quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/css_quotes/__snapshots__/jsfmt.spec.js.snap @@ -76,6 +76,13 @@ exports[`quotes.css 1`] = ` } @import "file.css"; +@import 'file.css'; + +@import url("foo.css"); +@import url('foo.css'); + +@import "foo.css" screen and (orientation: landscape); +@import 'foo.css' screen and (orientation: landscape); @foo "one"; @foo 'one'; @@ -162,6 +169,13 @@ one 'two' three {} } @import "file.css"; +@import "file.css"; + +@import url("foo.css"); +@import url("foo.css"); + +@import "foo.css" screen and (orientation: landscape); +@import "foo.css" screen and (orientation: landscape); @foo "one"; @foo "one"; @@ -253,6 +267,13 @@ exports[`quotes.css 2`] = ` } @import "file.css"; +@import 'file.css'; + +@import url("foo.css"); +@import url('foo.css'); + +@import "foo.css" screen and (orientation: landscape); +@import 'foo.css' screen and (orientation: landscape); @foo "one"; @foo 'one'; @@ -339,6 +360,13 @@ one 'two' three {} } @import 'file.css'; +@import 'file.css'; + +@import url('foo.css'); +@import url('foo.css'); + +@import 'foo.css' screen and (orientation: landscape); +@import 'foo.css' screen and (orientation: landscape); @foo 'one'; @foo 'one'; diff --git a/tests/css_quotes/quotes.css b/tests/css_quotes/quotes.css index bef61658..2313eb12 100644 --- a/tests/css_quotes/quotes.css +++ b/tests/css_quotes/quotes.css @@ -73,6 +73,13 @@ } @import "file.css"; +@import 'file.css'; + +@import url("foo.css"); +@import url('foo.css'); + +@import "foo.css" screen and (orientation: landscape); +@import 'foo.css' screen and (orientation: landscape); @foo "one"; @foo 'one';