Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsx-to-stylesheet): 修复 css module 行内使用 Object.assign 等callExpress… #11706

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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