Skip to content

Commit

Permalink
Fix less :extend format (#7984)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and thorn0 committed Apr 11, 2020
1 parent 5921497 commit e1a6a7a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
30 changes: 30 additions & 0 deletions changelog_unreleased/less/pr-7984.md
@@ -0,0 +1,30 @@
#### Fix `:extend` format ([#7984](https://github.com/prettier/prettier/pull/7984) by [@fisker](https://github.com/fisker))

<!-- prettier-ignore -->
```less
// Input
.class {
&:extend(.some-class .some-other-class .some-very-loooooooooooooong-class all);
}

// Prettier stable
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}

// Prettier stable (Second format)
.class {
&: extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}

// Prettier master
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}
```
10 changes: 10 additions & 0 deletions src/language-css/parser-postcss.js
Expand Up @@ -375,6 +375,16 @@ function parseNestedCSS(node, options) {
node.value = parseValue(value);
}

// extend is missing
if (
isLessParser(options) &&
node.type === "css-decl" &&
!node.extend &&
value.startsWith("extend(")
) {
node.extend = node.raws.between === ":";
}

if (node.type === "css-atrule") {
if (isLessParser(options)) {
// mixin
Expand Down
31 changes: 31 additions & 0 deletions tests/css_less/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -1766,6 +1766,19 @@ label {
// should not parse as custom-selector
@custom-selector :--icon #id;
// extend #7977
.class {
&:extend(.some-class .some-other-class .some-very-loooooooooooooong-class all);
}
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}
.class {
&:extend(.some-class .some-other-class .some-very-loooooooooooooong-class .some-very-loooooooooooooong-class all);
}
=====================================output=====================================
@nice-blue: #5b83ad;
@light-blue: @nice-blue + #111;
Expand Down Expand Up @@ -3378,6 +3391,24 @@ label {
// should not parse as custom-selector
@custom-selector: --icon #id;
// extend #7977
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class
.some-very-loooooooooooooong-class all
);
}
================================================================================
`;
Expand Down
13 changes: 13 additions & 0 deletions tests/css_less/less.less
Expand Up @@ -1674,3 +1674,16 @@ label {

// should not parse as custom-selector
@custom-selector :--icon #id;

// extend #7977
.class {
&:extend(.some-class .some-other-class .some-very-loooooooooooooong-class all);
}
.class {
&:extend(
.some-class .some-other-class .some-very-loooooooooooooong-class all
);
}
.class {
&:extend(.some-class .some-other-class .some-very-loooooooooooooong-class .some-very-loooooooooooooong-class all);
}

0 comments on commit e1a6a7a

Please sign in to comment.