Comparing version 1.20.2 to 1.21.0
@@ -18,3 +18,3 @@ // import parse from '@typedefs/parser' | ||
{ 'name': name, 'string': string, 'boolean': boolean, 'opt': opt, 'number': number, 'type': type }, | ||
namespace) { | ||
rootNamespace) { | ||
if (!name) throw new Error('Argument does not have a name.') | ||
@@ -24,4 +24,4 @@ this.name = name | ||
let t = getPropType({ number, string, boolean, type }) | ||
if (namespace) { | ||
const s = new RegExp(`([!?])?${namespace}\\.`, 'g') | ||
if (rootNamespace) { | ||
const s = new RegExp(`([!?])?${rootNamespace}\\.`, 'g') | ||
t = t.replace(s, '$1') | ||
@@ -73,5 +73,5 @@ } | ||
* @param {string} content | ||
* @param {string} [ns] The namespace to omit. | ||
* @param {?string} [rootNamespace] The namespace to omit. | ||
*/ | ||
const extractArgs = (content, ns) => { | ||
const extractArgs = (content, rootNamespace) => { | ||
let ai = content.lastIndexOf('</arg>') | ||
@@ -88,3 +88,3 @@ let newContent = content | ||
const ar = new Arg() | ||
ar.fromXML(ac, ap, ns) | ||
ar.fromXML(ac, ap, rootNamespace) | ||
return ar | ||
@@ -91,0 +91,0 @@ }) |
@@ -43,7 +43,8 @@ const extractTags = require('rexml'); | ||
const type = new Type() | ||
type.fromXML(content, props, ns) | ||
type.fromXML(content, props, ns, rootNamespace) | ||
acc.push(type) | ||
if (alias) { | ||
const type2 = parseType(content, { ...restProps, name: alias }, ns) | ||
const type2 = new Type() | ||
type2.fromXML(content, { ...restProps, name: alias }, ns, rootNamespace) | ||
acc.push(type2) | ||
@@ -53,3 +54,4 @@ } else if (aliases) { | ||
a.forEach((name) => { | ||
const type2 = parseType(content, { ...restProps, name }, ns) | ||
const type2 = new Type() | ||
type2.fromXML(content, { ...restProps, name }, ns, rootNamespace) | ||
acc.push(type2) | ||
@@ -125,2 +127,3 @@ }) | ||
/** | ||
* This should be applicable only to <interface> / <constructor> / <method> | ||
* @param {string} content | ||
@@ -127,0 +130,0 @@ * @param {Object} props |
@@ -29,3 +29,3 @@ const parse = require('@typedefs/parser'); | ||
*/ | ||
this.type = '*' | ||
this._type = '*' | ||
/** | ||
@@ -37,2 +37,7 @@ * The override on the type in externs. | ||
/** | ||
* The actual `closure` attribute. | ||
* @type {?string} | ||
*/ | ||
this._closure = null | ||
/** | ||
* Whether the property has the default value. | ||
@@ -59,10 +64,9 @@ * @type {boolean} | ||
/** | ||
* The parsed type. | ||
* Whether to skip function params serialisation (e.g., in case it's working incorrectly). | ||
*/ | ||
this.parsed = undefined | ||
this.noParams = false | ||
/** | ||
* Whether to skip function params serialisation (e.g., in case it's working incorrectly). | ||
* The parsed type. | ||
* @type {?_typedefsParser.Type} | ||
*/ | ||
this.noParams = false | ||
this.parsed = null | ||
@@ -79,2 +83,20 @@ | ||
/** | ||
* Serialises functions to TypeScript, e.g., | ||
* (param: string) => void | ||
*/ | ||
toTypeScriptType(getLinks) { | ||
if (!this.parsed) throw new Error('The property was not parsed.') | ||
const { function: { args, return: { name: ret } } } = this.parsed | ||
const a = args.map((_, i) => { | ||
let { name = `arg${i}`, type: t, optional } = this.args[i] || {} | ||
name = `${name}${optional ? '?' : ''}` | ||
if (t) t = getLinks(t) | ||
return `${name}${t ? `: ${t}` : ''}` | ||
}) | ||
const j = a.join(', ') | ||
const r = getLinks(ret || '*') | ||
const typeName = `(${j}) => ${r}` | ||
return typeName.replace(/\*/g, '\\*') | ||
} | ||
/** | ||
* When writing externs, this will prevent adding `.prototype`, e.g., | ||
@@ -101,5 +123,9 @@ * `Type.static` instead of `Type.prototype.static`. | ||
const t = getPropType({ number, string, boolean, type }) | ||
if (noParams) this.noParams = noParams | ||
if (closure) this._closure = closure | ||
this.type = t | ||
if (closure) this.closureType = closure | ||
else this.closureType = this.type | ||
if (def !== undefined) this.hasDefault = true | ||
@@ -111,8 +137,14 @@ if (this.hasDefault) this.default = def | ||
if (noParams) this.noParams = noParams | ||
if (Static) this._static = true | ||
// if optional, we want to keep "| undefined" on records | ||
// todo: lazy parse on demand as not always required... | ||
} | ||
get type() { | ||
return this._type | ||
} | ||
/** | ||
* Type can be overridden when removing namespace from properties. | ||
*/ | ||
set type(value) { | ||
this._type = value | ||
this.closureType = this._closure || value | ||
// can also check if closure changed or just type | ||
if (!this.noParams) { | ||
@@ -122,2 +154,3 @@ try { | ||
} catch (err) { /* ok */ | ||
this.parsed = null | ||
} | ||
@@ -152,3 +185,3 @@ } | ||
const { function: { args, return: ret } } = this.parsed | ||
const a = args.map(serialise) | ||
const a = args.map(ar => serialise(ar)) | ||
a.forEach((s, i) => { | ||
@@ -202,3 +235,3 @@ const { optional } = args[i] | ||
const a = args | ||
.map(serialise) | ||
.map((ar) => serialise(ar)) | ||
.map((type, i) => { | ||
@@ -210,3 +243,3 @@ const { optional } = args[i] | ||
const s = a.join(', ') | ||
const r = serialise(ret) | ||
const r = serialise(/** @type {!_typedefsParser.Type} */ (ret)) | ||
@@ -256,2 +289,7 @@ return `(${s}) => ${r}` | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {import('@typedefs/parser').Type} _typedefsParser.Type | ||
*/ | ||
module.exports = Property |
@@ -104,3 +104,3 @@ const extractTags = require('rexml'); | ||
'async': methodAsync, 'return': methodReturn, // for <method async return="{}"> elements | ||
}, namespace) { | ||
}, namespace, rootNamespace = null) { | ||
if (!name) throw new Error('Type does not have a name.') | ||
@@ -139,3 +139,3 @@ this.name = name | ||
const fnProps = fn.map(({ content: c, props: p, 'isStatic': isStatic }) => { | ||
const { newContent, argsArgs } = extractArgs(c) | ||
const { newContent, argsArgs } = extractArgs(c, rootNamespace) | ||
@@ -164,3 +164,9 @@ const { 'async': async, 'return': ret = 'void', ...rest } = p | ||
}) | ||
this.properties = [...props, ...fnProps] | ||
const all = [...props, ...fnProps] | ||
const { s, n } = all.reduce((acc, p) => { | ||
if (p.static) acc.s.push(p) | ||
else acc.n.push(p) | ||
return acc | ||
}, { s: [], n: [] }) | ||
this.properties = [...s, ...n] | ||
} | ||
@@ -262,3 +268,7 @@ if (namespace) this.namespace = namespace | ||
const s = ` * @typedef {${t}}${dd}` | ||
/** | ||
* @type {!Array<!Property>} | ||
*/ | ||
const properties = this.properties ? this.properties.reduce((acc, p) => { | ||
if (p._static) return acc | ||
acc.push(p) | ||
@@ -456,3 +466,2 @@ const a = p.aliases.map(al => p.makeAlias(al)) | ||
if (this.extends) { | ||
useTag = useTag || /_/.test(this.extends) | ||
let e = `\`${this.extends}\`` | ||
@@ -463,7 +472,5 @@ const foundExt = allTypes.find(({ fullName }) => { | ||
if (foundExt && foundExt.link) { | ||
useTag = useTag || /_/.test(foundExt.link) | ||
e = '<a ' | ||
if (foundExt.description) { | ||
e += `title="${foundExt.description}" ` | ||
useTag = useTag || /_/.test(foundExt.description) | ||
} | ||
@@ -477,5 +484,5 @@ e += `href="${foundExt.link}">\`${this.extends}\`</a>` | ||
if (this.extends != le) e = le | ||
useTag = useTag || /_/.test(e) | ||
} | ||
const extendS = ` extends ${e}` | ||
useTag = useTag || /_/.test(e) | ||
if (useTag) LINE += '<strong>' | ||
@@ -499,5 +506,4 @@ else LINE += '__' | ||
}) | ||
return { LINE, table, displayInDetails } // delegate rendering to typal | ||
// const r = `${LINE}${table}` | ||
// return r | ||
// delegate rendering to documentary | ||
return { LINE, table, displayInDetails } | ||
} | ||
@@ -542,3 +548,3 @@ } | ||
* @param {!Array<!Type>} allTypes | ||
* @param {string} type | ||
* @param {string|!_typedefsParser.Type} type | ||
* @param {Object} [opts] | ||
@@ -552,3 +558,4 @@ * @param {boolean} [opts.flatten] | ||
let parsed | ||
try { | ||
if (typeof type == 'object') parsed = type | ||
else try { | ||
parsed = parse(type) // should parse type when added | ||
@@ -683,9 +690,13 @@ if (!parsed) { | ||
...(anyHaveDefault ? ['Default'] : [])] | ||
const linkOptions = { | ||
flatten, | ||
escapePipe: !narrow, | ||
link, | ||
} | ||
const ps = props.map((prop) => { | ||
const typeName = | ||
getLinks(/** @type {!Array<!Type>} */ (allTypes), prop.type, { | ||
flatten, | ||
escapePipe: !narrow, | ||
link, | ||
}) | ||
let typeName | ||
if (prop.args && prop.isParsedFunction) { | ||
typeName = prop.toTypeScriptType((s) => getLinks(/** @type {!Array<!Type>} */ (allTypes), s, linkOptions)) | ||
} else | ||
typeName = getLinks(/** @type {!Array<!Type>} */ (allTypes), prop.parsed || prop.type, linkOptions) | ||
const name = prop.optional ? prop.name : `${prop.name}*` | ||
@@ -692,0 +703,0 @@ const d = !prop.hasDefault ? '-' : `\`${prop.default}\`` |
@@ -0,1 +1,9 @@ | ||
## 7 August 2019 | ||
### [1.21.0](https://github.com/artdecocode/typal/compare/v1.20.2...v1.21.0) | ||
- [feature] Display VSCode-style types in _README_ documentation. | ||
- [feature] Show static types at the top of typedef markdown table. | ||
- [fix] Remove root namespace from fn args. | ||
## 6 August 2019 | ||
@@ -2,0 +10,0 @@ |
@@ -7,8 +7,8 @@ #!/usr/bin/env node | ||
const path = require('path'); | ||
var da = "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) { | ||
var ca = "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) { | ||
a != Array.prototype && a != Object.prototype && (a[b] = c.value); | ||
}, ea = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this; | ||
function fa(a, b) { | ||
}, da = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this; | ||
function ea(a, b) { | ||
if (b) { | ||
var c = ea; | ||
var c = da; | ||
a = a.split("."); | ||
@@ -23,6 +23,6 @@ for (var d = 0; d < a.length - 1; d++) { | ||
b = b(d); | ||
b != d && null != b && da(c, a, {configurable:!0, writable:!0, value:b}); | ||
b != d && null != b && ca(c, a, {configurable:!0, writable:!0, value:b}); | ||
} | ||
} | ||
fa("String.prototype.trimRight", function(a) { | ||
ea("String.prototype.trimRight", function(a) { | ||
function b() { | ||
@@ -33,3 +33,3 @@ return this.replace(/[\s\xa0]+$/, ""); | ||
}); | ||
const ha = (a, b, c, d, e) => { | ||
const fa = (a, b, c, d, e) => { | ||
d = void 0 === d ? !1 : d; | ||
@@ -52,3 +52,3 @@ e = void 0 === e ? !1 : e; | ||
return {value:c, argv:[...a.slice(0, b), ...a.slice(d + 1)]}; | ||
}, ia = a => { | ||
}, ha = a => { | ||
const b = []; | ||
@@ -63,4 +63,4 @@ for (let c = 0; c < a.length; c++) { | ||
return b; | ||
}, ka = () => { | ||
var a = ja; | ||
}, ja = () => { | ||
var a = ia; | ||
return Object.keys(a).reduce((b, c) => { | ||
@@ -79,9 +79,9 @@ const d = a[c]; | ||
}; | ||
const ja = {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"}, externs:{description:"Whether to generate externs for _GCC_.", | ||
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"}, 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"}}, v = function(a, b) { | ||
version:{description:"Show the version's number and exit.", boolean:!0, short:"v"}}, w = function(a, b) { | ||
a = void 0 === a ? {} : a; | ||
b = void 0 === b ? process.argv : b; | ||
[, , ...b] = b; | ||
const c = ia(b); | ||
const c = ha(b); | ||
b = b.slice(c.length); | ||
@@ -99,7 +99,7 @@ let d = !c.length; | ||
if ("string" == typeof h) { | ||
({value:k, argv:e} = ha(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} = ha(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) { | ||
@@ -111,8 +111,8 @@ return Object.assign({}, {u:e}, g); | ||
}, {u:b}); | ||
}(ja), w = v.source, la = v.output, ma = v.closure, na = v.externs, oa = v.types, pa = v.template, qa = v.migrate, ra = v.help, sa = v.version; | ||
function ta(a = {usage:{}}) { | ||
}(ia), x = w.source, ka = w.output, la = w.closure, ma = w.externs, na = w.types, oa = w.template, pa = w.migrate, qa = w.help, ra = w.version; | ||
function sa(a = {usage:{}}) { | ||
const {usage:b = {}, description:c, line:d, example:e} = a; | ||
a = Object.keys(b); | ||
const f = Object.values(b), [g] = a.reduce(([l = 0, m = 0], n) => { | ||
const p = b[n].split("\n").reduce((q, r) => r.length > q ? r.length : q, 0); | ||
const p = b[n].split("\n").reduce((q, t) => t.length > q ? t.length : q, 0); | ||
p > m && (m = p); | ||
@@ -130,4 +130,4 @@ n.length > l && (l = n.length); | ||
m = `${m}\t${p}`; | ||
const r = h("", g); | ||
n = q.map(t => `${r}\t${t}`); | ||
const t = h("", g); | ||
n = q.map(u => `${t}\t${u}`); | ||
return [...l, m, ...n]; | ||
@@ -145,6 +145,6 @@ }, []).map(l => `\t${l}`); | ||
} | ||
;const {createReadStream:ua, createWriteStream:va, lstat:y, readdir:wa} = fs; | ||
var xa = stream; | ||
const {Transform:z, Writable:ya} = stream; | ||
const za = (a, b = 0, c = !1) => { | ||
;const {createReadStream:ta, createWriteStream:ua, lstat:y, readdir:va} = fs; | ||
var wa = stream; | ||
const {Transform:z, Writable:xa} = stream; | ||
const ya = (a, b = 0, c = !1) => { | ||
if (0 === b && !c) { | ||
@@ -155,3 +155,3 @@ return a; | ||
return c ? a[a.length - 1] : a.slice(b).join("\n"); | ||
}, Ca = (a, b = !1) => za(a, 2 + (b ? 1 : 0)), Da = a => { | ||
}, za = (a, b = !1) => ya(a, 2 + (b ? 1 : 0)), Da = a => { | ||
({callee:{caller:a}} = a); | ||
@@ -175,3 +175,3 @@ return a; | ||
var e = Da(arguments), {stack:f} = Error(); | ||
const g = za(f, 2, !0), h = (f = d instanceof Error) ? d.message : d; | ||
const g = ya(f, 2, !0), h = (f = d instanceof Error) ? d.message : d; | ||
e = [`Error: ${h}`, ...null !== e && a === e || c ? [b] : [g, b]].join("\n"); | ||
@@ -182,6 +182,6 @@ e = A(e); | ||
} | ||
;function C(a) { | ||
;function D(a) { | ||
var {stack:b} = Error(); | ||
const c = Da(arguments); | ||
b = Ca(b, a); | ||
b = za(b, a); | ||
return Ia(c, b, a); | ||
@@ -195,3 +195,3 @@ } | ||
}; | ||
class Ka extends ya { | ||
class Ka extends xa { | ||
constructor(a) { | ||
@@ -201,6 +201,6 @@ var b = a || {}, c = Object.assign({}, b); | ||
b = (delete c.binary, delete c.rs, c); | ||
const {U:f = C(!0), proxyError:g} = a || {}, h = (k, l) => f(l); | ||
const {W:f = D(!0), proxyError:g} = a || {}, h = (k, l) => f(l); | ||
super(b); | ||
this.b = []; | ||
this.S = new Promise((k, l) => { | ||
this.U = new Promise((k, l) => { | ||
this.on("finish", () => { | ||
@@ -230,19 +230,19 @@ let m; | ||
get f() { | ||
return this.S; | ||
return this.U; | ||
} | ||
} | ||
const E = async a => { | ||
const F = async a => { | ||
var b = void 0 === b ? {} : b; | ||
({f:a} = new Ka(Object.assign({}, {rs:a}, b, {U:C(!0)}))); | ||
({f:a} = new Ka(Object.assign({}, {rs:a}, b, {W:D(!0)}))); | ||
return await a; | ||
}; | ||
async function F(a) { | ||
a = ua(a); | ||
return await E(a); | ||
async function G(a) { | ||
a = ta(a); | ||
return await F(a); | ||
} | ||
;async function G(a, b) { | ||
;async function H(a, b) { | ||
if (!a) { | ||
throw Error("No path is given."); | ||
} | ||
const c = C(!0), d = va(a); | ||
const c = D(!0), d = ua(a); | ||
await new Promise((e, f) => { | ||
@@ -260,4 +260,4 @@ d.on("error", g => { | ||
} | ||
async function H(a, b, c) { | ||
const d = C(!0); | ||
async function I(a, b, c) { | ||
const d = D(!0); | ||
if ("function" !== typeof a) { | ||
@@ -279,7 +279,7 @@ throw Error("Function must be passed."); | ||
} | ||
;const {join:I} = path; | ||
;const {join:J} = path; | ||
async function Ma(a, b) { | ||
b = b.map(async c => { | ||
const d = I(a, c); | ||
return {lstat:await H(y, d), path:d, relativePath:c}; | ||
const d = J(a, c); | ||
return {lstat:await I(y, d), path:d, relativePath:c}; | ||
}); | ||
@@ -289,10 +289,10 @@ return await Promise.all(b); | ||
const Na = a => a.lstat.isDirectory(), Oa = a => !a.lstat.isDirectory(); | ||
async function J(a) { | ||
async function K(a) { | ||
if (!a) { | ||
throw Error("Please specify a path to the directory"); | ||
} | ||
if (!(await H(y, a)).isDirectory()) { | ||
if (!(await I(y, a)).isDirectory()) { | ||
throw a = Error("Path is not a directory"), a.code = "ENOTDIR", a; | ||
} | ||
var b = await H(wa, a); | ||
var b = await I(va, a); | ||
b = await Ma(a, b); | ||
@@ -307,3 +307,3 @@ a = b.filter(Na); | ||
c = await c; | ||
d = await J(e); | ||
d = await K(e); | ||
return Object.assign({}, c, {[f]:d}); | ||
@@ -313,11 +313,11 @@ }, {}); | ||
} | ||
const K = (a, b) => { | ||
const L = (a, b) => { | ||
let c = [], d = []; | ||
Object.keys(a).forEach(f => { | ||
const {type:g} = a[f]; | ||
"File" == g ? c.push(I(b, f)) : "Directory" == g && d.push(f); | ||
"File" == g ? c.push(J(b, f)) : "Directory" == g && d.push(f); | ||
}); | ||
const e = d.reduce((f, g) => { | ||
const {content:h} = a[g]; | ||
g = K(h, I(b, g)); | ||
g = L(h, J(b, g)); | ||
return [...f, ...g]; | ||
@@ -336,3 +336,3 @@ }, []); | ||
} | ||
const L = (a, b) => { | ||
const M = (a, b) => { | ||
if (!(b instanceof Error)) { | ||
@@ -367,3 +367,3 @@ throw b; | ||
} catch (l) { | ||
L(g, l); | ||
M(g, l); | ||
} | ||
@@ -380,3 +380,3 @@ }); | ||
;const Ra = a => new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`, "g"), Sa = (a, b) => `%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`, Ta = () => { | ||
var a = {V:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg}; | ||
var a = {X:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg}; | ||
return Object.keys(a).reduce((b, c) => { | ||
@@ -410,3 +410,3 @@ { | ||
} | ||
class M extends z { | ||
class N extends z { | ||
constructor(a, b) { | ||
@@ -419,3 +419,3 @@ super(b); | ||
async replace(a, b) { | ||
const c = new M(this.f, this.m); | ||
const c = new N(this.f, this.m); | ||
b && Object.assign(c, b); | ||
@@ -450,3 +450,3 @@ a = await Wa(c, a); | ||
} catch (l) { | ||
L(f, l); | ||
M(f, l); | ||
} | ||
@@ -459,3 +459,3 @@ }); | ||
} catch (h) { | ||
L(f, h); | ||
M(f, h); | ||
} | ||
@@ -480,4 +480,4 @@ } else { | ||
async function Xa(a, b) { | ||
b instanceof xa ? b.pipe(a) : a.end(b); | ||
return await E(a); | ||
b instanceof wa ? b.pipe(a) : a.end(b); | ||
return await F(a); | ||
} | ||
@@ -496,3 +496,3 @@ ;function Ya() { | ||
} | ||
;const N = (a, b, c, d) => { | ||
;const O = (a, b, c, d) => { | ||
if (!a) { | ||
@@ -507,11 +507,11 @@ throw Error("The name of the property is not given"); | ||
return `${a}=${b}`; | ||
}, $a = ({number:a, R: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 ? `/** | ||
}, $a = ({number:a, T:b, boolean:c, type:d}) => b ? "string" : a ? "number" : c ? "boolean" : d ? d : "*", ab = a => `${/[^\w\d._]/.test(a) ? `(${a})` : a}|undefined`, P = a => a ? `/** | ||
${a} | ||
*/ | ||
` : "/**\n */\n", Q = a => ` * @suppress {nonStandardJsDocs} | ||
${a}`, R = (a, b, c) => { | ||
${a}`, S = (a, b, c) => { | ||
a = `${a ? "" : "var "}${a ? `${a}.` : ""}${b}`; | ||
c && (a += ` = ${c}`); | ||
return a; | ||
}, S = a => { | ||
}, T = a => { | ||
a = a.trimRight(); | ||
@@ -539,3 +539,3 @@ var b = /\S/.exec(a); | ||
}; | ||
function T(a, b, c) { | ||
function U(a, b, c) { | ||
const d = []; | ||
@@ -556,7 +556,7 @@ b.replace(a, (e, ...f) => { | ||
;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) => T(new RegExp(`<${a}${cb.source}?(?:${/\s*\/>/.source}|${(new RegExp(`>([\\s\\S]+?)?</${a}>`)).source})`, "g"), b, ["a", "v", "v1", "v2", "c"]).map(({a:c = "", c:d = ""}) => { | ||
const V = (a, b) => U(new RegExp(`<${a}${cb.source}?(?:${/\s*\/>/.source}|${(new RegExp(`>([\\s\\S]+?)?</${a}>`)).source})`, "g"), b, ["a", "v", "v1", "v2", "c"]).map(({a:c = "", c:d = ""}) => { | ||
c = c.replace(/\/$/, "").trim(); | ||
c = db(c); | ||
return {content:d, props:c}; | ||
}), db = a => T(bb, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => { | ||
}), db = a => U(bb, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => { | ||
if (void 0 === d) { | ||
@@ -742,4 +742,4 @@ return b[c] = !0, b; | ||
a.name = c; | ||
b && (a.description = S(b)); | ||
b = $a({number:g, R:d, boolean:e, type:h}); | ||
b && (a.description = T(b)); | ||
b = $a({number:g, T:d, boolean:e, type:h}); | ||
k && (b = b.replace(new RegExp(`([!?])?${k}\\.`, "g"), "$1")); | ||
@@ -760,3 +760,3 @@ a.type = b; | ||
var e = []; | ||
-1 != c && (c += 6, e = a.slice(0, c), d = a.slice(c), e = U("arg", e), e = e.map(({content:f, props:g}) => { | ||
-1 != c && (c += 6, e = a.slice(0, c), d = a.slice(c), e = V("arg", e), e = e.map(({content:f, props:g}) => { | ||
const h = new ib; | ||
@@ -766,5 +766,5 @@ hb(h, f, g, b); | ||
})); | ||
return {W:d, M:e}; | ||
return {Y:d, N:e}; | ||
}; | ||
function V(a) { | ||
function W(a) { | ||
var b = ""; | ||
@@ -776,15 +776,15 @@ a.nullable ? b = "?" : !1 === a.nullable && (b = "!"); | ||
if (a.function.this) { | ||
var c = "this: " + V(a.function.this); | ||
var c = "this: " + W(a.function.this); | ||
d.push(c); | ||
} | ||
a.function.new && (c = "new: " + V(a.function.new), d.push(c)); | ||
a.function.new && (c = "new: " + W(a.function.new), d.push(c)); | ||
a.function.args.forEach(e => { | ||
let f = V(e); | ||
let f = W(e); | ||
e.optional && (f += "="); | ||
d.push(f); | ||
}); | ||
a.function.variableArgs && (c = "..." + V(a.function.variableArgs), d.push(c)); | ||
a.function.variableArgs && (c = "..." + W(a.function.variableArgs), d.push(c)); | ||
c = d.join(", "); | ||
b += c + ")"; | ||
a.function.return && (b += ": " + V(a.function.return)); | ||
a.function.return && (b += ": " + W(a.function.return)); | ||
} else { | ||
@@ -797,3 +797,3 @@ if (a.record) { | ||
} | ||
e = V(e); | ||
e = W(e); | ||
return `${d}: ${e}`; | ||
@@ -807,7 +807,7 @@ }), b += c.join(", "), b += " }"; | ||
b += a.name + "<"; | ||
c = a.application.map(d => V(d)); | ||
c = a.application.map(d => W(d)); | ||
b += c.join(", "); | ||
b += ">"; | ||
} else { | ||
a.union ? (b += "(", c = a.union.map(d => V(d)), b += c.join("|"), b += ")") : b += "any" == a.name ? "*" : a.name; | ||
a.union ? (b += "(", c = a.union.map(d => W(d)), b += c.join("|"), b += ")") : b += "any" == a.name ? "*" : a.name; | ||
} | ||
@@ -823,5 +823,7 @@ } | ||
a.name = c; | ||
b && (a.description = S(b)); | ||
a.type = $a({number:g, R:d, boolean:e, type:h}); | ||
l ? a.g = l : a.g = a.type; | ||
b && (a.description = T(b)); | ||
b = $a({number:g, T:d, boolean:e, type:h}); | ||
p && (a.D = p); | ||
l && (a.v = l); | ||
a.type = b; | ||
void 0 !== k && (a.i = !0); | ||
@@ -834,14 +836,7 @@ a.i && (a.default = k); | ||
n && (a.B = n.split(/\s*,\s*/)); | ||
p && (a.v = p); | ||
q && (a.f = !0); | ||
if (!a.v) { | ||
try { | ||
a.b = gb(a.g); | ||
} catch (r) { | ||
} | ||
} | ||
} | ||
function lb(a, b = !1) { | ||
if (b) { | ||
return a.g; | ||
return a.h; | ||
} | ||
@@ -852,3 +847,3 @@ if (!a.m) { | ||
const {function:{args:c, return:d}} = a.b; | ||
b = c.map(V).map((f, g) => { | ||
b = c.map(f => W(f)).map((f, g) => { | ||
const {optional:h} = c[g]; | ||
@@ -858,3 +853,3 @@ ({name:g = `arg${g}`} = a.args[g] || {}); | ||
}).join(", "); | ||
const e = V(d); | ||
const e = W(d); | ||
return `(${b}) => ${e}`; | ||
@@ -866,3 +861,3 @@ } | ||
} | ||
b = N(a.name, a.default, a.type, b); | ||
b = O(a.name, a.default, a.type, b); | ||
b = a.optional ? `[${b}]` : b; | ||
@@ -878,3 +873,3 @@ const d = `${a.description ? ` ${a.description}` : ""}${a.i ? ` Default \`${a.default}\`.` : ""}`; | ||
const b = [], {function:{args:c, return:d}} = a.b; | ||
c.map(V).forEach((e, f) => { | ||
c.map(e => W(e)).forEach((e, f) => { | ||
const {optional:g} = c[f], {name:h = `arg${f}`, description:k} = a.args[f] || {}; | ||
@@ -884,3 +879,3 @@ b.push(` * @param {${e}${g ? "=" : ""}} ${g ? `[${h}]` : h}${k ? ` ${k}` : ""}`); | ||
if ("void" != d.name) { | ||
const e = V(d); | ||
const e = W(d); | ||
b.push(` * @return {${e}}`); | ||
@@ -907,3 +902,3 @@ } | ||
} | ||
!a.optional && a.m ? (a = pb(a), c.push(...a)) : c.push(` * @type {${a.optional ? ab(a.g) : a.g}}`); | ||
!a.optional && a.m ? (a = pb(a), c.push(...a)) : c.push(` * @type {${a.optional ? ab(a.h) : a.h}}`); | ||
b && (c = c.map(d => `${b}${d}`)); | ||
@@ -921,4 +916,5 @@ return c.join("\n"); | ||
this.description = this.name = null; | ||
this.type = "*"; | ||
this.g = ""; | ||
this.C = "*"; | ||
this.h = ""; | ||
this.v = null; | ||
this.i = !1; | ||
@@ -928,3 +924,3 @@ this.default = null; | ||
this.B = []; | ||
this.v = !1; | ||
this.D = !1; | ||
this.b = null; | ||
@@ -934,9 +930,23 @@ this.args = a; | ||
} | ||
get H() { | ||
get S() { | ||
return this.f; | ||
} | ||
get type() { | ||
return this.C; | ||
} | ||
set type(a) { | ||
this.C = a; | ||
this.h = this.v || a; | ||
if (!this.D) { | ||
try { | ||
this.b = gb(this.h); | ||
} catch (b) { | ||
this.b = null; | ||
} | ||
} | ||
} | ||
get m() { | ||
return this.b && "function" == this.b.name; | ||
} | ||
L(a, b = "", c = !1) { | ||
M(a, b = "", c = !1) { | ||
a = mb(this, a, c); | ||
@@ -954,61 +964,67 @@ return `${b} * @param ${a}`; | ||
}).join("\n"); | ||
function W(a, b, c, d) { | ||
var {name:e, type:f, desc:g, noToc:h, spread:k, noExpand:l, "import":m, link:n, closure:p, constructor:q, "extends":r, "interface":t, record:x, "return":Aa} = c; | ||
if (!e) { | ||
function X(a, b, c, d, e) { | ||
var {name:f, type:g, desc:h, noToc:k, spread:l, noExpand:m, "import":n, link:p, closure:q, constructor:t, "extends":u, "interface":v, record:Aa, "return":Ba} = c; | ||
e = void 0 === e ? null : e; | ||
if (!f) { | ||
throw Error("Type does not have a name."); | ||
} | ||
a.name = e; | ||
f && (a.type = f); | ||
p ? a.g = p : a.g = a.type; | ||
g && (a.description = S(g)); | ||
a.P = !!h; | ||
a.O = !!k; | ||
a.N = !!l; | ||
a.import = !!m; | ||
n && (a.link = n); | ||
!0 === q && (a.isConstructor = q); | ||
!0 === t && (a.G = t); | ||
!0 === x && (a.v = x); | ||
r && (a.extends = r); | ||
a.name = f; | ||
g && (a.type = g); | ||
q ? a.h = q : a.h = a.type; | ||
h && (a.description = T(h)); | ||
a.P = !!k; | ||
a.O = !!l; | ||
a.D = !!m; | ||
a.import = !!n; | ||
p && (a.link = p); | ||
!0 === t && (a.isConstructor = t); | ||
!0 === v && (a.I = v); | ||
!0 === Aa && (a.v = Aa); | ||
u && (a.extends = u); | ||
if (b) { | ||
c = U("prop", b).map(u => { | ||
var {content:aa, props:B} = u; | ||
u = new tb; | ||
kb(u, aa, B); | ||
return u; | ||
c = V("prop", b).map(r => { | ||
var {content:B, props:C} = r; | ||
r = new tb; | ||
kb(r, B, C); | ||
return r; | ||
}); | ||
const Hb = U("function", b), Ib = U("fn", b); | ||
b = U("static", b).map(u => { | ||
u.isStatic = !0; | ||
return u; | ||
const Ib = V("function", b), Jb = V("fn", b); | ||
b = V("static", b).map(r => { | ||
r.isStatic = !0; | ||
return r; | ||
}); | ||
b = [...Hb, ...Ib, ...b].map(u => { | ||
var {content:aa, props:B, isStatic:Jb} = u; | ||
const {W:Kb, M:ba} = jb(aa); | ||
var D = Object.assign({}, B); | ||
u = B.async; | ||
var P = void 0 === B["return"] ? "void" : B["return"]; | ||
D = (delete D.async, delete D["return"], D); | ||
let {args:ca = ""} = B; | ||
!ca && ba.length && (ca = ba.map(Lb => { | ||
var {type:Ba, optional:Mb} = Lb; | ||
return null !== Mb ? `${Ba}=` : Ba; | ||
b = [...Ib, ...Jb, ...b].map(r => { | ||
var {content:B, props:C, isStatic:Kb} = r; | ||
const {Y:Lb, N:aa} = jb(B, e); | ||
var E = Object.assign({}, C); | ||
r = C.async; | ||
var R = void 0 === C["return"] ? "void" : C["return"]; | ||
E = (delete E.async, delete E["return"], E); | ||
let {args:ba = ""} = C; | ||
!ba && aa.length && (ba = aa.map(Mb => { | ||
var {type:Ca, optional:Nb} = Mb; | ||
return null !== Nb ? `${Ca}=` : Ca; | ||
}).join(",")); | ||
P = P.replace(/\n\s*/g, " "); | ||
D.type = `function(${ca}): ${u ? `!Promise<${P}>` : P}`; | ||
u = new tb(ba); | ||
kb(u, Kb, D); | ||
Jb && (u.f = !0); | ||
return u; | ||
R = R.replace(/\n\s*/g, " "); | ||
E.type = `function(${ba}): ${r ? `!Promise<${R}>` : R}`; | ||
r = new tb(aa); | ||
kb(r, Lb, E); | ||
Kb && (r.f = !0); | ||
return r; | ||
}); | ||
a.l = [...c, ...b]; | ||
c = [...c, ...b]; | ||
const {R:Ob, n:Pb} = c.reduce((r, B) => { | ||
B.S ? r.R.push(B) : r.n.push(B); | ||
return r; | ||
}, {R:[], n:[]}); | ||
a.l = [...Ob, ...Pb]; | ||
} | ||
d && (a.j = d); | ||
Aa && (a.m = Aa); | ||
Ba && (a.m = Ba); | ||
} | ||
function ub(a) { | ||
var b = vb(a); | ||
a.w || b.push(` * @${a.Y}`); | ||
b = O(b.join("\n")); | ||
b += R(a.j, a.name, a.X); | ||
a.w || b.push(` * @${a.$}`); | ||
b = P(b.join("\n")); | ||
b += S(a.j, a.name, a.Z); | ||
const c = a.l.reduce((d, e) => { | ||
@@ -1021,4 +1037,4 @@ d.push(e); | ||
let e = rb(d); | ||
e = O(e); | ||
e += R(`${a.h}${d.H ? "" : ".prototype"}`, d.name); | ||
e = P(e); | ||
e += S(`${a.g}${d.S ? "" : ".prototype"}`, d.name); | ||
return e += qb(d); | ||
@@ -1042,3 +1058,3 @@ }); | ||
d = void 0 === d ? b : d; | ||
d = ` * @typedef {${(b ? a.g : a.type) || xb(a)}}${` ${wb(a, d)}${a.f}`}`; | ||
d = ` * @typedef {${(b ? a.h : a.type) || xb(a)}}${` ${wb(a, d)}${a.f}`}`; | ||
a = (a.l ? a.l.reduce((e, f) => { | ||
@@ -1055,3 +1071,3 @@ if (f.f) { | ||
b && !c && (a = Q(a)); | ||
return a = O(a); | ||
return a = P(a); | ||
} | ||
@@ -1064,10 +1080,10 @@ function zb(a, b, c, d) { | ||
if (a.j && b) { | ||
var h = ` * @typedef {${a.h}} ${a.name}${a.f}`; | ||
var h = ` * @typedef {${a.g}} ${a.name}${a.f}`; | ||
b && !c && (h = Q(h)); | ||
h = O(h); | ||
h = P(h); | ||
g.push(h); | ||
} else { | ||
a.j && d && (h = ` * @typedef {${a.h}} ${a.name}${a.f}`, h = O(h), g.push(h)); | ||
a.j && d && (h = ` * @typedef {${a.g}} ${a.name}${a.f}`, h = P(h), g.push(h)); | ||
} | ||
e && (a = ` * @typedef {${a.extends} & ${wb(a, d)}} ${d ? a.h : a.name}${a.f}`, b && !c && (a = Q(a)), a = O(a), g.push(a)); | ||
e && (a = ` * @typedef {${a.extends} & ${wb(a, d)}} ${d ? a.g : a.name}${a.f}`, b && !c && (a = Q(a)), a = P(a), g.push(a)); | ||
g.push(f); | ||
@@ -1090,11 +1106,11 @@ return g.join(""); | ||
} | ||
class X { | ||
class Y { | ||
constructor() { | ||
this.name = ""; | ||
this.link = this.N = this.import = this.O = this.P = this.description = this.g = this.type = null; | ||
this.link = this.D = this.import = this.O = this.P = this.description = this.h = this.type = null; | ||
this.l = []; | ||
this.j = null; | ||
this.v = this.G = this.isConstructor = !1; | ||
this.v = this.I = this.isConstructor = !1; | ||
this.extends = null; | ||
this.H = !1; | ||
this.C = !1; | ||
this.m = this.b = null; | ||
@@ -1106,9 +1122,9 @@ } | ||
} | ||
this.H = a; | ||
this.C = a; | ||
} | ||
get w() { | ||
return this.H; | ||
return this.C; | ||
} | ||
get Z() { | ||
return this.isConstructor || this.G || this.v || this.w; | ||
get aa() { | ||
return this.isConstructor || this.I || this.v || this.w; | ||
} | ||
@@ -1121,3 +1137,3 @@ get return() { | ||
} | ||
get Y() { | ||
get $() { | ||
const a = this.i; | ||
@@ -1130,5 +1146,5 @@ if (!a) { | ||
get i() { | ||
return this.isConstructor ? "constructor" : this.G ? "interface" : this.v ? "record" : ""; | ||
return this.isConstructor ? "constructor" : this.I ? "interface" : this.v ? "record" : ""; | ||
} | ||
get X() { | ||
get Z() { | ||
return this.b ? `function(${this.b.map(a => { | ||
@@ -1142,6 +1158,6 @@ ({name:a} = a); | ||
} | ||
get h() { | ||
get g() { | ||
return `${this.A}${this.name}`; | ||
} | ||
L(a, b, c, d, e) { | ||
M(a, b, c, d, e) { | ||
e = void 0 === e ? !1 : e; | ||
@@ -1151,5 +1167,5 @@ var f = ""; | ||
d = this.description ? ` ${this.description}` : ""; | ||
const g = this.O ? Ab(this.l) : e ? this.h : this.name; | ||
const g = this.O ? Ab(this.l) : e ? this.g : this.name; | ||
b = `${c || ""} * @param {${f}${g}} ${b ? `[${a}]` : a}${d}`; | ||
f = this.l && !this.N ? this.l.map(h => h.L(a, c, e)) : []; | ||
f = this.l && !this.D ? this.l.map(h => h.M(a, c, e)) : []; | ||
return [b, ...f].join("\n"); | ||
@@ -1168,3 +1184,3 @@ } | ||
return `{ ${a.map(c => { | ||
const d = b ? c.g : c.type; | ||
const d = b ? c.h : c.type; | ||
let e = c.name, f = d; | ||
@@ -1178,3 +1194,3 @@ c.optional && !b ? e = `${c.name}?` : c.optional && b && (f = `(${ab(d)})`); | ||
a.from = c; | ||
a.J = d; | ||
a.K = d; | ||
a.link = e; | ||
@@ -1184,3 +1200,3 @@ a.A = f || a.from; | ||
function Cb(a, b = !0) { | ||
return ` * @typedef {import('${a.from}').${a.name}} ${b ? a.h : a.name}`; | ||
return ` * @typedef {import('${a.from}').${a.name}} ${b ? a.g : a.name}`; | ||
} | ||
@@ -1190,5 +1206,5 @@ class Db { | ||
this.from = this.name = this.A = ""; | ||
this.link = this.J = null; | ||
this.link = this.K = null; | ||
} | ||
get h() { | ||
get g() { | ||
return `${this.A}.${this.name}`; | ||
@@ -1198,10 +1214,10 @@ } | ||
;function Eb(a, b) { | ||
b = b.reduce((c, d) => Object.assign({}, c, {[d.h]:d}), {}); | ||
a.I = Object.assign({}, a.I, b); | ||
b = b.reduce((c, d) => Object.assign({}, c, {[d.g]:d}), {}); | ||
a.J = Object.assign({}, a.J, b); | ||
} | ||
class Fb extends M { | ||
class Fb extends N { | ||
constructor(a, b) { | ||
b = void 0 === b ? {} : b; | ||
super(a); | ||
this.I = {}; | ||
this.J = {}; | ||
this.on("types", c => { | ||
@@ -1220,3 +1236,3 @@ Eb(this, c); | ||
static get Type() { | ||
return X; | ||
return Y; | ||
} | ||
@@ -1227,7 +1243,7 @@ static get b() { | ||
get types() { | ||
return this.I; | ||
return this.J; | ||
} | ||
} | ||
;const Nb = a => { | ||
a = U("types", a); | ||
;const Hb = a => { | ||
a = V("types", a); | ||
if (!a.length) { | ||
@@ -1237,24 +1253,26 @@ 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; | ||
a = U("type", b).reduce((k, l) => { | ||
a = V("type", b).reduce((k, l) => { | ||
var {content:m, props:n} = l, p = Object.assign({}, n); | ||
l = n.alias; | ||
const q = n.aliases, r = (delete p.alias, delete p.aliases, p); | ||
p = new X; | ||
W(p, m, n, e); | ||
var q = n.aliases; | ||
const t = (delete p.alias, delete p.aliases, p); | ||
p = new Y; | ||
X(p, m, n, e, void 0); | ||
k.push(p); | ||
l ? (l = Y(m, Object.assign({}, r, {name:l}), e), k.push(l)) : q && q.split(/, */).forEach(t => { | ||
t = Y(m, Object.assign({}, r, {name:t}), e); | ||
k.push(t); | ||
l ? (q = new Y, X(q, m, Object.assign({}, t, {name:l}), e, void 0), k.push(q)) : q && q.split(/, */).forEach(u => { | ||
const v = new Y; | ||
X(v, m, Object.assign({}, t, {name:u}), e, void 0); | ||
k.push(v); | ||
}); | ||
return k; | ||
}, []); | ||
var f = U("interface", b).reduce((k, l) => { | ||
var f = V("interface", b).reduce((k, l) => { | ||
var {content:m, props:n} = l; | ||
l = Gb(m, n, e); | ||
l.forEach(p => { | ||
p.G = !0; | ||
p.I = !0; | ||
}); | ||
k.push(...l); | ||
return k; | ||
}, []), g = U("constructor", b).reduce((k, l) => { | ||
}, []), g = V("constructor", b).reduce((k, l) => { | ||
var {content:m, props:n} = l; | ||
@@ -1268,3 +1286,3 @@ l = Gb(m, n, e); | ||
}, []); | ||
const h = U("method", b).reduce((k, l) => { | ||
const h = V("method", b).reduce((k, l) => { | ||
var {content:m, props:n} = l; | ||
@@ -1279,6 +1297,6 @@ l = Gb(m, n, e, void 0); | ||
a = [...a, ...f, ...g, ...h]; | ||
f = U("import", b).map(k => { | ||
f = V("import", b).map(k => { | ||
var {props:l, content:m} = k; | ||
k = new Db; | ||
m && (l.desc = S(m)); | ||
m && (l.desc = T(m)); | ||
Bb(k, l); | ||
@@ -1288,14 +1306,14 @@ return k; | ||
g = f.map(k => { | ||
var {name:l, from:m, J:n, link:p, A:q} = k; | ||
k = new X; | ||
W(k, "", {name:l, type:`import('${m}').${l}`, P:!0, import:!0, J:n, link:p}, void 0 == q ? void 0 : q); | ||
var {name:l, from:m, K:n, link:p, A:q} = k; | ||
k = new Y; | ||
X(k, "", {name:l, type:`import('${m}').${l}`, P:!0, import:!0, K:n, link:p}, void 0 == q ? void 0 : q); | ||
return k; | ||
}); | ||
return {j:d, types:a, imports:f, $:g}; | ||
}, Y = (a, b, c, d) => { | ||
const e = new X, f = a.search(/<(prop|function|fn|static) /); | ||
return {j:d, types:a, imports:f, ba:g}; | ||
}, Qb = (a, b, c, d) => { | ||
const e = new Y, f = a.search(/<(prop|function|fn|static) /); | ||
let g = "", h = a; | ||
1 != f && (g = a.slice(0, f), h = a.slice(f)); | ||
({M:a} = jb(g, d)); | ||
W(e, h, b, c); | ||
({N:a} = jb(g, d)); | ||
X(e, h, b, c); | ||
e.b = a; | ||
@@ -1307,6 +1325,6 @@ return e; | ||
const h = b.aliases, k = (delete f.alias, delete f.aliases, f); | ||
b = Y(a, b, c, d); | ||
b = Qb(a, b, c, d); | ||
e.push(b); | ||
g ? (g = Y(a, Object.assign({}, k, {name:g}), c, d), g.description = `${g.description}${g.description ? " " : ""}Alias of \`${k.name}\`.`, e.push(g)) : h && h.split(/, */).forEach(l => { | ||
l = Y(a, Object.assign({}, k, {name:l}), c, d); | ||
g ? (g = Qb(a, Object.assign({}, k, {name:g}), c, d), g.description = `${g.description}${g.description ? " " : ""}Alias of \`${k.name}\`.`, e.push(g)) : h && h.split(/, */).forEach(l => { | ||
l = Qb(a, Object.assign({}, k, {name:l}), c, d); | ||
l.description = `${l.description}${l.description ? " " : ""}Alias of \`${k.name}\`.`; | ||
@@ -1316,12 +1334,12 @@ e.push(l); | ||
return e; | ||
}, Ob = async(a, b) => { | ||
}, Rb = async(a, b) => { | ||
b = void 0 === b ? [] : b; | ||
a = await F(a); | ||
let {j:c = null, types:d, imports:e} = Nb(a); | ||
a = await G(a); | ||
let {j:c = null, types:d, imports:e} = Hb(a); | ||
d = d.filter(f => { | ||
({h:f} = f); | ||
({g:f} = f); | ||
return b.includes(f) ? !1 : !0; | ||
}); | ||
e = e.filter(f => { | ||
({h:f} = f); | ||
({g:f} = f); | ||
return b.includes(f) ? !1 : !0; | ||
@@ -1331,15 +1349,15 @@ }); | ||
}; | ||
const Pb = (a, b, c) => { | ||
const Sb = (a, b, c) => { | ||
b = b.map(d => zb(d, !0, c)); | ||
a = a.map(d => { | ||
d = Cb(d); | ||
return O(c ? d : Q(d)); | ||
return P(c ? d : Q(d)); | ||
}); | ||
return [...b, ...a].join(""); | ||
}, Qb = (a, b, c, d = !1) => { | ||
}, Tb = (a, b, c, d = !1) => { | ||
a = [...a.map(e => { | ||
{ | ||
let f; | ||
e.g ? f = ` * @typedef {${e.g}}` : e.Z || (f = ` * @typedef {${Ab(e.l, !0)}}`); | ||
f ? (e.description && (f = ` * ${e.description}\n${f}`), f = O(f), e = f += R(e.j, e.name)) : e = ub(e); | ||
e.h ? f = ` * @typedef {${e.h}}` : e.aa || (f = ` * @typedef {${Ab(e.l, !0)}}`); | ||
f ? (e.description && (f = ` * ${e.description}\n${f}`), f = P(f), e = f += S(e.j, e.name)) : e = ub(e); | ||
} | ||
@@ -1352,7 +1370,7 @@ return e; | ||
}; | ||
const Sb = {re:/^\/\*\*? (documentary|typal) (.+?) \*\/\n(?:([^\n][\s\S]+?\n))?$/mg, replacement:async function(a, b, c) { | ||
const Vb = {re:/^\/\*\*? (documentary|typal) (.+?) \*\/\n(?:([^\n][\s\S]+?\n))?$/mg, replacement:async function(a, b, c) { | ||
const [d, ...e] = c.split(/\s+/), f = e.includes("closure"), g = e.includes("externs"), h = e.includes("noSuppress"), k = e.includes("skipNsDecl"), l = e.includes("namespace"); | ||
let m = e.find(q => q.startsWith("ignore:")); | ||
m = m ? m.replace("ignore:", "").split(",") : []; | ||
let {F:n, K:p} = this.i; | ||
let {H:n, L:p} = this.i; | ||
f && (n = !0); | ||
@@ -1362,20 +1380,20 @@ g && (p = !0); | ||
this.o("Detected type marker: %s", c); | ||
const {types:q, imports:r, j:t} = await Ob(d, m); | ||
const {types:q, imports:t, j:u} = await Rb(d, m); | ||
this.emit("types", q); | ||
this.emit("types", r); | ||
let x; | ||
n ? x = Pb(r, q, h) : p ? (x = Qb(q, t, this.b, k) + "\n", t && this.emit("namespace", t)) : l ? (t && this.emit("namespace", t), x = Rb(r, q, !0)) : x = Rb(r, q); | ||
return `/* ${b} ${c} */\n${x}`; | ||
this.emit("types", t); | ||
let v; | ||
n ? v = Sb(t, q, h) : p ? (v = Tb(q, u, this.b, k) + "\n", u && this.emit("namespace", u)) : l ? (u && this.emit("namespace", u), v = Ub(t, q, !0)) : v = Ub(t, q); | ||
return `/* ${b} ${c} */\n${v}`; | ||
} catch (q) { | ||
return this.o("(%s) Could not process typedef-js: %s", c, q.message), process.env.b && console.error(q.stack), a; | ||
} | ||
}}, Rb = (a, b, c = !1) => { | ||
}}, Ub = (a, b, c = !1) => { | ||
b = b.map(d => zb(d, !1, !1, c)); | ||
a = a.map(d => Cb(d, c)).map(O).join(""); | ||
a = a.map(d => Cb(d, c)).map(P).join(""); | ||
b = b.join(""); | ||
return `${a}${b}`.replace(Tb, " * @typedef"); | ||
}, Tb = / \*\/\n\/\*\*\n \* @typedef/g; | ||
const Vb = {re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\n(?: +)\* @param {(?:.+?)} \[?\4\]?.*)*)/gm, replacement:Ub}; | ||
function Ub(a, b, c, d, e, f, g) { | ||
const {F:h} = this.i; | ||
return `${a}${b}`.replace(Wb, " * @typedef"); | ||
}, Wb = / \*\/\n\/\*\*\n \* @typedef/g; | ||
const Yb = {re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\n(?: +)\* @param {(?:.+?)} \[?\4\]?.*)*)/gm, replacement:Xb}; | ||
function Xb(a, b, c, d, e, f, g) { | ||
const {H:h} = this.i; | ||
let k; | ||
@@ -1390,5 +1408,5 @@ f = () => { | ||
} | ||
m = {line:m, T:b.length + 11}; | ||
m = {line:m, V:b.length + 11}; | ||
} | ||
const {line:n, T:p} = m; | ||
const {line:n, V:p} = m; | ||
this.o("%s:%s:%s", this.file, n, p); | ||
@@ -1405,8 +1423,8 @@ } | ||
} | ||
const l = Object.values(this.types).map(({name:m, h:n}) => h ? n : m); | ||
const l = Object.values(this.types).map(({name:m, g:n}) => h ? n : m); | ||
if (!Z(k, l, this.o, c, f)) { | ||
return a; | ||
} | ||
c = Object.values(this.types).find(({name:m, h:n}) => h ? n == k.name : m == k.name); | ||
return !c || c instanceof Fb.b ? a : c.L(e, d, b, k.nullable, h); | ||
c = Object.values(this.types).find(({name:m, g:n}) => h ? n == k.name : m == k.name); | ||
return !c || c instanceof Fb.b ? a : c.M(e, d, b, k.nullable, h); | ||
} | ||
@@ -1419,3 +1437,3 @@ const Z = (a, b, c, d, e) => { | ||
let h = b.includes(f); | ||
h || (h = Wb.includes(f)); | ||
h || (h = Zb.includes(f)); | ||
if (h) { | ||
@@ -1439,28 +1457,28 @@ return !0; | ||
} | ||
}, Wb = "String Boolean Object Date Number Symbol Buffer Function".split(" "); | ||
var Xb = (a, b = !1) => { | ||
var {V:c} = Ta(); | ||
}, Zb = "String Boolean Object Date Number Symbol Buffer Function".split(" "); | ||
var $b = (a, b = !1) => { | ||
var {X:c} = Ta(); | ||
const d = Va(c); | ||
c = Ua(c); | ||
return new Fb(b ? [Sb] : [Sb, d, Vb, c], a); | ||
return new Fb(b ? [Vb] : [Vb, d, Yb, c], a); | ||
}; | ||
var Zb = async() => { | ||
const {F:a = !1, K:b = !1, C:c, types:d} = {F:ma, K:na, C:la, types:oa}; | ||
await Promise.all(w.map(async e => { | ||
var f = await H(y, e); | ||
var bc = async() => { | ||
const {H:a = !1, L:b = !1, F:c, types:d} = {H:la, L:ma, F:ka, types:na}; | ||
await Promise.all(x.map(async e => { | ||
var f = await I(y, e); | ||
let g; | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await J(e), g = K(f.content, e)); | ||
await Yb(g, a, b, c, d); | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await K(e), g = L(f.content, e)); | ||
await ac(g, a, b, c, d); | ||
})); | ||
}; | ||
const Yb = async(a, b = !1, c = !1, d = null, e = null) => { | ||
const ac = async(a, b = !1, c = !1, d = null, e = null) => { | ||
const f = []; | ||
e && await Promise.all(e.split(",").map(async g => { | ||
g = await F(g); | ||
const {types:h, imports:k} = Nb(g); | ||
g = await G(g); | ||
const {types:h, imports:k} = Hb(g); | ||
f.push(h, k); | ||
})); | ||
await Promise.all(a.map(async g => { | ||
var h = await F(g); | ||
const k = Xb({F:b, K:c}, c); | ||
var h = await G(g); | ||
const k = $b({H:b, L:c}, c); | ||
f.forEach(l => k.emit("types", l)); | ||
@@ -1471,11 +1489,11 @@ k.file = g; | ||
k.end(h); | ||
h = await E(k); | ||
"-" == d ? console.log(h) : d ? await G(d, h) : await G(g, h); | ||
h = await F(k); | ||
"-" == d ? console.log(h) : d ? await H(d, h) : await H(g, h); | ||
})); | ||
}; | ||
const $b = a => { | ||
const cc = a => { | ||
let b; | ||
"true" == a ? b = !0 : "false" == a ? b = !1 : /^\d+$/.test(a) && (b = parseInt(a, 10)); | ||
return void 0 !== b ? b : a; | ||
}, ac = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, bc = "type opt name quote defaultValue description Default".split(" "), Za = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), cc = (a, b, c, d) => { | ||
}, dc = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, ec = "type opt name quote defaultValue description Default".split(" "), Za = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), fc = (a, b, c, d) => { | ||
d = d.length; | ||
@@ -1486,3 +1504,3 @@ a = a && "Object" != a ? ` type="${a}"` : ""; | ||
}; | ||
class dc extends z { | ||
class gc extends z { | ||
constructor() { | ||
@@ -1493,3 +1511,3 @@ super({writableObjectMode:!0}); | ||
var {type:d, name:e, description:f, l:g} = a; | ||
a = d && d.startsWith("import") ? ec(d, e) : cc(d, e, f, g); | ||
a = d && d.startsWith("import") ? hc(d, e) : fc(d, e, f, g); | ||
this.push(a); | ||
@@ -1501,6 +1519,6 @@ g.forEach(h => { | ||
var q = void 0 !== m; | ||
const r = q ? ` default="${m}"` : ""; | ||
const t = q ? ` default="${m}"` : ""; | ||
q = p && !q ? " opt" : ""; | ||
const t = " ".repeat(4), x = " ".repeat(6); | ||
h = `${t}<prop${q}${h} name="${l}"${r}${n ? `>\n${x}${n}\n${t}</prop>` : "/>"}\n`; | ||
const u = " ".repeat(4), v = " ".repeat(6); | ||
h = `${u}<prop${q}${h} name="${l}"${t}${n ? `>\n${v}${n}\n${u}</prop>` : "/>"}\n`; | ||
} | ||
@@ -1513,3 +1531,3 @@ this.push(h); | ||
} | ||
const ec = (a, b) => { | ||
const hc = (a, b) => { | ||
const c = /import\((['"])(.+?)\1\)/.exec(a); | ||
@@ -1522,3 +1540,3 @@ if (!c) { | ||
}; | ||
class fc extends z { | ||
class ic extends z { | ||
constructor() { | ||
@@ -1529,3 +1547,3 @@ super({objectMode:!0}); | ||
var [, d, e, f, g] = a; | ||
a = T(ac, g, bc).map(h => { | ||
a = U(dc, g, ec).map(h => { | ||
var k = Object.assign({}, h), l = h.defaultValue; | ||
@@ -1537,5 +1555,5 @@ const m = h.Default; | ||
k = (delete k.defaultValue, delete k.Default, delete k.opt, delete k.name, delete k.type, k); | ||
n = Object.assign({}, k, {name:p, type:h}, l ? {defaultValue:$b(l)} : {}, m ? {D:$b(m)} : {}, n ? {optional:!0} : {}); | ||
n = Object.assign({}, k, {name:p, type:h}, l ? {defaultValue:cc(l)} : {}, m ? {G:cc(m)} : {}, n ? {optional:!0} : {}); | ||
if (l || m) { | ||
l ? l !== m && void 0 !== n.D && (l = N(p, m, h), console.error("%s[%s] does not match Default `%s`.", e, l, n.D)) : (l = N(p, m, h), console.error("%s[%s] got from Default.", e, l)), n.default = "defaultValue" in n ? n.defaultValue : n.D, delete n.defaultValue, delete n.D; | ||
l ? l !== m && void 0 !== n.G && (l = O(p, m, h), console.error("%s[%s] does not match Default `%s`.", e, l, n.G)) : (l = O(p, m, h), console.error("%s[%s] got from Default.", e, l)), n.default = "defaultValue" in n ? n.defaultValue : n.G, delete n.defaultValue, delete n.G; | ||
} | ||
@@ -1548,4 +1566,4 @@ return n; | ||
} | ||
async function gc(a) { | ||
const b = Ya(), c = new fc, d = new dc; | ||
async function jc(a) { | ||
const b = Ya(), c = new ic, d = new gc; | ||
b.pipe(c).pipe(d); | ||
@@ -1566,17 +1584,17 @@ b.end(a); | ||
return `<types> | ||
${(await E(d)).trim()} | ||
${(await F(d)).trim()} | ||
</types>`; | ||
} | ||
;var hc = async() => { | ||
const {C:a} = {C:la}; | ||
await Promise.all(w.map(async b => { | ||
b = await F(b); | ||
b = await gc(b); | ||
a ? await G(a, b) : console.log(b); | ||
;var kc = async() => { | ||
const {F:a} = {F:ka}; | ||
await Promise.all(x.map(async b => { | ||
b = await G(b); | ||
b = await jc(b); | ||
a ? await H(a, b) : console.log(b); | ||
})); | ||
}; | ||
const ic = /( *) \* @fnType {(.+?)}/gm; | ||
class jc extends M { | ||
const lc = /( *) \* @fnType {(.+?)}/gm; | ||
class mc extends N { | ||
constructor(a, b) { | ||
super([{re:ic, async replacement(c, d, e) { | ||
super([{re:lc, async replacement(c, d, e) { | ||
e = e.split("."); | ||
@@ -1593,3 +1611,3 @@ let f, g; | ||
} | ||
e = a.find(({h}) => h == f); | ||
e = a.find(({g:h}) => h == f); | ||
if (!e) { | ||
@@ -1606,15 +1624,15 @@ return console.error("Type %s in %s not found", f, b), c; | ||
} | ||
;const kc = async a => { | ||
;const nc = async a => { | ||
if (!a) { | ||
return []; | ||
} | ||
const b = await H(y, a); | ||
const b = await I(y, a); | ||
if (b.isFile()) { | ||
var c = [a]; | ||
} else { | ||
b.isDirectory() && (c = await J(a), c = K(c.content, a), c = c.filter(d => d.endsWith(".xml"))); | ||
b.isDirectory() && (c = await K(a), c = L(c.content, a), c = c.filter(d => d.endsWith(".xml"))); | ||
} | ||
return c; | ||
}, lc = async a => (await Promise.all(a.map(async b => { | ||
const c = await Ob(b); | ||
}, oc = async a => (await Promise.all(a.map(async b => { | ||
const c = await Rb(b); | ||
return Object.assign({}, c, {location:b}); | ||
@@ -1627,36 +1645,36 @@ }))).reduce((b, c) => { | ||
}, []); | ||
async function mc() { | ||
var a = {C:pa, types:oa}; | ||
async function pc() { | ||
var a = {F:oa, types:na}; | ||
a = void 0 === a ? {} : a; | ||
const {C:b, types:c} = a; | ||
a = await kc(c); | ||
const d = await lc(a); | ||
await Promise.all(w.map(async e => { | ||
var f = await H(y, e); | ||
const {F:b, types:c} = a; | ||
a = await nc(c); | ||
const d = await oc(a); | ||
await Promise.all(x.map(async e => { | ||
var f = await I(y, e); | ||
let g; | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await J(e), g = K(f.content, e)); | ||
await nc(g, d, b); | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await K(e), g = L(f.content, e)); | ||
await qc(g, d, b); | ||
})); | ||
} | ||
const nc = async(a, b, c) => { | ||
const qc = async(a, b, c) => { | ||
b = void 0 === b ? [] : b; | ||
c = void 0 === c ? null : c; | ||
await Promise.all(a.map(async d => { | ||
var e = await F(d); | ||
const f = new jc(b, d); | ||
var e = await G(d); | ||
const f = new mc(b, d); | ||
f.end(e); | ||
e = await E(f); | ||
"-" == c ? console.log(e) : c ? await G(c, e) : await G(d, e); | ||
e = await F(f); | ||
"-" == c ? console.log(e) : c ? await H(c, e) : await H(d, e); | ||
})); | ||
}; | ||
if (ra) { | ||
const a = ka(); | ||
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"})); | ||
if (qa) { | ||
const a = ja(); | ||
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"})); | ||
process.exit(); | ||
} else { | ||
sa && (console.log(require("../../package.json").version), process.exit()); | ||
ra && (console.log(require("../../package.json").version), process.exit()); | ||
} | ||
(async() => { | ||
try { | ||
return qa ? await hc() : pa ? await mc() : await Zb(); | ||
return pa ? await kc() : oa ? await pc() : await bc(); | ||
} catch (a) { | ||
@@ -1663,0 +1681,0 @@ process.env.DEBUG ? console.log(a.stack) : console.log(a.message); |
{ | ||
"name": "typal", | ||
"version": "1.20.2", | ||
"version": "1.21.0", | ||
"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": "build/index.js", |
@@ -18,3 +18,3 @@ // import parse from '@typedefs/parser' | ||
{ 'name': name, 'string': string, 'boolean': boolean, 'opt': opt, 'number': number, 'type': type }, | ||
namespace) { | ||
rootNamespace) { | ||
if (!name) throw new Error('Argument does not have a name.') | ||
@@ -24,4 +24,4 @@ this.name = name | ||
let t = getPropType({ number, string, boolean, type }) | ||
if (namespace) { | ||
const s = new RegExp(`([!?])?${namespace}\\.`, 'g') | ||
if (rootNamespace) { | ||
const s = new RegExp(`([!?])?${rootNamespace}\\.`, 'g') | ||
t = t.replace(s, '$1') | ||
@@ -73,5 +73,5 @@ } | ||
* @param {string} content | ||
* @param {string} [ns] The namespace to omit. | ||
* @param {?string} [rootNamespace] The namespace to omit. | ||
*/ | ||
export const extractArgs = (content, ns) => { | ||
export const extractArgs = (content, rootNamespace) => { | ||
let ai = content.lastIndexOf('</arg>') | ||
@@ -88,3 +88,3 @@ let newContent = content | ||
const ar = new Arg() | ||
ar.fromXML(ac, ap, ns) | ||
ar.fromXML(ac, ap, rootNamespace) | ||
return ar | ||
@@ -91,0 +91,0 @@ }) |
@@ -43,7 +43,8 @@ import extractTags from 'rexml' | ||
const type = new Type() | ||
type.fromXML(content, props, ns) | ||
type.fromXML(content, props, ns, rootNamespace) | ||
acc.push(type) | ||
if (alias) { | ||
const type2 = parseType(content, { ...restProps, name: alias }, ns) | ||
const type2 = new Type() | ||
type2.fromXML(content, { ...restProps, name: alias }, ns, rootNamespace) | ||
acc.push(type2) | ||
@@ -53,3 +54,4 @@ } else if (aliases) { | ||
a.forEach((name) => { | ||
const type2 = parseType(content, { ...restProps, name }, ns) | ||
const type2 = new Type() | ||
type2.fromXML(content, { ...restProps, name }, ns, rootNamespace) | ||
acc.push(type2) | ||
@@ -125,2 +127,3 @@ }) | ||
/** | ||
* This should be applicable only to <interface> / <constructor> / <method> | ||
* @param {string} content | ||
@@ -127,0 +130,0 @@ * @param {Object} props |
@@ -29,3 +29,3 @@ import parse from '@typedefs/parser' | ||
*/ | ||
this.type = '*' | ||
this._type = '*' | ||
/** | ||
@@ -37,2 +37,7 @@ * The override on the type in externs. | ||
/** | ||
* The actual `closure` attribute. | ||
* @type {?string} | ||
*/ | ||
this._closure = null | ||
/** | ||
* Whether the property has the default value. | ||
@@ -59,10 +64,9 @@ * @type {boolean} | ||
/** | ||
* The parsed type. | ||
* Whether to skip function params serialisation (e.g., in case it's working incorrectly). | ||
*/ | ||
this.parsed = undefined | ||
this.noParams = false | ||
/** | ||
* Whether to skip function params serialisation (e.g., in case it's working incorrectly). | ||
* The parsed type. | ||
* @type {?_typedefsParser.Type} | ||
*/ | ||
this.noParams = false | ||
this.parsed = null | ||
@@ -79,2 +83,20 @@ | ||
/** | ||
* Serialises functions to TypeScript, e.g., | ||
* (param: string) => void | ||
*/ | ||
toTypeScriptType(getLinks) { | ||
if (!this.parsed) throw new Error('The property was not parsed.') | ||
const { function: { args, return: { name: ret } } } = this.parsed | ||
const a = args.map((_, i) => { | ||
let { name = `arg${i}`, type: t, optional } = this.args[i] || {} | ||
name = `${name}${optional ? '?' : ''}` | ||
if (t) t = getLinks(t) | ||
return `${name}${t ? `: ${t}` : ''}` | ||
}) | ||
const j = a.join(', ') | ||
const r = getLinks(ret || '*') | ||
const typeName = `(${j}) => ${r}` | ||
return typeName.replace(/\*/g, '\\*') | ||
} | ||
/** | ||
* When writing externs, this will prevent adding `.prototype`, e.g., | ||
@@ -101,5 +123,9 @@ * `Type.static` instead of `Type.prototype.static`. | ||
const t = getPropType({ number, string, boolean, type }) | ||
if (noParams) this.noParams = noParams | ||
if (closure) this._closure = closure | ||
this.type = t | ||
if (closure) this.closureType = closure | ||
else this.closureType = this.type | ||
if (def !== undefined) this.hasDefault = true | ||
@@ -111,8 +137,14 @@ if (this.hasDefault) this.default = def | ||
if (noParams) this.noParams = noParams | ||
if (Static) this._static = true | ||
// if optional, we want to keep "| undefined" on records | ||
// todo: lazy parse on demand as not always required... | ||
} | ||
get type() { | ||
return this._type | ||
} | ||
/** | ||
* Type can be overridden when removing namespace from properties. | ||
*/ | ||
set type(value) { | ||
this._type = value | ||
this.closureType = this._closure || value | ||
// can also check if closure changed or just type | ||
if (!this.noParams) { | ||
@@ -122,2 +154,3 @@ try { | ||
} catch (err) { /* ok */ | ||
this.parsed = null | ||
} | ||
@@ -152,3 +185,3 @@ } | ||
const { function: { args, return: ret } } = this.parsed | ||
const a = args.map(serialise) | ||
const a = args.map(ar => serialise(ar)) | ||
a.forEach((s, i) => { | ||
@@ -202,3 +235,3 @@ const { optional } = args[i] | ||
const a = args | ||
.map(serialise) | ||
.map((ar) => serialise(ar)) | ||
.map((type, i) => { | ||
@@ -210,3 +243,3 @@ const { optional } = args[i] | ||
const s = a.join(', ') | ||
const r = serialise(ret) | ||
const r = serialise(/** @type {!_typedefsParser.Type} */ (ret)) | ||
@@ -254,2 +287,7 @@ return `(${s}) => ${r}` | ||
return d | ||
} | ||
} | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {import('@typedefs/parser').Type} _typedefsParser.Type | ||
*/ |
@@ -104,3 +104,3 @@ import extractTags from 'rexml' | ||
'async': methodAsync, 'return': methodReturn, // for <method async return="{}"> elements | ||
}, namespace) { | ||
}, namespace, rootNamespace = null) { | ||
if (!name) throw new Error('Type does not have a name.') | ||
@@ -139,3 +139,3 @@ this.name = name | ||
const fnProps = fn.map(({ content: c, props: p, 'isStatic': isStatic }) => { | ||
const { newContent, argsArgs } = extractArgs(c) | ||
const { newContent, argsArgs } = extractArgs(c, rootNamespace) | ||
@@ -164,3 +164,9 @@ const { 'async': async, 'return': ret = 'void', ...rest } = p | ||
}) | ||
this.properties = [...props, ...fnProps] | ||
const all = [...props, ...fnProps] | ||
const { s, n } = all.reduce((acc, p) => { | ||
if (p.static) acc.s.push(p) | ||
else acc.n.push(p) | ||
return acc | ||
}, { s: [], n: [] }) | ||
this.properties = [...s, ...n] | ||
} | ||
@@ -262,2 +268,5 @@ if (namespace) this.namespace = namespace | ||
const s = ` * @typedef {${t}}${dd}` | ||
/** | ||
* @type {!Array<!Property>} | ||
*/ | ||
const properties = this.properties ? this.properties.reduce((acc, p) => { | ||
@@ -457,3 +466,2 @@ if (p._static) return acc | ||
if (this.extends) { | ||
useTag = useTag || /_/.test(this.extends) | ||
let e = `\`${this.extends}\`` | ||
@@ -464,7 +472,5 @@ const foundExt = allTypes.find(({ fullName }) => { | ||
if (foundExt && foundExt.link) { | ||
useTag = useTag || /_/.test(foundExt.link) | ||
e = '<a ' | ||
if (foundExt.description) { | ||
e += `title="${foundExt.description}" ` | ||
useTag = useTag || /_/.test(foundExt.description) | ||
} | ||
@@ -478,5 +484,5 @@ e += `href="${foundExt.link}">\`${this.extends}\`</a>` | ||
if (this.extends != le) e = le | ||
useTag = useTag || /_/.test(e) | ||
} | ||
const extendS = ` extends ${e}` | ||
useTag = useTag || /_/.test(e) | ||
if (useTag) LINE += '<strong>' | ||
@@ -500,5 +506,4 @@ else LINE += '__' | ||
}) | ||
return { LINE, table, displayInDetails } // delegate rendering to typal | ||
// const r = `${LINE}${table}` | ||
// return r | ||
// delegate rendering to documentary | ||
return { LINE, table, displayInDetails } | ||
} | ||
@@ -543,3 +548,3 @@ } | ||
* @param {!Array<!Type>} allTypes | ||
* @param {string} type | ||
* @param {string|!_typedefsParser.Type} type | ||
* @param {Object} [opts] | ||
@@ -553,3 +558,4 @@ * @param {boolean} [opts.flatten] | ||
let parsed | ||
try { | ||
if (typeof type == 'object') parsed = type | ||
else try { | ||
parsed = parse(type) // should parse type when added | ||
@@ -684,9 +690,13 @@ if (!parsed) { | ||
...(anyHaveDefault ? ['Default'] : [])] | ||
const linkOptions = { | ||
flatten, | ||
escapePipe: !narrow, | ||
link, | ||
} | ||
const ps = props.map((prop) => { | ||
const typeName = | ||
getLinks(/** @type {!Array<!Type>} */ (allTypes), prop.type, { | ||
flatten, | ||
escapePipe: !narrow, | ||
link, | ||
}) | ||
let typeName | ||
if (prop.args && prop.isParsedFunction) { | ||
typeName = prop.toTypeScriptType((s) => getLinks(/** @type {!Array<!Type>} */ (allTypes), s, linkOptions)) | ||
} else | ||
typeName = getLinks(/** @type {!Array<!Type>} */ (allTypes), prop.parsed || prop.type, linkOptions) | ||
const name = prop.optional ? prop.name : `${prop.name}*` | ||
@@ -693,0 +703,0 @@ const d = !prop.hasDefault ? '-' : `\`${prop.default}\`` |
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
334828
6299