Comparing version 1.22.2 to 1.22.3
## 5 September 2019 | ||
### [1.22.3](https://github.com/artdecocode/typal/compare/v1.22.2...v1.22.3) | ||
- [fix] Correct `this` args count and allow to print `...custom` var args in typescript types. | ||
### [1.22.2](https://github.com/artdecocode/typal/compare/v1.22.1...v1.22.2) | ||
@@ -4,0 +8,0 @@ |
@@ -10,3 +10,3 @@ #!/usr/bin/env node | ||
}, ba = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this; | ||
function ca(a, b) { | ||
function ea(a, b) { | ||
if (b) { | ||
@@ -26,3 +26,3 @@ var c = ba; | ||
} | ||
ca("String.prototype.trimRight", function(a) { | ||
ea("String.prototype.trimRight", function(a) { | ||
function b() { | ||
@@ -33,3 +33,3 @@ return this.replace(/[\s\xa0]+$/, ""); | ||
}); | ||
const ea = (a, b, c, d = !1, e = !1) => { | ||
const fa = (a, b, c, d = !1, e = !1) => { | ||
const g = c ? new RegExp(`^-(${c}|-${b})`) : new RegExp(`^--${b}`); | ||
@@ -50,3 +50,3 @@ b = a.findIndex(f => g.test(f)); | ||
return {value:c, argv:[...a.slice(0, b), ...a.slice(d + 1)]}; | ||
}, fa = a => { | ||
}, ha = a => { | ||
const b = []; | ||
@@ -61,4 +61,4 @@ for (let c = 0; c < a.length; c++) { | ||
return b; | ||
}, ia = () => { | ||
var a = ha; | ||
}, ja = () => { | ||
var a = ia; | ||
return Object.keys(a).reduce((b, c) => { | ||
@@ -77,7 +77,7 @@ const d = a[c]; | ||
}; | ||
const ha = {source:{description:"The path to the source file or directory with files to embed types into. Can specify multiple values, e.g., `typal types/index.js types/vendor.js`.", command:!0, multiple:!0}, output:{description:"The destination where to save output.\nIf not passed, the file will be overwritten.\nIf `-` is passed, prints to stdout.", short:"o"}, closure:{description:"Whether to generate types in _Closure_ mode.", boolean:!0, short:"c"}, useNamespace:{description:"Generate JSDoc for functions using namespaces.", | ||
const ia = {source:{description:"The path to the source file or directory with files to embed types into. Can specify multiple values, e.g., `typal types/index.js types/vendor.js`.", command:!0, multiple:!0}, output:{description:"The destination where to save output.\nIf not passed, the file will be overwritten.\nIf `-` is passed, prints to stdout.", short:"o"}, closure:{description:"Whether to generate types in _Closure_ mode.", boolean:!0, short:"c"}, useNamespace:{description:"Generate JSDoc for functions using namespaces.", | ||
boolean:!0, short:"u"}, externs:{description:"Whether to generate externs for _GCC_.", boolean:!0, short:"e"}, types:{description:"Comma-separated location of files to read types from.", short:"t"}, template:{description:"Scans the input file for `@type` comment in functions' JSDoc, and inserts the annotations from types' files.", short:"T"}, migrate:{description:"Extracts types from JavaScript source code and saves them\ninto the types.xml file specified in the output option.", boolean:!0, short:"m"}, | ||
help:{description:"Print the help information and exit.", boolean:!0, short:"h"}, version:{description:"Show the version's number and exit.", boolean:!0, short:"v"}}, w = function(a = {}, b = process.argv) { | ||
[, , ...b] = b; | ||
const c = fa(b); | ||
const c = ha(b); | ||
b = b.slice(c.length); | ||
@@ -92,7 +92,7 @@ let d = !c.length; | ||
if ("string" == typeof h) { | ||
({value:k, argv:e} = ea(e, f, h)); | ||
({value:k, argv:e} = fa(e, f, h)); | ||
} else { | ||
try { | ||
const {short:l, boolean:m, number:n, command:p, multiple:q} = h; | ||
p && q && c.length ? (k = c, d = !0) : p && c.length ? (k = c[0], d = !0) : {value:k, argv:e} = ea(e, f, l, m, n); | ||
p && q && c.length ? (k = c, d = !0) : p && c.length ? (k = c[0], d = !0) : {value:k, argv:e} = fa(e, f, l, m, n); | ||
} catch (l) { | ||
@@ -104,4 +104,4 @@ return {m:e, ...g}; | ||
}, {m:b}); | ||
}(ha), y = w.source, ja = w.output, ka = w.closure, la = w.useNamespace, ma = w.externs, na = w.types, oa = w.template, pa = w.migrate, qa = w.help, ra = w.version; | ||
function sa(a = {usage:{}}) { | ||
}(ia), y = w.source, ka = w.output, la = w.closure, ma = w.useNamespace, na = w.externs, oa = w.types, pa = w.template, qa = w.migrate, ra = w.help, sa = w.version; | ||
function ta(a = {usage:{}}) { | ||
const {usage:b = {}, description:c, line:d, example:e} = a; | ||
@@ -137,6 +137,6 @@ a = Object.keys(b); | ||
} | ||
;const {createReadStream:ta, createWriteStream:ua, lstat:z, readdir:va} = fs; | ||
var wa = stream; | ||
const {Transform:A, Writable:xa} = stream; | ||
const ya = (a, b = 0, c = !1) => { | ||
;const {createReadStream:ua, createWriteStream:va, lstat:z, readdir:wa} = fs; | ||
var xa = stream; | ||
const {Transform:A, Writable:ya} = stream; | ||
const za = (a, b = 0, c = !1) => { | ||
if (0 === b && !c) { | ||
@@ -147,11 +147,11 @@ return a; | ||
return c ? a[a.length - 1] : a.slice(b).join("\n"); | ||
}, za = (a, b = !1) => ya(a, 2 + (b ? 1 : 0)), Da = a => { | ||
}, Da = (a, b = !1) => za(a, 2 + (b ? 1 : 0)), Ea = a => { | ||
({callee:{caller:a}} = a); | ||
return a; | ||
}; | ||
const {homedir:Ea} = os; | ||
const Fa = /\s+at.*(?:\(|\s)(.*)\)?/, Ga = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/, Ha = Ea(), B = a => { | ||
const {pretty:b = !1, ignoredModules:c = ["pirates"]} = {}, d = c.join("|"), e = new RegExp(Ga.source.replace("IGNORED_MODULES", d)); | ||
const {homedir:Fa} = os; | ||
const Ga = /\s+at.*(?:\(|\s)(.*)\)?/, Ha = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/, Ia = Fa(), B = a => { | ||
const {pretty:b = !1, ignoredModules:c = ["pirates"]} = {}, d = c.join("|"), e = new RegExp(Ha.source.replace("IGNORED_MODULES", d)); | ||
return a.replace(/\\/g, "/").split("\n").filter(g => { | ||
g = g.match(Fa); | ||
g = g.match(Ga); | ||
if (null === g || !g[1]) { | ||
@@ -162,8 +162,8 @@ return !0; | ||
return g.includes(".app/Contents/Resources/electron.asar") || g.includes(".app/Contents/Resources/default_app.asar") ? !1 : !e.test(g); | ||
}).filter(g => g.trim()).map(g => b ? g.replace(Fa, (f, h) => f.replace(h, h.replace(Ha, "~"))) : g).join("\n"); | ||
}).filter(g => g.trim()).map(g => b ? g.replace(Ga, (f, h) => f.replace(h, h.replace(Ia, "~"))) : g).join("\n"); | ||
}; | ||
function Ia(a, b, c = !1) { | ||
function Ja(a, b, c = !1) { | ||
return function(d) { | ||
var e = Da(arguments), {stack:g} = Error(); | ||
const f = ya(g, 2, !0), h = (g = d instanceof Error) ? d.message : d; | ||
var e = Ea(arguments), {stack:g} = Error(); | ||
const f = za(g, 2, !0), h = (g = d instanceof Error) ? d.message : d; | ||
e = [`Error: ${h}`, ...null !== e && a === e || c ? [b] : [f, b]].join("\n"); | ||
@@ -176,7 +176,7 @@ e = B(e); | ||
var {stack:b} = Error(); | ||
const c = Da(arguments); | ||
b = za(b, a); | ||
return Ia(c, b, a); | ||
const c = Ea(arguments); | ||
b = Da(b, a); | ||
return Ja(c, b, a); | ||
} | ||
;const Ja = (a, b) => { | ||
;const Ka = (a, b) => { | ||
b.once("error", c => { | ||
@@ -187,3 +187,3 @@ a.emit("error", c); | ||
}; | ||
class Ka extends xa { | ||
class La extends ya { | ||
constructor(a) { | ||
@@ -210,3 +210,3 @@ const {binary:b = !1, rs:c = null, ...d} = a || {}, {M:e = C(!0), proxyError:g} = a || {}, f = (h, k) => e(k); | ||
}); | ||
c && Ja(this, c).pipe(this); | ||
c && Ka(this, c).pipe(this); | ||
}); | ||
@@ -223,7 +223,7 @@ } | ||
const D = async a => { | ||
({f:a} = new Ka({rs:a, M:C(!0)})); | ||
({f:a} = new La({rs:a, M:C(!0)})); | ||
return await a; | ||
}; | ||
async function F(a) { | ||
a = ta(a); | ||
a = ua(a); | ||
return await D(a); | ||
@@ -235,3 +235,3 @@ } | ||
} | ||
const c = C(!0), d = ua(a); | ||
const c = C(!0), d = va(a); | ||
await new Promise((e, g) => { | ||
@@ -244,3 +244,3 @@ d.on("error", f => { | ||
} | ||
;function La(a, b) { | ||
;function Ma(a, b) { | ||
if (b > a - 2) { | ||
@@ -263,4 +263,4 @@ throw Error("Function does not accept that many arguments."); | ||
Array.isArray(b) ? (b.forEach((l, m) => { | ||
La(e, m); | ||
}), k = [...b, h]) : 1 < Array.from(arguments).length && (La(e, 0), k = [b, h]); | ||
Ma(e, m); | ||
}), k = [...b, h]) : 1 < Array.from(arguments).length && (Ma(e, 0), k = [b, h]); | ||
a(...k); | ||
@@ -270,3 +270,3 @@ }); | ||
;const {join:I} = path; | ||
async function Ma(a, b) { | ||
async function Na(a, b) { | ||
b = b.map(async c => { | ||
@@ -278,3 +278,3 @@ const d = I(a, c); | ||
} | ||
const Na = a => a.lstat.isDirectory(), Oa = a => !a.lstat.isDirectory(); | ||
const Oa = a => a.lstat.isDirectory(), Pa = a => !a.lstat.isDirectory(); | ||
async function J(a) { | ||
@@ -287,6 +287,6 @@ if (!a) { | ||
} | ||
var b = await H(va, a); | ||
b = await Ma(a, b); | ||
a = b.filter(Na); | ||
b = b.filter(Oa).reduce((c, d) => { | ||
var b = await H(wa, a); | ||
b = await Na(a, b); | ||
a = b.filter(Oa); | ||
b = b.filter(Pa).reduce((c, d) => { | ||
var e = d.lstat.isDirectory() ? "Directory" : d.lstat.isFile() ? "File" : d.lstat.isSymbolicLink() ? "SymbolicLink" : void 0; | ||
@@ -315,3 +315,3 @@ return {...c, [d.relativePath]:{type:e}}; | ||
}; | ||
function Pa(a) { | ||
function Qa(a) { | ||
if ("object" != typeof a) { | ||
@@ -339,5 +339,5 @@ return !1; | ||
}; | ||
function Qa(a, b) { | ||
function Ra(a, b) { | ||
function c() { | ||
return b.filter(Pa).reduce((d, {re:e, replacement:g}) => { | ||
return b.filter(Qa).reduce((d, {re:e, replacement:g}) => { | ||
if (this.j) { | ||
@@ -367,3 +367,3 @@ return d; | ||
} | ||
;const Ra = a => new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`, "g"), Sa = (a, b) => `%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`, Ta = () => { | ||
;const Sa = a => new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`, "g"), Ta = (a, b) => `%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`, Ua = () => { | ||
var a = {N:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg}; | ||
@@ -373,3 +373,3 @@ return Object.keys(a).reduce((b, c) => { | ||
var d = a[c]; | ||
const {getReplacement:e = Sa, getRegex:g = Ra} = {}, f = g(c); | ||
const {getReplacement:e = Ta, getRegex:g = Sa} = {}, f = g(c); | ||
d = {name:c, re:d, regExp:f, getReplacement:e, map:{}, lastIndex:0}; | ||
@@ -379,3 +379,3 @@ } | ||
}, {}); | ||
}, Ua = a => { | ||
}, Va = a => { | ||
var b = []; | ||
@@ -386,5 +386,5 @@ const {regExp:c, map:d} = a; | ||
delete d[g]; | ||
return Qa(e, Array.isArray(b) ? b : [b]); | ||
return Ra(e, Array.isArray(b) ? b : [b]); | ||
}}; | ||
}, Va = a => { | ||
}, Wa = a => { | ||
const {re:b, map:c, getReplacement:d, name:e} = a; | ||
@@ -398,4 +398,4 @@ return {re:b, replacement(g) { | ||
}; | ||
async function Wa(a, b) { | ||
return Xa(a, b); | ||
async function Xa(a, b) { | ||
return Ya(a, b); | ||
} | ||
@@ -405,3 +405,3 @@ class M extends A { | ||
super(b); | ||
this.f = (Array.isArray(a) ? a : [a]).filter(Pa); | ||
this.f = (Array.isArray(a) ? a : [a]).filter(Qa); | ||
this.j = !1; | ||
@@ -413,3 +413,3 @@ this.h = b; | ||
b && Object.assign(c, b); | ||
a = await Wa(c, a); | ||
a = await Xa(c, a); | ||
c.j && (this.j = !0); | ||
@@ -469,8 +469,8 @@ b && Object.keys(b).forEach(d => { | ||
} | ||
async function Xa(a, b) { | ||
b instanceof wa ? b.pipe(a) : a.end(b); | ||
async function Ya(a, b) { | ||
b instanceof xa ? b.pipe(a) : a.end(b); | ||
return await D(a); | ||
} | ||
;function Ya() { | ||
var a = Za; | ||
;function Za() { | ||
var a = $a; | ||
let b = ""; | ||
@@ -496,3 +496,3 @@ const c = new A({transform(d, e, g) { | ||
return `${a}=${b}`; | ||
}, $a = ({number:a, J:b, boolean:c, type:d}) => b ? "string" : a ? "number" : c ? "boolean" : d ? d : "*", ab = a => `${/[^\w\d._]/.test(a) ? `(${a})` : a}|undefined`, O = a => a ? `/** | ||
}, ab = ({number:a, J:b, boolean:c, type:d}) => b ? "string" : a ? "number" : c ? "boolean" : d ? d : "*", bb = a => `${/[^\w\d._]/.test(a) ? `(${a})` : a}|undefined`, O = a => a ? `/** | ||
${a} | ||
@@ -505,3 +505,3 @@ */ | ||
return a; | ||
}, S = a => { | ||
}, R = a => { | ||
a = a.trimRight(); | ||
@@ -529,3 +529,3 @@ var b = /\S/.exec(a); | ||
}; | ||
function T(a, b, c) { | ||
function S(a, b, c) { | ||
const d = []; | ||
@@ -545,11 +545,11 @@ b.replace(a, (e, ...g) => { | ||
} | ||
;const bb = new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`, "g"), cb = new RegExp(`(?:\\s+((?:${bb.source}\\s*)*))`); | ||
const U = (a, b) => { | ||
;const cb = new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`, "g"), db = new RegExp(`(?:\\s+((?:${cb.source}\\s*)*))`); | ||
const T = (a, b) => { | ||
a = (Array.isArray(a) ? a : [a]).join("|"); | ||
return T(new RegExp(`<(${a})${cb.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`, "g"), b, "t a v v1 v2 c".split(" ")).map(({t:c, a:d = "", c:e = ""}) => { | ||
return S(new RegExp(`<(${a})${db.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`, "g"), b, "t a v v1 v2 c".split(" ")).map(({t:c, a:d = "", c:e = ""}) => { | ||
d = d.replace(/\/$/, "").trim(); | ||
d = db(d); | ||
d = eb(d); | ||
return {content:e, props:d, tag:c}; | ||
}); | ||
}, db = a => T(bb, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => { | ||
}, eb = a => S(cb, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => { | ||
if (void 0 === d) { | ||
@@ -561,3 +561,3 @@ return b[c] = !0, b; | ||
}, {}); | ||
const eb = a => a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b => /\S/.test(b)).map(b => { | ||
const fb = a => a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b => /\S/.test(b)).map(b => { | ||
switch(b) { | ||
@@ -579,3 +579,3 @@ case "function": | ||
}); | ||
function fb(a) { | ||
function gb(a) { | ||
let b = 0; | ||
@@ -737,5 +737,5 @@ const c = (e = 1) => a[b + e], d = (e = !0, g = []) => { | ||
} | ||
;function gb(a) { | ||
a = eb(a); | ||
return fb(a); | ||
;function U(a) { | ||
a = fb(a); | ||
return gb(a); | ||
} | ||
@@ -747,4 +747,4 @@ ;function hb(a, b, {name:c, string:d, "boolean":e, opt:g, number:f, type:h}, k) { | ||
a.name = c; | ||
b && (a.description = S(b)); | ||
b = $a({number:f, J:d, boolean:e, type:h}); | ||
b && (a.description = R(b)); | ||
b = ab({number:f, J:d, boolean:e, type:h}); | ||
k && (b = b.replace(new RegExp(`([!?])?${k}\\.`, "g"), "$1")); | ||
@@ -762,3 +762,3 @@ b.endsWith("=") && (b = b.replace(/=$/, ""), g = !0); | ||
} | ||
get D() { | ||
get F() { | ||
return this.optional ? `${this.type}=` : this.type; | ||
@@ -770,3 +770,3 @@ } | ||
var e = []; | ||
-1 != c && (c += 6, e = a.slice(0, c), d = a.slice(c), e = U("arg", e), e = e.map(({content:g, props:f}) => { | ||
-1 != c && (c += 6, e = a.slice(0, c), d = a.slice(c), e = T("arg", e), e = e.map(({content:g, props:f}) => { | ||
const h = new ib; | ||
@@ -776,3 +776,3 @@ hb(h, g, f, b); | ||
})); | ||
return {H:d, C:e}; | ||
return {H:d, D:e}; | ||
}; | ||
@@ -836,5 +836,5 @@ function V(a) { | ||
a.name = c; | ||
b && (a.description = S(b)); | ||
b = $a({number:f, J:d, boolean:e, type:h}); | ||
p && (a.l = p); | ||
b && (a.description = R(b)); | ||
b = ab({number:f, J:d, boolean:e, type:h}); | ||
p && (a.o = p); | ||
l && (a.g = l); | ||
@@ -859,3 +859,3 @@ a.type = b; | ||
b = a.optional ? `[${b}]` : b; | ||
var {h:d} = a; | ||
var {l:d} = a; | ||
d = d ? ` ${d}` : ""; | ||
@@ -885,3 +885,3 @@ return `{${mb(a, c)}} ${b}${d}`; | ||
const {function:{args:b, variableArgs:c}} = a.parsed, d = b.map((e, g) => { | ||
({name:e = `arg${g}`} = a.args[g] || {}); | ||
({name:e = `arg${g}`} = a.h[0] || {}); | ||
return e; | ||
@@ -896,5 +896,5 @@ }); | ||
let c = []; | ||
var {h:d} = a; | ||
var {l:d} = a; | ||
d && (d = pb(d), c.push(d)); | ||
!a.optional && a.isParsedFunction ? (a = qb(a), c.push(...a)) : c.push(` * @type {${a.optional ? ab(a.closureType) : a.closureType}}`); | ||
!a.optional && a.isParsedFunction ? (a = qb(a), c.push(...a)) : c.push(` * @type {${a.optional ? bb(a.closureType) : a.closureType}}`); | ||
b && (c = c.map(e => `${b}${e}`)); | ||
@@ -916,3 +916,3 @@ return c.join("\n"); | ||
this.aliases = []; | ||
this.l = !1; | ||
this.o = !1; | ||
this.parsed = null; | ||
@@ -929,3 +929,3 @@ this.args = a; | ||
const {optional:l} = b[k]; | ||
let {name:m = `arg${k}`, optional:n = l} = this.args[k] || {}; | ||
let {name:m = `arg${k}`, optional:n = l} = this.h[k] || {}; | ||
return `${`${m}${n ? "?" : ""}`}: ${h}`; | ||
@@ -937,3 +937,11 @@ }); | ||
} | ||
e && (f = a(e), g.push(`...args: ${f}[]`)); | ||
if (e) { | ||
f = a(e); | ||
let h = "...args"; | ||
try { | ||
h = `${this.args[this.args.length - 1].name}`; | ||
} catch (k) { | ||
} | ||
g.push(`${h}: ${f}[]`); | ||
} | ||
g = g.join(", "); | ||
@@ -955,5 +963,5 @@ f = c ? a(c) : "?"; | ||
this.closureType = this.g || this.f || ""; | ||
if (!this.l) { | ||
if (!this.o) { | ||
try { | ||
this.parsed = gb(this.closureType), this.isParsedFunction && !this.args && (this.args = []); | ||
this.parsed = U(this.closureType), this.isParsedFunction && !this.args && (this.args = []); | ||
} catch (b) { | ||
@@ -964,10 +972,15 @@ this.parsed = null; | ||
} | ||
get h() { | ||
get l() { | ||
let a = this.description || ""; | ||
return `${a}${this.hasDefault ? `${/``` */.test(this.description) ? "\n" : a ? " " : ""}Default \`${this.default}\`.` : ""}`; | ||
} | ||
get h() { | ||
var a = this.args; | ||
this.args && this.args[0] && "this" == this.args[0].name && ([, ...a] = this.args); | ||
return a; | ||
} | ||
get isParsedFunction() { | ||
return !!this.parsed && "function" == this.parsed.name; | ||
} | ||
A(a, b = "", c = !1) { | ||
B(a, b = "", c = !1) { | ||
a = nb(this, a, c); | ||
@@ -991,3 +1004,3 @@ return `${b} * @param ${a}`; | ||
try { | ||
(d = gb(b)) || console.log("Could not parse %s", b); | ||
(d = U(b)) || console.log("Could not parse %s", b); | ||
} catch (e) { | ||
@@ -1101,3 +1114,3 @@ console.log("Could not parse %s", b), console.error(e.message); | ||
function Cb(a, b = !1, c = !1, d = b) { | ||
d = ` * @typedef {${(b ? a.closureType : a.type) || a.F()}}${` ${Bb(a, d)}${a.h}`}`; | ||
d = ` * @typedef {${(b ? a.closureType : a.type) || a.o()}}${` ${Bb(a, d)}${a.h}`}`; | ||
a = (a.properties ? a.properties.reduce((e, g) => { | ||
@@ -1140,3 +1153,3 @@ if (g.b) { | ||
k ? this.closureType = k : this.closureType = this.type; | ||
d && (this.description = S(d)); | ||
d && (this.description = R(d)); | ||
this.noToc = !!e; | ||
@@ -1151,3 +1164,3 @@ this.spread = !!g; | ||
if (a) { | ||
b = U("prop", a).map(({content:t, props:v}) => { | ||
b = T("prop", a).map(({content:t, props:v}) => { | ||
const E = new ub; | ||
@@ -1157,7 +1170,7 @@ lb(E, t, v); | ||
}); | ||
a = U(["function", "fn", "static"], a).map(({content:t, props:v, tag:E}) => { | ||
a = T(["function", "fn", "static"], a).map(({content:t, props:v, tag:E}) => { | ||
E = "static" == E; | ||
const {H:Pb, C:Aa} = jb(t, r), {async:Ba, "void":Qb, "return":Rb = Qb ? "void" : "", ...Ca} = v; | ||
const {H:Pb, D:Aa} = jb(t, r), {async:Ba, "void":Qb, "return":Rb = Qb ? "void" : "", ...Ca} = v; | ||
({args:v = ""} = v); | ||
v || (v = Aa.map(({D:da, name:R}) => "this" == R ? `${R}: ${da}` : "...args" == R || "..." == R ? `...${da}` : da).join(",")); | ||
v || (v = Aa.map(({F:ca, name:da}) => "this" == da ? `${da}: ${ca}` : da.startsWith("...") ? `...${ca}` : ca).join(",")); | ||
t = Rb.replace(/\n\s*/g, " "); | ||
@@ -1185,3 +1198,3 @@ Ba && t ? t = `!Promise<${t}>` : Ba && (t = "!Promise"); | ||
} | ||
F() { | ||
o() { | ||
return "Object"; | ||
@@ -1243,3 +1256,3 @@ } | ||
} | ||
A(a, b, c, d, e = !1, g = !1) { | ||
B(a, b, c, d, e = !1, g = !1) { | ||
var f = ""; | ||
@@ -1250,3 +1263,3 @@ !0 === d ? f = "?" : !1 === d && (f = "!"); | ||
b = `${c || ""} * @param {${f}${h}} ${b ? `[${a}]` : a}${d}`; | ||
f = this.properties && !this.noExpand ? this.properties.map(k => k.A(a, c, e, g)) : []; | ||
f = this.properties && !this.noExpand ? this.properties.map(k => k.B(a, c, e, g)) : []; | ||
return [b, ...f].join("\n"); | ||
@@ -1289,3 +1302,3 @@ } | ||
let e = c.name, g = d; | ||
c.optional && !b ? e = `${c.name}?` : c.optional && b && (g = `(${ab(d)})`); | ||
c.optional && !b ? e = `${c.name}?` : c.optional && b && (g = `(${bb(d)})`); | ||
return `${e}: ${g}`; | ||
@@ -1307,3 +1320,3 @@ }).join(", ")} }`; | ||
this.from = b; | ||
this.description = S(a); | ||
this.description = R(a); | ||
super.b("", {...d, noToc:!0, name:c, type:`import('${b}').${c}`}, e != g ? e : null); | ||
@@ -1317,3 +1330,3 @@ } | ||
b = b.reduce((c, d) => ({...c, [d.fullName]:d}), {}); | ||
a.v = {...a.v, ...b}; | ||
a.w = {...a.w, ...b}; | ||
} | ||
@@ -1323,3 +1336,3 @@ class Hb extends M { | ||
super(a); | ||
this.v = {}; | ||
this.w = {}; | ||
this.on("types", c => { | ||
@@ -1344,3 +1357,3 @@ Gb(this, c); | ||
get types() { | ||
return this.v; | ||
return this.w; | ||
} | ||
@@ -1361,3 +1374,3 @@ } | ||
b(a, {async:b, "return":c, ...d}, ...e) { | ||
this.description = S(a); | ||
this.description = R(a); | ||
super.b("", d, ...e); | ||
@@ -1378,3 +1391,3 @@ c && (this.l = c.replace(/\n\s*/g, " ")); | ||
} | ||
F() { | ||
o() { | ||
return `(${this.args.map(({name:a, type:b, optional:c}) => `${a}${c ? "?" : ""}: ${b}`).join(", ")}) => ${this.return}`; | ||
@@ -1385,3 +1398,3 @@ } | ||
if (a.args && a.args.length) { | ||
var b = `function(${a.args.map(({D:d}) => d).join(", ")}): ${a.fullName}`, c = new ub(a.args); | ||
var b = `function(${a.args.map(({F:d}) => d).join(", ")}): ${a.fullName}`, c = new ub(a.args); | ||
c.isConstructor = !0; | ||
@@ -1393,3 +1406,3 @@ lb(c, "Constructor method.", {type:b, name:"constructor"}); | ||
}, Lb = a => { | ||
a = U("types", a); | ||
a = T("types", a); | ||
if (!a.length) { | ||
@@ -1399,3 +1412,3 @@ throw Error("XML file should contain root types element."); | ||
const [{content:b, props:{namespace:c, ns:d = c}}] = a, e = void 0 == d ? void 0 : d, g = []; | ||
a = U(["type", "interface", "constructor", "method", "import"], b).reduce((f, {content:h, props:k, tag:l}) => { | ||
a = T(["type", "interface", "constructor", "method", "import"], b).reduce((f, {content:h, props:k, tag:l}) => { | ||
const {alias:m, aliases:n, ...p} = k; | ||
@@ -1444,3 +1457,3 @@ var q = m ? [m] : n ? n.split(/, */) : []; | ||
1 != g && (f = a.slice(0, g), h = a.slice(g)); | ||
const {C:k, H:l} = jb(f, void 0); | ||
const {D:k, H:l} = jb(f, void 0); | ||
e.b(d ? l : h, b, c, void 0); | ||
@@ -1495,3 +1508,3 @@ e.args = k; | ||
m = m ? m.replace("ignore:", "").split(",") : []; | ||
let {u:n, w:p} = this.g; | ||
let {v:n, A:p} = this.g; | ||
g && (n = !0); | ||
@@ -1518,3 +1531,3 @@ f && (p = !0); | ||
function Wb(a, b, c, d, e, g, f) { | ||
const {u:h, B:k} = this.g; | ||
const {v:h, C:k} = this.g; | ||
let l; | ||
@@ -1536,3 +1549,3 @@ g = () => { | ||
try { | ||
l = gb(c); | ||
l = U(c); | ||
} catch (n) { | ||
@@ -1549,3 +1562,3 @@ return this.i("Error while parsing the type %s", c), this.i(process.env.DEBUG ? n.stack : n.message), g(), a; | ||
c = Object.values(this.types).find(({name:n, fullName:p}) => h || k ? p == l.name : n == l.name); | ||
return !c || c instanceof Hb.Import ? a : c.A(e, d, b, l.nullable, h, k); | ||
return !c || c instanceof Hb.Import ? a : c.B(e, d, b, l.nullable, h, k); | ||
} | ||
@@ -1579,9 +1592,9 @@ const Z = (a, b, c, d, e) => { | ||
var Zb = (a, b = !1) => { | ||
var {N:c} = Ta(); | ||
const d = Va(c); | ||
c = Ua(c); | ||
var {N:c} = Ua(); | ||
const d = Wa(c); | ||
c = Va(c); | ||
return new Hb(b ? [Ub] : [Ub, d, Xb, c], a); | ||
}; | ||
var ac = async() => { | ||
const {u:a = !1, B:b = !1, w:c = !1, o:d, types:e} = {u:ka, w:ma, o:ja, types:na, B:la}; | ||
const {v:a = !1, C:b = !1, A:c = !1, s:d, types:e} = {v:la, A:na, s:ka, types:oa, C:ma}; | ||
await Promise.all(y.map(async g => { | ||
@@ -1603,3 +1616,3 @@ var f = await H(z, g); | ||
var k = await F(h); | ||
const l = Zb({u:b, w:c, B:g}, c); | ||
const l = Zb({v:b, A:c, C:g}, c); | ||
f.forEach(m => l.emit("types", m)); | ||
@@ -1618,3 +1631,3 @@ l.file = h; | ||
return void 0 !== b ? b : a; | ||
}, cc = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, dc = "type opt name quote defaultValue description Default".split(" "), Za = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), ec = (a, b, c, d) => { | ||
}, cc = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, dc = "type opt name quote defaultValue description Default".split(" "), $a = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), ec = (a, b, c, d) => { | ||
d = d.length; | ||
@@ -1661,8 +1674,8 @@ a = a && "Object" != a ? ` type="${a}"` : ""; | ||
_transform([, a, b, c, d], e, g) { | ||
d = T(cc, d, dc).map(f => { | ||
d = S(cc, d, dc).map(f => { | ||
const {defaultValue:h, Default:k, opt:l, name:m, type:n, ...p} = f; | ||
f = {...p, name:m, type:n, ...h ? {defaultValue:bc(h)} : {}, ...k ? {s:bc(k)} : {}, ...l ? {optional:!0} : {}}; | ||
f = {...p, name:m, type:n, ...h ? {defaultValue:bc(h)} : {}, ...k ? {u:bc(k)} : {}, ...l ? {optional:!0} : {}}; | ||
if (h || k) { | ||
if (h) { | ||
h !== k && void 0 !== f.s && (q = N(m, k, n), console.error("%s[%s] does not match Default `%s`.", b, q, f.s)); | ||
h !== k && void 0 !== f.u && (q = N(m, k, n), console.error("%s[%s] does not match Default `%s`.", b, q, f.u)); | ||
} else { | ||
@@ -1672,5 +1685,5 @@ var q = N(m, k, n); | ||
} | ||
f.default = "defaultValue" in f ? f.defaultValue : f.s; | ||
f.default = "defaultValue" in f ? f.defaultValue : f.u; | ||
delete f.defaultValue; | ||
delete f.s; | ||
delete f.u; | ||
} | ||
@@ -1684,3 +1697,3 @@ return f; | ||
async function ic(a) { | ||
const b = Ya(), c = new hc, d = new fc; | ||
const b = Za(), c = new hc, d = new fc; | ||
b.pipe(c).pipe(d); | ||
@@ -1705,3 +1718,3 @@ b.end(a); | ||
;var jc = async() => { | ||
const {o:a} = {o:ja}; | ||
const {s:a} = {s:ka}; | ||
await Promise.all(y.map(async b => { | ||
@@ -1761,3 +1774,3 @@ b = await F(b); | ||
async function oc() { | ||
const {o:a, types:b} = {o:oa, types:na}, c = await mc(b), d = await nc(c); | ||
const {s:a, types:b} = {s:pa, types:oa}, c = await mc(b), d = await nc(c); | ||
await Promise.all(y.map(async e => { | ||
@@ -1779,12 +1792,12 @@ var g = await H(z, e); | ||
}; | ||
if (qa) { | ||
const a = ia(); | ||
console.log(sa({usage:a, description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.", line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]", example:"typal src/index.js -c"})); | ||
if (ra) { | ||
const a = ja(); | ||
console.log(ta({usage:a, description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.", line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]", example:"typal src/index.js -c"})); | ||
process.exit(); | ||
} else { | ||
ra && (console.log(require("../../package.json").version), process.exit()); | ||
sa && (console.log(require("../../package.json").version), process.exit()); | ||
} | ||
(async() => { | ||
try { | ||
return pa ? await jc() : oa ? await oc() : await ac(); | ||
return qa ? await jc() : pa ? await oc() : await ac(); | ||
} catch (a) { | ||
@@ -1791,0 +1804,0 @@ process.env.DEBUG ? console.log(a.stack) : console.log(a.message); |
{ | ||
"name": "typal", | ||
"version": "1.22.2", | ||
"version": "1.22.3", | ||
"description": "Organises TypeDefs By Placing Them Into Types.Xml File To Be Embedded Into Source Code Compatible With VSCode And Google Closure Compiler, Generates Externs And Allows To Place Documentation In README Markdown.", | ||
@@ -5,0 +5,0 @@ "main": "compile/index.js", |
@@ -94,3 +94,3 @@ import parse from '@typedefs/parser' | ||
name = `arg${i}`, optional = argOptional, | ||
} = this.args[i] || {} | ||
} = this.argsWithoutThis[i] || {} | ||
name = `${name}${optional ? '?' : ''}` | ||
@@ -105,3 +105,7 @@ return `${name}: ${type}` | ||
const tt = serialiseType(variableArgs) | ||
a.push(`...args: ${tt}[]`) | ||
let n = '...args' | ||
try { | ||
n = `${this.args[this.args.length - 1].name}` | ||
} catch (er) { /* */ } | ||
a.push(`${n}: ${tt}[]`) | ||
} | ||
@@ -233,2 +237,13 @@ const j = a.join(', ') | ||
/** | ||
* When args are assigned, this returns the array without the first arg. | ||
*/ | ||
get argsWithoutThis() { | ||
let argsWithoutThis = this.args | ||
if (this.args && this.args[0] && this.args[0].name == 'this') { | ||
const [, ...args] = this.args | ||
return args | ||
} | ||
return argsWithoutThis | ||
} | ||
/** | ||
* Generates string to append to methods when assigning to variables in externs. | ||
@@ -242,3 +257,3 @@ * Only works for functions. | ||
const a = args.map((_, i) => { | ||
const { name = `arg${i}` } = this.args[i] || {} | ||
const { name = `arg${i}` } = this.argsWithoutThis[0] || {} | ||
return name | ||
@@ -245,0 +260,0 @@ }) |
@@ -130,3 +130,3 @@ import extractTags from 'rexml' | ||
if (n == 'this') return `${n}: ${fullType}` | ||
if (n == '...args' || n == '...') return `...${fullType}` | ||
if (n.startsWith('...')) return `...${fullType}` | ||
return fullType | ||
@@ -133,0 +133,0 @@ }).join(',') |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
422876
5354