Skip to content

Commit

Permalink
fix: consider ruleless declarations as standard
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Jan 2, 2023
1 parent 8e744de commit 3ed733f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
10 changes: 10 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxDeclaration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ describe('isStandardSyntaxDeclaration', () => {
true,
);
});

it('supports root-level declarations', () => {
const doc = new postcss.Document();
const root = postcss.parse('color: yellow;');

root.parent = doc;
doc.nodes.push(root);

expect(isStandardSyntaxDeclaration(root.nodes[0])).toBe(true);
});
});

function decl(css, parser = postcss) {
Expand Down
21 changes: 1 addition & 20 deletions lib/utils/isStandardSyntaxDeclaration.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
'use strict';

const isScssVariable = require('./isScssVariable');
const { isRoot, isRule } = require('./typeGuards');

/**
* @param {string} [lang]
*/
function isStandardSyntaxLang(lang) {
return lang && (lang === 'css' || lang === 'custom-template' || lang === 'template-literal');
}
const { isRule } = require('./typeGuards');

/**
* Check whether a declaration is standard
Expand All @@ -19,18 +12,6 @@ module.exports = function isStandardSyntaxDeclaration(decl) {
const prop = decl.prop;
const parent = decl.parent;

// Declarations belong in a declaration block or standard CSS source
if (
parent &&
isRoot(parent) &&
parent.source &&
!isStandardSyntaxLang(
/** @type {import('postcss').Source & {lang?: string}} */ (parent.source).lang,
)
) {
return false;
}

// SCSS var; covers map and list declarations
if (isScssVariable(prop)) {
return false;
Expand Down

0 comments on commit 3ed733f

Please sign in to comment.