rollup-plugin-react-scoped-css 1.0.0-alpha.0 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,33 +28,43 @@ function scopeCss(css, filename, hash) {
28
28
  return acc;
29
29
  }, []);
30
30
  selectorLists.map((selectorList) => {
31
- const results = (0, css_tree_1.findAll)(selectorList, (node) => node.type === "PseudoElementSelector" &&
32
- (node.name === "v-deep" || node.name === "deep"));
33
- if (results.length > 0) {
34
- results.map((node) => {
31
+ selectorList.children.forEach((selector) => {
32
+ if (selector.type === "Selector") {
35
33
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36
- //@ts-ignore: optimization hack, we need to override the object without changing the reference.
37
- node.children = undefined;
38
- node.loc = undefined;
39
- Object.assign(node, attributeSelector);
40
- });
41
- }
42
- else {
43
- selectorList.children.forEach((selector) => {
44
- if (selector.type === "Selector") {
45
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
46
- // @ts-ignore: Tail is not exposed via @types/css-tree but does exist.
47
- let item = selector.children.tail;
48
- while (item !== null &&
49
- (item?.data?.type === "PseudoClassSelector" ||
50
- item?.data?.type === "PseudoElementSelector" ||
51
- item?.data?.type === "Combinator")) {
52
- item = item.prev;
34
+ // @ts-ignore: Head is not exposed via @types/css-tree but does exist.
35
+ let item = selector.children.head;
36
+ let hasHitDeep = false;
37
+ while (item !== null) {
38
+ if (item?.next?.data?.type === "PseudoElementSelector" &&
39
+ (item?.next?.data?.name === "v-deep" ||
40
+ item?.next?.data?.name === "deep")) {
41
+ hasHitDeep = true;
42
+ item.next.children = undefined;
43
+ item.next.loc = undefined;
44
+ Object.assign(item.next.data, attributeSelector);
45
+ if (!item.next) {
46
+ break;
47
+ }
48
+ item = item?.next ?? null;
49
+ }
50
+ if (hasHitDeep) {
51
+ break;
52
+ }
53
+ if (item?.data?.type === "Combinator") {
54
+ item = item?.next ?? null;
55
+ continue;
53
56
  }
54
- selector.children.insertData(attributeSelector, item.next);
57
+ if ((item?.data?.type === "TypeSelector" ||
58
+ item?.data?.type === "ClassSelector") &&
59
+ item?.next?.data?.type === "ClassSelector") {
60
+ item = item?.next ?? null;
61
+ continue;
62
+ }
63
+ item = item?.next ?? null;
64
+ selector.children.insertData(attributeSelector, item);
55
65
  }
56
- });
57
- }
66
+ }
67
+ });
58
68
  });
59
69
  return (0, css_tree_1.generate)(ast);
60
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-react-scoped-css",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "A rollup plugin designed to allow scoped css to be run in react (Compatible with vite and rollup)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",