UNPKG

stylelint-processor-glamorous

Version:
70 lines (55 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractValues = exports.extractDeclarations = exports.isAnnotatedExpression = exports.isCssAttribute = exports.isTopLevelExpression = exports.hasLeadingComment = void 0; var hasLeadingComment = function hasLeadingComment(path, pattern) { return path.node.leadingComments && path.node.leadingComments.filter(function (comment) { return pattern.test(comment.value); })[0]; }; exports.hasLeadingComment = hasLeadingComment; var isTopLevelExpression = function isTopLevelExpression(path) { return path.isObjectExpression() && !path.findParent(function (p) { return p.isObjectExpression(); }); }; exports.isTopLevelExpression = isTopLevelExpression; var isCssAttribute = function isCssAttribute(path) { return isTopLevelExpression(path) && path.findParent(function (p) { return p.isJSXAttribute() && p.node.name && p.node.name.name === 'css'; }); }; exports.isCssAttribute = isCssAttribute; var isAnnotatedExpression = function isAnnotatedExpression(path) { return path.isObjectExpression() && hasLeadingComment(path, /^\s*@css\s*$/); }; exports.isAnnotatedExpression = isAnnotatedExpression; var extractDeclarations = function extractDeclarations(path) { var declarations = []; path.traverse({ ObjectExpression(p) { if (!p.findParent(function (parent) { return parent.isObjectProperty(); })) { p.node.properties.forEach(function (prop) { declarations = declarations.concat([prop]); }); } } }); return declarations; }; exports.extractDeclarations = extractDeclarations; var extractValues = function extractValues(path) { var values = []; path.traverse({ Literal(p) { if (p.node.value) { values = values.concat([p.node]); } } }); return values; }; exports.extractValues = extractValues;