Skip to content

Commit

Permalink
Use Type Conditional Return Clause for isVendor (#3)
Browse files Browse the repository at this point in the history
* feat: use type conditionals for `isVendor`

* chore: bundle web module

* chore: update testing deps

* chore: update changelong
  • Loading branch information
sno2 committed Jan 15, 2021
1 parent b758ff9 commit ce69754
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 183 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.2.1 - [2021-01-14]

- added better type inferation with return type clauses for `isVendor()`
- updated std version to 0.83.0 for testing module

## 0.2.0 - [2020-09-17]

- new `Vendor` type
Expand Down
205 changes: 25 additions & 180 deletions bundle/web/deno-vendors.js
Original file line number Diff line number Diff line change
@@ -1,180 +1,25 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

// This is a specialised implementation of a System module loader.

"use strict";

// @ts-nocheck
/* eslint-disable */
let System, __instantiate;
(() => {
const r = new Map();

System = {
register(id, d, f) {
r.set(id, { d, f, exp: {} });
},
};
async function dI(mid, src) {
let id = mid.replace(/\.\w+$/i, "");
if (id.includes("./")) {
const [o, ...ia] = id.split("/").reverse(),
[, ...sa] = src.split("/").reverse(),
oa = [o];
let s = 0,
i;
while ((i = ia.shift())) {
if (i === "..") s++;
else if (i === ".") break;
else oa.push(i);
}
if (s < sa.length) oa.push(...sa.slice(s));
id = oa.reverse().join("/");
}
return r.has(id) ? gExpA(id) : import(mid);
}

function gC(id, main) {
return {
id,
import: (m) => dI(m, id),
meta: { url: id, main },
};
}

function gE(exp) {
return (id, v) => {
v = typeof id === "string" ? { [id]: v } : id;
for (const [id, value] of Object.entries(v)) {
Object.defineProperty(exp, id, {
value,
writable: true,
enumerable: true,
});
}
};
}

function rF(main) {
for (const [id, m] of r.entries()) {
const { f, exp } = m;
const { execute: e, setters: s } = f(gE(exp), gC(id, id === main));
delete m.f;
m.e = e;
m.s = s;
}
}

async function gExpA(id) {
if (!r.has(id)) return;
const m = r.get(id);
if (m.s) {
const { d, e, s } = m;
delete m.s;
delete m.e;
for (let i = 0; i < s.length; i++) s[i](await gExpA(d[i]));
const r = e();
if (r) await r;
}
return m.exp;
}

function gExp(id) {
if (!r.has(id)) return;
const m = r.get(id);
if (m.s) {
const { d, e, s } = m;
delete m.s;
delete m.e;
for (let i = 0; i < s.length; i++) s[i](gExp(d[i]));
e();
}
return m.exp;
}
__instantiate = (m, a) => {
System = __instantiate = undefined;
rF(m);
return a ? gExpA(m) : gExp(m);
};
})();

System.register("vendors", [], function (exports_1, context_1) {
"use strict";
var vendors;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("vendors", vendors = [
"ah",
"apple",
"atsc",
"epub",
"fx",
"hp",
"khtml",
"moz",
"ms",
"o",
"rim",
"ro",
"tc",
"wap",
"webkit",
"xv",
]);
}
};
});
System.register("types/vendor", [], function (exports_2, context_2) {
"use strict";
var __moduleName = context_2 && context_2.id;
return {
setters: [],
execute: function () {
}
};
});
System.register("is_vendor", ["vendors"], function (exports_3, context_3) {
"use strict";
var vendors_ts_1;
var __moduleName = context_3 && context_3.id;
function isVendor(vendor) {
return vendors_ts_1.vendors.includes(vendor);
}
exports_3("isVendor", isVendor);
return {
setters: [
function (vendors_ts_1_1) {
vendors_ts_1 = vendors_ts_1_1;
}
],
execute: function () {
}
};
});
System.register("mod", ["vendors", "is_vendor"], function (exports_4, context_4) {
"use strict";
var __moduleName = context_4 && context_4.id;
return {
setters: [
function (vendors_ts_2_1) {
exports_4({
"vendors": vendors_ts_2_1["vendors"]
});
},
function (is_vendor_ts_1_1) {
exports_4({
"isVendor": is_vendor_ts_1_1["isVendor"]
});
}
],
execute: function () {
}
};
});

const __exp = __instantiate("mod", false);
export const Vendor = __exp["Vendor"];
export const vendors = __exp["vendors"];
export const isVendor = __exp["isVendor"];
const vendors2 = [
"ah",
"apple",
"atsc",
"epub",
"fx",
"hp",
"khtml",
"moz",
"ms",
"o",
"rim",
"ro",
"tc",
"wap",
"webkit",
"xv",
];
const vendors1 = vendors2;
export { vendors1 as vendors };
function isVendor2(vendor) {
return vendors2.includes(vendor);
}
const isVendor1 = isVendor2;
export { isVendor1 as isVendor };
4 changes: 2 additions & 2 deletions is_vendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { vendors } from "./vendors.ts";
* @param vendor the given vendor string
* @returns boolean for if the `vendor` argument is in the `vendors` list
*/
export function isVendor(vendor: string) {
return vendors.includes(<Vendor> vendor);
export function isVendor(vendor: string): vendor is Vendor {
return vendors.includes(vendor as Vendor);
}
2 changes: 1 addition & 1 deletion tests/deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
assert,
assertStrictEquals,
} from "https://deno.land/std@0.69.0/testing/asserts.ts";
} from "https://deno.land/std@0.83.0/testing/asserts.ts";

0 comments on commit ce69754

Please sign in to comment.