Skip to content

Commit

Permalink
Fix TypeError for spaceless condition in media-feature-name-value-all…
Browse files Browse the repository at this point in the history
…owed-list (#5581)

* update rule to exit early if parsing is not possible

* change type to indicate optional nodes property

* add test to cover invalid media rule

* update code for rule after updating types
  • Loading branch information
lachieh committed Oct 12, 2021
1 parent 816b19a commit a413527
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/rules/media-feature-name-allowed-list/__tests__/index.js
Expand Up @@ -39,6 +39,9 @@ testRule({
{
code: '@media (color) { }',
},
{
code: '@media only screen and(min-width: 640px) { }',
},
],

reject: [
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/media-feature-name-value-allowed-list/index.js
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-duplicate-at-import-rules/index.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/postcss-media-query-parser/index.d.ts
Expand Up @@ -7,7 +7,7 @@ declare module 'postcss-media-query-parser' {
after: string;
before: string;
sourceIndex: number;
nodes: Child[];
nodes?: Child[];
walk: Walker;
};

Expand Down

0 comments on commit a413527

Please sign in to comment.