From 4649de6efb75481bfe1907c410e69d928579420b Mon Sep 17 00:00:00 2001 From: Nishan Date: Thu, 30 Sep 2021 20:11:39 +0530 Subject: [PATCH 1/2] feat: rn-web support --- packages/babel-plugin-open-source/babel.js | 34 +++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-open-source/babel.js b/packages/babel-plugin-open-source/babel.js index 8edc963..293f7ea 100644 --- a/packages/babel-plugin-open-source/babel.js +++ b/packages/babel-plugin-open-source/babel.js @@ -44,12 +44,38 @@ module.exports = declare(api => { end: location.end.line }) - path.container.openingElement.attributes.push( - t.jsxAttribute( - t.jsxIdentifier('data-source'), + if (state.opts.reactNativeWeb) { + const dataSetAttr = path.container.openingElement.attributes.find( + (attr) => { + return attr.name && attr.name.name === "dataSet"; + } + ); + const dataSetProperty = t.objectProperty( + t.identifier("source"), t.stringLiteral(sourceData) + ); + + if (dataSetAttr && t.isJSXExpressionContainer(dataSetAttr.value)) { + // dataSet={{x: a}} + if (t.isObjectExpression(dataSetAttr.value.expression)) { + dataSetAttr.value.expression.properties.push(dataSetProperty); + } + // dataSet={x} + else if (t.isIdentifier(dataSetAttr.value.expression)) { + dataSetAttr.value.expression = t.objectExpression([ + t.spreadElement(dataSetAttr.value.expression), + dataSetProperty, + ]); + } + } + } else { + path.container.openingElement.attributes.push( + t.jsxAttribute( + t.jsxIdentifier('data-source'), + t.stringLiteral(sourceData) + ) ) - ) + } } } From 492e2d620285e6b6db5a9decaa14a3b7d065a869 Mon Sep 17 00:00:00 2001 From: Nishan Date: Thu, 30 Sep 2021 20:24:59 +0530 Subject: [PATCH 2/2] fix: rn-web dataset not found --- packages/babel-plugin-open-source/babel.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/babel-plugin-open-source/babel.js b/packages/babel-plugin-open-source/babel.js index 293f7ea..9f121da 100644 --- a/packages/babel-plugin-open-source/babel.js +++ b/packages/babel-plugin-open-source/babel.js @@ -67,6 +67,13 @@ module.exports = declare(api => { dataSetProperty, ]); } + } else { + path.container.openingElement.attributes.push( + t.jsxAttribute( + t.jsxIdentifier('dataSet'), + t.jsxExpressionContainer(t.objectExpression([dataSetProperty])) + ) + ); } } else { path.container.openingElement.attributes.push(