@@ -51,6 +51,12 @@ module.exports = (babel) => {
5151 const t = babel . types
5252 const nanohtmlModuleNames = [ 'nanohtml' , 'bel' , 'yo-yo' , 'choo/html' ]
5353
54+ /**
55+ * Returns an object which specifies the custom elements by which a built-in is extended.
56+ */
57+ const createExtendsObjectExpression = ( is ) =>
58+ t . objectExpression ( [ t . objectProperty ( t . identifier ( 'is' ) , t . stringLiteral ( is ) ) ] )
59+
5460 /**
5561 * Returns a node that creates a namespaced HTML element.
5662 */
@@ -60,6 +66,15 @@ module.exports = (babel) => {
6066 [ ns , t . stringLiteral ( tag ) ]
6167 )
6268
69+ /**
70+ * Returns a node that creates a extended namespaced HTML element.
71+ */
72+ const createNsCustomBuiltIn = ( ns , tag , is ) =>
73+ t . callExpression (
74+ t . memberExpression ( t . identifier ( 'document' ) , t . identifier ( 'createElementNS' ) ) ,
75+ [ ns , t . stringLiteral ( tag ) , createExtendsObjectExpression ( is ) ]
76+ )
77+
6378 /**
6479 * Returns a node that creates an element.
6580 */
@@ -69,6 +84,15 @@ module.exports = (babel) => {
6984 [ t . stringLiteral ( tag ) ]
7085 )
7186
87+ /**
88+ * Returns a node that creates an extended element.
89+ */
90+ const createCustomBuiltIn = ( tag , is ) =>
91+ t . callExpression (
92+ t . memberExpression ( t . identifier ( 'document' ) , t . identifier ( 'createElement' ) ) ,
93+ [ t . stringLiteral ( tag ) , createExtendsObjectExpression ( is ) ]
94+ )
95+
7296 /**
7397 * Returns a node that creates a comment.
7498 */
@@ -195,10 +219,20 @@ module.exports = (babel) => {
195219
196220 const result = [ ]
197221
222+ var isCustomElement = props . is
223+ delete props . is
224+
198225 // Use the SVG namespace for svg elements.
199226 if ( SVG_TAGS . includes ( tag ) ) {
200227 state . svgNamespaceId . used = true
201- result . push ( t . assignmentExpression ( '=' , id , createNsElement ( state . svgNamespaceId , tag ) ) )
228+
229+ if ( isCustomElement ) {
230+ result . push ( t . assignmentExpression ( '=' , id , createNsCustomBuiltIn ( state . svgNamespaceId , tag , isCustomElement ) ) )
231+ } else {
232+ result . push ( t . assignmentExpression ( '=' , id , createNsElement ( state . svgNamespaceId , tag ) ) )
233+ }
234+ } else if ( isCustomElement ) {
235+ result . push ( t . assignmentExpression ( '=' , id , createCustomBuiltIn ( tag , isCustomElement ) ) )
202236 } else {
203237 result . push ( t . assignmentExpression ( '=' , id , createElement ( tag ) ) )
204238 }
0 commit comments