Skip to content

Commit

Permalink
Revert "Update postcss to v8 (prettier#9209)"
Browse files Browse the repository at this point in the history
This reverts commit b77da32.
  • Loading branch information
sosukesuzuki committed Oct 26, 2020
1 parent bc9db85 commit 5263999
Show file tree
Hide file tree
Showing 24 changed files with 37 additions and 388 deletions.
42 changes: 0 additions & 42 deletions changelog_unreleased/css/pr-9209.md

This file was deleted.

11 changes: 2 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ if (isProduction) {
presets: [
[
"@babel/env",
{
targets: { node: "current" },
exclude: [
"transform-async-to-generator",
"transform-classes",
"proposal-async-generator-functions",
"transform-regenerator",
],
},
// Workaround for https://github.com/babel/babel/issues/11994
{ loose: true },
],
],
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"outdent": "0.7.1",
"parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
"please-upgrade-node": "3.2.0",
"postcss": "8.1.3",
"postcss": "7.0.32",
"postcss-less": "4.0.0",
"postcss-media-query-parser": "0.2.3",
"postcss-scss": "3.0.2",
Expand Down
59 changes: 0 additions & 59 deletions src/language-css/parser-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,64 +300,6 @@ function parseNestedCSS(node, options) {
node.raws = {};
}

// Custom properties looks like declarations
if (
node.type === "css-decl" &&
typeof node.prop === "string" &&
node.prop.startsWith("--") &&
typeof node.value === "string" &&
node.value.startsWith("{")
) {
let rules;
if (node.value.endsWith("}")) {
const textBefore = options.originalText.slice(
0,
node.source.start.offset
);
const nodeText =
"a".repeat(node.prop.length) +
options.originalText.slice(
node.source.start.offset + node.prop.length,
node.source.end.offset + 1
);
const fakeContent = textBefore.replace(/[^\n]/g, " ") + nodeText;
let parse;
if (options.parser === "scss") {
parse = parseScss;
} else if (options.parser === "less") {
parse = parseLess;
} else {
parse = parseCss;
}
let ast;
try {
ast = parse(fakeContent, [], { ...options });
} catch (_) {
// noop
}
if (
ast &&
ast.nodes &&
ast.nodes.length === 1 &&
ast.nodes[0].type === "css-rule"
) {
rules = ast.nodes[0].nodes;
}
}
if (rules) {
node.value = {
type: "css-rule",
nodes: rules,
};
} else {
node.value = {
type: "value-unknown",
value: node.raws.value.raw,
};
}
return node;
}

let selector = "";

if (typeof node.selector === "string") {
Expand Down Expand Up @@ -657,7 +599,6 @@ function parseWithParser(parse, text, options) {
throw createError(`${name}: ${reason}`, { start: { line, column } });
}

options.originalText = text;
result = parseNestedCSS(addTypePrefix(result, "css-"), options);

calculateLoc(result, text);
Expand Down
8 changes: 2 additions & 6 deletions src/language-css/printer-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ function genericPrint(path, options, print) {
node.selector.type === "selector-unknown" &&
lastLineHasInlineComment(node.selector.value)
? line
: node.selector
? " "
: "",
: " ",
"{",
node.nodes.length > 0
? indent(
Expand All @@ -143,8 +141,6 @@ function genericPrint(path, options, print) {
const { between: rawBetween } = node.raws;
const trimmedBetween = rawBetween.trim();
const isColon = trimmedBetween === ":";
const isValueAllSpace =
typeof node.value === "string" && /^ *$/.test(node.value);

let value = hasComposesNode(node)
? removeLines(path.call(print, "value"))
Expand All @@ -159,7 +155,7 @@ function genericPrint(path, options, print) {
insideICSSRuleNode(path) ? node.prop : maybeToLowerCase(node.prop),
trimmedBetween.startsWith("//") ? " " : "",
trimmedBetween,
node.extend || isValueAllSpace ? "" : " ",
node.extend ? "" : " ",
options.parser === "less" && node.extend && node.selector
? concat(["extend(", path.call(print, "selector"), ")"])
: "",
Expand Down
42 changes: 2 additions & 40 deletions tests/css/comments/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -304,44 +304,6 @@ printWidth: 80
================================================================================
`;

exports[`custom-properties.css format 1`] = `
====================================options=====================================
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
/* comment 1 */
:root {
/* comment 2 */
--prop : {
/* comment 3 */
color/* comment 4 */: /* comment 5 */#fff/* comment 6 */;/* comment 7 */
/* comment 8 */
font-size: 12px;
/* comment 9 */
};
/* comment 10 */
}
/* comment 11 */
=====================================output=====================================
/* comment 1 */
:root {
/* comment 2 */
--prop: {
/* comment 3 */
color/* comment 4 */: /* comment 5 */ #fff /* comment 6 */; /* comment 7 */
/* comment 8 */
font-size: 12px;
/* comment 9 */
};
/* comment 10 */
}
/* comment 11 */
================================================================================
`;

exports[`declaration.css format 1`] = `
====================================options=====================================
parsers: ["css"]
Expand Down Expand Up @@ -925,11 +887,11 @@ article /* comment 168 */ :--heading /* comment 169 */ + /* comment 170 */ p /*
/* custom properties set & @apply rule */
:root {
/* comments 192 */
--centered/* comments 193 */ : /* comments 194 */ {
--centered /* comments 193 */ : /* comments 194 */ {
display: flex;
align-items: center;
justify-content: center;
};
}
}
================================================================================
Expand Down
13 changes: 0 additions & 13 deletions tests/css/comments/custom-properties.css

This file was deleted.

71 changes: 0 additions & 71 deletions tests/css/postcss-8-improment/__snapshots__/jsfmt.spec.js.snap

This file was deleted.

6 changes: 0 additions & 6 deletions tests/css/postcss-8-improment/empty-props.css

This file was deleted.

1 change: 0 additions & 1 deletion tests/css/postcss-8-improment/jsfmt.spec.js

This file was deleted.

17 changes: 0 additions & 17 deletions tests/css/postcss-8-improment/test.css

This file was deleted.

0 comments on commit 5263999

Please sign in to comment.