Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rnyell committed Nov 15, 2024
1 parent e70684f commit bbfd995
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-contains",
"version": "0.1.0",
"version": "0.1.1",
"description": "A PostCSS plugin to styles selectors based on specific declaration or property.",
"keywords": [
"css",
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ div {

```css
@contains overrides (display: grid) {
/* this looses the conflict to the below contains despite including `overrides`; as mentioned, `overrides` only comes to play when there is a conflict between @contains and selectors styles, not when two `@contains` are duplicated. */
/* this looses the conflict to the below contains despite including `overrides`;
as mentioned, `overrides` only comes to play when there is a conflict between @contains and selectors styles, not when two `@contains` are duplicated. */
padding: 1rem;
color: red;
}
Expand Down
38 changes: 19 additions & 19 deletions src/contains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const STORE: Store = new Set();

class Pairs {
#duplication: Duplication = "merge";
properties: string[] = [];
buckets: Bucket[] = [];
#properties: string[] = [];
#buckets: Bucket[] = [];
static indices: number[] = []; // holds the indices of matched properties temply
static duplicatedIndex: number | null; // holde duplicated index temply

Expand All @@ -52,27 +52,27 @@ class Pairs {
}

add(property: string, bucket: Bucket) {
const isDuplicated = this.isDuplicated(property, bucket);
const isDuplicated = this.#isDuplicated(property, bucket);

if (isDuplicated) {
this.resolve(bucket);
this.#resolve(bucket);
return;
}

this.properties.push(property);
this.buckets.push(bucket);
this.#properties.push(property);
this.#buckets.push(bucket);
STORE.add({ property, bucket });
}

isDuplicated(property: string, bucket: Bucket) {
this.properties.forEach((p, i) => {
#isDuplicated(property: string, bucket: Bucket) {
this.#properties.forEach((p, i) => {
if (p === property) {
Pairs.indices.push(i);
}
});

for (const index of Pairs.indices) {
if (this.buckets[index]?.value === bucket.value) {
if (this.#buckets[index]?.value === bucket.value) {
Pairs.duplicatedIndex = index;
return true;
}
Expand All @@ -81,8 +81,8 @@ class Pairs {
return false;
}

resolve(bucket: Bucket) {
let oldBucket = this.buckets[Pairs.duplicatedIndex!]; //!
#resolve(bucket: Bucket) {
let oldBucket = this.#buckets[Pairs.duplicatedIndex!]; //!
let oldDecls = oldBucket?.declarations;
let newDecls = bucket.declarations;

Expand All @@ -102,8 +102,8 @@ class Pairs {
}

reset() {
this.properties = [];
this.buckets = [];
this.#properties = [];
this.#buckets = [];
}
}

Expand All @@ -117,18 +117,18 @@ class Singles {
}

add(property: string, bucket: Bucket) {
const isDuplicated = this.isDuplicated(property);
const isDuplicated = this.#isDuplicated(property);

if (isDuplicated) {
this.resolve(bucket);
this.#resolve(bucket);
return;
}

this.#piles.set(property, bucket);
STORE.add({ property, bucket });
}

isDuplicated(property: string) {
#isDuplicated(property: string) {
if (this.#piles.has(property)) {
Singles.duplicatedProperty = property;
return true;
Expand All @@ -137,7 +137,7 @@ class Singles {
}
}

resolve(bucket: Bucket) {
#resolve(bucket: Bucket) {
const property = Singles.duplicatedProperty;

if (property) {
Expand Down Expand Up @@ -269,7 +269,7 @@ export default class Contains {
}

// 2) check each rule to find matches property/declaration
find() {
#find() {
let found: boolean | undefined;

this.#container!.each((child) => {
Expand Down Expand Up @@ -330,7 +330,7 @@ export default class Contains {
}

process() {
const found = this.find();
const found = this.#find();

if (found) {
this.#container?.each((child) => {
Expand Down

0 comments on commit bbfd995

Please sign in to comment.