From 002ed55f288d93597bc9eb94872e461ccca011d4 Mon Sep 17 00:00:00 2001 From: shinken008 Date: Sat, 23 Apr 2022 16:07:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(jsx-to-stylesheet):=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?css=20module=20=E8=A1=8C=E5=86=85=E4=BD=BF=E7=94=A8=20Object.as?= =?UTF-8?q?sign=20=E7=AD=89callExpression=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/index.spec.js | 4 ++-- .../src/index.ts | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/__tests__/index.spec.js b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/__tests__/index.spec.js index 70f00d8125b3..da45946c168f 100644 --- a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/__tests__/index.spec.js +++ b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/__tests__/index.spec.js @@ -607,7 +607,7 @@ class App extends Component { render() { const a = Object.assign({}, styleSheet.red); const b = Object.assign({}, a); - return
; + return
; } }`, false, { enableCSSModule: true })).toBe(`import { createElement, Component } from 'rax'; import styleSheet from './app.module.scss'; @@ -617,7 +617,7 @@ class App extends Component { render() { const a = Object.assign({}, styleSheet.red); const b = Object.assign({}, a); - return
; + return
; }\n }`) }) diff --git a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts index 295893f656af..54d0b7e5e3c9 100644 --- a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts +++ b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts @@ -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 } } @@ -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) {