Skip to content

Commit 51ca488

Browse files
committed
feat: Treat string as component if declared in scope
1 parent 566d9b7 commit 51ca488

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: packages/babel-plugin-transform-vue-jsx/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const getTag = (t, path) => {
4040
const namePath = path.get('name')
4141
if (t.isJSXIdentifier(namePath)) {
4242
const name = namePath.get('name').node
43-
if (name[0] > 'A' && name[0] < 'Z') {
43+
if (path.scope.hasBinding(name)) {
4444
return t.identifier(name)
4545
} else {
4646
return t.stringLiteral(name)

Diff for: packages/babel-plugin-transform-vue-jsx/test/snapshot.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ const tests = [
2525
to: `render(h => h("div", ["test"]));`,
2626
},
2727
{
28-
name: 'Uppercase component',
29-
from: `render(h => <Div>test</Div>)`,
30-
to: `render(h => h(Div, ["test"]));`,
28+
name: 'Tag & Component',
29+
from: `const Alpha = {}; render(h => [<Alpha>test</Alpha>, <Beta>test</Beta>])`,
30+
to: `const Alpha = {};
31+
render(h => [h(Alpha, ["test"]), h("Beta", ["test"])]);`,
3132
},
3233
{
3334
name: 'MemberExpression component',

0 commit comments

Comments
 (0)