// https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export // Work in progress // e.g. // foo.bar.baz('something') // callee = foo.bar.baz (MemberExpression) // returns = foo const getRootObject = (callee, depth = 0) => { // TODO: Find a test case for this if (!_.isObject(callee)) return {}; if (callee.object === undefined) { return { name: callee.name, depth }; } if (t.isThisExpression(callee.object)) { return { name: 'this', depth }; } return getRootObject(callee.object, depth + 1); }
MemberExpression(path, scope) { const { node } = path; if ( (t.isIdentifier(node.property) && (t.isThisExpression(node.object) && (node.property.name === "props" || node.property.name === "state"))) || (t.isIdentifier(node.object) && scope.hasOwnBinding(node.object.name)) ) { throw path.buildCodeFrameError( `Expected a constant ` + `as part of the template literal expression ` + `(eg: <style jsx>{\`p { color: $\{myColor}\`}</style>), ` + `but got a MemberExpression: this.${node.property.name}` ); } }