From 83df2a119efc3d6f98528ae442046173fc47ac19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 24 May 2024 13:50:41 +0900 Subject: [PATCH 1/3] Add a test --- .../fixture/issues-8xxx/8971/input/.swcrc | 65 +++++++++++++++++++ .../tests/fixture/issues-8xxx/8971/input/1.js | 7 ++ 2 files changed, 72 insertions(+) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8971/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-8xxx/8971/input/1.js diff --git a/crates/swc/tests/fixture/issues-8xxx/8971/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8971/input/.swcrc new file mode 100644 index 000000000000..886393e975da --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8971/input/.swcrc @@ -0,0 +1,65 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": false + }, + "target": "es5", + "loose": false, + "minify": { + "compress": { + "arguments": false, + "arrows": true, + "booleans": true, + "booleans_as_integers": false, + "collapse_vars": true, + "comparisons": true, + "computed_props": true, + "conditionals": true, + "dead_code": true, + "directives": true, + "drop_console": false, + "drop_debugger": true, + "evaluate": true, + "expression": false, + "hoist_funs": false, + "hoist_props": true, + "hoist_vars": false, + "if_return": true, + "join_vars": true, + "keep_classnames": false, + "keep_fargs": true, + "keep_fnames": false, + "keep_infinity": false, + "loops": true, + "negate_iife": true, + "properties": true, + "reduce_funcs": false, + "reduce_vars": false, + "side_effects": true, + "switches": true, + "typeofs": true, + "unsafe": false, + "unsafe_arrows": false, + "unsafe_comps": false, + "unsafe_Function": false, + "unsafe_math": false, + "unsafe_symbols": true, + "unsafe_methods": false, + "unsafe_proto": false, + "unsafe_regexp": false, + "unsafe_undefined": false, + "unused": true, + "const_to_let": true, + "pristine_globals": true + }, + "mangle": false + }, + "externalHelpers": true + }, + "module": { + "type": "es6" + }, + "minify": false, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8971/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8971/input/1.js new file mode 100644 index 000000000000..d6d42685a08a --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8971/input/1.js @@ -0,0 +1,7 @@ +export function f() { + return [ + typeof a === 'object', /* if a is a polyfilled symbol the result is wrong */ + typeof b === 'symbol', + typeof c + ] +} \ No newline at end of file From cd9a97a943eeb700b3aaeb74979cc5d4aab0cca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 24 May 2024 13:52:46 +0900 Subject: [PATCH 2/3] fix --- crates/swc_ecma_compat_es2015/src/typeof_symbol.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs index c01f62d1dc79..d103a569f726 100644 --- a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs +++ b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs @@ -137,7 +137,7 @@ fn is_non_symbol_literal(e: &Expr) -> bool { match e { Expr::Lit(Lit::Str(Str { value, .. })) => matches!( &**value, - "undefined" | "object" | "boolean" | "number" | "string" | "function" + "undefined" | "boolean" | "number" | "string" | "function" ), _ => false, } From f080b75ad47aa7b7c88b706d2e601ad06e91a96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 24 May 2024 13:53:16 +0900 Subject: [PATCH 3/3] Update test refs --- .../fixture/issues-2xxx/2056/1/output/index.js | 4 ++-- .../tests/fixture/issues-8xxx/8616/output/1.js | 3 ++- .../tests/fixture/issues-8xxx/8971/output/1.js | 8 ++++++++ .../TypeGuardWithEnumUnion.1.normal.js | 3 ++- .../TypeGuardWithEnumUnion.2.minified.js | 1 + .../controlFlowTypeofObject.1.normal.js | 15 ++++++++------- .../controlFlowTypeofObject.2.minified.js | 1 + .../tsc-references/mappedTypes4.1.normal.js | 3 ++- .../tsc-references/mappedTypes4.2.minified.js | 1 + .../nonPrimitiveNarrow.1.normal.js | 3 ++- .../nonPrimitiveNarrow.2.minified.js | 3 ++- .../typeGuardOfFormTypeOfFunction.1.normal.js | 3 ++- .../typeGuardOfFormTypeOfFunction.2.minified.js | 1 + .../typeGuardsWithAny.1.normal.js | 3 ++- .../typeGuardsWithAny.2.minified.js | 3 ++- .../unknownControlFlow.1.normal.js | 13 +++++++------ .../unknownControlFlow.2.minified.js | 1 + .../swc/tests/vercel/full/ms/1/output/index.ts | 17 +++++++++-------- 18 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8971/output/1.js diff --git a/crates/swc/tests/fixture/issues-2xxx/2056/1/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2056/1/output/index.js index cdabf22170de..06f1aef73472 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2056/1/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2056/1/output/index.js @@ -130,7 +130,7 @@ export var preTransforms = Object.freeze([ _classCallCheck(this, Mat4); var _this; _this = _possibleConstructorReturn(this, _getPrototypeOf(Mat4).call(this)); - if (m00 && typeof m00 === "object") { + if (m00 && (typeof m00 === "undefined" ? "undefined" : _type_of(m00)) === "object") { if (ArrayBuffer.isView(m00)) { _this._array = m00; _this._array.set([ @@ -399,7 +399,7 @@ export var preTransforms = Object.freeze([ key: "set", value: function set(param, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15) { var m00 = param === void 0 ? 1 : param, m01 = param1 === void 0 ? 0 : param1, m02 = param2 === void 0 ? 0 : param2, m03 = param3 === void 0 ? 0 : param3, m04 = param4 === void 0 ? 0 : param4, m05 = param5 === void 0 ? 1 : param5, m06 = param6 === void 0 ? 0 : param6, m07 = param7 === void 0 ? 0 : param7, m08 = param8 === void 0 ? 0 : param8, m09 = param9 === void 0 ? 0 : param9, m10 = param10 === void 0 ? 1 : param10, m11 = param11 === void 0 ? 0 : param11, m12 = param12 === void 0 ? 0 : param12, m13 = param13 === void 0 ? 0 : param13, m14 = param14 === void 0 ? 0 : param14, m15 = param15 === void 0 ? 1 : param15; - if (m00 && typeof m00 === "object") { + if (m00 && (typeof m00 === "undefined" ? "undefined" : _type_of(m00)) === "object") { var v = m00.array; this._array[1] = v[1]; this._array[2] = v[2]; diff --git a/crates/swc/tests/fixture/issues-8xxx/8616/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8616/output/1.js index 196f0b7f93ee..d9e292e4595b 100644 --- a/crates/swc/tests/fixture/issues-8xxx/8616/output/1.js +++ b/crates/swc/tests/fixture/issues-8xxx/8616/output/1.js @@ -1,3 +1,4 @@ +var _type_of = require("@swc/helpers/_/_type_of"); var Module = (function() { var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; if (typeof __filename !== 'undefined') _scriptDir || (_scriptDir = __filename); @@ -13,7 +14,7 @@ var Module = (function() { return moduleArg; }; })()(); -if (typeof exports === 'object' && typeof module === 'object') module.exports = Module; +if ((typeof exports === "undefined" ? "undefined" : _type_of._(exports)) === 'object' && (typeof module === "undefined" ? "undefined" : _type_of._(module)) === 'object') module.exports = Module; else if (typeof define === 'function' && define['amd']) define([], function() { return Module; }); diff --git a/crates/swc/tests/fixture/issues-8xxx/8971/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8971/output/1.js new file mode 100644 index 000000000000..4d6dcb25b826 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8971/output/1.js @@ -0,0 +1,8 @@ +import { _ as _type_of } from "@swc/helpers/_/_type_of"; +export function f() { + return [ + ("undefined" == typeof a ? "undefined" : _type_of(a)) === 'object', + ("undefined" == typeof b ? "undefined" : _type_of(b)) === 'symbol', + "undefined" == typeof c ? "undefined" : _type_of(c) + ]; +} diff --git a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.1.normal.js b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.1.normal.js index ef7e34374cf4..1718b5a421e5 100644 --- a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.1.normal.js +++ b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.1.normal.js @@ -1,4 +1,5 @@ //// [TypeGuardWithEnumUnion.ts] +import { _ as _type_of } from "@swc/helpers/_/_type_of"; var Color; (function(Color) { Color[Color["R"] = 0] = "R"; @@ -15,7 +16,7 @@ function f1(x) { } } function f2(x) { - if (typeof x === "object") { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === "object") { var y = x; var y; } diff --git a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.2.minified.js b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.2.minified.js index 58fe61f44188..d94cc1dcc4cc 100644 --- a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.2.minified.js +++ b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion.2.minified.js @@ -1,3 +1,4 @@ //// [TypeGuardWithEnumUnion.ts] var Color, Color1; +import "@swc/helpers/_/_type_of"; (Color1 = Color || (Color = {}))[Color1.R = 0] = "R", Color1[Color1.G = 1] = "G", Color1[Color1.B = 2] = "B"; diff --git a/crates/swc/tests/tsc-references/controlFlowTypeofObject.1.normal.js b/crates/swc/tests/tsc-references/controlFlowTypeofObject.1.normal.js index a16f7acd1d61..47163305db9a 100644 --- a/crates/swc/tests/tsc-references/controlFlowTypeofObject.1.normal.js +++ b/crates/swc/tests/tsc-references/controlFlowTypeofObject.1.normal.js @@ -1,9 +1,10 @@ //// [controlFlowTypeofObject.ts] +import { _ as _type_of } from "@swc/helpers/_/_type_of"; function f1(x) { if (!x) { return; } - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); } } @@ -11,7 +12,7 @@ function f2(x) { if (x === null) { return; } - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); } } @@ -19,7 +20,7 @@ function f3(x) { if (x == null) { return; } - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); } } @@ -27,7 +28,7 @@ function f4(x) { if (x == undefined) { return; } - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); } } @@ -41,7 +42,7 @@ function f5(x) { return; } } - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); } } @@ -50,11 +51,11 @@ function f6(x) { x; } else { x; - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); } } - if (typeof x === 'object') { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object') { obj(x); // Error } } diff --git a/crates/swc/tests/tsc-references/controlFlowTypeofObject.2.minified.js b/crates/swc/tests/tsc-references/controlFlowTypeofObject.2.minified.js index d4f39942237f..fd03c9ca34d9 100644 --- a/crates/swc/tests/tsc-references/controlFlowTypeofObject.2.minified.js +++ b/crates/swc/tests/tsc-references/controlFlowTypeofObject.2.minified.js @@ -1 +1,2 @@ //// [controlFlowTypeofObject.ts] +import "@swc/helpers/_/_type_of"; diff --git a/crates/swc/tests/tsc-references/mappedTypes4.1.normal.js b/crates/swc/tests/tsc-references/mappedTypes4.1.normal.js index fe57687a4afc..4aa60adffaf3 100644 --- a/crates/swc/tests/tsc-references/mappedTypes4.1.normal.js +++ b/crates/swc/tests/tsc-references/mappedTypes4.1.normal.js @@ -1,6 +1,7 @@ //// [mappedTypes4.ts] +import { _ as _type_of } from "@swc/helpers/_/_type_of"; function boxify(obj) { - if (typeof obj === "object") { + if ((typeof obj === "undefined" ? "undefined" : _type_of(obj)) === "object") { var result = {}; for(var k in obj){ result[k] = { diff --git a/crates/swc/tests/tsc-references/mappedTypes4.2.minified.js b/crates/swc/tests/tsc-references/mappedTypes4.2.minified.js index 98be04dba287..ccabab859c8d 100644 --- a/crates/swc/tests/tsc-references/mappedTypes4.2.minified.js +++ b/crates/swc/tests/tsc-references/mappedTypes4.2.minified.js @@ -1 +1,2 @@ //// [mappedTypes4.ts] +import "@swc/helpers/_/_type_of"; diff --git a/crates/swc/tests/tsc-references/nonPrimitiveNarrow.1.normal.js b/crates/swc/tests/tsc-references/nonPrimitiveNarrow.1.normal.js index 8dd36db26c95..f702799781c7 100644 --- a/crates/swc/tests/tsc-references/nonPrimitiveNarrow.1.normal.js +++ b/crates/swc/tests/tsc-references/nonPrimitiveNarrow.1.normal.js @@ -1,6 +1,7 @@ //// [nonPrimitiveNarrow.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _instanceof } from "@swc/helpers/_/_instanceof"; +import { _ as _type_of } from "@swc/helpers/_/_type_of"; var Narrow = function Narrow() { "use strict"; _class_call_check(this, Narrow); @@ -14,7 +15,7 @@ if (typeof a === 'number') { a.toFixed(); // error, never } var b; -if (typeof b === 'object') { +if ((typeof b === "undefined" ? "undefined" : _type_of(b)) === 'object') { b.toString(); // ok, object | null } else { b.toString(); // error, never diff --git a/crates/swc/tests/tsc-references/nonPrimitiveNarrow.2.minified.js b/crates/swc/tests/tsc-references/nonPrimitiveNarrow.2.minified.js index 066cf6cf9c9d..9022431c6ce4 100644 --- a/crates/swc/tests/tsc-references/nonPrimitiveNarrow.2.minified.js +++ b/crates/swc/tests/tsc-references/nonPrimitiveNarrow.2.minified.js @@ -2,6 +2,7 @@ var a, b; import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _instanceof } from "@swc/helpers/_/_instanceof"; +import { _ as _type_of } from "@swc/helpers/_/_type_of"; _instanceof(a, function Narrow() { _class_call_check(this, Narrow); -}) && (a.narrowed, a = 123), 'number' == typeof a && a.toFixed(), b.toString(); +}) && (a.narrowed, a = 123), 'number' == typeof a && a.toFixed(), void 0 === b || _type_of(b), b.toString(); diff --git a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.1.normal.js b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.1.normal.js index 3c3196f6b40e..ed1dee2671e4 100644 --- a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.1.normal.js +++ b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.1.normal.js @@ -1,4 +1,5 @@ //// [typeGuardOfFormTypeOfFunction.ts] +import { _ as _type_of } from "@swc/helpers/_/_type_of"; function f1(x) { if (typeof x === "function") { x; // any @@ -82,5 +83,5 @@ function configureStore(reducer) { } } function f101(x) { - return typeof x === "object" && x.anything; + return (typeof x === "undefined" ? "undefined" : _type_of(x)) === "object" && x.anything; } diff --git a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.2.minified.js b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.2.minified.js index d1aa6026e799..bc68c5aae00c 100644 --- a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.2.minified.js +++ b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfFunction.2.minified.js @@ -1 +1,2 @@ //// [typeGuardOfFormTypeOfFunction.ts] +import "@swc/helpers/_/_type_of"; diff --git a/crates/swc/tests/tsc-references/typeGuardsWithAny.1.normal.js b/crates/swc/tests/tsc-references/typeGuardsWithAny.1.normal.js index c921dfe2bf25..1152e18f6d57 100644 --- a/crates/swc/tests/tsc-references/typeGuardsWithAny.1.normal.js +++ b/crates/swc/tests/tsc-references/typeGuardsWithAny.1.normal.js @@ -1,5 +1,6 @@ //// [typeGuardsWithAny.ts] import { _ as _instanceof } from "@swc/helpers/_/_instanceof"; +import { _ as _type_of } from "@swc/helpers/_/_type_of"; var x = { p: 0 }; @@ -23,7 +24,7 @@ if (typeof x === "boolean") { } else { x.p; // No error, type unaffected in this branch } -if (typeof x === "object") { +if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === "object") { x.p; // No error, type any only affected by primitive type check } else { x.p; // No error, type unaffected in this branch diff --git a/crates/swc/tests/tsc-references/typeGuardsWithAny.2.minified.js b/crates/swc/tests/tsc-references/typeGuardsWithAny.2.minified.js index 9efa8b523922..0e1f21cb84e4 100644 --- a/crates/swc/tests/tsc-references/typeGuardsWithAny.2.minified.js +++ b/crates/swc/tests/tsc-references/typeGuardsWithAny.2.minified.js @@ -1,6 +1,7 @@ //// [typeGuardsWithAny.ts] import { _ as _instanceof } from "@swc/helpers/_/_instanceof"; +import { _ as _type_of } from "@swc/helpers/_/_type_of"; var x = { p: 0 }; -_instanceof(x, Object), x.p, x.p, x.p, x.p, x.p; +_instanceof(x, Object), x.p, x.p, x.p, x.p, _type_of(x), x.p; diff --git a/crates/swc/tests/tsc-references/unknownControlFlow.1.normal.js b/crates/swc/tests/tsc-references/unknownControlFlow.1.normal.js index 8d307320f6ee..a8045c6e8cef 100644 --- a/crates/swc/tests/tsc-references/unknownControlFlow.1.normal.js +++ b/crates/swc/tests/tsc-references/unknownControlFlow.1.normal.js @@ -1,4 +1,5 @@ //// [unknownControlFlow.ts] +import { _ as _type_of } from "@swc/helpers/_/_type_of"; function f01(u) { var x1 = u; // Error var x2 = u; @@ -132,23 +133,23 @@ function f23(x) { } } function f30(x) { - if (typeof x === "object") { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === "object") { x; // object } } function f31(x) { - if (typeof x === "object") { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === "object") { x; // T & object | T & null } - if (x && typeof x === "object") { + if (x && (typeof x === "undefined" ? "undefined" : _type_of(x)) === "object") { x; // T & object } - if (typeof x === "object" && x) { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === "object" && x) { x; // T & object } } function f32(x) { - if (typeof x === "object") { + if ((typeof x === "undefined" ? "undefined" : _type_of(x)) === "object") { x; // T & object } } @@ -189,7 +190,7 @@ function f41(a) { } // Repro from #48468 function deepEquals(a, b) { - if (typeof a !== 'object' || typeof b !== 'object' || !a || !b) { + if ((typeof a === "undefined" ? "undefined" : _type_of(a)) !== 'object' || (typeof b === "undefined" ? "undefined" : _type_of(b)) !== 'object' || !a || !b) { return false; } if (Array.isArray(a) || Array.isArray(b)) { diff --git a/crates/swc/tests/tsc-references/unknownControlFlow.2.minified.js b/crates/swc/tests/tsc-references/unknownControlFlow.2.minified.js index 3d28118a4191..5749f68a4207 100644 --- a/crates/swc/tests/tsc-references/unknownControlFlow.2.minified.js +++ b/crates/swc/tests/tsc-references/unknownControlFlow.2.minified.js @@ -1,2 +1,3 @@ //// [unknownControlFlow.ts] +import "@swc/helpers/_/_type_of"; null.foo, null.foo, null.foo, null.foo; diff --git a/crates/swc/tests/vercel/full/ms/1/output/index.ts b/crates/swc/tests/vercel/full/ms/1/output/index.ts index 13044f7897c9..e9fc80bfe93b 100644 --- a/crates/swc/tests/vercel/full/ms/1/output/index.ts +++ b/crates/swc/tests/vercel/full/ms/1/output/index.ts @@ -1,7 +1,8 @@ -export default function(s, c) { - var a, r; +import { _ as e } from "@swc/helpers/_/_type_of"; +export default function(c, a) { + var r, n; try { - if ("string" == typeof s && s.length > 0) return function(e) { + if ("string" == typeof c && c.length > 0) return function(e) { if ((e = String(e)).length > 100) throw Error("Value exceeds the maximum length of 100 characters."); var s = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e); if (!s) return NaN; @@ -48,13 +49,13 @@ export default function(s, c) { default: throw Error("The unit ".concat(a, " was matched, but no matching case exists.")); } - }(s); - if ("number" == typeof s && isFinite(s)) return (null == c ? void 0 : c.long) ? (a = Math.abs(s)) >= 86400000 ? e(s, a, 86400000, "day") : a >= 3600000 ? e(s, a, 3600000, "hour") : a >= 60000 ? e(s, a, 60000, "minute") : a >= 1000 ? e(s, a, 1000, "second") : "".concat(s, " ms") : (r = Math.abs(s)) >= 86400000 ? "".concat(Math.round(s / 86400000), "d") : r >= 3600000 ? "".concat(Math.round(s / 3600000), "h") : r >= 60000 ? "".concat(Math.round(s / 60000), "m") : r >= 1000 ? "".concat(Math.round(s / 1000), "s") : "".concat(s, "ms"); + }(c); + if ("number" == typeof c && isFinite(c)) return (null == a ? void 0 : a.long) ? (r = Math.abs(c)) >= 86400000 ? s(c, r, 86400000, "day") : r >= 3600000 ? s(c, r, 3600000, "hour") : r >= 60000 ? s(c, r, 60000, "minute") : r >= 1000 ? s(c, r, 1000, "second") : "".concat(c, " ms") : (n = Math.abs(c)) >= 86400000 ? "".concat(Math.round(c / 86400000), "d") : n >= 3600000 ? "".concat(Math.round(c / 3600000), "h") : n >= 60000 ? "".concat(Math.round(c / 60000), "m") : n >= 1000 ? "".concat(Math.round(c / 1000), "s") : "".concat(c, "ms"); throw Error("Value is not a string or number."); - } catch (e) { - throw Error("object" == typeof e && null !== e && "message" in e ? "".concat(e.message, ". value=").concat(JSON.stringify(s)) : "An unknown error has occurred."); + } catch (s) { + throw Error((void 0 === s ? "undefined" : e(s)) === "object" && null !== s && "message" in s ? "".concat(s.message, ". value=").concat(JSON.stringify(c)) : "An unknown error has occurred."); } } -function e(e, s, c, a) { +function s(e, s, c, a) { return "".concat(Math.round(e / c), " ").concat(a).concat(s >= 1.5 * c ? "s" : ""); }