diff --git a/lib/react-jsx-parser.min.js b/lib/react-jsx-parser.min.js index fc54c06..8c2abbd 100644 --- a/lib/react-jsx-parser.min.js +++ b/lib/react-jsx-parser.min.js @@ -23,18 +23,18 @@ case"Identifier":return(i.props.bindings||{})[t.name] case"JSXExpressionContainer":return i.parseExpression(t.expression) case"Literal":return t.value case"MemberExpression":return(i.parseExpression(t.object)||{})[t.property.name] -default:return}},i.parseElement=function(t){var e=i.props.components,s=void 0===e?{}:e,r=t.children,n=void 0===r?[]:r,a=t.openingElement,h=a.attributes,p=void 0===h?[]:h,u=a.name -u=void 0===u?{}:u -var f=u.name,y=(i.props.blacklistedAttrs||[]).map(function(t){return t instanceof RegExp?t:new RegExp(t,"i")}),v=(i.props.blacklistedTags||[]).map(function(t){return t.trim().toLowerCase()}).filter(Boolean) -if(/^(html|head|body)$/i.test(f))return n.map(function(t){return i.parseElement(t)}) -if(-1===v.indexOf(f.trim().toLowerCase())){var g=void 0 -if(s[f]||(0,x.canHaveChildren)(f))if(g=n.map(i.parseExpression),s[f]||(0,x.canHaveWhitespace)(f)||(g=g.filter(function(t){return"string"!=typeof t||!/^\s*$/.test(t)})),0===g.length)g=void 0 -else if(1===g.length){var b=g,k=o(b,1) -g=k[0]}var E={key:(0,d.randomHash)()} -return p.forEach(function(t){var e=t.name.name,s=m.default[e]||e,r=i.parseExpression(t) -0===y.filter(function(t){return t.test(s)}).length&&(E[s]=r)}),"string"==typeof E.style&&(E.style=(0,l.default)(E.style)),g&&(E.children=g),c.default.createElement(s[f]||f.toLowerCase(),E)}},i.render=function(){var t=(i.props.jsx||"").trim().replace(/]*)>/g,"") +default:return}},i.parseElement=function(t){var e=i.props,s=e.components,r=void 0===s?{}:s,n=e.componentsOnly,a=t.children,h=void 0===a?[]:a,p=t.openingElement,u=p.attributes,f=void 0===u?[]:u,y=p.name +y=void 0===y?{}:y +var v=y.name,g=(i.props.blacklistedAttrs||[]).map(function(t){return t instanceof RegExp?t:new RegExp(t,"i")}),b=(i.props.blacklistedTags||[]).map(function(t){return t.trim().toLowerCase()}).filter(Boolean) +if(/^(html|head|body)$/i.test(v))return h.map(function(t){return i.parseElement(t)}) +if(-1===b.indexOf(v.trim().toLowerCase())&&(!n||r[v])){var k=void 0 +if(r[v]||(0,x.canHaveChildren)(v))if(k=h.map(i.parseExpression),r[v]||(0,x.canHaveWhitespace)(v)||(k=k.filter(function(t){return"string"!=typeof t||!/^\s*$/.test(t)})),0===k.length)k=void 0 +else if(1===k.length){var E=k,w=o(E,1) +k=w[0]}var A={key:(0,d.randomHash)()} +return f.forEach(function(t){var e=t.name.name,s=m.default[e]||e,r=i.parseExpression(t) +0===g.filter(function(t){return t.test(s)}).length&&(A[s]=r)}),"string"==typeof A.style&&(A.style=(0,l.default)(A.style)),k&&(A.children=k),c.default.createElement(r[v]||v.toLowerCase(),A)}},i.render=function(){var t=(i.props.jsx||"").trim().replace(/]*)>/g,"") return i.ParsedChildren=i.parseJSX(t),i.props.renderInWrapper?c.default.createElement("div",{className:"jsx-parser"},i.ParsedChildren):c.default.createElement(p.Fragment,null,i.ParsedChildren)},a=s,n(i,a)}return a(e,t),e}(p.Component) -v.defaultProps={bindings:{},blacklistedAttrs:[/^on.+/i],blacklistedTags:["script"],components:[],jsx:"",onError:function(){},showWarnings:!1,renderInWrapper:!0},v.displayName="JsxParser",e.default=v},function(t,e,s){"use strict" +v.defaultProps={bindings:{},blacklistedAttrs:[/^on.+/i],blacklistedTags:["script"],components:[],componentsOnly:!1,jsx:"",onError:function(){},showWarnings:!1,renderInWrapper:!0},v.displayName="JsxParser",e.default=v},function(t,e,s){"use strict" t.exports=s(2)(s(4))},function(t,e,s){"use strict" var i=s(3),r=/^[\da-fA-F]+$/,n=/^\d+$/ t.exports=function(t){function e(t){return t?"JSXIdentifier"===t.type?t.name:"JSXNamespacedName"===t.type?t.namespace.name+":"+t.name.name:"JSXMemberExpression"===t.type?e(t.object)+"."+e(t.property):void 0:t}var s=t.tokTypes,a=t.tokContexts diff --git a/package.json b/package.json index 90f75cf..c43b322 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-jsx-parser", - "version": "1.3.1", + "version": "1.3.2", "description": "A React component which can parse JSX and output rendered React Components", "main": "lib/react-jsx-parser.min.js", "author": "Troy Alford", @@ -23,6 +23,7 @@ "babel-preset-env": "^1.6.1", "babel-preset-jest": "^22.0.3", "babel-preset-react": "^6.22.0", + "cross-env": "^5.1.4", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "eslint": "^4.14.0", @@ -32,16 +33,17 @@ "eslint-plugin-react": "^7.5.1", "jest": "^22.0.4", "jest-cli": "^22.0.4", + "mkdirp": "^0.5.1", "prop-types": "^15.6.0", "react-dom": "^16.2.0", "source-map-explorer": "^1.5.0", "webpack": "^3.10.0" }, "scripts": { - "build": "yarn prebuild && NODE_ENV=production webpack", - "inspect-sourcemap": "NODE_ENV=production SOURCEMAP=true webpack && source-map-explorer ./lib/react-jsx-parser.min.js", + "build": "yarn prebuild && cross-env NODE_ENV=production webpack", + "inspect-sourcemap": "cross-env NODE_ENV=production SOURCEMAP=true webpack && source-map-explorer ./lib/react-jsx-parser.min.js", "postversion": "git push origin HEAD && git push origin HEAD --tags", - "prebuild": "mkdir -p ./lib && rm -rf ./lib/*", + "prebuild": "mkdirp ./lib && rm -rf ./lib/*", "preversion": "yarn test", "test": "jest", "version": "yarn build && git add -A ./lib"