From a039f7ebae60d218e39b674efb4b73484cda77cd Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 7 Dec 2022 15:41:04 -0500 Subject: [PATCH] Fix support for latest Liquid scripting plugin (#109) --- package-lock.json | 14 +++++++------- package.json | 2 +- src/index.js | 13 +++++++++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4a18769a..75ddbb3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@prettier/plugin-php": "^0.19.2", "@prettier/plugin-pug": "^2.3.0", - "@shopify/prettier-plugin-liquid": "^0.4.0", + "@shopify/prettier-plugin-liquid": "^1.0.0-rc.2", "@shufo/prettier-plugin-blade": "^1.8.0", "@tailwindcss/line-clamp": "^0.3.0", "@trivago/prettier-plugin-sort-imports": "^3.3.0", @@ -1780,9 +1780,9 @@ } }, "node_modules/@shopify/prettier-plugin-liquid": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@shopify/prettier-plugin-liquid/-/prettier-plugin-liquid-0.4.0.tgz", - "integrity": "sha512-pJDTud9alhtCF0ZNDKpREmjvrWSVL60ZJsd1BE1kZ+QWBuuj6MYiVth9edYsupFp3Xa29VqrZ0QaEzgIouOeSg==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@shopify/prettier-plugin-liquid/-/prettier-plugin-liquid-1.0.0.tgz", + "integrity": "sha512-TClfYCO+Z6mlF8hAh454CCUZ2e4WBU6zLCMvPBb3zB3h62gy0pYZ9u8UdBM4/bMCAqRH9YV41j9YOJDbQMpoDw==", "dev": true, "dependencies": { "html-styles": "^1.0.0", @@ -13911,9 +13911,9 @@ } }, "@shopify/prettier-plugin-liquid": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@shopify/prettier-plugin-liquid/-/prettier-plugin-liquid-0.4.0.tgz", - "integrity": "sha512-pJDTud9alhtCF0ZNDKpREmjvrWSVL60ZJsd1BE1kZ+QWBuuj6MYiVth9edYsupFp3Xa29VqrZ0QaEzgIouOeSg==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@shopify/prettier-plugin-liquid/-/prettier-plugin-liquid-1.0.0.tgz", + "integrity": "sha512-TClfYCO+Z6mlF8hAh454CCUZ2e4WBU6zLCMvPBb3zB3h62gy0pYZ9u8UdBM4/bMCAqRH9YV41j9YOJDbQMpoDw==", "dev": true, "requires": { "html-styles": "^1.0.0", diff --git a/package.json b/package.json index c1c9cce4..23be83d3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "devDependencies": { "@prettier/plugin-php": "^0.19.2", "@prettier/plugin-pug": "^2.3.0", - "@shopify/prettier-plugin-liquid": "^0.4.0", + "@shopify/prettier-plugin-liquid": "^1.0.0-rc.2", "@shufo/prettier-plugin-blade": "^1.8.0", "@tailwindcss/line-clamp": "^0.3.0", "@trivago/prettier-plugin-sort-imports": "^3.3.0", diff --git a/src/index.js b/src/index.js index 7f444041..360bad2a 100644 --- a/src/index.js +++ b/src/index.js @@ -346,9 +346,18 @@ function transformGlimmer(ast, { env }) { } function transformLiquid(ast, { env }) { + /** @param {{name: string | {type: string, value: string}[]}} node */ + function isClassAttr(node) { + if (Array.isArray(node.name)) { + return node.name.every((n) => n.type === 'TextNode' && n.value === 'class'); + } + + return node.name === 'class' + } + visit(ast, { AttrSingleQuoted(node, _parent, _key, _index, meta) { - if (node.name !== "class") { + if (!isClassAttr(node)) { return; } @@ -357,7 +366,7 @@ function transformLiquid(ast, { env }) { }, AttrDoubleQuoted(node, _parent, _key, _index, meta) { - if (node.name !== "class") { + if (!isClassAttr(node)) { return; }