diff --git a/src/_utils.js b/src/_utils.js index 7b6a02ac..c89025f4 100644 --- a/src/_utils.js +++ b/src/_utils.js @@ -129,11 +129,13 @@ export const validateExpressionVisitor = { } }, Identifier(path, scope) { - if (t.isMemberExpression(path.parentPath)) { + const { name } = path.node + + if (t.isMemberExpression(path.parentPath) && scope.hasOwnBinding(name)) { return } - const { name } = path.node - if (scope.hasOwnBinding(name)) { + + if (scope.hasOwnBinding(name) || path.scope.hasOwnBinding(name)) { throw path.buildCodeFrameError( `Expected \`${name}\` ` + `to not come from the closest scope.\n` + diff --git a/test/__snapshots__/attribute.js.snap b/test/__snapshots__/attribute.js.snap index 66050b83..65aba8f2 100644 --- a/test/__snapshots__/attribute.js.snap +++ b/test/__snapshots__/attribute.js.snap @@ -53,6 +53,36 @@ export const Test6 = ({ color }) =>

dynamic only

<_JSXStyle styleId={\\"1947484460\\"} css={\`p.__jsx-style-dynamic-selector{color:\${color};}\`} dynamic={[color]} /> +
; + +// dynamic with scoped compound variable +export const Test8 = ({ color }) => { + if (color) { + const innerProps = { color }; + + return
+

dynamic with scoped compound variable

+ <_JSXStyle styleId={\\"1791723528\\"} css={\`p.__jsx-style-dynamic-selector{color:\${innerProps.color};}\`} dynamic={[innerProps.color]} /> +
; + } +}; + +// dynamic with compound variable +export const Test9 = ({ color }) => { + const innerProps = { color }; + + return
+

dynamic with compound variable

+ <_JSXStyle styleId={\\"248922593\\"} css={\`p.__jsx-style-dynamic-selector{color:\${innerProps.color};}\`} dynamic={[innerProps.color]} /> +
; +}; + +const foo = 'red'; + +// dynamic with constant variable +export const Test10 = () =>
+

dynamic with constant variable

+ <_JSXStyle styleId={\\"461505126\\"} css={\`p.jsx-461505126{color:\${foo};}\`} />
;" `; diff --git a/test/fixtures/attribute-generation-modes.js b/test/fixtures/attribute-generation-modes.js index 0c4098ea..be140f3f 100644 --- a/test/fixtures/attribute-generation-modes.js +++ b/test/fixtures/attribute-generation-modes.js @@ -3,19 +3,16 @@ import styles from './styles' const styles2 = require('./styles2') // external only -export const Test1 = () => +export const Test1 = () => (

external only

- - + +
+) // external and static -export const Test2 = () => +export const Test2 = () => (

external and static

- +
+) // external and dynamic -export const Test3 = ({ color }) => +export const Test3 = ({ color }) => (

external and dynamic

- +
+) // external, static and dynamic -export const Test4 = ({ color }) => +export const Test4 = ({ color }) => (

external, static and dynamic

- +
+) // static only -export const Test5 = () => +export const Test5 = () => (

static only

+) // static and dynamic -export const Test6 = ({ color }) => +export const Test6 = ({ color }) => (

static and dynamic

+) // dynamic only -export const Test7 = ({ color }) => +export const Test7 = ({ color }) => (

dynamic only

+) + +// dynamic with scoped compound variable +export const Test8 = ({ color }) => { + if (color) { + const innerProps = { color } + + return ( +
+

dynamic with scoped compound variable

+ +
+ ) + } +} + +// dynamic with compound variable +export const Test9 = ({ color }) => { + const innerProps = { color } + + return ( +
+

dynamic with compound variable

+ +
+ ) +} + +const foo = 'red' + +// dynamic with constant variable +export const Test10 = () => ( +
+

dynamic with constant variable

+ +
+)