From b82aa0179cc2842330e3254a5d2b4886af63bb43 Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Fri, 8 Oct 2021 18:22:35 -0400 Subject: [PATCH 1/4] update rule to exit early if parsing is not possible --- lib/rules/media-feature-name-value-allowed-list/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/rules/media-feature-name-value-allowed-list/index.js b/lib/rules/media-feature-name-value-allowed-list/index.js index 293112f5a1..0dc4e7cd1c 100644 --- a/lib/rules/media-feature-name-value-allowed-list/index.js +++ b/lib/rules/media-feature-name-value-allowed-list/index.js @@ -31,6 +31,8 @@ const rule = (primary) => { root.walkAtRules(/^media$/i, (atRule) => { mediaParser(atRule.params).walk(/^media-feature-expression$/i, (node) => { + if (!node.nodes) return; + const mediaFeatureRangeContext = isRangeContextMediaFeature(node.parent.value); // Ignore boolean From c95617d6db83503af94e69596f0feec3207fd130 Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Sat, 9 Oct 2021 11:27:59 -0400 Subject: [PATCH 2/4] change type to indicate optional nodes property --- types/postcss-media-query-parser/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/postcss-media-query-parser/index.d.ts b/types/postcss-media-query-parser/index.d.ts index e4cbe00873..9e6049065b 100644 --- a/types/postcss-media-query-parser/index.d.ts +++ b/types/postcss-media-query-parser/index.d.ts @@ -7,7 +7,7 @@ declare module 'postcss-media-query-parser' { after: string; before: string; sourceIndex: number; - nodes: Child[]; + nodes?: Child[]; walk: Walker; }; From 374ee0758ac3f2f5a7eb7f059fb30f0df59a5a16 Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Sat, 9 Oct 2021 11:28:11 -0400 Subject: [PATCH 3/4] add test to cover invalid media rule --- lib/rules/media-feature-name-allowed-list/__tests__/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/rules/media-feature-name-allowed-list/__tests__/index.js b/lib/rules/media-feature-name-allowed-list/__tests__/index.js index 75753abb7c..74ed58340b 100644 --- a/lib/rules/media-feature-name-allowed-list/__tests__/index.js +++ b/lib/rules/media-feature-name-allowed-list/__tests__/index.js @@ -39,6 +39,9 @@ testRule({ { code: '@media (color) { }', }, + { + code: '@media only screen and(min-width: 640px) { }', + }, ], reject: [ From 1f413f78ff9054f0270b85c45a9346b3b24f408d Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Mon, 11 Oct 2021 20:43:38 -0400 Subject: [PATCH 4/4] update code for rule after updating types --- lib/rules/no-duplicate-at-import-rules/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-duplicate-at-import-rules/index.js b/lib/rules/no-duplicate-at-import-rules/index.js index de4d5c7340..34084170ab 100644 --- a/lib/rules/no-duplicate-at-import-rules/index.js +++ b/lib/rules/no-duplicate-at-import-rules/index.js @@ -38,8 +38,8 @@ const rule = (primary) => { : firstParam.value; // extract media queries if any - const media = mediaParser(valueParser.stringify(restParams)) - .nodes.map((n) => n.value.replace(/\s/g, '')) + const media = (mediaParser(valueParser.stringify(restParams)).nodes || []) + .map((n) => n.value.replace(/\s/g, '')) .filter((n) => n.length); const isDuplicate = media.length