Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix less :extend format #7984

Merged
merged 6 commits into from Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}