ember-scoped-css 0.8.0 → 0.9.0

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.
@@ -22672,6 +22672,7 @@ function renameClass_default(className, postfix, classesInCss) {
22672
22672
  // src/lib/rewriteHbs.js
22673
22673
  function rewriteHbs(hbs, classes, tags, postfix) {
22674
22674
  let ast = import_ember_template_recast.default.parse(hbs);
22675
+ let stack = [];
22675
22676
  import_ember_template_recast.default.traverse(ast, {
22676
22677
  AttrNode(node) {
22677
22678
  if (node.name === "class") {
@@ -22699,6 +22700,41 @@ function rewriteHbs(hbs, classes, tags, postfix) {
22699
22700
  );
22700
22701
  }
22701
22702
  }
22703
+ },
22704
+ All: {
22705
+ enter(node) {
22706
+ stack.push(node);
22707
+ },
22708
+ exit() {
22709
+ stack.pop();
22710
+ }
22711
+ },
22712
+ MustacheStatement(node) {
22713
+ let cssClass;
22714
+ if (node.path?.original === "scoped-class" && node.params?.length === 1 && node.params[0].type === "StringLiteral") {
22715
+ cssClass = node.params[0].value;
22716
+ }
22717
+ if (node.path?.path?.original === "scoped-class" && node.path?.params?.length === 1 && node.path?.params[0].type === "StringLiteral") {
22718
+ cssClass = node.path.params[0].value;
22719
+ }
22720
+ if (cssClass) {
22721
+ const textNode = import_ember_template_recast.default.builders.text(renameClass_default(cssClass, postfix));
22722
+ const parent = stack[stack.length - 1];
22723
+ if (parent.type === "AttrNode") {
22724
+ parent.quoteType = '"';
22725
+ }
22726
+ return textNode;
22727
+ }
22728
+ },
22729
+ SubExpression(node) {
22730
+ if (node.path?.original === "scoped-class" && node.params?.length === 1 && node.params[0].type === "StringLiteral") {
22731
+ const cssClass = node.params[0].value;
22732
+ const textNode = import_ember_template_recast.default.builders.literal(
22733
+ "StringLiteral",
22734
+ renameClass_default(cssClass, postfix)
22735
+ );
22736
+ return textNode;
22737
+ }
22702
22738
  }
22703
22739
  });
22704
22740
  let result = import_ember_template_recast.default.print(ast);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-scoped-css",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -3,6 +3,7 @@ import renameClass from './renameClass.js';
3
3
 
4
4
  export default function rewriteHbs(hbs, classes, tags, postfix) {
5
5
  let ast = recast.parse(hbs);
6
+ let stack = [];
6
7
 
7
8
  recast.traverse(ast, {
8
9
  AttrNode(node) {
@@ -35,6 +36,59 @@ export default function rewriteHbs(hbs, classes, tags, postfix) {
35
36
  }
36
37
  }
37
38
  },
39
+
40
+ All: {
41
+ enter(node) {
42
+ stack.push(node);
43
+ },
44
+ exit() {
45
+ stack.pop();
46
+ },
47
+ },
48
+
49
+ MustacheStatement(node) {
50
+ let cssClass;
51
+
52
+ if (
53
+ node.path?.original === 'scoped-class' &&
54
+ node.params?.length === 1 &&
55
+ node.params[0].type === 'StringLiteral'
56
+ ) {
57
+ cssClass = node.params[0].value;
58
+ }
59
+
60
+ if (
61
+ node.path?.path?.original === 'scoped-class' &&
62
+ node.path?.params?.length === 1 &&
63
+ node.path?.params[0].type === 'StringLiteral'
64
+ ) {
65
+ cssClass = node.path.params[0].value;
66
+ }
67
+
68
+ if (cssClass) {
69
+ const textNode = recast.builders.text(renameClass(cssClass, postfix));
70
+ const parent = stack[stack.length - 1];
71
+ if (parent.type === 'AttrNode') {
72
+ parent.quoteType = '"';
73
+ }
74
+ return textNode;
75
+ }
76
+ },
77
+
78
+ SubExpression(node) {
79
+ if (
80
+ node.path?.original === 'scoped-class' &&
81
+ node.params?.length === 1 &&
82
+ node.params[0].type === 'StringLiteral'
83
+ ) {
84
+ const cssClass = node.params[0].value;
85
+ const textNode = recast.builders.literal(
86
+ 'StringLiteral',
87
+ renameClass(cssClass, postfix)
88
+ );
89
+ return textNode;
90
+ }
91
+ },
38
92
  });
39
93
 
40
94
  let result = recast.print(ast);
@@ -1,27 +0,0 @@
1
- import replaceScopedClass from './lib/replaceScopedClass.js';
2
-
3
- const scopedClass = () => {
4
- return {
5
- visitor: {
6
- CallExpression(path, state) {
7
- if (path.node?.callee?.name === 'precompileTemplate') {
8
- if (path.node.arguments[0].type === 'StringLiteral') {
9
- path.node.arguments[0].value = replaceScopedClass(
10
- path.node.arguments[0].value,
11
- state.filename,
12
- state.cwd
13
- );
14
- } else if (path.node.arguments[0].type === 'TemplateLiteral') {
15
- path.node.arguments[0].quasis[0].value.raw = replaceScopedClass(
16
- path.node.arguments[0].quasis[0].value.raw,
17
- state.filename,
18
- state.cwd
19
- );
20
- }
21
- }
22
- },
23
- },
24
- };
25
- };
26
-
27
- export default scopedClass;
@@ -1,66 +0,0 @@
1
- import recast from 'ember-template-recast';
2
- import renameClass from './renameClass.js';
3
- import generateHash from './generateAbsolutePathHash.js';
4
-
5
- export default function (hbs, templatePath) {
6
- let ast = recast.parse(hbs);
7
- let stack = [];
8
- const cssPath = templatePath.replace(/(\.hbs)?\.js$/, '.css');
9
- const postfix = generateHash(cssPath);
10
-
11
- recast.traverse(ast, {
12
- All: {
13
- enter(node) {
14
- stack.push(node);
15
- },
16
- exit() {
17
- stack.pop();
18
- },
19
- },
20
- MustacheStatement(node) {
21
- let cssClass;
22
-
23
- if (
24
- node.path?.original === 'scoped-class' &&
25
- node.params?.length === 1 &&
26
- node.params[0].type === 'StringLiteral'
27
- ) {
28
- cssClass = node.params[0].value;
29
- }
30
-
31
- if (
32
- node.path?.path?.original === 'scoped-class' &&
33
- node.path?.params?.length === 1 &&
34
- node.path?.params[0].type === 'StringLiteral'
35
- ) {
36
- cssClass = node.path.params[0].value;
37
- }
38
-
39
- if (cssClass) {
40
- const textNode = recast.builders.text(renameClass(cssClass, postfix));
41
- const parent = stack[stack.length - 1];
42
- if (parent.type === 'AttrNode') {
43
- parent.quoteType = '"';
44
- }
45
- return textNode;
46
- }
47
- },
48
- SubExpression(node) {
49
- if (
50
- node.path?.original === 'scoped-class' &&
51
- node.params?.length === 1 &&
52
- node.params[0].type === 'StringLiteral'
53
- ) {
54
- const cssClass = node.params[0].value;
55
- const textNode = recast.builders.literal(
56
- 'StringLiteral',
57
- renameClass(cssClass, postfix)
58
- );
59
- return textNode;
60
- }
61
- },
62
- });
63
-
64
- let result = recast.print(ast);
65
- return result;
66
- }