UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

41 lines (40 loc) • 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isXcssValue = isXcssValue; var _contextCompat = require("@atlaskit/eslint-utils/context-compat"); var _findVariable = require("@atlaskit/eslint-utils/find-variable"); var importSources = new Set(['@atlaskit/primitives', '@atlaskit/primitives/xcss', '@atlaskit/primitives/xcss/xcss']); function isXcssValue(node, context) { var _variable$defs$some; var current = node; while (current.parent) { var parent = current.parent; if (parent.type === 'Property' && parent.value === current) { current = parent; } else if (parent.type === 'ObjectExpression') { current = parent; } else { break; } } var call = current.parent; if ((call === null || call === void 0 ? void 0 : call.type) !== 'CallExpression' || call.arguments[0] !== current) { return false; } var callee = call.callee; var isNamespaceCall = callee.type === 'MemberExpression' && !callee.computed && callee.property.type === 'Identifier' && callee.property.name === 'xcss'; var identifier = callee.type === 'Identifier' ? callee : isNamespaceCall ? callee.object : null; if ((identifier === null || identifier === void 0 ? void 0 : identifier.type) !== 'Identifier') { return false; } var variable = (0, _findVariable.findVariable)({ identifier: identifier, sourceCode: (0, _contextCompat.getSourceCode)(context) }); return (_variable$defs$some = variable === null || variable === void 0 ? void 0 : variable.defs.some(function (def) { var _def$parent; return def.type === 'ImportBinding' && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && importSources.has(String(def.parent.source.value)) && (isNamespaceCall ? def.node.type === 'ImportNamespaceSpecifier' : def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === 'xcss'); })) !== null && _variable$defs$some !== void 0 ? _variable$defs$some : false; }