diff --git a/packages/remax-cli/src/__tests__/integration/fixtures/lifeCycle/expected/remax-vendors.js b/packages/remax-cli/src/__tests__/integration/fixtures/lifeCycle/expected/remax-vendors.js index 148e1da4f..28273f4e3 100644 --- a/packages/remax-cli/src/__tests__/integration/fixtures/lifeCycle/expected/remax-vendors.js +++ b/packages/remax-cli/src/__tests__/integration/fixtures/lifeCycle/expected/remax-vendors.js @@ -635,8 +635,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return propsAlias; }); /* harmony import */ var _utils_plainStyle__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11); /* harmony import */ var _createHostComponent__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13); -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - function getAlias(prop, type) { @@ -654,7 +652,7 @@ function getAlias(prop, type) { } function getValue(prop, value) { - if (prop.toLowerCase().endsWith('style') && _typeof(value) === 'object') { + if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') { return Object(_utils_plainStyle__WEBPACK_IMPORTED_MODULE_0__["default"])(value); } diff --git a/packages/remax-cli/src/__tests__/integration/fixtures/runtime-plugin/expected/remax-vendors.js b/packages/remax-cli/src/__tests__/integration/fixtures/runtime-plugin/expected/remax-vendors.js index a30c5a979..e8db83f98 100644 --- a/packages/remax-cli/src/__tests__/integration/fixtures/runtime-plugin/expected/remax-vendors.js +++ b/packages/remax-cli/src/__tests__/integration/fixtures/runtime-plugin/expected/remax-vendors.js @@ -635,8 +635,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return propsAlias; }); /* harmony import */ var _utils_plainStyle__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11); /* harmony import */ var _createHostComponent__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13); -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - function getAlias(prop, type) { @@ -654,7 +652,7 @@ function getAlias(prop, type) { } function getValue(prop, value) { - if (prop.toLowerCase().endsWith('style') && _typeof(value) === 'object') { + if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') { return Object(_utils_plainStyle__WEBPACK_IMPORTED_MODULE_0__["default"])(value); } diff --git a/packages/remax-runtime/src/__tests__/__snapshots__/propsAlias.test.ts.snap b/packages/remax-runtime/src/__tests__/__snapshots__/propsAlias.test.ts.snap index 97e0ce57f..e4dd9b157 100644 --- a/packages/remax-runtime/src/__tests__/__snapshots__/propsAlias.test.ts.snap +++ b/packages/remax-runtime/src/__tests__/__snapshots__/propsAlias.test.ts.snap @@ -5,3 +5,9 @@ Object { "style": "color:#ffffff;height:2rpx;-webkit-flex:1;--color:red;--textColor:blue;background-color:var(--textColor);", } `; + +exports[`props alias transform style prop correctly 2`] = ` +Object { + "style": null, +} +`; diff --git a/packages/remax-runtime/src/__tests__/propsAlias.test.ts b/packages/remax-runtime/src/__tests__/propsAlias.test.ts index 67eeb1f76..21ba500c8 100644 --- a/packages/remax-runtime/src/__tests__/propsAlias.test.ts +++ b/packages/remax-runtime/src/__tests__/propsAlias.test.ts @@ -42,6 +42,15 @@ describe('props alias', () => { 'any' ) ).toMatchSnapshot(); + + expect( + propsAlias( + { + style: null, + }, + 'any' + ) + ).toMatchSnapshot(); }); it('transform props by component type correctly', () => { diff --git a/packages/remax-runtime/src/propsAlias.ts b/packages/remax-runtime/src/propsAlias.ts index 343096ca6..910cb6c09 100644 --- a/packages/remax-runtime/src/propsAlias.ts +++ b/packages/remax-runtime/src/propsAlias.ts @@ -17,7 +17,7 @@ export function getAlias(prop: string, type: string) { } function getValue(prop: string, value: any): any { - if (prop.toLowerCase().endsWith('style') && typeof value === 'object') { + if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') { return plainStyle(value); }