Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

Butternut generated invalid JavaScript. #201

Open aladdin-add opened 5 years ago

aladdin-add commented 5 years ago

The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string
Butternut generated invalid JavaScript. Please raise an issue at https://github.com/Rich-Harris/butternut/issues
Errored minifying code near line 0, column 2267. Reproducible with this input:
process.env.NODE_ENV!=="production"&&!function(){var e=require('object-assign'),n=require('prop-types/checkPropTypes'),t='16.8.6',r=typeof Symbol==='function'&&Symbol.for,o=r?Symbol.for('react.element'):60103,u=r?Symbol.for('react.portal'):60106,a=r?Symbol.for('react.fragment'):60107,i=r?Symbol.for('react.strict_mode'):60108,c=r?Symbol.for('react.profiler'):60114,s=r?Symbol.for('react.provider'):60109,l=r?Symbol.for('react.context'):60110,p=r?Symbol.for('react.concurrent_mode'):60111,f=r?Symbol.for('react.forward_ref'):60112,d=r?Symbol.for('react.suspense'):60113,y=r?Symbol.for('react.memo'):60115,m=r?Symbol.for('react.lazy'):60116,h=typeof Symbol==='function'&&Symbol.iterator,g='@@iterator';function w(e){if(e===null||typeof e!=='object'){return null}var n=h&&e[h]||e[g];if(typeof n==='function'){return n}return null}var b=function(){};function k(e,n,t,r,o,u,a,i){b(n);if(!e){var c=void 0;if(n===void 0)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[t,r,o,u,a,i],l=0;c=new Error(n.replace(/%s/g,function(){return s[l++]}));c.name='Invariant Violation'}c.framesToPop=1;throw c}}var _=function(){};var v=_,C=function(){};var x=C,R={};function S(e,n){}var $={isMounted:function(e){return!1},enqueueForceUpdate:function(e,n,t){S(e,'forceUpdate')},enqueueReplaceState:function(e,n,t,r){S(e,'replaceState')},enqueueSetState:function(e,n,t,r){S(e,'setState')}},j={};function N(e,n,t){this.props=e;this.context=n;this.refs=j;this.updater=t||$}N.prototype.isReactComponent={};N.prototype.setState=function(e,n){!(typeof e==='object'||typeof e==='function'||e==null)?k(!1,'setState(...): takes an object of state variables to update or a function which returns an object of state variables.'):void 0;this.updater.enqueueSetState(this,e,n,'setState')};N.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,'forceUpdate')};function z(){}z.prototype=N.prototype;function U(e,n,t){this.props=e;this.context=n;this.refs=j;this.updater=t||$}var W=U.prototype=new z;W.constructor=U;e(W,N.prototype);W.isPureReactComponent=!0;function A(){var e={current:null};return e}var O={current:null},q={current:null},E=/^(.*)[\\\/]/,F=function(e,n,t){var r='';if(n){var o=n.fileName,u=o.replace(E,'');r=' (at '+u+':'+n.lineNumber+')'}else t&&(r=' (created by '+t+')');return'\n    in '+(e||'Unknown')+r},M=1;function V(e){return e._status===M?e._result:null}function Y(e,n,t){var r=n.displayName||n.name||'';return e.displayName||(r!==''?t+'('+r+')':t)}function H(e){if(e==null){return null}if(typeof e==='function'){return e.displayName||e.name||null}if(typeof e==='string'){return e}switch(e){case p:return'ConcurrentMode';case a:return'Fragment';case u:return'Portal';case c:return'Profiler';case i:return'StrictMode';case d:return'Suspense'}if(typeof e==='object'){switch(e.$$typeof){case l:return'Context.Consumer';case s:return'Context.Provider';case f:return Y(e,e.render,'ForwardRef');case y:return H(e.type);case m:{var n=e,t=V(n);if(t){return H(t)}}}}return null}var J={},B=null;function L(e){}var X={ReactCurrentDispatcher:O,ReactCurrentOwner:q,assign:e};var G=x;var K=G,Q=Object.prototype.hasOwnProperty,Z={key:!0,ref:!0,__self:!0,__source:!0},ee=void 0,ne=void 0;function te(e){return e.ref!==void 0}function re(e){return e.key!==void 0}function oe(e,n){var t=function(){ee||(ee=!0,x(!1,"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)",n))};t.isReactWarning=!0;Object.defineProperty(e,'key',{get:t,configurable:!0})}function ue(e,n){var t=function(){ne||(ne=!0,x(!1,"%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)",n))};t.isReactWarning=!0;Object.defineProperty(e,'ref',{get:t,configurable:!0})}var ae=function(e,n,t,r,u,a,i){var c={$$typeof:o,type:e,key:n,ref:t,props:i,_owner:a};return c};function ie(e,n,t){var r=void 0,o={},u=null,a=null,i=null,c=null;if(n!=null){te(n)&&(a=n.ref);re(n)&&(u=''+n.key);i=n.__self===void 0?null:n.__self;c=n.__source===void 0?null:n.__source;for(r in n)Q.call(n,r)&&!Z.hasOwnProperty(r)&&(o[r]=n[r])}var s=arguments.length-2;if(s===1)o.children=t;else if(s>1){var l=Array(s);for(var p=0;p<s;p++)l[p]=arguments[p+2];o.children=l}if(e&&e.defaultProps){var f=e.defaultProps;for(r in f)o[r]===void 0&&(o[r]=f[r])}return ae(e,u,a,i,c,q.current,o)}function ce(e,n){var t=ae(e.type,n,e.ref,e._self,e._source,e._owner,e.props);return t}function se(n,t,r){!!(n===null||n===void 0)?k(!1,'React.cloneElement(...): The argument must be a React element, but you passed %s.',n):void 0;var o=void 0,u=e({},n.props),a=n.key,i=n.ref,c=n._self,s=n._source,l=n._owner;if(t!=null){te(t)&&(i=t.ref,l=q.current);re(t)&&(a=''+t.key);var p=void 0;n.type&&n.type.defaultProps&&(p=n.type.defaultProps);for(o in t)Q.call(t,o)&&!Z.hasOwnProperty(o)&&(t[o]===void 0&&p!==void 0?(u[o]=p[o]):(u[o]=t[o]))}var f=arguments.length-2;if(f===1)u.children=r;else if(f>1){var d=Array(f);for(var y=0;y<f;y++)d[y]=arguments[y+2];u.children=d}return ae(n.type,a,i,c,s,l,u)}function le(e){return typeof e==='object'&&e!==null&&e.$$typeof===o}var pe='.',fe=':';function de(e){var n=/[=:]/g,t={'=':'=0',':':'=2'},r=(''+e).replace(n,function(e){return t[e]});return'$'+r}var ye=!1,me=/\/+/g;function he(e){return(''+e).replace(me,'$&/')}var ge=10,we=[];function be(e,n,t,r){if(we.length){var o=we.pop();o.result=e;o.keyPrefix=n;o.func=t;o.context=r;o.count=0;return o}else{return{result:e,keyPrefix:n,func:t,context:r,count:0}}}function ke(e){e.result=null;e.keyPrefix=null;e.func=null;e.context=null;e.count=0;we.length<ge&&we.push(e)}function _e(e,n,t,r){var a=typeof e;(a==='undefined'||a==='boolean')&&(e=null);var i=!1;if(e===null)i=!0;else{switch(a){case 'string':;case 'number':i=!0;break;case 'object':switch(e.$$typeof){case o:;case u:i=!0}}}if(i){t(r,e,n===''?pe+ve(e,0):n);return 1}var c=void 0,s=void 0,l=0,p=n===''?pe:n+fe;if(Array.isArray(e)){for(var f=0;f<e.length;f++)c=e[f],s=p+ve(c,f),l+=_e(c,s,t,r)}else{var d=w(e);if(typeof d==='function'){var y=d.call(e),m=void 0,h=0;while(!(m=y.next()).done)c=m.value,s=p+ve(c,h++),l+=_e(c,s,t,r)}else if(a==='object'){var g='';var b=''+e;k(!1,'Objects are not valid as a React child (found: %s).%s',b==='[object Object]'?'object with keys {'+Object.keys(e).join(', ')+'}':b,g)}}return l}function Pe(e,n,t){if(e==null){return 0}return _e(e,'',n,t)}function ve(e,n){if(typeof e==='object'&&e!==null&&e.key!=null){return de(e.key)}return n.toString(36)}function Ce(e,n,t){var r=e.func,o=e.context;r.call(o,n,e.count++)}function xe(e,n,t){if(e==null){return e}var r=be(null,null,n,t);Pe(e,Ce,r);ke(r)}function Re(e,n,t){var r=e.result,o=e.keyPrefix,u=e.func,a=e.context,i=u.call(a,n,e.count++);Array.isArray(i)?Se(i,r,t,function(e){return e}):i!=null&&(le(i)&&(i=ce(i,o+(i.key&&(!n||n.key!==i.key)?he(i.key)+'/':'')+t)),r.push(i))}function Se(e,n,t,r,o){var u='';t!=null&&(u=he(t)+'/');var a=be(n,u,r,o);Pe(e,Re,a);ke(a)}function $e(e,n,t){if(e==null){return e}var r=[];Se(e,r,null,n,t);return r}function je(e){return Pe(e,function(){return null},null)}function Ne(e){var n=[];Se(e,n,null,function(e){return e});return n}function De(e){!le(e)?k(!1,'React.Children.only expected to receive a single React element child.'):void 0;return e}function Te(e,n){n===void 0&&(n=null);var t={$$typeof:l,_calculateChangedBits:n,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null};t.Provider={$$typeof:s,_context:t};var r=!1,o=!1;return t}function Ie(e){var n={$$typeof:m,_ctor:e,_status:-1,_result:null};return n}function ze(e){return{$$typeof:f,render:e}}function Ue(e){return typeof e==='string'||typeof e==='function'||e===a||e===p||e===c||e===i||e===d||typeof e==='object'&&e!==null&&(e.$$typeof===m||e.$$typeof===y||e.$$typeof===s||e.$$typeof===l||e.$$typeof===f)}function We(e,n){return{$$typeof:y,type:e,compare:n===void 0?null:n}}function A%