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

Rename ambiguously named variables #392

Merged
merged 3 commits into from
Dec 19, 2023
Merged
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
30 changes: 14 additions & 16 deletions dev/generate-css-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,27 @@ export function formatRulesJson(rules) {
const indent3 = indent1.repeat(3);
let result = '';
result += '[';
let index1 = 0;
let ruleIndex = 0;
for (const {selectors, styles} of rules) {
if (index1 > 0) { result += ','; }
if (ruleIndex > 0) { result += ','; }
result += `\n${indent1}{\n${indent2}"selectors": `;
if (selectors.length === 1) {
result += `[${JSON.stringify(selectors[0], null, 4)}]`;
} else {
result += JSON.stringify(selectors, null, 4).replace(/\n/g, '\n' + indent2);
}
result += `,\n${indent2}"styles": [`;
let index2 = 0;
let styleIndex = 0;
for (const [key, value] of styles) {
if (index2 > 0) { result += ','; }
if (styleIndex > 0) { result += ','; }
result += `\n${indent3}[${JSON.stringify(key)}, ${JSON.stringify(value)}]`;
++index2;
++styleIndex;
}
if (index2 > 0) { result += `\n${indent2}`; }
if (styleIndex > 0) { result += `\n${indent2}`; }
result += `]\n${indent1}}`;
++index1;
++ruleIndex;
}
if (index1 > 0) { result += '\n'; }
if (ruleIndex > 0) { result += '\n'; }
result += ']';
return result;
}
Expand All @@ -130,10 +130,10 @@ export function formatRulesJson(rules) {
* @throws {Error}
*/
export function generateRules(cssFilePath, overridesCssFilePath) {
const content1 = fs.readFileSync(cssFilePath, {encoding: 'utf8'});
const content2 = fs.readFileSync(overridesCssFilePath, {encoding: 'utf8'});
const stylesheet1 = /** @type {css.StyleRules} */ (css.parse(content1, {}).stylesheet);
const stylesheet2 = /** @type {css.StyleRules} */ (css.parse(content2, {}).stylesheet);
const cssFileContent = fs.readFileSync(cssFilePath, {encoding: 'utf8'});
const overridesCssFileContent = fs.readFileSync(overridesCssFilePath, {encoding: 'utf8'});
const defaultStylesheet = /** @type {css.StyleRules} */ (css.parse(cssFileContent, {}).stylesheet);
const overridesStylesheet = /** @type {css.StyleRules} */ (css.parse(overridesCssFileContent, {}).stylesheet);

const removePropertyPattern = /^remove-property\s+([\w\W]+)$/;
const removeRulePattern = /^remove-rule$/;
Expand All @@ -142,8 +142,7 @@ export function generateRules(cssFilePath, overridesCssFilePath) {
/** @type {import('css-style-applier').RawStyleData} */
const rules = [];

// Default stylesheet
for (const rule of stylesheet1.rules) {
for (const rule of defaultStylesheet.rules) {
if (rule.type !== 'rule') { continue; }
const {selectors, declarations} = /** @type {css.Rule} */ (rule);
if (typeof selectors === 'undefined') { continue; }
Expand All @@ -162,8 +161,7 @@ export function generateRules(cssFilePath, overridesCssFilePath) {
}
}

// Overrides
for (const rule of stylesheet2.rules) {
for (const rule of overridesStylesheet.rules) {
if (rule.type !== 'rule') { continue; }
const {selectors, declarations} = /** @type {css.Rule} */ (rule);
if (typeof selectors === 'undefined' || typeof declarations === 'undefined') { continue; }
Expand Down