diff --git a/lib/react-jsx-parser.min.js b/lib/react-jsx-parser.min.js index 9d8ec7e..86a777c 100644 --- a/lib/react-jsx-parser.min.js +++ b/lib/react-jsx-parser.min.js @@ -1,57 +1,535 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define("react-jsx-parser",["react"],t):"object"==typeof exports?exports["react-jsx-parser"]=t(require("react")):e["react-jsx-parser"]=t(e.react)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports -var o=r[n]={i:n,l:!1,exports:{}} -return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={} -return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e} -return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict" -function n(e){return e.replace(/([A-Z])([A-Z])/g,"$1 $2").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[^a-zA-Z\u00C0-\u00ff]/g," ").toLowerCase().split(" ").filter(function(e){return e}).map(function(e,t){return t>0?e[0].toUpperCase()+e.slice(1):e}).join("")}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t,r){"use strict" -function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called") -return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t) -e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}) -var s=Object.assign||function(e){for(var t=1;t "+t.nodeValue)} -t.forEach(function(e){return r(e," ")})},N=function(e){function t(e){a(this,t) -var r=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)) -return r.parseJSX.bind(r),r.parseNode.bind(r),r.ParsedChildren=r.parseJSX(e.jsx||""),r}return u(t,e),c(t,[{key:"componentWillReceiveProps",value:function(e){this.ParsedChildren=this.parseJSX(e.jsx||"")}},{key:"parseJSX",value:function(e){if(!e||"string"!=typeof e)return[] -var t=this.props.blacklistedTags.reduce(function(e,t){return e.replace(new RegExp("(\n"+t+"",n=_.parseFromString(r,"application/xhtml+xml") -if(!n)return[] -Array.from(n.getElementsByTagName("REMOVE")).forEach(function(e){return e.parentNode.removeChild(e)}) -var o=n.getElementsByTagName("body")[0] -return o&&"parseerror"!==o.nodeName.toLowerCase()?this.parseNode(o.childNodes||[],this.props.components):(this.props.showWarnings&&x(n),[])}},{key:"parseNode",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2] -if(e instanceof NodeList||Array.isArray(e))return Array.from(e).map(function(e,n){return t.parseNode(e,r,n)}).filter(Boolean) -if(e.nodeType===E.default.TEXT)return("textContent"in e?e.textContent:e.nodeValue||"").replace(/[\r\n\t\f\v]/g,"").replace(/\s{2,}/g," ") -if(e.nodeType===E.default.ELEMENT){var o=void 0 -return(0,T.canHaveChildren)(e.nodeName)&&(o=this.parseNode(e.childNodes,r),(0,T.canHaveWhitespace)(e.nodeName)||(o=o.filter(function(e){return"string"!=typeof e||!e.match(/^\s*$/)}))),l.default.createElement(r[e.nodeName]||e.nodeName,s({},this.props.bindings||{},this.parseAttrs(e.attributes,n)),o)}return this.props.showWarnings&&console.warn("JsxParser encountered a(n) "+E.default[e.nodeType]+" node, and discarded it."),null}},{key:"parseAttrs",value:function(e,t){if(!e||!e.length)return{key:t} -var r=this.props.blacklistedAttrs -return Array.from(e).filter(function(e){return!r.map(function(t){return e.name.match(new RegExp(t,"gi"))}).filter(function(e){return null!==e}).length}).reduce(function(e,t){var r=t.name,n=t.value -return""===n&&(n=!0),r.match(/^on/i)?n=new Function(n):"style"===r&&(n=(0,m.default)(n)),r=g.default[r.toLowerCase()]||(0,d.default)(r),s({},e,o({},r,n))},{key:t})}},{key:"render",value:function(){return l.default.createElement("div",{className:"jsx-parser"},this.ParsedChildren)}}]),t}(f.Component) -t.default=N,N.defaultProps={bindings:{},blacklistedAttrs:["on[a-z]*"],blacklistedTags:["script"],components:[],jsx:"",showWarnings:!1} -r(8)},function(t,r){t.exports=e},function(e,t,r){"use strict" -function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e){switch(void 0===e?"undefined":i(e)){case"string":return e.split(";").filter(function(e){return e}).reduce(function(e,t){var r=t.slice(0,t.indexOf(":")).trim(),o=t.slice(t.indexOf(":")+1).trim() -return a({},e,n({},(0,s.default)(r),o))},{}) -case"object":return e -default:return}}Object.defineProperty(t,"__esModule",{value:!0}) -var a=Object.assign||function(e){for(var t=1;t/.test(e)&&/<(\/?|!?)html>/.test(e)&&/<(\/?|!?)head>/.test(e)&&/<(\/?|!?)body>/.test(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t,r){"use strict" -Object.defineProperty(t,"__esModule",{value:!0}),t.default={class:"className",for:"htmlFor",maxlength:"maxLength",colspan:"colSpan",rowspan:"rowSpan"}},function(e,t,r){"use strict" -Object.defineProperty(t,"__esModule",{value:!0}),t.default={ELEMENT:1,TEXT:3,PROCESSING_INSTRUCTION:7,COMMENT:8,DOCUMENT:9,DOCUMENT_TYPE:10,DOCUMENT_FRAGMENT:11,1:"Element",3:"Text",7:"Processing Instruction",8:"Comment",9:"Document",10:"Document Type",11:"Document Fragment",ATTRIBUTE:2,CDATA:4,XML_ENTITY_REFERENCE:5,XML_ENTITY:6,XML_NOTATION:12,2:"Attribute (Deprecated)",4:"CData (Deprecated)",5:"XML Entity Reference (Deprecated)",6:"XML Entity (Deprecated)",12:"XML Notation (Deprecated)"}},function(e,t,r){"use strict" -function n(e){return-1===a.indexOf(e.toLowerCase())}function o(e){return-1!==i.indexOf(e.toLowerCase())}Object.defineProperty(t,"__esModule",{value:!0}),t.canHaveChildren=n,t.canHaveWhitespace=o -var a=["area","base","br","col","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],i=["table","tbody","tfoot","thead","tr"] -t.default=a},function(e,t,r){e.exports=r(9)()},function(e,t,r){"use strict" -var n=r(10),o=r(11),a=r(12) -e.exports=function(){function e(e,t,r,n,i,u){u!==a&&o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e -var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t} -return r.checkPropTypes=n,r.PropTypes=r,r}},function(e,t,r){"use strict" -function n(e){return function(){return e}}var o=function(){} -o.thatReturns=n,o.thatReturnsFalse=n(!1),o.thatReturnsTrue=n(!0),o.thatReturnsNull=n(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e},e.exports=o},function(e,t,r){"use strict" -function n(e,t,r,n,a,i,u,s){if(o(t),!e){var c -if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.") -else{var f=[r,n,a,i,u,s],l=0 -c=new Error(t.replace(/%s/g,function(){return f[l++]})),c.name="Invariant Violation"}throw c.framesToPop=1,c}}var o=function(e){} -e.exports=n},function(e,t,r){"use strict" -e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}])}) +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define("react-jsx-parser",["react"],e):"object"==typeof exports?exports["react-jsx-parser"]=e(require("react")):t["react-jsx-parser"]=e(t.react)}(this,function(t){return function(t){function e(i){if(s[i])return s[i].exports +var r=s[i]={i:i,l:!1,exports:{}} +return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var s={} +return e.m=t,e.c=s,e.d=function(t,s,i){e.o(t,s)||Object.defineProperty(t,s,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var s=t&&t.__esModule?function(){return t.default}:function(){return t} +return e.d(s,"a",s),s},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,s){"use strict" +function i(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called") +return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e) +t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}) +var o=Object.assign||function(t){for(var e=1;e]*)>/g,"") +this.ParsedChildren=this.parseJSX(e)}},{key:"parseJSX",value:function(t){var e=""+t+"",s=[] +try{s=new p.Parser(y,e).parse(),s=s.body[0].expression.children||[]}catch(t){return this.props.showWarnings&&console.warn(t),[]}return s.map(this.parseExpression).filter(Boolean)}},{key:"parseExpression",value:function(t,e){var s=this,i=t.value +switch(t.type){case"JSXElement":return this.parseElement(t,e) +case"JSXText":return(i||"").replace(/\s+/g," ") +case"JSXAttribute":return null===t.value||this.parseExpression(t.value) +case"ArrayExpression":return t.elements.map(this.parseExpression) +case"ObjectExpression":var r={} +return t.properties.forEach(function(t){r[t.key.name]=s.parseExpression(t.value)}),r +case"JsxExpressionContainer":return this.parseExpression(t.expression) +case"Literal":return i +default:return}}},{key:"parseElement",value:function(t,e){var s=this,i=this.props,r=i.bindings,n=void 0===r?{}:r,a=i.components,h=void 0===a?{}:a,p=t.children,c=void 0===p?[]:p,u=t.openingElement,f=u.attributes,y=u.name.name +if(/^(html|head|body)$/i.test(y))return c.map(function(t){return s.parseElement(t)}) +if(-1===this.blacklistedTags.indexOf(y.trim().toLowerCase())){var v=void 0;(0,x.canHaveChildren)(y)&&(v=c.map(this.parseExpression),(0,x.canHaveWhitespace)(y)||(v=v.filter(function(t){return"string"!=typeof t||!/^\s*$/.test(t)}))) +var b=o({key:e},n) +return f.forEach(function(t){var e=t.name.name,i=m.default[e]||e,r=s.parseExpression(t) +0===s.blacklistedAttrs.filter(function(t){return t.test(i)}).length&&(b[i]=r)}),"string"==typeof b.style&&(b.style=(0,d.default)(b.style)),l.default.createElement(h[y]||y,b,v)}}},{key:"render",value:function(){return l.default.createElement("div",{className:"jsx-parser"},this.ParsedChildren)}}]),e}(c.Component) +e.default=v,v.defaultProps={bindings:{},blacklistedAttrs:[/^on.+/i],blacklistedTags:["script"],components:[],jsx:"",showWarnings:!1}},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"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}var s=t.tokTypes,a=t.tokContexts +a.j_oTag=new t.TokContext("...",!0,!0),s.jsxName=new t.TokenType("jsxName"),s.jsxText=new t.TokenType("jsxText",{beforeExpr:!0}),s.jsxTagStart=new t.TokenType("jsxTagStart"),s.jsxTagEnd=new t.TokenType("jsxTagEnd"),s.jsxTagStart.updateContext=function(){this.context.push(a.j_expr),this.context.push(a.j_oTag),this.exprAllowed=!1},s.jsxTagEnd.updateContext=function(t){var e=this.context.pop() +e===a.j_oTag&&t===s.slash||e===a.j_cTag?(this.context.pop(),this.exprAllowed=this.curContext()===a.j_expr):this.exprAllowed=!0} +var o=t.Parser.prototype +return o.jsx_readToken=function(){for(var e="",i=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated JSX contents") +var r=this.input.charCodeAt(this.pos) +switch(r){case 60:case 123:return this.pos===this.start?60===r&&this.exprAllowed?(++this.pos,this.finishToken(s.jsxTagStart)):this.getTokenFromCode(r):(e+=this.input.slice(i,this.pos),this.finishToken(s.jsxText,e)) +case 38:e+=this.input.slice(i,this.pos),e+=this.jsx_readEntity(),i=this.pos +break +default:t.isNewLine(r)?(e+=this.input.slice(i,this.pos),e+=this.jsx_readNewLine(!0),i=this.pos):++this.pos}}},o.jsx_readNewLine=function(t){var e,s=this.input.charCodeAt(this.pos) +return++this.pos,13===s&&10===this.input.charCodeAt(this.pos)?(++this.pos,e=t?"\n":"\r\n"):e=String.fromCharCode(s),this.options.locations&&(++this.curLine,this.lineStart=this.pos),e},o.jsx_readString=function(e){for(var i="",r=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant") +var n=this.input.charCodeAt(this.pos) +if(n===e)break +38===n?(i+=this.input.slice(r,this.pos),i+=this.jsx_readEntity(),r=this.pos):t.isNewLine(n)?(i+=this.input.slice(r,this.pos),i+=this.jsx_readNewLine(!1),r=this.pos):++this.pos}return i+=this.input.slice(r,this.pos++),this.finishToken(s.string,i)},o.jsx_readEntity=function(){var t,e="",s=0,a=this.input[this.pos] +"&"!==a&&this.raise(this.pos,"Entity must start with an ampersand") +for(var o=++this.pos;this.pos")}return r.openingElement=a,r.closingElement=o,r.children=n,this.type===s.relational&&"<"===this.value&&this.raise(this.start,"Adjacent JSX elements must be wrapped in an enclosing tag"),this.finishNode(r,"JSXElement")},o.jsx_parseText=function(t){var e=this.parseLiteral(t) +return e.type="JSXText",e},o.jsx_parseElement=function(){var t=this.start,e=this.startLoc +return this.next(),this.jsx_parseElementAt(t,e)},t.plugins.jsx=function(e,i){i&&("object"!=typeof i&&(i={}),e.options.plugins.jsx={allowNamespaces:!1!==i.allowNamespaces,allowNamespacedObjects:!!i.allowNamespacedObjects},e.extend("parseExprAtom",function(t){return function(e){return this.type===s.jsxText?this.jsx_parseText(this.value):this.type===s.jsxTagStart?this.jsx_parseElement():t.call(this,e)}}),e.extend("readToken",function(e){return function(i){var r=this.curContext() +if(r===a.j_expr)return this.jsx_readToken() +if(r===a.j_oTag||r===a.j_cTag){if(t.isIdentifierStart(i))return this.jsx_readWord() +if(62==i)return++this.pos,this.finishToken(s.jsxTagEnd) +if((34===i||39===i)&&r==a.j_oTag)return this.jsx_readString(i)}return 60===i&&this.exprAllowed&&33!==this.input.charCodeAt(this.pos+1)?(++this.pos,this.finishToken(s.jsxTagStart)):e.call(this,i)}}),e.extend("updateContext",function(t){return function(e){if(this.type==s.braceL){var i=this.curContext() +i==a.j_oTag?this.context.push(a.b_expr):i==a.j_expr?this.context.push(a.b_tmpl):t.call(this,e),this.exprAllowed=!0}else{if(this.type!==s.slash||e!==s.jsxTagStart)return t.call(this,e) +this.context.length-=2,this.context.push(a.j_cTag),this.exprAllowed=!1}}}))},t}},function(t,e){t.exports={quot:'"',amp:"&",apos:"'",lt:"<",gt:">",nbsp:" ",iexcl:"¡",cent:"¢",pound:"£",curren:"¤",yen:"¥",brvbar:"¦",sect:"§",uml:"¨",copy:"©",ordf:"ª",laquo:"«",not:"¬",shy:"­",reg:"®",macr:"¯",deg:"°",plusmn:"±",sup2:"²",sup3:"³",acute:"´",micro:"µ",para:"¶",middot:"·",cedil:"¸",sup1:"¹",ordm:"º",raquo:"»",frac14:"¼",frac12:"½",frac34:"¾",iquest:"¿",Agrave:"À",Aacute:"Á",Acirc:"Â",Atilde:"Ã",Auml:"Ä",Aring:"Å",AElig:"Æ",Ccedil:"Ç",Egrave:"È",Eacute:"É",Ecirc:"Ê",Euml:"Ë",Igrave:"Ì",Iacute:"Í",Icirc:"Î",Iuml:"Ï",ETH:"Ð",Ntilde:"Ñ",Ograve:"Ò",Oacute:"Ó",Ocirc:"Ô",Otilde:"Õ",Ouml:"Ö",times:"×",Oslash:"Ø",Ugrave:"Ù",Uacute:"Ú",Ucirc:"Û",Uuml:"Ü",Yacute:"Ý",THORN:"Þ",szlig:"ß",agrave:"à",aacute:"á",acirc:"â",atilde:"ã",auml:"ä",aring:"å",aelig:"æ",ccedil:"ç",egrave:"è",eacute:"é",ecirc:"ê",euml:"ë",igrave:"ì",iacute:"í",icirc:"î",iuml:"ï",eth:"ð",ntilde:"ñ",ograve:"ò",oacute:"ó",ocirc:"ô",otilde:"õ",ouml:"ö",divide:"÷",oslash:"ø",ugrave:"ù",uacute:"ú",ucirc:"û",uuml:"ü",yacute:"ý",thorn:"þ",yuml:"ÿ",OElig:"Œ",oelig:"œ",Scaron:"Š",scaron:"š",Yuml:"Ÿ",fnof:"ƒ",circ:"ˆ",tilde:"˜",Alpha:"Α",Beta:"Β",Gamma:"Γ",Delta:"Δ",Epsilon:"Ε",Zeta:"Ζ",Eta:"Η",Theta:"Θ",Iota:"Ι",Kappa:"Κ",Lambda:"Λ",Mu:"Μ",Nu:"Ν",Xi:"Ξ",Omicron:"Ο",Pi:"Π",Rho:"Ρ",Sigma:"Σ",Tau:"Τ",Upsilon:"Υ",Phi:"Φ",Chi:"Χ",Psi:"Ψ",Omega:"Ω",alpha:"α",beta:"β",gamma:"γ",delta:"δ",epsilon:"ε",zeta:"ζ",eta:"η",theta:"θ",iota:"ι",kappa:"κ",lambda:"λ",mu:"μ",nu:"ν",xi:"ξ",omicron:"ο",pi:"π",rho:"ρ",sigmaf:"ς",sigma:"σ",tau:"τ",upsilon:"υ",phi:"φ",chi:"χ",psi:"ψ",omega:"ω",thetasym:"ϑ",upsih:"ϒ",piv:"ϖ",ensp:" ",emsp:" ",thinsp:" ",zwnj:"‌",zwj:"‍",lrm:"‎",rlm:"‏",ndash:"–",mdash:"—",lsquo:"‘",rsquo:"’",sbquo:"‚",ldquo:"“",rdquo:"”",bdquo:"„",dagger:"†",Dagger:"‡",bull:"•",hellip:"…",permil:"‰",prime:"′",Prime:"″",lsaquo:"‹",rsaquo:"›",oline:"‾",frasl:"⁄",euro:"€",image:"ℑ",weierp:"℘",real:"ℜ",trade:"™",alefsym:"ℵ",larr:"←",uarr:"↑",rarr:"→",darr:"↓",harr:"↔",crarr:"↵",lArr:"⇐",uArr:"⇑",rArr:"⇒",dArr:"⇓",hArr:"⇔",forall:"∀",part:"∂",exist:"∃",empty:"∅",nabla:"∇",isin:"∈",notin:"∉",ni:"∋",prod:"∏",sum:"∑",minus:"−",lowast:"∗",radic:"√",prop:"∝",infin:"∞",ang:"∠",and:"∧",or:"∨",cap:"∩",cup:"∪",int:"∫",there4:"∴",sim:"∼",cong:"≅",asymp:"≈",ne:"≠",equiv:"≡",le:"≤",ge:"≥",sub:"⊂",sup:"⊃",nsub:"⊄",sube:"⊆",supe:"⊇",oplus:"⊕",otimes:"⊗",perp:"⊥",sdot:"⋅",lceil:"⌈",rceil:"⌉",lfloor:"⌊",rfloor:"⌋",lang:"〈",rang:"〉",loz:"◊",spades:"♠",clubs:"♣",hearts:"♥",diams:"♦"}},function(t,e,s){!function(t,s){s(e)}(0,function(t){"use strict" +function e(t,e){for(var s=65536,i=0;it)return!1 +if((s+=e[i+1])>=t)return!0}}function s(t,s){return t<65?36===t:t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&A.test(String.fromCharCode(t)):!1!==s&&e(t,C)))}function i(t,s){return t<48?36===t:t<58||!(t<65)&&(t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&S.test(String.fromCharCode(t)):!1!==s&&(e(t,C)||e(t,_)))))}function r(t,e){return new N(t,{beforeExpr:!0,binop:e})}function n(t,e){return void 0===e&&(e={}),e.keyword=t,P[t]=new N(t,e)}function a(t){return 10===t||13===t||8232===t||8233===t}function o(t,e){return M.call(t,e)}function h(t,e){for(var s=1,i=0;;){R.lastIndex=i +var r=R.exec(t) +if(!(r&&r.index=2015&&(e.ecmaVersion-=2009),null==e.allowReserved&&(e.allowReserved=e.ecmaVersion<5),B(e.onToken)){var i=e.onToken +e.onToken=function(t){return i.push(t)}}return B(e.onComment)&&(e.onComment=c(e,e.onComment)),e}function c(t,e){return function(s,i,r,n,a,o){var h={type:s?"Block":"Line",value:i,start:r,end:n} +t.locations&&(h.loc=new X(this,a,o)),t.ranges&&(h.range=[r,n]),e.push(h)}}function l(t){return new RegExp("^("+t.replace(/ /g,"|")+")$")}function u(t,e,s,i){return t.type=e,t.end=s,this.options.locations&&(t.loc.end=i),this.options.ranges&&(t.range[1]=s),t}function d(t,e,s,i){try{return new RegExp(t,e)}catch(t){if(void 0!==s)throw t instanceof SyntaxError&&i.raise(s,"Error parsing regular expression: "+t.message),t}}function f(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function m(t,e){return new W(e,t).parse()}function x(t,e,s){var i=new W(s,t,e) +return i.nextToken(),i.parseExpression()}function y(t,e){return new W(e,t)}function v(e,s,i){t.parse_dammit=e,t.LooseParser=s,t.pluginsLoose=i}var b={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},g="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",k={5:g,6:g+" const class extends export import super"},E="ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢴࢶ-ࢽऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-ᲈᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿕ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞮꞰ-ꞷꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",w="‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣔ-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_",A=new RegExp("["+E+"]"),S=new RegExp("["+E+w+"]") +E=w=null +var C=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541],_=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239],N=function(t,e){void 0===e&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null},T={beforeExpr:!0},L={startsExpr:!0},P={},j={num:new N("num",L),regexp:new N("regexp",L),string:new N("string",L),name:new N("name",L),eof:new N("eof"),bracketL:new N("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new N("]"),braceL:new N("{",{beforeExpr:!0,startsExpr:!0}),braceR:new N("}"),parenL:new N("(",{beforeExpr:!0,startsExpr:!0}),parenR:new N(")"),comma:new N(",",T),semi:new N(";",T),colon:new N(":",T),dot:new N("."),question:new N("?",T),arrow:new N("=>",T),template:new N("template"),ellipsis:new N("...",T),backQuote:new N("`",L),dollarBraceL:new N("${",{beforeExpr:!0,startsExpr:!0}),eq:new N("=",{beforeExpr:!0,isAssign:!0}),assign:new N("_=",{beforeExpr:!0,isAssign:!0}),incDec:new N("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new N("prefix",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:r("||",1),logicalAND:r("&&",2),bitwiseOR:r("|",3),bitwiseXOR:r("^",4),bitwiseAND:r("&",5),equality:r("==/!=",6),relational:r("",7),bitShift:r("<>",8),plusMin:new N("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:r("%",10),star:r("*",10),slash:r("/",10),starstar:new N("**",{beforeExpr:!0}),_break:n("break"),_case:n("case",T),_catch:n("catch"),_continue:n("continue"),_debugger:n("debugger"),_default:n("default",T),_do:n("do",{isLoop:!0,beforeExpr:!0}),_else:n("else",T),_finally:n("finally"),_for:n("for",{isLoop:!0}),_function:n("function",L),_if:n("if"),_return:n("return",T),_switch:n("switch"),_throw:n("throw",T),_try:n("try"),_var:n("var"),_const:n("const"),_while:n("while",{isLoop:!0}),_with:n("with"),_new:n("new",{beforeExpr:!0,startsExpr:!0}),_this:n("this",L),_super:n("super",L),_class:n("class"),_extends:n("extends",T),_export:n("export"),_import:n("import"),_null:n("null",L),_true:n("true",L),_false:n("false",L),_in:n("in",{beforeExpr:!0,binop:7}),_instanceof:n("instanceof",{beforeExpr:!0,binop:7}),_typeof:n("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:n("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:n("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},I=/\r\n?|\n|\u2028|\u2029/,R=new RegExp(I.source,"g"),O=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/,V=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,F=Object.prototype,M=F.hasOwnProperty,D=F.toString,B=Array.isArray||function(t){return"[object Array]"===D.call(t)},q=function(t,e){this.line=t,this.column=e} +q.prototype.offset=function(t){return new q(this.line,this.column+t)} +var X=function(t,e,s){this.start=e,this.end=s,null!==t.sourceFile&&(this.source=t.sourceFile)},z={ecmaVersion:7,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowHashBang:!1,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1,plugins:{}},J={},W=function(t,e,s){this.options=t=p(t),this.sourceFile=t.sourceFile,this.keywords=l(k[t.ecmaVersion>=6?6:5]) +var i="" +if(!t.allowReserved){for(var r=t.ecmaVersion;!(i=b[r]);r--);"module"==t.sourceType&&(i+=" await")}this.reservedWords=l(i) +var n=(i?i+" ":"")+b.strict +this.reservedWordsStrict=l(n),this.reservedWordsStrictBind=l(n+" "+b.strictBind),this.input=String(e),this.containsEsc=!1,this.loadPlugins(t.plugins),s?(this.pos=s,this.lineStart=this.input.lastIndexOf("\n",s-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(I).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=j.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule="module"===t.sourceType,this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.inFunction=this.inGenerator=this.inAsync=!1,this.yieldPos=this.awaitPos=0,this.labels=[],0===this.pos&&t.allowHashBang&&"#!"===this.input.slice(0,2)&&this.skipLineComment(2),this.scopeStack=[],this.enterFunctionScope()} +W.prototype.isKeyword=function(t){return this.keywords.test(t)},W.prototype.isReservedWord=function(t){return this.reservedWords.test(t)},W.prototype.extend=function(t,e){this[t]=e(this[t])},W.prototype.loadPlugins=function(t){var e=this +for(var s in t){var i=J[s] +if(!i)throw new Error("Plugin '"+s+"' not found") +i(e,t[s])}},W.prototype.parse=function(){var t=this.options.program||this.startNode() +return this.nextToken(),this.parseTopLevel(t)} +var U=W.prototype,G=/^(?:'((?:[^']|\.)*)'|"((?:[^"]|\.)*)"|;)/ +U.strictDirective=function(t){for(var e=this;;){V.lastIndex=t,t+=V.exec(e.input)[0].length +var s=G.exec(e.input.slice(t)) +if(!s)return!1 +if("use strict"==(s[1]||s[2]))return!0 +t+=s[0].length}},U.eat=function(t){return this.type===t&&(this.next(),!0)},U.isContextual=function(t){return this.type===j.name&&this.value===t},U.eatContextual=function(t){return this.value===t&&this.eat(j.name)},U.expectContextual=function(t){this.eatContextual(t)||this.unexpected()},U.canInsertSemicolon=function(){return this.type===j.eof||this.type===j.braceR||I.test(this.input.slice(this.lastTokEnd,this.start))},U.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},U.semicolon=function(){this.eat(j.semi)||this.insertSemicolon()||this.unexpected()},U.afterTrailingComma=function(t,e){if(this.type==t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0},U.expect=function(t){this.eat(t)||this.unexpected()},U.unexpected=function(t){this.raise(null!=t?t:this.start,"Unexpected token")} +var $=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=-1} +U.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element") +var s=e?t.parenthesizedAssign:t.parenthesizedBind +s>-1&&this.raiseRecoverable(s,"Parenthesized pattern")}},U.checkExpressionErrors=function(t,e){var s=t?t.shorthandAssign:-1 +if(!e)return s>=0 +s>-1&&this.raise(s,"Shorthand property assignments are valid only in destructuring patterns")},U.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos=6&&(t.sourceType=this.options.sourceType),this.finishNode(t,"Program")} +var Y={kind:"loop"},Q={kind:"switch"} +H.isLet=function(){if(this.type!==j.name||this.options.ecmaVersion<6||"let"!=this.value)return!1 +V.lastIndex=this.pos +var t=V.exec(this.input),e=this.pos+t[0].length,r=this.input.charCodeAt(e) +if(91===r||123==r)return!0 +if(s(r,!0)){for(var n=e+1;i(this.input.charCodeAt(n),!0);)++n +var a=this.input.slice(e,n) +if(!this.isKeyword(a))return!0}return!1},H.isAsyncFunction=function(){if(this.type!==j.name||this.options.ecmaVersion<8||"async"!=this.value)return!1 +V.lastIndex=this.pos +var t=V.exec(this.input),e=this.pos+t[0].length +return!(I.test(this.input.slice(this.pos,e))||"function"!==this.input.slice(e,e+8)||e+8!=this.input.length&&i(this.input.charAt(e+8)))},H.parseStatement=function(t,e,s){var i,r=this.type,n=this.startNode() +switch(this.isLet()&&(r=j._var,i="let"),r){case j._break:case j._continue:return this.parseBreakContinueStatement(n,r.keyword) +case j._debugger:return this.parseDebuggerStatement(n) +case j._do:return this.parseDoStatement(n) +case j._for:return this.parseForStatement(n) +case j._function:return!t&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(n,!1) +case j._class:return t||this.unexpected(),this.parseClass(n,!0) +case j._if:return this.parseIfStatement(n) +case j._return:return this.parseReturnStatement(n) +case j._switch:return this.parseSwitchStatement(n) +case j._throw:return this.parseThrowStatement(n) +case j._try:return this.parseTryStatement(n) +case j._const:case j._var:return i=i||this.value,t||"var"==i||this.unexpected(),this.parseVarStatement(n,i) +case j._while:return this.parseWhileStatement(n) +case j._with:return this.parseWithStatement(n) +case j.braceL:return this.parseBlock() +case j.semi:return this.parseEmptyStatement(n) +case j._export:case j._import:return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"'import' and 'export' may only appear at the top level"),this.inModule||this.raise(this.start,"'import' and 'export' may appear only with 'sourceType: module'")),r===j._import?this.parseImport(n):this.parseExport(n,s) +default:if(this.isAsyncFunction()&&t)return this.next(),this.parseFunctionStatement(n,!0) +var a=this.value,o=this.parseExpression() +return r===j.name&&"Identifier"===o.type&&this.eat(j.colon)?this.parseLabeledStatement(n,a,o):this.parseExpressionStatement(n,o)}},H.parseBreakContinueStatement=function(t,e){var s=this,i="break"==e +this.next(),this.eat(j.semi)||this.insertSemicolon()?t.label=null:this.type!==j.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon()) +for(var r=0;r=6?this.eat(j.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")},H.parseForStatement=function(t){if(this.next(),this.labels.push(Y),this.enterLexicalScope(),this.expect(j.parenL),this.type===j.semi)return this.parseFor(t,null) +var e=this.isLet() +if(this.type===j._var||this.type===j._const||e){var s=this.startNode(),i=e?"let":this.value +return this.next(),this.parseVar(s,!0,i),this.finishNode(s,"VariableDeclaration"),!(this.type===j._in||this.options.ecmaVersion>=6&&this.isContextual("of"))||1!==s.declarations.length||"var"!==i&&s.declarations[0].init?this.parseFor(t,s):this.parseForIn(t,s)}var r=new $,n=this.parseExpression(!0,r) +return this.type===j._in||this.options.ecmaVersion>=6&&this.isContextual("of")?(this.toAssignable(n),this.checkLVal(n),this.checkPatternErrors(r,!0),this.parseForIn(t,n)):(this.checkExpressionErrors(r,!0),this.parseFor(t,n))},H.parseFunctionStatement=function(t,e){return this.next(),this.parseFunction(t,!0,!1,e)},H.isFunction=function(){return this.type===j._function||this.isAsyncFunction()},H.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement(!this.strict&&this.isFunction()),t.alternate=this.eat(j._else)?this.parseStatement(!this.strict&&this.isFunction()):null,this.finishNode(t,"IfStatement")},H.parseReturnStatement=function(t){return this.inFunction||this.options.allowReturnOutsideFunction||this.raise(this.start,"'return' outside of function"),this.next(),this.eat(j.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")},H.parseSwitchStatement=function(t){var e=this +this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(j.braceL),this.labels.push(Q),this.enterLexicalScope() +for(var s,i=!1;this.type!=j.braceR;)if(e.type===j._case||e.type===j._default){var r=e.type===j._case +s&&e.finishNode(s,"SwitchCase"),t.cases.push(s=e.startNode()),s.consequent=[],e.next(),r?s.test=e.parseExpression():(i&&e.raiseRecoverable(e.lastTokStart,"Multiple default clauses"),i=!0,s.test=null),e.expect(j.colon)}else s||e.unexpected(),s.consequent.push(e.parseStatement(!0)) +return this.exitLexicalScope(),s&&this.finishNode(s,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(t,"SwitchStatement")},H.parseThrowStatement=function(t){return this.next(),I.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),t.argument=this.parseExpression(),this.semicolon(),this.finishNode(t,"ThrowStatement")} +var Z=[] +H.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===j._catch){var e=this.startNode() +this.next(),this.expect(j.parenL),e.param=this.parseBindingAtom(),this.enterLexicalScope(),this.checkLVal(e.param,"let"),this.expect(j.parenR),e.body=this.parseBlock(!1),this.exitLexicalScope(),t.handler=this.finishNode(e,"CatchClause")}return t.finalizer=this.eat(j._finally)?this.parseBlock():null,t.handler||t.finalizer||this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")},H.parseVarStatement=function(t,e){return this.next(),this.parseVar(t,!1,e),this.semicolon(),this.finishNode(t,"VariableDeclaration")},H.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(Y),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,"WhileStatement")},H.parseWithStatement=function(t){return this.strict&&this.raise(this.start,"'with' in strict mode"),this.next(),t.object=this.parseParenExpression(),t.body=this.parseStatement(!1),this.finishNode(t,"WithStatement")},H.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")},H.parseLabeledStatement=function(t,e,s){for(var i=this,r=0;r=0;a--){var o=i.labels[a] +if(o.statementStart!=t.start)break +o.statementStart=i.start,o.kind=n}return this.labels.push({name:e,kind:n,statementStart:this.start}),t.body=this.parseStatement(!0),("ClassDeclaration"==t.body.type||"VariableDeclaration"==t.body.type&&"var"!=t.body.kind||"FunctionDeclaration"==t.body.type&&(this.strict||t.body.generator))&&this.raiseRecoverable(t.body.start,"Invalid labeled declaration"),this.labels.pop(),t.label=s,this.finishNode(t,"LabeledStatement")},H.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")},H.parseBlock=function(t){var e=this +void 0===t&&(t=!0) +var s=this.startNode() +for(s.body=[],this.expect(j.braceL),t&&this.enterLexicalScope();!this.eat(j.braceR);){var i=e.parseStatement(!0) +s.body.push(i)}return t&&this.exitLexicalScope(),this.finishNode(s,"BlockStatement")},H.parseFor=function(t,e){return t.init=e,this.expect(j.semi),t.test=this.type===j.semi?null:this.parseExpression(),this.expect(j.semi),t.update=this.type===j.parenR?null:this.parseExpression(),this.expect(j.parenR),this.exitLexicalScope(),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,"ForStatement")},H.parseForIn=function(t,e){var s=this.type===j._in?"ForInStatement":"ForOfStatement" +return this.next(),t.left=e,t.right=this.parseExpression(),this.expect(j.parenR),this.exitLexicalScope(),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,s)},H.parseVar=function(t,e,s){var i=this +for(t.declarations=[],t.kind=s;;){var r=i.startNode() +if(i.parseVarId(r,s),i.eat(j.eq)?r.init=i.parseMaybeAssign(e):"const"!==s||i.type===j._in||i.options.ecmaVersion>=6&&i.isContextual("of")?"Identifier"==r.id.type||e&&(i.type===j._in||i.isContextual("of"))?r.init=null:i.raise(i.lastTokEnd,"Complex binding patterns require an initialization value"):i.unexpected(),t.declarations.push(i.finishNode(r,"VariableDeclarator")),!i.eat(j.comma))break}return t},H.parseVarId=function(t,e){t.id=this.parseBindingAtom(e),this.checkLVal(t.id,e,!1)},H.parseFunction=function(t,e,s,i){this.initFunction(t),this.options.ecmaVersion>=6&&!i&&(t.generator=this.eat(j.star)),this.options.ecmaVersion>=8&&(t.async=!!i),e&&(t.id="nullableID"===e&&this.type!=j.name?null:this.parseIdent(),t.id&&this.checkLVal(t.id,"var")) +var r=this.inGenerator,n=this.inAsync,a=this.yieldPos,o=this.awaitPos,h=this.inFunction +return this.inGenerator=t.generator,this.inAsync=t.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),e||(t.id=this.type==j.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,s),this.inGenerator=r,this.inAsync=n,this.yieldPos=a,this.awaitPos=o,this.inFunction=h,this.finishNode(t,e?"FunctionDeclaration":"FunctionExpression")},H.parseFunctionParams=function(t){this.expect(j.parenL),t.params=this.parseBindingList(j.parenR,!1,this.options.ecmaVersion>=8,!0),this.checkYieldAwaitInDefaultParams()},H.parseClass=function(t,e){var s=this +this.next(),this.parseClassId(t,e),this.parseClassSuper(t) +var i=this.startNode(),r=!1 +for(i.body=[],this.expect(j.braceL);!this.eat(j.braceR);)if(!s.eat(j.semi)){var n=s.startNode(),a=s.eat(j.star),o=!1,h=s.type===j.name&&"static"===s.value +s.parsePropertyName(n),n.static=h&&s.type!==j.parenL,n.static&&(a&&s.unexpected(),a=s.eat(j.star),s.parsePropertyName(n)),s.options.ecmaVersion>=8&&!a&&!n.computed&&"Identifier"===n.key.type&&"async"===n.key.name&&s.type!==j.parenL&&!s.canInsertSemicolon()&&(o=!0,s.parsePropertyName(n)),n.kind="method" +var p=!1 +if(!n.computed){var c=n.key +a||o||"Identifier"!==c.type||s.type===j.parenL||"get"!==c.name&&"set"!==c.name||(p=!0,n.kind=c.name,c=s.parsePropertyName(n)),!n.static&&("Identifier"===c.type&&"constructor"===c.name||"Literal"===c.type&&"constructor"===c.value)&&(r&&s.raise(c.start,"Duplicate constructor in the same class"),p&&s.raise(c.start,"Constructor can't have get/set modifier"),a&&s.raise(c.start,"Constructor can't be a generator"),o&&s.raise(c.start,"Constructor can't be an async method"),n.kind="constructor",r=!0)}if(s.parseClassMethod(i,n,a,o),p){var l="get"===n.kind?0:1 +if(n.value.params.length!==l){var u=n.value.start +"get"===n.kind?s.raiseRecoverable(u,"getter should have no params"):s.raiseRecoverable(u,"setter should have exactly one param")}else"set"===n.kind&&"RestElement"===n.value.params[0].type&&s.raiseRecoverable(n.value.params[0].start,"Setter cannot use rest params")}}return t.body=this.finishNode(i,"ClassBody"),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")},H.parseClassMethod=function(t,e,s,i){e.value=this.parseMethod(s,i),t.body.push(this.finishNode(e,"MethodDefinition"))},H.parseClassId=function(t,e){t.id=this.type===j.name?this.parseIdent():!0===e?this.unexpected():null},H.parseClassSuper=function(t){t.superClass=this.eat(j._extends)?this.parseExprSubscripts():null},H.parseExport=function(t,e){var s=this +if(this.next(),this.eat(j.star))return this.expectContextual("from"),t.source=this.type===j.string?this.parseExprAtom():this.unexpected(),this.semicolon(),this.finishNode(t,"ExportAllDeclaration") +if(this.eat(j._default)){this.checkExport(e,"default",this.lastTokStart) +var i +if(this.type===j._function||(i=this.isAsyncFunction())){var r=this.startNode() +this.next(),i&&this.next(),t.declaration=this.parseFunction(r,"nullableID",!1,i)}else if(this.type===j._class){var n=this.startNode() +t.declaration=this.parseClass(n,"nullableID")}else t.declaration=this.parseMaybeAssign(),this.semicolon() +return this.finishNode(t,"ExportDefaultDeclaration")}if(this.shouldParseExportStatement())t.declaration=this.parseStatement(!0),"VariableDeclaration"===t.declaration.type?this.checkVariableExport(e,t.declaration.declarations):this.checkExport(e,t.declaration.id.name,t.declaration.id.start),t.specifiers=[],t.source=null +else{if(t.declaration=null,t.specifiers=this.parseExportSpecifiers(e),this.eatContextual("from"))t.source=this.type===j.string?this.parseExprAtom():this.unexpected() +else{for(var a=0;a=6&&t)switch(t.type){case"Identifier":this.inAsync&&"await"===t.name&&this.raise(t.start,"Can not use 'await' as identifier inside an async function") +break +case"ObjectPattern":case"ArrayPattern":break +case"ObjectExpression":t.type="ObjectPattern" +for(var i=0;i=6&&(t.computed||t.method||t.shorthand))){var s,i=t.key +switch(i.type){case"Identifier":s=i.name +break +case"Literal":s=String(i.value) +break +default:return}var r=t.kind +if(this.options.ecmaVersion>=6)return void("__proto__"===s&&"init"===r&&(e.proto&&this.raiseRecoverable(i.start,"Redefinition of __proto__ property"),e.proto=!0)) +s="$"+s +var n=e[s] +if(n){var a +a="init"===r?this.strict&&n.init||n.get||n.set:n.init||n[r],a&&this.raiseRecoverable(i.start,"Redefinition of property")}else n=e[s]={init:!1,get:!1,set:!1} +n[r]=!0}},tt.parseExpression=function(t,e){var s=this,i=this.start,r=this.startLoc,n=this.parseMaybeAssign(t,e) +if(this.type===j.comma){var a=this.startNodeAt(i,r) +for(a.expressions=[n];this.eat(j.comma);)a.expressions.push(s.parseMaybeAssign(t,e)) +return this.finishNode(a,"SequenceExpression")}return n},tt.parseMaybeAssign=function(t,e,s){if(this.inGenerator&&this.isContextual("yield"))return this.parseYield() +var i=!1,r=-1,n=-1 +e?(r=e.parenthesizedAssign,n=e.trailingComma,e.parenthesizedAssign=e.trailingComma=-1):(e=new $,i=!0) +var a=this.start,o=this.startLoc +this.type!=j.parenL&&this.type!=j.name||(this.potentialArrowAt=this.start) +var h=this.parseMaybeConditional(t,e) +if(s&&(h=s.call(this,h,a,o)),this.type.isAssign){this.checkPatternErrors(e,!0),i||$.call(e) +var p=this.startNodeAt(a,o) +return p.operator=this.value,p.left=this.type===j.eq?this.toAssignable(h):h,e.shorthandAssign=-1,this.checkLVal(h),this.next(),p.right=this.parseMaybeAssign(t),this.finishNode(p,"AssignmentExpression")}return i&&this.checkExpressionErrors(e,!0),r>-1&&(e.parenthesizedAssign=r),n>-1&&(e.trailingComma=n),h},tt.parseMaybeConditional=function(t,e){var s=this.start,i=this.startLoc,r=this.parseExprOps(t,e) +if(this.checkExpressionErrors(e))return r +if(this.eat(j.question)){var n=this.startNodeAt(s,i) +return n.test=r,n.consequent=this.parseMaybeAssign(),this.expect(j.colon),n.alternate=this.parseMaybeAssign(t),this.finishNode(n,"ConditionalExpression")}return r},tt.parseExprOps=function(t,e){var s=this.start,i=this.startLoc,r=this.parseMaybeUnary(e,!1) +return this.checkExpressionErrors(e)?r:r.start==s&&"ArrowFunctionExpression"===r.type?r:this.parseExprOp(r,s,i,-1,t)},tt.parseExprOp=function(t,e,s,i,r){var n=this.type.binop +if(null!=n&&(!r||this.type!==j._in)&&n>i){var a=this.type===j.logicalOR||this.type===j.logicalAND,o=this.value +this.next() +var h=this.start,p=this.startLoc,c=this.parseExprOp(this.parseMaybeUnary(null,!1),h,p,n,r),l=this.buildBinary(e,s,t,c,o,a) +return this.parseExprOp(l,e,s,i,r)}return t},tt.buildBinary=function(t,e,s,i,r,n){var a=this.startNodeAt(t,e) +return a.left=s,a.operator=r,a.right=i,this.finishNode(a,n?"LogicalExpression":"BinaryExpression")},tt.parseMaybeUnary=function(t,e){var s,i=this,r=this.start,n=this.startLoc +if(this.inAsync&&this.isContextual("await"))s=this.parseAwait(t),e=!0 +else if(this.type.prefix){var a=this.startNode(),o=this.type===j.incDec +a.operator=this.value,a.prefix=!0,this.next(),a.argument=this.parseMaybeUnary(null,!0),this.checkExpressionErrors(t,!0),o?this.checkLVal(a.argument):this.strict&&"delete"===a.operator&&"Identifier"===a.argument.type?this.raiseRecoverable(a.start,"Deleting local variable in strict mode"):e=!0,s=this.finishNode(a,o?"UpdateExpression":"UnaryExpression")}else{if(s=this.parseExprSubscripts(t),this.checkExpressionErrors(t))return s +for(;this.type.postfix&&!this.canInsertSemicolon();){var h=i.startNodeAt(r,n) +h.operator=i.value,h.prefix=!1,h.argument=s,i.checkLVal(s),i.next(),s=i.finishNode(h,"UpdateExpression")}}return!e&&this.eat(j.starstar)?this.buildBinary(r,n,s,this.parseMaybeUnary(null,!1),"**",!1):s},tt.parseExprSubscripts=function(t){var e=this.start,s=this.startLoc,i=this.parseExprAtom(t),r="ArrowFunctionExpression"===i.type&&")"!==this.input.slice(this.lastTokStart,this.lastTokEnd) +if(this.checkExpressionErrors(t)||r)return i +var n=this.parseSubscripts(i,e,s) +return t&&"MemberExpression"===n.type&&(t.parenthesizedAssign>=n.start&&(t.parenthesizedAssign=-1),t.parenthesizedBind>=n.start&&(t.parenthesizedBind=-1)),n},tt.parseSubscripts=function(t,e,s,i){for(var r,n=this,a=this.options.ecmaVersion>=8&&"Identifier"===t.type&&"async"===t.name&&this.lastTokEnd==t.end&&!this.canInsertSemicolon();;)if((r=n.eat(j.bracketL))||n.eat(j.dot)){var o=n.startNodeAt(e,s) +o.object=t,o.property=r?n.parseExpression():n.parseIdent(!0),o.computed=!!r,r&&n.expect(j.bracketR),t=n.finishNode(o,"MemberExpression")}else if(!i&&n.eat(j.parenL)){var h=new $,p=n.yieldPos,c=n.awaitPos +n.yieldPos=0,n.awaitPos=0 +var l=n.parseExprList(j.parenR,n.options.ecmaVersion>=8,!1,h) +if(a&&!n.canInsertSemicolon()&&n.eat(j.arrow))return n.checkPatternErrors(h,!1),n.checkYieldAwaitInDefaultParams(),n.yieldPos=p,n.awaitPos=c,n.parseArrowExpression(n.startNodeAt(e,s),l,!0) +n.checkExpressionErrors(h,!0),n.yieldPos=p||n.yieldPos,n.awaitPos=c||n.awaitPos +var u=n.startNodeAt(e,s) +u.callee=t,u.arguments=l,t=n.finishNode(u,"CallExpression")}else{if(n.type!==j.backQuote)return t +var d=n.startNodeAt(e,s) +d.tag=t,d.quasi=n.parseTemplate(),t=n.finishNode(d,"TaggedTemplateExpression")}},tt.parseExprAtom=function(t){var e,s=this.potentialArrowAt==this.start +switch(this.type){case j._super:this.inFunction||this.raise(this.start,"'super' outside of function or class") +case j._this:var i=this.type===j._this?"ThisExpression":"Super" +return e=this.startNode(),this.next(),this.finishNode(e,i) +case j.name:var r=this.start,n=this.startLoc,a=this.parseIdent(this.type!==j.name) +if(this.options.ecmaVersion>=8&&"async"===a.name&&!this.canInsertSemicolon()&&this.eat(j._function))return this.parseFunction(this.startNodeAt(r,n),!1,!1,!0) +if(s&&!this.canInsertSemicolon()){if(this.eat(j.arrow))return this.parseArrowExpression(this.startNodeAt(r,n),[a],!1) +if(this.options.ecmaVersion>=8&&"async"===a.name&&this.type===j.name)return a=this.parseIdent(),!this.canInsertSemicolon()&&this.eat(j.arrow)||this.unexpected(),this.parseArrowExpression(this.startNodeAt(r,n),[a],!0)}return a +case j.regexp:var o=this.value +return e=this.parseLiteral(o.value),e.regex={pattern:o.pattern,flags:o.flags},e +case j.num:case j.string:return this.parseLiteral(this.value) +case j._null:case j._true:case j._false:return e=this.startNode(),e.value=this.type===j._null?null:this.type===j._true,e.raw=this.type.keyword,this.next(),this.finishNode(e,"Literal") +case j.parenL:var h=this.start,p=this.parseParenAndDistinguishExpression(s) +return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=h),t.parenthesizedBind<0&&(t.parenthesizedBind=h)),p +case j.bracketL:return e=this.startNode(),this.next(),e.elements=this.parseExprList(j.bracketR,!0,!0,t),this.finishNode(e,"ArrayExpression") +case j.braceL:return this.parseObj(!1,t) +case j._function:return e=this.startNode(),this.next(),this.parseFunction(e,!1) +case j._class:return this.parseClass(this.startNode(),!1) +case j._new:return this.parseNew() +case j.backQuote:return this.parseTemplate() +default:this.unexpected()}},tt.parseLiteral=function(t){var e=this.startNode() +return e.value=t,e.raw=this.input.slice(this.start,this.end),this.next(),this.finishNode(e,"Literal")},tt.parseParenExpression=function(){this.expect(j.parenL) +var t=this.parseExpression() +return this.expect(j.parenR),t},tt.parseParenAndDistinguishExpression=function(t){var e,s=this,i=this.start,r=this.startLoc,n=this.options.ecmaVersion>=8 +if(this.options.ecmaVersion>=6){this.next() +var a,o,h=this.start,p=this.startLoc,c=[],l=!0,u=!1,d=new $,f=this.yieldPos,m=this.awaitPos +for(this.yieldPos=0,this.awaitPos=0;this.type!==j.parenR;){if(l?l=!1:s.expect(j.comma),n&&s.afterTrailingComma(j.parenR,!0)){u=!0 +break}if(s.type===j.ellipsis){a=s.start,c.push(s.parseParenItem(s.parseRest())),s.type===j.comma&&s.raise(s.start,"Comma is not permitted after the rest element") +break}s.type!==j.parenL||o||(o=s.start),c.push(s.parseMaybeAssign(!1,d,s.parseParenItem))}var x=this.start,y=this.startLoc +if(this.expect(j.parenR),t&&!this.canInsertSemicolon()&&this.eat(j.arrow))return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),o&&this.unexpected(o),this.yieldPos=f,this.awaitPos=m,this.parseParenArrowList(i,r,c) +c.length&&!u||this.unexpected(this.lastTokStart),a&&this.unexpected(a),this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=m||this.awaitPos,c.length>1?(e=this.startNodeAt(h,p),e.expressions=c,this.finishNodeAt(e,"SequenceExpression",x,y)):e=c[0]}else e=this.parseParenExpression() +if(this.options.preserveParens){var v=this.startNodeAt(i,r) +return v.expression=e,this.finishNode(v,"ParenthesizedExpression")}return e},tt.parseParenItem=function(t){return t},tt.parseParenArrowList=function(t,e,s){return this.parseArrowExpression(this.startNodeAt(t,e),s)} +var et=[] +tt.parseNew=function(){var t=this.startNode(),e=this.parseIdent(!0) +if(this.options.ecmaVersion>=6&&this.eat(j.dot))return t.meta=e,t.property=this.parseIdent(!0),"target"!==t.property.name&&this.raiseRecoverable(t.property.start,"The only valid meta property for new is new.target"),this.inFunction||this.raiseRecoverable(t.start,"new.target can only be used in functions"),this.finishNode(t,"MetaProperty") +var s=this.start,i=this.startLoc +return t.callee=this.parseSubscripts(this.parseExprAtom(),s,i,!0),this.eat(j.parenL)?t.arguments=this.parseExprList(j.parenR,this.options.ecmaVersion>=8,!1):t.arguments=et,this.finishNode(t,"NewExpression")},tt.parseTemplateElement=function(){var t=this.startNode() +return t.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,"\n"),cooked:this.value},this.next(),t.tail=this.type===j.backQuote,this.finishNode(t,"TemplateElement")},tt.parseTemplate=function(){var t=this,e=this.startNode() +this.next(),e.expressions=[] +var s=this.parseTemplateElement() +for(e.quasis=[s];!s.tail;)t.expect(j.dollarBraceL),e.expressions.push(t.parseExpression()),t.expect(j.braceR),e.quasis.push(s=t.parseTemplateElement()) +return this.next(),this.finishNode(e,"TemplateLiteral")},tt.parseObj=function(t,e){var s=this,i=this.startNode(),r=!0,n={} +for(i.properties=[],this.next();!this.eat(j.braceR);){if(r)r=!1 +else if(s.expect(j.comma),s.afterTrailingComma(j.braceR))break +var a,o,h,p,c=s.startNode() +s.options.ecmaVersion>=6&&(c.method=!1,c.shorthand=!1,(t||e)&&(h=s.start,p=s.startLoc),t||(a=s.eat(j.star))),s.parsePropertyName(c),t||!(s.options.ecmaVersion>=8)||a||c.computed||"Identifier"!==c.key.type||"async"!==c.key.name||s.type===j.parenL||s.type===j.colon||s.canInsertSemicolon()?o=!1:(o=!0,s.parsePropertyName(c,e)),s.parsePropertyValue(c,t,a,o,h,p,e),s.checkPropClash(c,n),i.properties.push(s.finishNode(c,"Property"))}return this.finishNode(i,t?"ObjectPattern":"ObjectExpression")},tt.parsePropertyValue=function(t,e,s,i,r,n,a){if((s||i)&&this.type===j.colon&&this.unexpected(),this.eat(j.colon))t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),t.kind="init" +else if(this.options.ecmaVersion>=6&&this.type===j.parenL)e&&this.unexpected(),t.kind="init",t.method=!0,t.value=this.parseMethod(s,i) +else if(this.options.ecmaVersion>=5&&!t.computed&&"Identifier"===t.key.type&&("get"===t.key.name||"set"===t.key.name)&&this.type!=j.comma&&this.type!=j.braceR){(s||i||e)&&this.unexpected(),t.kind=t.key.name,this.parsePropertyName(t),t.value=this.parseMethod(!1) +var o="get"===t.kind?0:1 +if(t.value.params.length!==o){var h=t.value.start +"get"===t.kind?this.raiseRecoverable(h,"getter should have no params"):this.raiseRecoverable(h,"setter should have exactly one param")}else"set"===t.kind&&"RestElement"===t.value.params[0].type&&this.raiseRecoverable(t.value.params[0].start,"Setter cannot use rest params")}else this.options.ecmaVersion>=6&&!t.computed&&"Identifier"===t.key.type?((this.keywords.test(t.key.name)||(this.strict?this.reservedWordsStrict:this.reservedWords).test(t.key.name)||this.inGenerator&&"yield"==t.key.name||this.inAsync&&"await"==t.key.name)&&this.raiseRecoverable(t.key.start,"'"+t.key.name+"' can not be used as shorthand property"),t.kind="init",e?t.value=this.parseMaybeDefault(r,n,t.key):this.type===j.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),t.value=this.parseMaybeDefault(r,n,t.key)):t.value=t.key,t.shorthand=!0):this.unexpected()},tt.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(j.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(j.bracketR),t.key +t.computed=!1}return t.key=this.type===j.num||this.type===j.string?this.parseExprAtom():this.parseIdent(!0)},tt.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=!1,t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)},tt.parseMethod=function(t,e){var s=this.startNode(),i=this.inGenerator,r=this.inAsync,n=this.yieldPos,a=this.awaitPos,o=this.inFunction +return this.initFunction(s),this.options.ecmaVersion>=6&&(s.generator=t),this.options.ecmaVersion>=8&&(s.async=!!e),this.inGenerator=s.generator,this.inAsync=s.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),this.expect(j.parenL),s.params=this.parseBindingList(j.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(s,!1),this.inGenerator=i,this.inAsync=r,this.yieldPos=n,this.awaitPos=a,this.inFunction=o,this.finishNode(s,"FunctionExpression")},tt.parseArrowExpression=function(t,e,s){var i=this.inGenerator,r=this.inAsync,n=this.yieldPos,a=this.awaitPos,o=this.inFunction +return this.enterFunctionScope(),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!s),this.inGenerator=!1,this.inAsync=t.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0),this.inGenerator=i,this.inAsync=r,this.yieldPos=n,this.awaitPos=a,this.inFunction=o,this.finishNode(t,"ArrowFunctionExpression")},tt.parseFunctionBody=function(t,e){var s=e&&this.type!==j.braceL,i=this.strict,r=!1 +if(s)t.body=this.parseMaybeAssign(),t.expression=!0,this.checkParams(t,!1) +else{var n=this.options.ecmaVersion>=7&&!this.isSimpleParamList(t.params) +i&&!n||(r=this.strictDirective(this.end))&&n&&this.raiseRecoverable(t.start,"Illegal 'use strict' directive in function with non-simple parameter list") +var a=this.labels +this.labels=[],r&&(this.strict=!0),this.checkParams(t,!i&&!r&&!e&&this.isSimpleParamList(t.params)),t.body=this.parseBlock(!1),t.expression=!1,this.labels=a}this.exitFunctionScope(),this.strict&&t.id&&this.checkLVal(t.id,"none"),this.strict=i},tt.isSimpleParamList=function(t){for(var e=0;e=6||-1==this.input.slice(this.start,this.end).indexOf("\\"))&&this.raiseRecoverable(this.start,"The keyword '"+this.value+"' is reserved"),this.inGenerator&&"yield"===this.value&&this.raiseRecoverable(this.start,"Can not use 'yield' as identifier inside a generator"),this.inAsync&&"await"===this.value&&this.raiseRecoverable(this.start,"Can not use 'await' as identifier inside an async function"),e.name=this.value):t&&this.type.keyword?e.name=this.type.keyword:this.unexpected(),this.next(),this.finishNode(e,"Identifier")},tt.parseYield=function(){this.yieldPos||(this.yieldPos=this.start) +var t=this.startNode() +return this.next(),this.type==j.semi||this.canInsertSemicolon()||this.type!=j.star&&!this.type.startsExpr?(t.delegate=!1,t.argument=null):(t.delegate=this.eat(j.star),t.argument=this.parseMaybeAssign()),this.finishNode(t,"YieldExpression")},tt.parseAwait=function(){this.awaitPos||(this.awaitPos=this.start) +var t=this.startNode() +return this.next(),t.argument=this.parseMaybeUnary(null,!0),this.finishNode(t,"AwaitExpression")} +var st=W.prototype +st.raise=function(t,e){var s=h(this.input,t) +e+=" ("+s.line+":"+s.column+")" +var i=new SyntaxError(e) +throw i.pos=t,i.loc=s,i.raisedAt=this.pos,i},st.raiseRecoverable=st.raise,st.curPosition=function(){if(this.options.locations)return new q(this.curLine,this.pos-this.lineStart)} +var it=W.prototype,rt=Object.assign||function(t){for(var e=[],s=arguments.length-1;s-- >0;)e[s]=arguments[s+1] +for(var i=0;i=0;e--)if(t.context[e].generator)return!0 +return!1},pt.updateContext=function(t){var e,s=this.type +s.keyword&&t==j.dot?this.exprAllowed=!1:(e=s.updateContext)?e.call(this,t):this.exprAllowed=s.beforeExpr},j.parenR.updateContext=j.braceR.updateContext=function(){if(1==this.context.length)return void(this.exprAllowed=!0) +var t,e=this.context.pop() +e===ht.b_stat&&(t=this.curContext())&&"function"===t.token?(this.context.pop(),this.exprAllowed=!1):this.exprAllowed=e===ht.b_tmpl||!e.isExpr},j.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?ht.b_stat:ht.b_expr),this.exprAllowed=!0},j.dollarBraceL.updateContext=function(){this.context.push(ht.b_tmpl),this.exprAllowed=!0},j.parenL.updateContext=function(t){var e=t===j._if||t===j._for||t===j._with||t===j._while +this.context.push(e?ht.p_stat:ht.p_expr),this.exprAllowed=!0},j.incDec.updateContext=function(){},j._function.updateContext=function(t){t.beforeExpr&&t!==j.semi&&t!==j._else&&(t!==j.colon&&t!==j.braceL||this.curContext()!==ht.b_stat)&&this.context.push(ht.f_expr),this.exprAllowed=!1},j.backQuote.updateContext=function(){this.curContext()===ht.q_tmpl?this.context.pop():this.context.push(ht.q_tmpl),this.exprAllowed=!1},j.star.updateContext=function(t){t==j._function&&(this.curContext()===ht.f_expr?this.context[this.context.length-1]=ht.f_expr_gen:this.context.push(ht.f_gen)),this.exprAllowed=!0},j.name.updateContext=function(t){var e=!1 +this.options.ecmaVersion>=6&&("of"==this.value&&!this.exprAllowed||"yield"==this.value&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e} +var ct=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new X(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},lt=W.prototype,ut="object"==typeof Packages&&"[object JavaPackage]"==Object.prototype.toString.call(Packages) +lt.next=function(){this.options.onToken&&this.options.onToken(new ct(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},lt.getToken=function(){return this.next(),new ct(this)},"undefined"!=typeof Symbol&&(lt[Symbol.iterator]=function(){var t=this +return{next:function(){var e=t.getToken() +return{done:e.type===j.eof,value:e}}}}),lt.curContext=function(){return this.context[this.context.length-1]},lt.nextToken=function(){var t=this.curContext() +return t&&t.preserveSpace||this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length?this.finishToken(j.eof):t.override?t.override(this):void this.readToken(this.fullCharCodeAtPos())},lt.readToken=function(t){return s(t,this.options.ecmaVersion>=6)||92===t?this.readWord():this.getTokenFromCode(t)},lt.fullCharCodeAtPos=function(){var t=this.input.charCodeAt(this.pos) +return t<=55295||t>=57344?t:(t<<10)+this.input.charCodeAt(this.pos+1)-56613888},lt.skipBlockComment=function(){var t=this,e=this.options.onComment&&this.curPosition(),s=this.pos,i=this.input.indexOf("*/",this.pos+=2) +if(-1===i&&this.raise(this.pos-2,"Unterminated comment"),this.pos=i+2,this.options.locations){R.lastIndex=s +for(var r;(r=R.exec(this.input))&&r.index8&&e<14||e>=5760&&O.test(String.fromCharCode(e))))break t;++t.pos}}},lt.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition()) +var s=this.type +this.type=t,this.value=e,this.updateContext(s)},lt.readToken_dot=function(){var t=this.input.charCodeAt(this.pos+1) +if(t>=48&&t<=57)return this.readNumber(!0) +var e=this.input.charCodeAt(this.pos+2) +return this.options.ecmaVersion>=6&&46===t&&46===e?(this.pos+=3,this.finishToken(j.ellipsis)):(++this.pos,this.finishToken(j.dot))},lt.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1) +return this.exprAllowed?(++this.pos,this.readRegexp()):61===t?this.finishOp(j.assign,2):this.finishOp(j.slash,1)},lt.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),s=1,i=42===t?j.star:j.modulo +return this.options.ecmaVersion>=7&&42===e&&(++s,i=j.starstar,e=this.input.charCodeAt(this.pos+2)),61===e?this.finishOp(j.assign,s+1):this.finishOp(i,s)},lt.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1) +return e===t?this.finishOp(124===t?j.logicalOR:j.logicalAND,2):61===e?this.finishOp(j.assign,2):this.finishOp(124===t?j.bitwiseOR:j.bitwiseAND,1)},lt.readToken_caret=function(){return 61===this.input.charCodeAt(this.pos+1)?this.finishOp(j.assign,2):this.finishOp(j.bitwiseXOR,1)},lt.readToken_plus_min=function(t){var e=this.input.charCodeAt(this.pos+1) +return e===t?45==e&&62==this.input.charCodeAt(this.pos+2)&&I.test(this.input.slice(this.lastTokEnd,this.pos))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(j.incDec,2):61===e?this.finishOp(j.assign,2):this.finishOp(j.plusMin,1)},lt.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),s=1 +return e===t?(s=62===t&&62===this.input.charCodeAt(this.pos+2)?3:2,61===this.input.charCodeAt(this.pos+s)?this.finishOp(j.assign,s+1):this.finishOp(j.bitShift,s)):33==e&&60==t&&45==this.input.charCodeAt(this.pos+2)&&45==this.input.charCodeAt(this.pos+3)?(this.inModule&&this.unexpected(),this.skipLineComment(4),this.skipSpace(),this.nextToken()):(61===e&&(s=2),this.finishOp(j.relational,s))},lt.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1) +return 61===e?this.finishOp(j.equality,61===this.input.charCodeAt(this.pos+2)?3:2):61===t&&62===e&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(j.arrow)):this.finishOp(61===t?j.eq:j.prefix,1)},lt.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot() +case 40:return++this.pos,this.finishToken(j.parenL) +case 41:return++this.pos,this.finishToken(j.parenR) +case 59:return++this.pos,this.finishToken(j.semi) +case 44:return++this.pos,this.finishToken(j.comma) +case 91:return++this.pos,this.finishToken(j.bracketL) +case 93:return++this.pos,this.finishToken(j.bracketR) +case 123:return++this.pos,this.finishToken(j.braceL) +case 125:return++this.pos,this.finishToken(j.braceR) +case 58:return++this.pos,this.finishToken(j.colon) +case 63:return++this.pos,this.finishToken(j.question) +case 96:if(this.options.ecmaVersion<6)break +return++this.pos,this.finishToken(j.backQuote) +case 48:var e=this.input.charCodeAt(this.pos+1) +if(120===e||88===e)return this.readRadixNumber(16) +if(this.options.ecmaVersion>=6){if(111===e||79===e)return this.readRadixNumber(8) +if(98===e||66===e)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1) +case 34:case 39:return this.readString(t) +case 47:return this.readToken_slash() +case 37:case 42:return this.readToken_mult_modulo_exp(t) +case 124:case 38:return this.readToken_pipe_amp(t) +case 94:return this.readToken_caret() +case 43:case 45:return this.readToken_plus_min(t) +case 60:case 62:return this.readToken_lt_gt(t) +case 61:case 33:return this.readToken_eq_excl(t) +case 126:return this.finishOp(j.prefix,1)}this.raise(this.pos,"Unexpected character '"+f(t)+"'")},lt.finishOp=function(t,e){var s=this.input.slice(this.pos,this.pos+e) +return this.pos+=e,this.finishToken(t,s)} +var dt=!!d("￿","u") +lt.readRegexp=function(){for(var t,e,s=this,i=this.pos;;){s.pos>=s.input.length&&s.raise(i,"Unterminated regular expression") +var r=s.input.charAt(s.pos) +if(I.test(r)&&s.raise(i,"Unterminated regular expression"),t)t=!1 +else{if("["===r)e=!0 +else if("]"===r&&e)e=!1 +else if("/"===r&&!e)break +t="\\"===r}++s.pos}var n=this.input.slice(i,this.pos);++this.pos +var a=this.readWord1(),o=n,h="" +if(a){var p=/^[gim]*$/ +this.options.ecmaVersion>=6&&(p=/^[gimuy]*$/),p.test(a)||this.raise(i,"Invalid regular expression flag"),a.indexOf("u")>=0&&(dt?h="u":(o=o.replace(/\\u\{([0-9a-fA-F]+)\}/g,function(t,e,r){return e=Number("0x"+e),e>1114111&&s.raise(i+r+3,"Code point out of bounds"),"x"}),o=o.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"x"),h=h.replace("u","")))}var c=null +return ut||(d(o,h,i,this),c=d(n,a)),this.finishToken(j.regexp,{pattern:n,flags:a,value:c})},lt.readInt=function(t,e){for(var s=this,i=this.pos,r=0,n=0,a=null==e?1/0:e;n=97?h-97+10:h>=65?h-65+10:h>=48&&h<=57?h-48:1/0)>=t)break;++s.pos,r=r*t+o}return this.pos===i||null!=e&&this.pos-i!==e?null:r},lt.readRadixNumber=function(t){this.pos+=2 +var e=this.readInt(t) +return null==e&&this.raise(this.start+2,"Expected number in radix "+t),s(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(j.num,e)},lt.readNumber=function(t){var e=this.pos,i=!1,r=48===this.input.charCodeAt(this.pos) +t||null!==this.readInt(10)||this.raise(e,"Invalid number"),r&&this.pos==e+1&&(r=!1) +var n=this.input.charCodeAt(this.pos) +46!==n||r||(++this.pos,this.readInt(10),i=!0,n=this.input.charCodeAt(this.pos)),69!==n&&101!==n||r||(n=this.input.charCodeAt(++this.pos),43!==n&&45!==n||++this.pos,null===this.readInt(10)&&this.raise(e,"Invalid number"),i=!0),s(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number") +var a,o=this.input.slice(e,this.pos) +return i?a=parseFloat(o):r&&1!==o.length?/[89]/.test(o)||this.strict?this.raise(e,"Invalid number"):a=parseInt(o,8):a=parseInt(o,10),this.finishToken(j.num,a)},lt.readCodePoint=function(){var t,e=this.input.charCodeAt(this.pos) +if(123===e){this.options.ecmaVersion<6&&this.unexpected() +var s=++this.pos +t=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,t>1114111&&this.raise(s,"Code point out of bounds")}else t=this.readHexChar(4) +return t},lt.readString=function(t){for(var e=this,s="",i=++this.pos;;){e.pos>=e.input.length&&e.raise(e.start,"Unterminated string constant") +var r=e.input.charCodeAt(e.pos) +if(r===t)break +92===r?(s+=e.input.slice(i,e.pos),s+=e.readEscapedChar(!1),i=e.pos):(a(r)&&e.raise(e.start,"Unterminated string constant"),++e.pos)}return s+=this.input.slice(i,this.pos++),this.finishToken(j.string,s)},lt.readTmplToken=function(){for(var t=this,e="",s=this.pos;;){t.pos>=t.input.length&&t.raise(t.start,"Unterminated template") +var i=t.input.charCodeAt(t.pos) +if(96===i||36===i&&123===t.input.charCodeAt(t.pos+1))return t.pos===t.start&&t.type===j.template?36===i?(t.pos+=2,t.finishToken(j.dollarBraceL)):(++t.pos,t.finishToken(j.backQuote)):(e+=t.input.slice(s,t.pos),t.finishToken(j.template,e)) +if(92===i)e+=t.input.slice(s,t.pos),e+=t.readEscapedChar(!0),s=t.pos +else if(a(i)){switch(e+=t.input.slice(s,t.pos),++t.pos,i){case 13:10===t.input.charCodeAt(t.pos)&&++t.pos +case 10:e+="\n" +break +default:e+=String.fromCharCode(i)}t.options.locations&&(++t.curLine,t.lineStart=t.pos),s=t.pos}else++t.pos}},lt.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos) +switch(++this.pos,e){case 110:return"\n" +case 114:return"\r" +case 120:return String.fromCharCode(this.readHexChar(2)) +case 117:return f(this.readCodePoint()) +case 116:return"\t" +case 98:return"\b" +case 118:return"\v" +case 102:return"\f" +case 13:10===this.input.charCodeAt(this.pos)&&++this.pos +case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"" +default:if(e>=48&&e<=55){var s=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],i=parseInt(s,8) +return i>255&&(s=s.slice(0,-1),i=parseInt(s,8)),"0"!==s&&(this.strict||t)&&this.raise(this.pos-2,"Octal literal in strict mode"),this.pos+=s.length-1,String.fromCharCode(i)}return String.fromCharCode(e)}},lt.readHexChar=function(t){var e=this.pos,s=this.readInt(16,t) +return null===s&&this.raise(e,"Bad character escape sequence"),s},lt.readWord1=function(){var t=this +this.containsEsc=!1 +for(var e="",r=!0,n=this.pos,a=this.options.ecmaVersion>=6;this.pos0?t[0].toUpperCase()+t.slice(1):t}).join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.default=i},function(t,e,s){"use strict" +Object.defineProperty(e,"__esModule",{value:!0}),e.default={class:"className",for:"htmlFor",maxlength:"maxLength",colspan:"colSpan",rowspan:"rowSpan"}},function(t,e,s){"use strict" +function i(t){return-1===n.indexOf(t.toLowerCase())}function r(t){return-1!==a.indexOf(t.toLowerCase())}Object.defineProperty(e,"__esModule",{value:!0}),e.canHaveChildren=i,e.canHaveWhitespace=r +var n=["area","base","br","col","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],a=["table","tbody","tfoot","thead","tr"] +e.default=n}])}) diff --git a/package.json b/package.json index 75ee4bd..68e6eb2 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,14 @@ "url": "git@github.com:TroyAlford/react-jsx-parser.git" }, "dependencies": { - "babel-plugin-transform-react-remove-prop-types": "^0.4.6", + "acorn-jsx": "^4.0.1", "react": "^15.6.1" }, "devDependencies": { "babel-cli": "^6.22.2", "babel-loader": "^7.1.0", "babel-plugin-transform-object-rest-spread": "^6.22.0", + "babel-plugin-transform-react-remove-prop-types": "^0.4.6", "babel-preset-es2015": "^6.22.0", "babel-preset-jest": "^20.0.3", "babel-preset-react": "^6.22.0", diff --git a/source/components/JsxParser.js b/source/components/JsxParser.js index b388ddb..db98470 100644 --- a/source/components/JsxParser.js +++ b/source/components/JsxParser.js @@ -1,139 +1,116 @@ +import { Parser } from 'acorn-jsx' import React, { Component } from 'react' -import camelCase from '../helpers/camelCase' import parseStyle from '../helpers/parseStyle' -import hasDoctype from '../helpers/hasDoctype' import ATTRIBUTES from '../constants/attributeNames' -import NODE_TYPES from '../constants/nodeTypes' import { canHaveChildren, canHaveWhitespace } from '../constants/specialTags' -const parser = new DOMParser() - -const warnParseErrors = (doc) => { - const errors = Array.from(doc.documentElement.childNodes) - // eslint-disable-next-line no-console - console.warn(`Unable to parse jsx. Found ${errors.length} error(s):`) - - const warn = (node, indent) => { - if (node.childNodes.length) { - Array.from(node.childNodes) - .forEach(n => warn(n, indent.concat(' '))) - } - - // eslint-disable-next-line no-console - console.warn(`${indent}==> ${node.nodeValue}`) - } - - errors.forEach(e => warn(e, ' ')) -} +const parserOptions = { plugins: { jsx: true } } export default class JsxParser extends Component { constructor(props) { super(props) - this.parseJSX.bind(this) - this.parseNode.bind(this) + this.parseElement = this.parseElement.bind(this) + this.parseExpression = this.parseExpression.bind(this) + this.parseJSX = this.parseJSX.bind(this) + this.handleNewProps = this.handleNewProps.bind(this) - this.ParsedChildren = this.parseJSX(props.jsx || '') + this.handleNewProps(props) } + componentWillReceiveProps(props) { - this.ParsedChildren = this.parseJSX(props.jsx || '') + this.handleNewProps(props) } - parseJSX(rawJSX) { - if (!rawJSX || typeof rawJSX !== 'string') return [] - - const jsx = this.props.blacklistedTags.reduce((raw, tag) => - raw.replace(new RegExp(`(\n${jsx}` - - const doc = parser.parseFromString(wrappedJsx, 'application/xhtml+xml') + handleNewProps(props) { + this.blacklistedTags = (props.blacklistedTags || []) + .map(tag => tag.trim().toLowerCase()).filter(Boolean) + this.blacklistedAttrs = (props.blacklistedAttrs || []) + .map(attr => (attr instanceof RegExp ? attr : new RegExp(attr, 'i'))) - if (!doc) return [] - - Array.from(doc.getElementsByTagName('REMOVE')).forEach(tag => - tag.parentNode.removeChild(tag) - ) + const jsx = (props.jsx || '').trim().replace(/]*)>/g, '') + this.ParsedChildren = this.parseJSX(jsx) + } - const body = doc.getElementsByTagName('body')[0] - if (!body || body.nodeName.toLowerCase() === 'parseerror') { - if (this.props.showWarnings) warnParseErrors(doc) + parseJSX(rawJSX) { + const wrappedJsx = `${rawJSX}` + let parsed = [] + try { + parsed = (new Parser(parserOptions, wrappedJsx)).parse() + parsed = parsed.body[0].expression.children || [] + } catch (error) { + // eslint-disable-next-line no-console + if (this.props.showWarnings) console.warn(error) return [] } - return this.parseNode(body.childNodes || [], this.props.components) + return parsed.map(this.parseExpression).filter(Boolean) } - parseNode(node, components = {}, key) { - if (node instanceof NodeList || Array.isArray(node)) { - return Array.from(node) // handle nodeList or [] - .map((child, index) => this.parseNode(child, components, index)) - .filter(Boolean) // remove falsy nodes - } - - if (node.nodeType === NODE_TYPES.TEXT) { - // Text node. Collapse whitespace and return it as a String. - return ('textContent' in node ? node.textContent : node.nodeValue || '') - .replace(/[\r\n\t\f\v]/g, '') - .replace(/\s{2,}/g, ' ') - } else if (node.nodeType === NODE_TYPES.ELEMENT) { - // Element node. Parse its Attributes and Children, then call createElement - let children - if (canHaveChildren(node.nodeName)) { - children = this.parseNode(node.childNodes, components) - if (!canHaveWhitespace(node.nodeName)) { - children = children.filter(child => - typeof child !== 'string' || !child.match(/^\s*$/) - ) - } - } - - return React.createElement( - components[node.nodeName] || node.nodeName, - { - ...this.props.bindings || {}, - ...this.parseAttrs(node.attributes, key), - }, - children, - ) - } - if (this.props.showWarnings) { - // eslint-disable-next-line no-console - console.warn(`JsxParser encountered a(n) ${NODE_TYPES[node.nodeType]} node, and discarded it.`) + parseExpression(expression, key) { + /* eslint-disable no-case-declarations */ + const value = expression.value + + switch (expression.type) { + case 'JSXElement': + return this.parseElement(expression, key) + case 'JSXText': + return (value || '').replace(/\s+/g, ' ') + case 'JSXAttribute': + if (expression.value === null) return true + return this.parseExpression(expression.value) + + case 'ArrayExpression': + return expression.elements.map(this.parseExpression) + case 'ObjectExpression': + const object = {} + expression.properties.forEach((prop) => { + object[prop.key.name] = this.parseExpression(prop.value) + }) + return object + case 'JsxExpressionContainer': + return this.parseExpression(expression.expression) + case 'Literal': + return value + + default: + return undefined } - return null } - parseAttrs(attrs, key) { - if (!attrs || !attrs.length) return { key } + parseElement(element, key) { + const { bindings = {}, components = {} } = this.props + const { children = [], openingElement: { attributes, name: { name } } } = element - const blacklist = this.props.blacklistedAttrs + if (/^(html|head|body)$/i.test(name)) return children.map(c => this.parseElement(c)) - return Array.from(attrs) - .filter(attr => - !blacklist.map(mask => - // If any mask matches, it will return a non-null value - attr.name.match(new RegExp(mask, 'gi')) - ).filter(match => match !== null).length - ) - .reduce((current, attr) => { - let { name, value } = attr - if (value === '') value = true - - if (name.match(/^on/i)) { - value = new Function(value) // eslint-disable-line no-new-func - } else if (name === 'style') { - value = parseStyle(value) + if (this.blacklistedTags.indexOf(name.trim().toLowerCase()) !== -1) return undefined + let parsedChildren + if (canHaveChildren(name)) { + parsedChildren = children.map(this.parseExpression) + if (!canHaveWhitespace(name)) { + parsedChildren = parsedChildren.filter(child => + typeof child !== 'string' || !/^\s*$/.test(child) + ) } + } - name = ATTRIBUTES[name.toLowerCase()] || camelCase(name) + const attrs = { key, ...bindings } + attributes.forEach((expr) => { + const rawName = expr.name.name + const attributeName = ATTRIBUTES[rawName] || rawName + // if the value is null, this is an implicitly "true" prop, such as readOnly + const value = this.parseExpression(expr) - return { - ...current, - [name]: value, - } - }, { key }) + const matches = this.blacklistedAttrs.filter(re => re.test(attributeName)) + if (matches.length === 0) attrs[attributeName] = value + }) + + if (typeof attrs.style === 'string') { + attrs.style = parseStyle(attrs.style) + } + + return React.createElement(components[name] || name, attrs, parsedChildren) } render() { @@ -147,22 +124,26 @@ export default class JsxParser extends Component { JsxParser.defaultProps = { bindings: {}, - blacklistedAttrs: ['on[a-z]*'], + blacklistedAttrs: [/^on.+/i], blacklistedTags: ['script'], components: [], jsx: '', showWarnings: false, } -if (process.env.NODE_ENV === 'production') { +if (process.env.NODE_ENV !== 'production') { + /* eslint-disable react/no-unused-prop-types*/ // eslint-disable-next-line global-require,import/no-extraneous-dependencies const PropTypes = require('prop-types') JsxParser.propTypes = { bindings: PropTypes.shape({}), - blacklistedAttrs: PropTypes.arrayOf(PropTypes.string), - blacklistedTags: PropTypes.arrayOf(PropTypes.string), - components: PropTypes.shape({}), - jsx: PropTypes.string, + blacklistedAttrs: PropTypes.arrayOf(PropTypes.oneOfType([ + PropTypes.string, + PropTypes.instanceOf(RegExp), + ])), + blacklistedTags: PropTypes.arrayOf(PropTypes.string), + components: PropTypes.shape({}), + jsx: PropTypes.string, showWarnings: PropTypes.bool, } diff --git a/source/components/JsxParser.test.js b/source/components/JsxParser.test.js index 81e697b..070df09 100644 --- a/source/components/JsxParser.test.js +++ b/source/components/JsxParser.test.js @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom' import TestUtils from 'react-dom/test-utils' import JsxParser from './JsxParser' +jest.unmock('acorn-jsx') jest.unmock('./JsxParser') // eslint-disable-next-line react/prefer-stateless-function @@ -233,7 +234,6 @@ describe('JsxParser Component', () => { ) expect(component.ParsedChildren).toHaveLength(2) - // The expect(component.ParsedChildren[0].props).toEqual({ foo: 'Foo', // from `bindings` bar: 'Baz', // from jsx attributes (takes precedence) @@ -363,6 +363,19 @@ describe('JsxParser Component', () => { expect(rendered.childNodes).toHaveLength(2) }) + it('handles implicit boolean props correctly', () => { + const { component } = render( + + ) + + expect(component.ParsedChildren).toHaveLength(1) + expect(component.ParsedChildren[0].props.shouldBeTrue).toBeTruthy() + expect(component.ParsedChildren[0].props.shouldBeFalse).not.toBeTruthy() + }) + it('does not render children for poorly formed void elements', () => { const { rendered } = render( { expect(rendered.getElementsByTagName('h1')[1].textContent).toEqual('Lorem') }) - it('does work when DOCTYPE and html is already added', () => { + it('skips over DOCTYPE, html, head, and div if found', () => { const { rendered } = render(

Test

Another Text

'} diff --git a/source/constants/nodeTypes.js b/source/constants/nodeTypes.js deleted file mode 100644 index 7775998..0000000 --- a/source/constants/nodeTypes.js +++ /dev/null @@ -1,30 +0,0 @@ -export default { - ELEMENT: 1, - TEXT: 3, - PROCESSING_INSTRUCTION: 7, - COMMENT: 8, - DOCUMENT: 9, - DOCUMENT_TYPE: 10, - DOCUMENT_FRAGMENT: 11, - - 1: 'Element', - 3: 'Text', - 7: 'Processing Instruction', - 8: 'Comment', - 9: 'Document', - 10: 'Document Type', - 11: 'Document Fragment', - - /* Deprecated Nodes */ - ATTRIBUTE: 2, - CDATA: 4, - XML_ENTITY_REFERENCE: 5, - XML_ENTITY: 6, - XML_NOTATION: 12, - - 2: 'Attribute (Deprecated)', - 4: 'CData (Deprecated)', - 5: 'XML Entity Reference (Deprecated)', - 6: 'XML Entity (Deprecated)', - 12: 'XML Notation (Deprecated)', -} diff --git a/source/helpers/hasDoctype.js b/source/helpers/hasDoctype.js deleted file mode 100644 index 356dfe3..0000000 --- a/source/helpers/hasDoctype.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function hasDoctype(jsx) { - return /<(\/?|!?)DOCTYPE html>/.test(jsx) && - /<(\/?|!?)html>/.test(jsx) && - /<(\/?|!?)head>/.test(jsx) && - /<(\/?|!?)body>/.test(jsx) -} - diff --git a/source/helpers/hasDoctype.test.js b/source/helpers/hasDoctype.test.js deleted file mode 100644 index 74b6415..0000000 --- a/source/helpers/hasDoctype.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import hasDoctype from './hasDoctype' - -jest.unmock('./hasDoctype') - -describe('hasDoctype', () => { - it('recognizes correct html markup with spaces', () => { - const input = ` - - - - - ` - const result = hasDoctype(input) - - expect(result).toEqual(true) - }) - it('recognizes correct html markup without spaces', () => { - const input = '' - const result = hasDoctype(input) - - expect(result).toEqual(true) - }) - it('recognizes correct html markup with content', () => { - const input = '
' - const result = hasDoctype(input) - - expect(result).toEqual(true) - }) - it('doesn\'t have false positives', () => { - const input = '
Test
' - const result = hasDoctype(input) - - expect(result).toEqual(false) - }) - it('requires DOCTYPE', () => { - const input = '
' - const result = hasDoctype(input) - - expect(result).toEqual(false) - }) -}) diff --git a/yarn.lock b/yarn.lock index 212acb2..83e8704 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28,6 +28,12 @@ acorn-jsx@^3.0.0: dependencies: acorn "^3.0.4" +acorn-jsx@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-4.0.1.tgz#ada5a01573727a237774ce625564d079ec9de12a" + dependencies: + acorn "^5.0.3" + acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" @@ -36,7 +42,7 @@ acorn@^4.0.3, acorn@^4.0.4: version "4.0.13" resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" -acorn@^5.0.0, acorn@^5.0.1: +acorn@^5.0.0, acorn@^5.0.1, acorn@^5.0.3: version "5.0.3" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.0.3.tgz#c460df08491463f028ccb82eab3730bf01087b3d"