Skip to content

Commit c8af617

Browse files
authored
feat: enable expression as valid children (#2)
1 parent 31b70be commit c8af617

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

__mocks__/Examples.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const MockFragment = () => {
5959
export const MockText = () => {
6060
return (
6161
<ComponentBox data-test="id">
62-
text
62+
text {'text'}
6363
<span>content</span>
64-
text
64+
text {'text'}
6565
</ComponentBox>
6666
)
6767
}

__tests__/babelPluginReactLive.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ it('babelPluginReactLive', async () => {
8585
return (
8686
<ComponentBox data-test="id">{\`<>
8787
text
88+
{'text'}
8889
<span>content</span>
8990
text
91+
{'text'}
9092
</>
9193
\`}</ComponentBox>
9294
)

babelPluginReactLive.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ function babelPluginReactLive(babel, options) {
3939
* Do nothing, if the child is already a string / template literal
4040
*/
4141
!path.node.children.some((node) => {
42-
return (
43-
node.expression &&
44-
(t.isTemplateLiteral(node.expression) ||
45-
t.isStringLiteral(node.expression))
46-
)
42+
return node.expression && t.isTemplateLiteral(node.expression)
4743
})
4844
) {
4945
const rootPath = path
@@ -107,6 +103,18 @@ function babelPluginReactLive(babel, options) {
107103
}
108104
}
109105
},
106+
JSXExpressionContainer(path) {
107+
if (
108+
rootPath === path.parentPath &&
109+
path.node.expression.type !== 'ArrowFunctionExpression'
110+
) {
111+
const code = path.getSource()
112+
113+
if (code.length) {
114+
children.push(code)
115+
}
116+
}
117+
},
110118
})
111119

112120
if (children.length > 0) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "git",
1414
"url": "https://github.com/dnbexperience/eufemia.git"
1515
},
16-
"version": "1.1.0",
16+
"version": "1.2.0",
1717
"main": "babelPluginReactLive.js",
1818
"scripts": {
1919
"test": "jest",

0 commit comments

Comments
 (0)