Skip to content

Commit

Permalink
fix(jsx-to-stylesheet): 修复 css module 行内使用 Object.assign 等callExpress…
Browse files Browse the repository at this point in the history
…ion问题 (#11706)
  • Loading branch information
shinken008 authored Apr 24, 2022
1 parent 0ca8117 commit 71c900f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ class App extends Component {
render() {
const a = Object.assign({}, styleSheet.red);
const b = Object.assign({}, a);
return <div className={a}><span className={b} /></div>;
return <div className={a}><span className={b} /><span className={Object.assign({}, b)} /></div>;
}
}`, false, { enableCSSModule: true })).toBe(`import { createElement, Component } from 'rax';
import styleSheet from './app.module.scss';
Expand All @@ -617,7 +617,7 @@ class App extends Component {
render() {
const a = Object.assign({}, styleSheet.red);
const b = Object.assign({}, a);
return <div style={a}><span style={b} /></div>;
return <div style={a}><span style={b} /><span style={Object.assign({}, b)} /></div>;
}\n
}`)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,7 @@ export default function (babel: {
const binding = astPath.scope.getBinding(expression.name)
if (binding) {
const { node } = binding.path
// some call expression args references like Object.assign or @babel/runtime/helpers/extends
if (t.isCallExpression(node.init)) {
const { arguments: args } = node.init
for (const arg of args) {
if (isCSSMemberOrBindings(arg, cssModuleStylesheets, astPath)) {
return true
}
}
} else if (isCSSMemberOrBindings(node.init, cssModuleStylesheets, astPath)) {
if (isCSSMemberOrBindings(node.init, cssModuleStylesheets, astPath)) {
return true
}
}
Expand Down Expand Up @@ -196,6 +188,17 @@ export default function (babel: {
}
}
}

// 函数调用
// some call expression args references like Object.assign or @babel/runtime/helpers/extends
if (t.isCallExpression(expression)) {
const { arguments: args } = expression
for (const arg of args) {
if (isCSSMemberOrBindings(arg, cssModuleStylesheets, astPath)) {
return true
}
}
}
}

function isJSXCSSModuleExpression (value, cssModuleStylesheets, astPath) {
Expand Down

0 comments on commit 71c900f

Please sign in to comment.