Skip to content

Commit 1d326ba

Browse files
authored
Merge branch 'master' into patch-1
2 parents e3154f5 + 12af51c commit 1d326ba

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"import": "./dist/htm.mjs",
1414
"require": "./dist/htm.js"
1515
},
16-
"./": "./",
1716
"./preact": {
1817
"browser": "./preact/index.module.js",
1918
"umd": "./preact/index.umd.js",
@@ -37,7 +36,8 @@
3736
"umd": "./mini/index.umd.js",
3837
"import": "./mini/index.mjs",
3938
"require": "./mini/index.js"
40-
}
39+
},
40+
"./": "./"
4141
},
4242
"scripts": {
4343
"build": "npm run -s build:main && npm run -s build:mini && npm run -s build:preact && npm run -s build:react && npm run -s build:babel && npm run -s build:babel-transform-jsx && npm run -s build:mjsalias",
@@ -106,6 +106,7 @@
106106
"devDependencies": {
107107
"@babel/core": "^7.2.2",
108108
"@babel/preset-env": "^7.1.6",
109+
"@types/jest": "^26.0.24",
109110
"babel-jest": "^24.1.0",
110111
"babel-preset-env": "^1.7.0",
111112
"eslint": "^5.2.0",

packages/babel-plugin-transform-jsx-to-htm/index.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ export default function jsxToHtmBabelPlugin({ types: t }, options = {}) {
8989
}
9090

9191
function isComponentName(node) {
92+
if (t.isJSXNamespacedName(node)) return false;
9293
return !t.isIdentifier(node) || node.name.match(/^[$_A-Z]/);
9394
}
9495

9596
function getNameExpr(node) {
97+
if (t.isJSXNamespacedName(node)) {
98+
return t.identifier(node.namespace.name + ':' + node.name.name);
99+
}
96100
if (!t.isJSXMemberExpression(node)) {
97101
return t.identifier(node.name);
98102
}
@@ -169,7 +173,12 @@ export default function jsxToHtmBabelPlugin({ types: t }, options = {}) {
169173
continue;
170174
}
171175
const { name, value } = attr;
172-
raw(name.name);
176+
if (t.isJSXNamespacedName(name)) {
177+
raw(name.namespace.name + ':' + name.name.name);
178+
}
179+
else {
180+
raw(name.name);
181+
}
173182
if (value) {
174183
raw('=');
175184
if (value.expression) {

test/babel-transform-jsx.test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ describe('babel-plugin-transform-jsx-to-htm', () => {
137137
).toBe('html`<${a.b.c}>a</${a.b.c}>`;');
138138
});
139139

140+
test('namespaced element names', () => {
141+
expect(
142+
compile('(<a:b/>);')
143+
).toBe('html`<a:b/>`;');
144+
145+
expect(
146+
compile('(<a:b><x:y/></a:b>);')
147+
).toBe('html`<a:b><x:y/></a:b>`;');
148+
});
149+
150+
test('namespaced attributes', () => {
151+
expect(
152+
compile('(<a b:c="d"/>);')
153+
).toBe('html`<a b:c="d"/>`;');
154+
155+
expect(
156+
compile('(<a b:c="d" e:f={1} g>h</a>);')
157+
).toBe('html`<a b:c="d" e:f=${1} g>h</a>`;');
158+
});
159+
140160
test('static text', () => {
141161
expect(
142162
compile(`(<div>Hello</div>);`)

0 commit comments

Comments
 (0)