@wix/origami-lint 1.34.44 → 1.34.46

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.
@@ -50,13 +50,21 @@ export function attributeName(attr) {
50
50
  export const isIdAttribute = (attr) => attributeName(attr) === 'id';
51
51
  /** id="comp-x" → 'comp-x'; no id, or id={variable} → null. */
52
52
  export const getLiteralId = (node) => getLiteralAttribute(node, 'id');
53
- /** className="comp-x card" → ['comp-x', 'card']; no className, or className={variable} → []. */
54
- export const getLiteralClassNames = (node) => getLiteralAttribute(node, 'className')?.split(/\s+/).filter(Boolean) ?? [];
55
- function getLiteralAttribute(node, name) {
53
+ /**
54
+ * className="comp-x card" → ['comp-x', 'card']; className={['comp-x', 'open', {…}]} → ['comp-x'], as the import reads it: the
55
+ * array's first item is the class, the rest are states (parseJsx.ts splitClassName). No className, or className={variable} → [].
56
+ */
57
+ export function getLiteralClassNames(node) {
58
+ const value = getAttributeValue(node, 'className');
59
+ const classes = value?.type === 'JSXExpressionContainer' && value.expression.type === 'ArrayExpression' ? getStringLiteral(value.expression.elements[0]) : getStringLiteral(value);
60
+ return classes?.split(/\s+/).filter(Boolean) ?? [];
61
+ }
62
+ const getLiteralAttribute = (node, name) => getStringLiteral(getAttributeValue(node, name));
63
+ function getAttributeValue(node, name) {
56
64
  const attr = node.openingElement.attributes.find((attribute) => attributeName(attribute) === name);
57
- const value = attr?.type === 'JSXAttribute' ? attr.value : null;
58
- return value?.type === 'Literal' && typeof value.value === 'string' ? value.value : null;
65
+ return attr?.type === 'JSXAttribute' ? attr.value : null;
59
66
  }
67
+ const getStringLiteral = (node) => node?.type === 'Literal' && typeof node.value === 'string' ? node.value : null;
60
68
  export function createSourceReader(text) {
61
69
  const lineStarts = [0];
62
70
  for (let i = 0; i < text.length; i++)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-lint",
3
- "version": "1.34.44",
3
+ "version": "1.34.46",
4
4
  "description": "Offline lint for an exported Origami site: lints the pages that changed since the last passing run",
5
5
  "type": "module",
6
6
  "bin": {
@@ -26,7 +26,7 @@
26
26
  "eslint": "^10.12.0",
27
27
  "postcss": "^8.5.3",
28
28
  "typescript": "^5.8.3 || ~6.0.3",
29
- "@wix/origami-bi": "0.18.0"
29
+ "@wix/origami-bi": "0.19.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "^22.0.0",
@@ -54,5 +54,5 @@
54
54
  ]
55
55
  }
56
56
  },
57
- "falconPackageHash": "dd56bf015e4bd3779535e6af5723b0f06fe7f30031097ebd9e6a964e"
57
+ "falconPackageHash": "ad752a9dd8af06d1fe52431c6d99b83e4586a0299b78c56894ab5352"
58
58
  }