Skip to content

Commit

Permalink
Fix wildcard syntax in @forward (#11482) (#11487)
Browse files Browse the repository at this point in the history
* Fix wildcard syntax in `@forward` (#11482)

* Add additional tests

* Apply suggestions from code review

Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>

Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
  • Loading branch information
niksy and thorn0 committed Sep 16, 2021
1 parent aa63269 commit 59b5eb4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
13 changes: 13 additions & 0 deletions changelog_unreleased/scss/11487.md
@@ -0,0 +1,13 @@
#### Fix wildcard syntax in `@forward` (#11482) (#11487 by @niksy)

<!-- prettier-ignore -->
```scss
// Input
@forward "library" as btn-*;

// Prettier stable
@forward "library" as btn- *;

// Prettier main
@forward "library" as btn-*;
```
13 changes: 13 additions & 0 deletions src/language-css/printer-postcss.js
Expand Up @@ -550,6 +550,19 @@ function genericPrint(path, options, print) {
continue;
}

// Ignore SCSS @forward wildcard suffix
if (
insideAtRuleNode(path, "forward") &&
iNode.type === "value-word" &&
iNode.value &&
iPrevNode.type === "value-word" &&
iPrevNode.value === "as" &&
iNextNode.type === "value-operator" &&
iNextNode.value === "*"
) {
continue;
}

// Ignore after latest node (i.e. before semicolon)
if (!iNextNode) {
continue;
Expand Down
12 changes: 10 additions & 2 deletions tests/format/scss/quotes/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -29,6 +29,8 @@ singleQuote: true
@forward "library" as btn-*;
@forward "library" as btn*;
=====================================output=====================================
@use 'library';
Expand All @@ -47,7 +49,9 @@ singleQuote: true
@forward 'library' hide gradient;
@forward 'library' as btn- *;
@forward 'library' as btn-*;
@forward 'library' as btn*;
================================================================================
`;
Expand Down Expand Up @@ -80,6 +84,8 @@ printWidth: 80
@forward "library" as btn-*;
@forward "library" as btn*;
=====================================output=====================================
@use "library";
Expand All @@ -98,7 +104,9 @@ printWidth: 80
@forward "library" hide gradient;
@forward "library" as btn- *;
@forward "library" as btn-*;
@forward "library" as btn*;
================================================================================
`;
2 changes: 2 additions & 0 deletions tests/format/scss/quotes/quotes.scss
Expand Up @@ -19,3 +19,5 @@
@forward "library" hide gradient;

@forward "library" as btn-*;

@forward "library" as btn*;

0 comments on commit 59b5eb4

Please sign in to comment.