UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

33 lines 1.73 kB
import { cleanComments } from './clean-comments'; import { getRawExpression } from './get-raw-expression'; import { getValue } from './get-value'; import { splitCssProperties } from './split-css-properties'; /** * Returns an array of tuples representing a processed css within `TaggedTemplateExpression` node. * Each element of the array is a tuple `[string, string]`, * where the first element is the processed css line with computed values * and the second element of the tuple is the original css line from source. * @param node TaggedTemplateExpression node. * @param context Rule.RuleContext. * @example * ``` * `[['padding: 8', 'padding: ${gridSize()}'], ['margin: 6', 'margin: 6px' ]]` * ``` */ export function processCssNode(node, context) { var combinedString = node.quasi.quasis.map(function (q, i) { return "".concat(q.value.raw).concat(node.quasi.expressions[i] ? getValue(node.quasi.expressions[i], context) : ''); }).join(''); var rawString = node.quasi.quasis.map(function (q, i) { return "".concat(q.value.raw).concat(node.quasi.expressions[i] ? getRawExpression(node.quasi.expressions[i], context) ? "${".concat(getRawExpression(node.quasi.expressions[i], context), "}") : null : ''); }).join(''); var cssProperties = splitCssProperties(cleanComments(combinedString)); var unalteredCssProperties = splitCssProperties(cleanComments(rawString)); if (cssProperties.length !== unalteredCssProperties.length) { // this means something went wrong with the parsing, the original lines can't be reconciled with the processed lines return undefined; } return cssProperties.map(function (cssProperty, index) { return [cssProperty, unalteredCssProperties[index]]; }); }