jsx-dom-runtime
Advanced tools
Comparing version 0.20.0 to 0.21.0
import { declarePreset } from '@babel/helper-plugin-utils'; | ||
import _createPlugin from '@babel/plugin-transform-react-jsx/lib/create-plugin.js'; | ||
const svgTags = new Set([ | ||
const svg = [ | ||
'svg', | ||
@@ -55,11 +55,134 @@ 'animate', | ||
'use', | ||
]); | ||
]; | ||
const html = [ | ||
'a', | ||
'abbr', | ||
'address', | ||
'area', | ||
'article', | ||
'aside', | ||
'audio', | ||
'b', | ||
'base', | ||
'bdi', | ||
'bdo', | ||
'big', | ||
'blockquote', | ||
'body', | ||
'br', | ||
'button', | ||
'canvas', | ||
'caption', | ||
'cite', | ||
'code', | ||
'col', | ||
'colgroup', | ||
'data', | ||
'datalist', | ||
'dd', | ||
'del', | ||
'details', | ||
'dfn', | ||
'dialog', | ||
'div', | ||
'dl', | ||
'dt', | ||
'em', | ||
'embed', | ||
'fieldset', | ||
'figcaption', | ||
'figure', | ||
'footer', | ||
'form', | ||
'h1', | ||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'head', | ||
'header', | ||
'hgroup', | ||
'hr', | ||
'html', | ||
'i', | ||
'iframe', | ||
'img', | ||
'input', | ||
'ins', | ||
'kbd', | ||
'keygen', | ||
'label', | ||
'legend', | ||
'li', | ||
'link', | ||
'main', | ||
'map', | ||
'mark', | ||
'menu', | ||
'menuitem', | ||
'meta', | ||
'meter', | ||
'nav', | ||
'noindex', | ||
'noscript', | ||
'object', | ||
'ol', | ||
'optgroup', | ||
'option', | ||
'output', | ||
'p', | ||
'param', | ||
'picture', | ||
'pre', | ||
'progress', | ||
'q', | ||
'rp', | ||
'rt', | ||
'ruby', | ||
's', | ||
'samp', | ||
'script', | ||
'section', | ||
'select', | ||
'slot', | ||
'small', | ||
'source', | ||
'span', | ||
'strong', | ||
'style', | ||
'sub', | ||
'summary', | ||
'sup', | ||
'table', | ||
'template', | ||
'tbody', | ||
'td', | ||
'textarea', | ||
'tfoot', | ||
'th', | ||
'thead', | ||
'time', | ||
'title', | ||
'tr', | ||
'track', | ||
'u', | ||
'ul', | ||
'var', | ||
'video', | ||
'wbr', | ||
'webview', | ||
]; | ||
const svgTags = new Set(svg); | ||
const htmlTags = new Set(html); | ||
const jsxPlugin = (babel) => { | ||
const { types: t } = babel; | ||
const svgNsAttribute = () => { | ||
const createNsAttribute = (val) => { | ||
return t.jSXAttribute( | ||
t.jSXIdentifier('__ns'), | ||
t.JSXExpressionContainer(t.numericLiteral(1)) | ||
t.JSXExpressionContainer(t.numericLiteral(val)) | ||
); | ||
@@ -72,3 +195,3 @@ }; | ||
if (svgTags.has(path.node.name.name)) { | ||
path.node.attributes.push(svgNsAttribute()); | ||
path.node.attributes.push(createNsAttribute(1)); | ||
} | ||
@@ -79,20 +202,21 @@ }, | ||
switch (attr.name) { | ||
case 'className': | ||
case 'classname': { | ||
attr.name = 'class'; | ||
break; | ||
if (htmlTags.has(path.parent.name.name)) { | ||
const name = attr.name.toLowerCase(); | ||
switch (name) { | ||
case 'classname': { | ||
attr.name = 'class'; | ||
return; | ||
} | ||
case 'htmlfor': { | ||
attr.name = 'for'; | ||
return; | ||
} | ||
} | ||
case 'htmlFor': | ||
case 'htmlfor': { | ||
attr.name = 'for'; | ||
break; | ||
if (attr.name.startsWith('on')) { | ||
attr.name = name; | ||
return; | ||
} | ||
} | ||
if (attr.name.startsWith('on')) { | ||
attr.name = attr.name.toLowerCase(); | ||
return; | ||
} | ||
} | ||
@@ -99,0 +223,0 @@ } |
{ | ||
"name": "jsx-dom-runtime", | ||
"version": "0.20.0", | ||
"version": "0.21.0", | ||
"description": "A tiny in 500 bytes library to JSX syntax templates for DOM", | ||
@@ -38,3 +38,3 @@ "type": "module", | ||
"size": "size-limit", | ||
"dev": "npm run lint && npm run build && npm test && npm run size" | ||
"dev": "npm run lint && npm run build && npx jest --clearCache && npm test && npm run size" | ||
}, | ||
@@ -41,0 +41,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
46874
1496