UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

29 lines (28 loc) 1.06 kB
import { callExpression, identifier, literal } from 'eslint-codemod-utils'; import { findTokenNameByPropertyValue } from './find-token-name-by-property-value'; /** * Returns a token node for a given value including fallbacks. * @param propertyName camelCase CSS property * @param value string representing pixel value, or font family, or number representing font weight * @example * ``` * propertyName: padding, value: '8px' => token('space.100', '8px') * propertyName: fontWeight, value: 400 => token('font.weight.regular', '400') * ``` */ export function getTokenNodeForValue(propertyName, value) { var token = findTokenNameByPropertyValue(propertyName, value); var fallbackValue = propertyName === 'fontFamily' ? { value: "".concat(value), raw: "`".concat(value, "`") } : "".concat(value); return callExpression({ callee: identifier({ name: 'token' }), arguments: [literal({ value: "'".concat(token !== null && token !== void 0 ? token : '', "'") }), literal(fallbackValue)], optional: false }); }