From 61497b2616e249cb8821a7587f071eb4cf412333 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 6 Feb 2024 16:28:43 -0500 Subject: [PATCH] prettier --- .../compiler/phases/2-analyze/css/Selector.js | 27 ++++++++++++------- .../phases/2-analyze/css/Stylesheet.js | 23 +++++++++------- packages/svelte/src/compiler/types/css.d.ts | 2 +- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js b/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js index 2768e50532..a4c4262a96 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js +++ b/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js @@ -104,8 +104,8 @@ export default class Selector { // We don't make any changes to the invisible selectors // because they don't exist in reality in css nesting // and changing them would affect the nested rules parent rule selectors - if(selector.invisible) { - continue + if (selector.invisible) { + continue; } if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector') { @@ -129,7 +129,7 @@ export default class Selector { if (block.should_encapsulate) { encapsulate_block( block, - index === this.blocks.filter(block => !block.invisible).length - 1 + index === this.blocks.filter((block) => !block.invisible).length - 1 ? attr.repeat(amount_class_specificity_to_increase + 1) : attr ); @@ -808,7 +808,7 @@ class Block { should_encapsulate; /** @type {boolean} */ - invisible + invisible; /** @param {import('#compiler').Css.Combinator | null} combinator */ constructor(combinator) { @@ -819,7 +819,7 @@ class Block { this.start = -1; this.end = -1; this.should_encapsulate = false; - this.invisible = false + this.invisible = false; } /** @param {import('#compiler').Css.SimpleSelector} selector */ @@ -845,7 +845,12 @@ class Block { } } -const InvisibleCombinator = { type: /** @type {"Combinator"} **/ ("Combinator"), name: ' ', start: -1, end: -1} +const InvisibleCombinator = { + type: /** @type {"Combinator"} **/ ('Combinator'), + name: ' ', + start: -1, + end: -1 +}; /** * Groups selectors by combinator into blocks @@ -867,11 +872,11 @@ function group_selectors(selector, parent_selector) { if (parent_selector) { const nested_rule_indices = selector.children .map((child, index) => (child.type === 'NestedSelector' ? index : -1)) - .filter(index => index !== -1); + .filter((index) => index !== -1); - const parent_children = parent_selector.node.children.map(child => ({ + const parent_children = parent_selector.node.children.map((child) => ({ ...child, - invisible: true, + invisible: true })); if (nested_rule_indices.length === 0) { @@ -884,7 +889,9 @@ function group_selectors(selector, parent_selector) { } else { // There's an & nesting selectors somewhere // so we delete it and insert invisible parent's children there - nested_rule_indices.forEach(nested_rule_index => selector.children.splice(nested_rule_index, 1, ...parent_children)); + nested_rule_indices.forEach((nested_rule_index) => + selector.children.splice(nested_rule_index, 1, ...parent_children) + ); } } diff --git a/packages/svelte/src/compiler/phases/2-analyze/css/Stylesheet.js b/packages/svelte/src/compiler/phases/2-analyze/css/Stylesheet.js index 45c3371190..597351f433 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/css/Stylesheet.js +++ b/packages/svelte/src/compiler/phases/2-analyze/css/Stylesheet.js @@ -88,17 +88,18 @@ export class Rule { * - .b .c */ if (parent && parent.node.type === 'Rule') { - this.selectors = /** @type {Rule} **/ (parent) - .selectors - .map(parent_selector => node.prelude.children.map((node) => new Selector(node, stylesheet, parent_selector))) - .flat() + this.selectors = /** @type {Rule} **/ (parent).selectors + .map((parent_selector) => + node.prelude.children.map((node) => new Selector(node, stylesheet, parent_selector)) + ) + .flat(); } else { this.selectors = node.prelude.children.map((node) => new Selector(node, stylesheet, null)); } this.nested_rules = node.block.children .filter((node) => node.type === 'Rule') - .map(node => new Rule(/** @type {import('#compiler').Css.Rule}*/ (node), stylesheet, this)); + .map((node) => new Rule(/** @type {import('#compiler').Css.Rule}*/ (node), stylesheet, this)); this.declarations = node.block.children .filter((node) => node.type === 'Declaration') .map((node) => new Declaration(/** @type {import('#compiler').Css.Declaration} */ (node))); @@ -122,7 +123,9 @@ export class Rule { // see them in devtools if (this.declarations.length === 0) return dev; - return [this.selectors.some((s) => s.used), this.nested_rules.some(r => r.is_used(dev))].some(Boolean); + return [this.selectors.some((s) => s.used), this.nested_rules.some((r) => r.is_used(dev))].some( + Boolean + ); } /** @@ -141,7 +144,9 @@ export class Rule { selector.transform(code, attr, max_amount_class_specificity_increased) ); this.declarations.forEach((declaration) => declaration.transform(code, keyframes)); - this.nested_rules.forEach((rule) => rule.transform(code, id, keyframes, max_amount_class_specificity_increased)); + this.nested_rules.forEach((rule) => + rule.transform(code, id, keyframes, max_amount_class_specificity_increased) + ); } /** @param {import('../../types.js').ComponentAnalysis} analysis */ @@ -430,7 +435,7 @@ export default class Stylesheet { const state = { /** @type {Atrule | undefined} */ - atrule: undefined, + atrule: undefined }; walk(/** @type {import('#compiler').Css.Node} */ (ast), state, { @@ -478,7 +483,7 @@ export default class Stylesheet { if (rule.nested_rules.length > 0) { // Skip nested rules as they are instantiated in the Rule constructor - return node + return node; } context.next(); } diff --git a/packages/svelte/src/compiler/types/css.d.ts b/packages/svelte/src/compiler/types/css.d.ts index 0aa905a448..2ca708fc7c 100644 --- a/packages/svelte/src/compiler/types/css.d.ts +++ b/packages/svelte/src/compiler/types/css.d.ts @@ -89,7 +89,7 @@ export interface Combinator extends BaseNode { export interface NestingSelector extends BaseNode { type: 'NestedSelector'; - name: "&"; + name: '&'; } export interface Block extends BaseNode {