You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
961 B
54 lines
961 B
'use strict'; |
|
|
|
/** @typedef {import('postcss').Rule} Rule */ |
|
/** @typedef {import('postcss').AtRule} AtRule */ |
|
|
|
/** |
|
* @param {Rule | AtRule} statement |
|
* @param {{ |
|
* noRawBefore?: boolean |
|
* }} options |
|
* |
|
* @returns {string} |
|
*/ |
|
module.exports = function (statement, options = {}) { |
|
let result = ''; |
|
/** @type {Rule | undefined} */ |
|
let rule; /*?: postcss$rule*/ |
|
/** @type {AtRule | undefined} */ |
|
let atRule; /*?: postcss$atRule*/ |
|
|
|
if (statement.type === 'rule') { |
|
rule = statement; |
|
} |
|
|
|
if (statement.type === 'atrule') { |
|
atRule = statement; |
|
} |
|
|
|
if (!rule && !atRule) { |
|
return result; |
|
} |
|
|
|
const before = statement.raws.before || ''; |
|
|
|
if (!options.noRawBefore) { |
|
result += before; |
|
} |
|
|
|
if (rule) { |
|
result += rule.selector; |
|
} |
|
|
|
if (atRule) { |
|
result += `@${atRule.name}${atRule.raws.afterName || ''}${atRule.params}`; |
|
} |
|
|
|
const between = statement.raws.between; |
|
|
|
if (between !== undefined) { |
|
result += between; |
|
} |
|
|
|
return result; |
|
};
|
|
|