From fbafa666d1a94056f74933f912466578d8e3ecf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Fri, 10 Sep 2021 08:52:37 +0200 Subject: [PATCH 1/3] Fix wildcard syntax in `@forward` (#11482) --- changelog_unreleased/scss/11487.md | 13 +++++++++++++ src/language-css/printer-postcss.js | 16 ++++++++++++++++ .../scss/quotes/__snapshots__/jsfmt.spec.js.snap | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 changelog_unreleased/scss/11487.md diff --git a/changelog_unreleased/scss/11487.md b/changelog_unreleased/scss/11487.md new file mode 100644 index 000000000000..f562cf488cc5 --- /dev/null +++ b/changelog_unreleased/scss/11487.md @@ -0,0 +1,13 @@ +#### Fix wildcard syntax in `@forward` (#11482) (#11487 by @niksy) + + +```scss +// Input +@forward "library" as btn-*; + +// Prettier stable +@forward "library" as btn- *; + +// Prettier main +@forward "library" as btn-*; +``` diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index c7ebe7e561f4..9accdd4e7087 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -550,6 +550,22 @@ function genericPrint(path, options, print) { continue; } + // Ignore SCSS @forward wildcard suffix + if ( + insideAtRuleNode(path, "forward") && + iNode.type === "value-word" && + iNode.value && + iNode.value.endsWith("-") && + iPrevNode.type === "value-word" && + iPrevNode.value && + iPrevNode.value === "as" && + iNextNode.type === "value-operator" && + iNextNode.value && + iNextNode.value === "*" + ) { + continue; + } + // Ignore after latest node (i.e. before semicolon) if (!iNextNode) { continue; diff --git a/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap index 042fdbb3bf79..4d368ad98852 100644 --- a/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap @@ -47,7 +47,7 @@ singleQuote: true @forward 'library' hide gradient; -@forward 'library' as btn- *; +@forward 'library' as btn-*; ================================================================================ `; @@ -98,7 +98,7 @@ printWidth: 80 @forward "library" hide gradient; -@forward "library" as btn- *; +@forward "library" as btn-*; ================================================================================ `; From 4e226bba43768935ef81124b8ba1245d7b0a4ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 13 Sep 2021 09:05:03 +0200 Subject: [PATCH 2/3] Add additional tests --- src/language-css/printer-postcss.js | 1 - tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap | 8 ++++++++ tests/format/scss/quotes/quotes.scss | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 9accdd4e7087..e2d90df32e07 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -555,7 +555,6 @@ function genericPrint(path, options, print) { insideAtRuleNode(path, "forward") && iNode.type === "value-word" && iNode.value && - iNode.value.endsWith("-") && iPrevNode.type === "value-word" && iPrevNode.value && iPrevNode.value === "as" && diff --git a/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap index 4d368ad98852..06419858dada 100644 --- a/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap @@ -29,6 +29,8 @@ singleQuote: true @forward "library" as btn-*; +@forward "library" as btn*; + =====================================output===================================== @use 'library'; @@ -49,6 +51,8 @@ singleQuote: true @forward 'library' as btn-*; +@forward 'library' as btn*; + ================================================================================ `; @@ -80,6 +84,8 @@ printWidth: 80 @forward "library" as btn-*; +@forward "library" as btn*; + =====================================output===================================== @use "library"; @@ -100,5 +106,7 @@ printWidth: 80 @forward "library" as btn-*; +@forward "library" as btn*; + ================================================================================ `; diff --git a/tests/format/scss/quotes/quotes.scss b/tests/format/scss/quotes/quotes.scss index 332074a453a5..20607380fbad 100644 --- a/tests/format/scss/quotes/quotes.scss +++ b/tests/format/scss/quotes/quotes.scss @@ -19,3 +19,5 @@ @forward "library" hide gradient; @forward "library" as btn-*; + +@forward "library" as btn*; From 3d042eb8d828819562c9db5f0760b1f75ee39911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 15 Sep 2021 15:52:57 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Georgii Dolzhykov --- src/language-css/printer-postcss.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index e2d90df32e07..0c326d6d26bd 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -556,10 +556,8 @@ function genericPrint(path, options, print) { iNode.type === "value-word" && iNode.value && iPrevNode.type === "value-word" && - iPrevNode.value && iPrevNode.value === "as" && iNextNode.type === "value-operator" && - iNextNode.value && iNextNode.value === "*" ) { continue;