Workaround bug with comment ending in */ (#1810)

Reported in the original repo: https://github.com/postcss/postcss-scss/issues/64
master
Christopher Chedeau 2017-05-29 13:05:20 -07:00 committed by GitHub
parent 59e4e83355
commit 2ab3d6d6ac
3 changed files with 22 additions and 3 deletions

View File

@ -2537,13 +2537,14 @@ function genericPrintNoParens(path, options, print, args) {
return n.raws.content;
}
const text = options.originalText.slice(util.locStart(n), util.locEnd(n));
const rawText = n.raws.text || n.text;
// Workaround a bug where the location is off.
// https://github.com/postcss/postcss-scss/issues/63
if (text.indexOf(n.text) === -1) {
if (text.indexOf(rawText) === -1) {
if (n.raws.inline) {
return concat(["// ", n.text]);
return concat(["// ", rawText]);
}
return concat(["/* ", n.text, " */"]);
return concat(["/* ", rawText, " */"]);
}
return text;
}

View File

@ -82,3 +82,17 @@ exports[`selector.css 1`] = `
}
`;
exports[`trailing_star_slash.css 1`] = `
@media (max-width: 1) {}
a {
// element.style */
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@media (max-width: 1) {
}
a {
// element.style */
}
`;

View File

@ -0,0 +1,4 @@
@media (max-width: 1) {}
a {
// element.style */
}