Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"remark-footnotes": "2.0.0",
"remark-math": "3.0.1",
"remark-parse": "8.0.3",
"sass-parser": "0.4.21",
"sdbm": "2.0.0",
"search-closest": "1.1.0",
"smol-toml": "1.3.4",
Expand Down
36 changes: 16 additions & 20 deletions src/language-css/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function clean(original, cloned, parent) {
}

if (
original.type === "css-comment" &&
parent.type === "css-root" &&
original.type === "comment" &&
parent.type === "root" &&
parent.nodes.length > 0
) {
// --insert-pragma
Expand All @@ -41,15 +41,11 @@ function clean(original, cloned, parent) {
}

// Last comment is not parsed, when omitting semicolon, #8675
if (parent.type === "css-root" && parent.nodes.at(-1) === original) {
if (parent.type === "root" && parent.nodes.at(-1) === original) {
return null;
}
}

if (original.type === "value-root") {
delete cloned.text;
}

if (
original.type === "media-query" ||
original.type === "media-query-list" ||
Expand All @@ -58,7 +54,7 @@ function clean(original, cloned, parent) {
delete cloned.value;
}

if (original.type === "css-rule") {
if (original.type === "rule") {
delete cloned.params;
}

Expand All @@ -73,7 +69,7 @@ function clean(original, cloned, parent) {
original.type === "selector-string" ||
original.type === "selector-class" ||
original.type === "selector-combinator" ||
original.type === "value-string") &&
original.type === "string") &&
original.value
) {
cloned.value = cleanCSSStrings(original.value);
Expand All @@ -99,16 +95,16 @@ function clean(original, cloned, parent) {
) {
cloned.value = cloned.value.toLowerCase();
}
if (original.type === "css-decl") {
if (original.type === "decl") {
cloned.prop = original.prop.toLowerCase();
}
if (original.type === "css-atrule" || original.type === "css-import") {
if (original.type === "atrule" || original.type === "import") {
cloned.name = original.name.toLowerCase();
}
if (original.type === "value-number") {
if (original.type === "number") {
cloned.unit = original.unit.toLowerCase();
}
if (original.type === "value-unknown") {
if (original.type === "unknown") {
cloned.value = cloned.value.replaceAll(/;$/gu, "");
}

Expand All @@ -128,7 +124,7 @@ function clean(original, cloned, parent) {
if (
(original.type === "media-value" ||
original.type === "media-type" ||
original.type === "value-number" ||
original.type === "number" ||
original.type === "selector-root-invalid" ||
original.type === "selector-class" ||
original.type === "selector-combinator" ||
Expand All @@ -153,12 +149,12 @@ function clean(original, cloned, parent) {
}

// Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
if (
original.type === "css-atrule" &&
original.name.toLowerCase() === "supports"
) {
delete cloned.value;
}
// if (
// original.type === "css-atrule" &&
// original.name.toLowerCase() === "supports"
// ) {
// delete cloned.value;
// }

// Workaround for SCSS nested properties
if (original.type === "selector-unknown") {
Expand Down
47 changes: 2 additions & 45 deletions src/language-css/loc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function calculateLocStart(node, text) {
}

function calculateLocEnd(node, text) {
if (node.type === "css-comment" && node.inline) {
if (node.type === "comment" && node.sassType === "sass-comment") {
return skipEverythingButNewLine(text, node.source.startOffset);
}

Expand Down Expand Up @@ -72,51 +72,8 @@ function calculateLoc(node, text) {
continue;
}

if (child.type === "value-root" || child.type === "value-unknown") {
calculateValueNodeLoc(
child,
getValueRootOffset(node),
child.text || child.value,
);
} else {
calculateLoc(child, text);
}
}
}

function calculateValueNodeLoc(node, rootOffset, text) {
if (node.source) {
node.source.startOffset = calculateLocStart(node, text) + rootOffset;
node.source.endOffset = calculateLocEnd(node, text) + rootOffset;
}

for (const key in node) {
const child = node[key];

if (key === "source" || !child || typeof child !== "object") {
continue;
}

calculateValueNodeLoc(child, rootOffset, text);
}
}

function getValueRootOffset(node) {
let result = node.source.startOffset;
if (typeof node.prop === "string") {
result += node.prop.length;
calculateLoc(child, text);
}

if (node.type === "css-atrule" && typeof node.name === "string") {
result +=
1 + node.name.length + node.raws.afterName.match(/^\s*:?\s*/u)[0].length;
}

if (node.type !== "css-atrule" && typeof node.raws?.between === "string") {
result += node.raws.between.length;
}

return result;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/language-css/parse/parse-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function parseValueNode(valueNode, options) {
parenGroupStack.pop();
parenGroup = parenGroupStack.at(-1);
} else if (node.type === "comma") {
// Trialing comma
// Trailing comma
if (
i === nodes.length - 3 &&
nodes[i + 1].type === "comment" &&
Expand Down
Loading