mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 04:32:01 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
210 lines
4.8 KiB
TypeScript
210 lines
4.8 KiB
TypeScript
// Loaded from https://cdn.skypack.dev/-/universal-user-agent@v6.0.0-fUAPE3UH5QP7qG0fd0dH/dist=es2020,mode=imports/optimized/universal-user-agent.js
|
|
|
|
|
|
function defaultSetTimout() {
|
|
throw new Error("setTimeout has not been defined");
|
|
}
|
|
function defaultClearTimeout() {
|
|
throw new Error("clearTimeout has not been defined");
|
|
}
|
|
var cachedSetTimeout = defaultSetTimout;
|
|
var cachedClearTimeout = defaultClearTimeout;
|
|
var globalContext;
|
|
if (typeof window !== "undefined") {
|
|
globalContext = window;
|
|
} else if (typeof self !== "undefined") {
|
|
globalContext = self;
|
|
} else {
|
|
globalContext = {};
|
|
}
|
|
if (typeof globalContext.setTimeout === "function") {
|
|
cachedSetTimeout = setTimeout;
|
|
}
|
|
if (typeof globalContext.clearTimeout === "function") {
|
|
cachedClearTimeout = clearTimeout;
|
|
}
|
|
function runTimeout(fun) {
|
|
if (cachedSetTimeout === setTimeout) {
|
|
return setTimeout(fun, 0);
|
|
}
|
|
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
cachedSetTimeout = setTimeout;
|
|
return setTimeout(fun, 0);
|
|
}
|
|
try {
|
|
return cachedSetTimeout(fun, 0);
|
|
} catch (e) {
|
|
try {
|
|
return cachedSetTimeout.call(null, fun, 0);
|
|
} catch (e2) {
|
|
return cachedSetTimeout.call(this, fun, 0);
|
|
}
|
|
}
|
|
}
|
|
function runClearTimeout(marker) {
|
|
if (cachedClearTimeout === clearTimeout) {
|
|
return clearTimeout(marker);
|
|
}
|
|
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
cachedClearTimeout = clearTimeout;
|
|
return clearTimeout(marker);
|
|
}
|
|
try {
|
|
return cachedClearTimeout(marker);
|
|
} catch (e) {
|
|
try {
|
|
return cachedClearTimeout.call(null, marker);
|
|
} catch (e2) {
|
|
return cachedClearTimeout.call(this, marker);
|
|
}
|
|
}
|
|
}
|
|
var queue = [];
|
|
var draining = false;
|
|
var currentQueue;
|
|
var queueIndex = -1;
|
|
function cleanUpNextTick() {
|
|
if (!draining || !currentQueue) {
|
|
return;
|
|
}
|
|
draining = false;
|
|
if (currentQueue.length) {
|
|
queue = currentQueue.concat(queue);
|
|
} else {
|
|
queueIndex = -1;
|
|
}
|
|
if (queue.length) {
|
|
drainQueue();
|
|
}
|
|
}
|
|
function drainQueue() {
|
|
if (draining) {
|
|
return;
|
|
}
|
|
var timeout = runTimeout(cleanUpNextTick);
|
|
draining = true;
|
|
var len = queue.length;
|
|
while (len) {
|
|
currentQueue = queue;
|
|
queue = [];
|
|
while (++queueIndex < len) {
|
|
if (currentQueue) {
|
|
currentQueue[queueIndex].run();
|
|
}
|
|
}
|
|
queueIndex = -1;
|
|
len = queue.length;
|
|
}
|
|
currentQueue = null;
|
|
draining = false;
|
|
runClearTimeout(timeout);
|
|
}
|
|
function nextTick(fun) {
|
|
var args = new Array(arguments.length - 1);
|
|
if (arguments.length > 1) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
args[i - 1] = arguments[i];
|
|
}
|
|
}
|
|
queue.push(new Item(fun, args));
|
|
if (queue.length === 1 && !draining) {
|
|
runTimeout(drainQueue);
|
|
}
|
|
}
|
|
function Item(fun, array) {
|
|
this.fun = fun;
|
|
this.array = array;
|
|
}
|
|
Item.prototype.run = function() {
|
|
this.fun.apply(null, this.array);
|
|
};
|
|
var title = "browser";
|
|
var platform = "browser";
|
|
var browser = true;
|
|
var argv = [];
|
|
var version = "";
|
|
var versions = {};
|
|
var release = {};
|
|
var config = {};
|
|
function noop() {
|
|
}
|
|
var on = noop;
|
|
var addListener = noop;
|
|
var once = noop;
|
|
var off = noop;
|
|
var removeListener = noop;
|
|
var removeAllListeners = noop;
|
|
var emit = noop;
|
|
function binding(name) {
|
|
throw new Error("process.binding is not supported");
|
|
}
|
|
function cwd() {
|
|
return "/";
|
|
}
|
|
function chdir(dir) {
|
|
throw new Error("process.chdir is not supported");
|
|
}
|
|
function umask() {
|
|
return 0;
|
|
}
|
|
var performance = globalContext.performance || {};
|
|
var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function() {
|
|
return new Date().getTime();
|
|
};
|
|
function hrtime(previousTimestamp) {
|
|
var clocktime = performanceNow.call(performance) * 1e-3;
|
|
var seconds = Math.floor(clocktime);
|
|
var nanoseconds = Math.floor(clocktime % 1 * 1e9);
|
|
if (previousTimestamp) {
|
|
seconds = seconds - previousTimestamp[0];
|
|
nanoseconds = nanoseconds - previousTimestamp[1];
|
|
if (nanoseconds < 0) {
|
|
seconds--;
|
|
nanoseconds += 1e9;
|
|
}
|
|
}
|
|
return [seconds, nanoseconds];
|
|
}
|
|
var startTime = new Date();
|
|
function uptime() {
|
|
var currentTime = new Date();
|
|
var dif = currentTime - startTime;
|
|
return dif / 1e3;
|
|
}
|
|
var process = {
|
|
nextTick,
|
|
title,
|
|
browser,
|
|
env: {NODE_ENV: "production"},
|
|
argv,
|
|
version,
|
|
versions,
|
|
on,
|
|
addListener,
|
|
once,
|
|
off,
|
|
removeListener,
|
|
removeAllListeners,
|
|
emit,
|
|
binding,
|
|
cwd,
|
|
chdir,
|
|
umask,
|
|
hrtime,
|
|
platform,
|
|
release,
|
|
config,
|
|
uptime
|
|
};
|
|
function getUserAgent() {
|
|
if (typeof navigator === "object" && "userAgent" in navigator) {
|
|
return navigator.userAgent;
|
|
}
|
|
if (typeof process === "object" && "version" in process) {
|
|
return `Node.js/${process.version.substr(1)} (${process.platform}; ${process.arch})`;
|
|
}
|
|
return "<environment undetectable>";
|
|
}
|
|
export {getUserAgent};
|
|
export default null;
|