Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const key = getPropertyName(path, property)
serialized[key] = value
}
return serialized
}, {})
}
// injectSheet({a: {margin: [0, 1]}})
if (t.isArrayExpression(node)) {
return node.elements.map(elementNode => serializeNode(path, elementNode, theme))
}
// Styles are defined by a function whith a theme argument
// `injectSheet((theme) => ({a: {color: theme.primary}}))`.
// We enter this on `theme.primary`.
if (t.isMemberExpression(node)) {
const {object, props} = serializePropAccess(node)
if (props[0] in path.scope.bindings) {
const data = serializeNode(path, path.scope.bindings[props[0]].identifier, theme)
if (!data) return null
return getValueByPath(path, data, props.slice(1))
}
// When object name we are accessing is the argument name.
const firstArgNode = resolveRef(path, path.node.arguments[0])
if (t.isFunction(firstArgNode) && hasThemeArg(firstArgNode, object.name)) {
return getValueByPath(path, theme, props.slice(1))
}
}
// injectSheet({a: {left: 1 + 2}}) || injectSheet(getStyles(5))
const isStyled = (tag, state) => {
if (
t.isCallExpression(tag) &&
t.isMemberExpression(tag.callee) &&
tag.callee.property.name !== 'default' /** ignore default for #93 below */
) {
// styled.something()
return isStyled(tag.callee.object, state);
}
return (
(t.isMemberExpression(tag) && tag.object.name === importLocalName('default', state)) ||
(t.isCallExpression(tag) && tag.callee.name === importLocalName('default', state)) ||
(t.isCallExpression(tag) &&
t.isCallExpression(tag.callee.object) &&
tag.callee.object.callee.name === 'require' &&
tag.callee.object.arguments[0].value === 'styled-components')
);
};
export function MemberExpression(node) {
this.print(node, "object");
if (!node.computed && t.isMemberExpression(node.property)) {
throw new TypeError("Got a MemberExpression for MemberExpression property");
}
let computed = node.computed;
if (t.isLiteral(node.property) && isNumber(node.property.value)) {
computed = true;
}
if (computed) {
this.push("[");
this.print(node, "property");
this.push("]");
} else {
if (t.isLiteral(node.object)) {
let val = this._stringLiteral(node.object);
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".")) {
function isMemberExpressionSuper(node) {
return t.isMemberExpression(node) && t.isSuper(node.object);
}
} else if (t.isIdentifier(p.node.declaration)) {
className = p.node.declaration.name;
}
objArr.forEach(obj => {
if (obj.className == className || obj.alias == className) {
exportObj = obj;
}
})
}
if (t.isAssignmentExpression(p.node) &&
t.isMemberExpression(p.node.left) &&
t.isIdentifier(p.node.left.object) &&
p.node.left.object.name == 'module' &&
t.isIdentifier(p.node.left.property) &&
p.node.left.property.name == 'exports' &&
t.isIdentifier(p.node.right)
) {
let className = p.node.name;
objArr.forEach(obj => {
if (obj.className == className || obj.alias == className) {
exportObj = obj;
}
})
}
function _resolveInterfacePath(node) {
var subNode = "";
if (t.isMemberExpression(node)) {
if (t.isMemberExpression(node.object)) {
subNode += _resolveInterfacePath(node.object);
subNode += node.property.name + ".";
} else {
subNode += node.object.name + ".";
subNode += node.property.name + ".";
}
}
return subNode;
}
CallExpression(path) {
const { node } = path;
if (Array.isArray(node.arguments)) {
for (let i = 0, l = node.arguments.length; i < l; i++) {
add(node.arguments[i]);
if (t.isMemberExpression(node.arguments[i])) {
add(node.arguments[i].object);
}
}
}
add(node.callee);
},
BinaryExpression(path) {
function isArrayMapCallExpression(callExpression) {
return callExpression &&
t.isCallExpression(callExpression.node) &&
t.isMemberExpression(callExpression.node.callee) &&
t.isIdentifier(callExpression.node.callee.property, { name: 'map' });
}
exports.isArrayMapCallExpression = isArrayMapCallExpression;