diff options
author | 2021-05-15 17:23:55 -0700 | |
---|---|---|
committer | 2021-05-15 17:23:55 -0700 | |
commit | e80f865974df7aae5e2f6abb966b36497da693c6 (patch) | |
tree | e82bcf4860c1fc43de189f13a18e8526a2966f44 /src/test | |
parent | c88625436cf866bdaa68249d10880a2271f611e0 (diff) | |
download | bun-e80f865974df7aae5e2f6abb966b36497da693c6.tar.gz bun-e80f865974df7aae5e2f6abb966b36497da693c6.tar.zst bun-e80f865974df7aae5e2f6abb966b36497da693c6.zip |
lots
Former-commit-id: d8b1d296562a01800248bd1148bc4778225b436e
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fixtures/cannot-assign-to-import-bug.js | 369 | ||||
-rw-r--r-- | src/test/fixtures/img-bug.js | 105 | ||||
-rw-r--r-- | src/test/fixtures/react-dev-crash.js | 108 |
3 files changed, 535 insertions, 47 deletions
diff --git a/src/test/fixtures/cannot-assign-to-import-bug.js b/src/test/fixtures/cannot-assign-to-import-bug.js new file mode 100644 index 000000000..cbf9087f1 --- /dev/null +++ b/src/test/fixtures/cannot-assign-to-import-bug.js @@ -0,0 +1,369 @@ +/** @license React v17.0.2 + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +"use strict"; +var l = require("object-assign"), + n = 60103, + p = 60106; +exports.Fragment = 60107; +exports.StrictMode = 60108; +exports.Profiler = 60114; +var q = 60109, + r = 60110, + t = 60112; +exports.Suspense = 60113; +var u = 60115, + v = 60116; +if ("function" === typeof Symbol && Symbol.for) { + var w = Symbol.for; + n = w("react.element"); + p = w("react.portal"); + exports.Fragment = w("react.fragment"); + exports.StrictMode = w("react.strict_mode"); + exports.Profiler = w("react.profiler"); + q = w("react.provider"); + r = w("react.context"); + t = w("react.forward_ref"); + exports.Suspense = w("react.suspense"); + u = w("react.memo"); + v = w("react.lazy"); +} +var x = "function" === typeof Symbol && Symbol.iterator; +function y(a) { + if (null === a || "object" !== typeof a) return null; + a = (x && a[x]) || a["@@iterator"]; + return "function" === typeof a ? a : null; +} +function z(a) { + for ( + var b = "https://reactjs.org/docs/error-decoder.html?invariant=" + a, c = 1; + c < arguments.length; + c++ + ) + b += "&args[]=" + encodeURIComponent(arguments[c]); + return ( + "Minified React error #" + + a + + "; visit " + + b + + " for the full message or use the non-minified dev environment for full errors and additional helpful warnings." + ); +} +var A = { + isMounted: function () { + return !1; + }, + enqueueForceUpdate: function () {}, + enqueueReplaceState: function () {}, + enqueueSetState: function () {}, + }, + B = {}; +function C(a, b, c) { + this.props = a; + this.context = b; + this.refs = B; + this.updater = c || A; +} +C.prototype.isReactComponent = {}; +C.prototype.setState = function (a, b) { + if ("object" !== typeof a && "function" !== typeof a && null != a) + throw Error(z(85)); + this.updater.enqueueSetState(this, a, b, "setState"); +}; +C.prototype.forceUpdate = function (a) { + this.updater.enqueueForceUpdate(this, a, "forceUpdate"); +}; +function D() {} +D.prototype = C.prototype; +function E(a, b, c) { + this.props = a; + this.context = b; + this.refs = B; + this.updater = c || A; +} +var F = (E.prototype = new D()); +F.constructor = E; +l(F, C.prototype); +F.isPureReactComponent = !0; +var G = { current: null }, + H = Object.prototype.hasOwnProperty, + I = { key: !0, ref: !0, __self: !0, __source: !0 }; +function J(a, b, c) { + var e, + d = {}, + k = null, + h = null; + if (null != b) + for (e in (void 0 !== b.ref && (h = b.ref), + void 0 !== b.key && (k = "" + b.key), + b)) + H.call(b, e) && !I.hasOwnProperty(e) && (d[e] = b[e]); + var g = arguments.length - 2; + if (1 === g) d.children = c; + else if (1 < g) { + for (var f = Array(g), m = 0; m < g; m++) f[m] = arguments[m + 2]; + d.children = f; + } + if (a && a.defaultProps) + for (e in ((g = a.defaultProps), g)) void 0 === d[e] && (d[e] = g[e]); + return { $$typeof: n, type: a, key: k, ref: h, props: d, _owner: G.current }; +} +function K(a, b) { + return { + $$typeof: n, + type: a.type, + key: b, + ref: a.ref, + props: a.props, + _owner: a._owner, + }; +} +function L(a) { + return "object" === typeof a && null !== a && a.$$typeof === n; +} +function escape(a) { + var b = { "=": "=0", ":": "=2" }; + return ( + "$" + + a.replace(/[=:]/g, function (a) { + return b[a]; + }) + ); +} +var M = /\/+/g; +function N(a, b) { + return "object" === typeof a && null !== a && null != a.key + ? escape("" + a.key) + : b.toString(36); +} +function O(a, b, c, e, d) { + var k = typeof a; + if ("undefined" === k || "boolean" === k) a = null; + var h = !1; + if (null === a) h = !0; + else + switch (k) { + case "string": + case "number": + h = !0; + break; + case "object": + switch (a.$$typeof) { + case n: + case p: + h = !0; + } + } + if (h) + return ( + (h = a), + (d = d(h)), + (a = "" === e ? "." + N(h, 0) : e), + Array.isArray(d) + ? ((c = ""), + null != a && (c = a.replace(M, "$&/") + "/"), + O(d, b, c, "", function (a) { + return a; + })) + : null != d && + (L(d) && + (d = K( + d, + c + + (!d.key || (h && h.key === d.key) + ? "" + : ("" + d.key).replace(M, "$&/") + "/") + + a + )), + b.push(d)), + 1 + ); + h = 0; + e = "" === e ? "." : e + ":"; + if (Array.isArray(a)) + for (var g = 0; g < a.length; g++) { + k = a[g]; + var f = e + N(k, g); + h += O(k, b, c, f, d); + } + else if (((f = y(a)), "function" === typeof f)) + for (a = f.call(a), g = 0; !(k = a.next()).done; ) + (k = k.value), (f = e + N(k, g++)), (h += O(k, b, c, f, d)); + else if ("object" === k) + throw ( + ((b = "" + a), + Error( + z( + 31, + "[object Object]" === b + ? "object with keys {" + Object.keys(a).join(", ") + "}" + : b + ) + )) + ); + return h; +} +function P(a, b, c) { + if (null == a) return a; + var e = [], + d = 0; + O(a, e, "", "", function (a) { + return b.call(c, a, d++); + }); + return e; +} +function Q(a) { + if (-1 === a._status) { + var b = a._result; + b = b(); + a._status = 0; + a._result = b; + b.then( + function (b) { + 0 === a._status && ((b = b.default), (a._status = 1), (a._result = b)); + }, + function (b) { + 0 === a._status && ((a._status = 2), (a._result = b)); + } + ); + } + if (1 === a._status) return a._result; + throw a._result; +} +var R = { current: null }; +function S() { + var a = R.current; + if (null === a) throw Error(z(321)); + return a; +} +var T = { + ReactCurrentDispatcher: R, + ReactCurrentBatchConfig: { transition: 0 }, + ReactCurrentOwner: G, + IsSomeRendererActing: { current: !1 }, + assign: l, +}; +exports.Children = { + map: P, + forEach: function (a, b, c) { + P( + a, + function () { + b.apply(this, arguments); + }, + c + ); + }, + count: function (a) { + var b = 0; + P(a, function () { + b++; + }); + return b; + }, + toArray: function (a) { + return ( + P(a, function (a) { + return a; + }) || [] + ); + }, + only: function (a) { + if (!L(a)) throw Error(z(143)); + return a; + }, +}; +exports.Component = C; +exports.PureComponent = E; +exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = T; +exports.cloneElement = function (a, b, c) { + if (null === a || void 0 === a) throw Error(z(267, a)); + var e = l({}, a.props), + d = a.key, + k = a.ref, + h = a._owner; + if (null != b) { + void 0 !== b.ref && ((k = b.ref), (h = G.current)); + void 0 !== b.key && (d = "" + b.key); + if (a.type && a.type.defaultProps) var g = a.type.defaultProps; + for (f in b) + H.call(b, f) && + !I.hasOwnProperty(f) && + (e[f] = void 0 === b[f] && void 0 !== g ? g[f] : b[f]); + } + var f = arguments.length - 2; + if (1 === f) e.children = c; + else if (1 < f) { + g = Array(f); + for (var m = 0; m < f; m++) g[m] = arguments[m + 2]; + e.children = g; + } + return { $$typeof: n, type: a.type, key: d, ref: k, props: e, _owner: h }; +}; +exports.createContext = function (a, b) { + void 0 === b && (b = null); + a = { + $$typeof: r, + _calculateChangedBits: b, + _currentValue: a, + _currentValue2: a, + _threadCount: 0, + Provider: null, + Consumer: null, + }; + a.Provider = { $$typeof: q, _context: a }; + return (a.Consumer = a); +}; +exports.createElement = J; +exports.createFactory = function (a) { + var b = J.bind(null, a); + b.type = a; + return b; +}; +exports.createRef = function () { + return { current: null }; +}; +exports.forwardRef = function (a) { + return { $$typeof: t, render: a }; +}; +exports.isValidElement = L; +exports.lazy = function (a) { + return { $$typeof: v, _payload: { _status: -1, _result: a }, _init: Q }; +}; +exports.memo = function (a, b) { + return { $$typeof: u, type: a, compare: void 0 === b ? null : b }; +}; +exports.useCallback = function (a, b) { + return S().useCallback(a, b); +}; +exports.useContext = function (a, b) { + return S().useContext(a, b); +}; +exports.useDebugValue = function () {}; +exports.useEffect = function (a, b) { + return S().useEffect(a, b); +}; +exports.useImperativeHandle = function (a, b, c) { + return S().useImperativeHandle(a, b, c); +}; +exports.useLayoutEffect = function (a, b) { + return S().useLayoutEffect(a, b); +}; +exports.useMemo = function (a, b) { + return S().useMemo(a, b); +}; +exports.useReducer = function (a, b, c) { + return S().useReducer(a, b, c); +}; +exports.useRef = function (a) { + return S().useRef(a); +}; +exports.useState = function (a) { + return S().useState(a); +}; +exports.version = "17.0.2"; diff --git a/src/test/fixtures/img-bug.js b/src/test/fixtures/img-bug.js index 1d5ec8a82..89b6d464d 100644 --- a/src/test/fixtures/img-bug.js +++ b/src/test/fixtures/img-bug.js @@ -1,48 +1,59 @@ -const hi = () => ({ - its_ireelevant: () => true, -}); -const hey = () => ({ - any_name_will_do: () => true, -}); - -// function getWidths(width, layout, sizes) { -// if (sizes && (layout === "fill" || layout === "responsive")) { -// // Find all the "vw" percent sizes used in the sizes prop -// const percentSizes = [...sizes.matchAll(/(^|\s)(1?\d?\d)vw/g)].map((m) => -// parseInt(m[2]) -// ); -// if (percentSizes.length) { - -// // const smallestRatio = Math.min(...percentSizes) * 0.01; -// // return { -// // widths: allSizes.filter( -// // (s) => s >= configDeviceSizes[0] * smallestRatio -// // ), -// // kind: "w", -// // }; -// } -// return { widths: allSizes, kind: "w" }; -// } -// if ( -// typeof width !== "number" || -// layout === "fill" || -// layout === "responsive" -// ) { -// return { widths: configDeviceSizes, kind: "w" }; -// } -// // const widths = [ -// // ...new Set( // > This means that most OLED screens that say they are 3x resolution, -// // // > are actually 3x in the green color, but only 1.5x in the red and -// // // > blue colors. Showing a 3x resolution image in the app vs a 2x -// // // > resolution image will be visually the same, though the 3x image -// // // > takes significantly more data. Even true 3x resolution screens are -// // // > wasteful as the human eye cannot see that level of detail without -// // // > something like a magnifying glass. -// // // https://blog.twitter.com/engineering/en_us/topics/infrastructure/2019/capping-image-fidelity-on-ultra-high-resolution-devices.html -// // [width, width * 2 /*, width * 3*/].map( -// // (w) => allSizes.find((p) => p >= w) || allSizes[allSizes.length - 1] -// // ) -// // ), -// // ]; -// // return { widths, kind: "x" }; +function hey() { + const well = { + baz: function () {}, + }; +} + +function yo() { + const hi = { + yo: function () {}, + }; +} + +// function yo() { +// const hi = { +// yo: function () {}, +// }; // } + +// This bug is the same as function-scope-bug.jsx, except this time, +// it's specific to scopes created in property definitions +// That means, either arrow functions or non-arrow functions + +// ESBUILD +// Scope: (5 -1) | Scope (5, -100) +// Scope: (6 12) | Scope (6, 12) +// Scope: (7 15) | Scope (7, 15) +// Scope: (6 43) | Scope (6, 43) +// Scope: (7 55) | Scope (7, 55) +// Scope: (6 78) | Scope (6, 78) +// Scope: (7 81) | Scope (7, 81) + +// Scope (6, 106) +// Scope (7, 118) + +// Scope: (5 -1) | Scope (5, -100) +// Scope: (6 12) | Scope (6, 12) +// Scope: (7 15) | Scope (7, 15) +// Scope: (6 43) | Scope (6, 43) +// Scope: (7 55) | Scope (7, 55) +// Scope: (6 78) | Scope (6, 78) +// Scope: (7 81) | Scope (7, 81) +// Scope: (6 106) | Scope (6, 106) +// Scope: (7 118) | Scope (7, 118) + +// ESBUILD + +// Scope: (5 -1) +// Scope: (6 12) +// Scope: (7 15) +// Scope: (6 43) +// Scope: (7 55) +// Scope: (6 78) +// Scope: (7 81) +// Scope: (6 106) +// Scope: (7 118) +// Scope: (6 141) +// Scope: (7 144) +// Scope: (6 169) +// Scope: (7 181) diff --git a/src/test/fixtures/react-dev-crash.js b/src/test/fixtures/react-dev-crash.js new file mode 100644 index 000000000..1bed979a5 --- /dev/null +++ b/src/test/fixtures/react-dev-crash.js @@ -0,0 +1,108 @@ +try { + // This should throw. + if (construct) { + // Something should be setting the props in the constructor. + var Fake = function () { + throw Error(); + }; // $FlowFixMe + + Object.defineProperty(Fake.prototype, "props", { + set: function () { + // We use a throwing setter instead of frozen or non-writable props + // because that won't throw in a non-strict mode function. + throw Error(); + }, + }); + + if (typeof Reflect === "object" && Reflect.construct) { + // We construct a different control for this case to include any extra + // frames added by the construct call. + try { + Reflect.construct(Fake, []); + } catch (x) { + control = x; + } + + Reflect.construct(fn, [], Fake); + } else { + try { + Fake.call(); + } catch (x) { + control = x; + } + + fn.call(Fake.prototype); + } + } else { + try { + throw Error(); + } catch (x) { + control = x; + } + + fn(); + } +} catch (sample) { + // This is inlined manually because closure doesn't do it for us. + if (sample && control && typeof sample.stack === "string") { + // This extracts the first frame from the sample that isn't also in the control. + // Skipping one frame that we assume is the frame that calls the two. + var sampleLines = sample.stack.split("\n"); + var controlLines = control.stack.split("\n"); + var s = sampleLines.length - 1; + var c = controlLines.length - 1; + + while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) { + // We expect at least one stack frame to be shared. + // Typically this will be the root most one. However, stack frames may be + // cut off due to maximum stack limits. In this case, one maybe cut off + // earlier than the other. We assume that the sample is longer or the same + // and there for cut off earlier. So we should find the root most frame in + // the sample somewhere in the control. + c--; + } + + for (; s >= 1 && c >= 0; s--, c--) { + // Next we find the first one that isn't the same which should be the + // frame that called our sample function and the control. + if (sampleLines[s] !== controlLines[c]) { + // In V8, the first line is describing the message but other VMs don't. + // If we're about to return the first line, and the control is also on the same + // line, that's a pretty good indicator that our sample threw at same line as + // the control. I.e. before we entered the sample frame. So we ignore this result. + // This can happen if you passed a class to function component, or non-function. + if (s !== 1 || c !== 1) { + do { + s--; + c--; // We may still have similar intermediate frames from the construct call. + // The next one that isn't the same should be our match though. + + if (c < 0 || sampleLines[s] !== controlLines[c]) { + // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier. + var _frame = "\n" + sampleLines[s].replace(" at new ", " at "); + + { + if (typeof fn === "function") { + componentFrameCache.set(fn, _frame); + } + } // Return the line we found. + + return _frame; + } + } while (s >= 1 && c >= 0); + } + + break; + } + } + } +} finally { + reentry = false; + + { + ReactCurrentDispatcher$1.current = previousDispatcher; + reenableLogs(); + } + + Error.prepareStackTrace = previousPrepareStackTrace; +} // Fallback to just using the name if we couldn't make it throw. |