Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typal

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typal - npm Package Compare versions

Comparing version 1.17.0 to 1.18.0

build/bin/commands/extract.js

13

build/lib/make-JSTypal.js

@@ -0,1 +1,2 @@

const { makeMarkers, makeCutRule, makePasteRule } = require('restream');
const typedefJsRule = require('./typedef/rule');

@@ -6,5 +7,15 @@ const JSDocRule = require('./typedef/jsdoc');

module.exports=(conf, onlyTypedef = false) => {
const rules = onlyTypedef ? [typedefJsRule] : [typedefJsRule, JSDocRule]
const { externsTypedef } = makeMarkers({
externsTypedef: /^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg,
})
// to exclude @params in externs block from JSDoc warnings
const cr = makeCutRule(externsTypedef)
const pr = makePasteRule(externsTypedef)
const rules = onlyTypedef ? [typedefJsRule] : [typedefJsRule,
cr,
JSDocRule,
pr,
]
const jsTypal = new JSTypal(rules, conf)
return jsTypal
}

@@ -5,2 +5,3 @@ const extractTags = require('rexml');

const { trimD } = require('./');
let read = require('@wrote/read'); if (read && read.__esModule) read = read.default;

@@ -67,2 +68,21 @@ /**

module.exports=parseFile
module.exports=parseFile
/**
* @param {string} path
*/
const readTypesFile = async (path, ignore = []) => {
const xml = await read(path)
let { namespace = null, types, imports } = parseFile(xml)
types = types.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
imports = imports.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
return { types, imports, namespace }
}
module.exports.readTypesFile = readTypesFile

@@ -0,2 +1,4 @@

const parse = require('@typedefs/parser');
const { getPropType, getNameWithDefault, makeOptional, trimD } = require('./');
const Arg = require('./Arg'); // eslint-disable-line

@@ -7,3 +9,7 @@ /**

class Property {
constructor() {
/**
* @param {!Array<!Arg>} [args] If a property was written as a function with inner
* <arg> elements, this array will contain parsed entries.
*/
constructor(args = []) {
/**

@@ -49,2 +55,15 @@ * The name of the property.

this.aliases = []
/**
* The parsed type.
*/
this.parsed = undefined
/**
* Whether to skip function params serialisation (e.g., in case it's working incorrectly).
*/
this.noParams = false
this.parsed = null
this.args = args
}

@@ -57,3 +76,3 @@ static fromXML(...args) {

fromXML(content,
{ 'name': name, 'string': string, 'boolean': boolean, 'opt': opt, 'number': number, 'type': type, 'default': def, 'closure': closure, 'alias': alias, 'aliases': aliases },
{ 'name': name, 'string': string, 'boolean': boolean, 'opt': opt, 'number': number, 'type': type, 'default': def, 'closure': closure, 'alias': alias, 'aliases': aliases, 'noParams': noParams },
) {

@@ -72,2 +91,12 @@ if (!name) throw new Error('Property does not have a name.')

if (aliases) this.aliases = aliases.split(/\s*,\s*/)
if (noParams) this.noParams = noParams
// if optional, we want to keep "| undefined" on records
if (!this.optional && !this.noParams) {
try {
this.parsed = parse(this.closureType)
} catch (err) { /* ok */
}
}
}

@@ -90,4 +119,22 @@ toJSDoc(parentParam = null, closure = false) {

}
toExtern() {
toFunctionJsDoc() {
const pp = []
const { function: { args, return: ret } } = this.parsed
const a = args.map(parsedToString)
a.forEach((s, i) => {
const { optional } = args[i]
const { name = `arg${i}`, description } = this.args[i] || {}
const arg = optional ? `[${name}]` : name
const d = description ? ` ${description}` : ''
pp.push(` * @param {${s}${optional ? '=' : ''}} ${arg}${d}`)
})
if (ret.name != 'void') {
const r = parsedToString(ret)
pp.push(` * @return {${r}}`)
}
return pp
}
toExtern(ws = '') {
const pp = []
if (this.description) {

@@ -98,5 +145,10 @@ let d = indentWithAster(this.description)

}
const t = this.optional ? makeOptional(this.closureType) : this.closureType
pp.push(` * @type {${t}}`)
return pp.join('\n')
if (this.parsed && this.parsed.name == 'function') {
const lines = this.toFunctionJsDoc()
pp.push(...lines)
} else {
const t = this.optional ? makeOptional(this.closureType) : this.closureType
pp.push(` * @type {${t}}`)
}
return pp.map(p => `${ws}${p}`).join('\n')
}

@@ -127,2 +179,76 @@ toParam(parentParam, ws = '', closure = false) {

/**
* @param {!_typedefsParser.Type} type
*/
const parsedToString = (type) => {
let s = ''
let nullable = ''
if (type.nullable) nullable = '?'
else if (type.nullable === false) nullable = '!'
s += nullable
if (type.function) {
s += type.name + '(' // Function or function
const args = []
if (type.function.this) {
let t = 'this: '
t += parsedToString(type.function.this)
args.push(t)
}
if (type.function.new) {
let t = 'new: '
t += parsedToString(type.function.new)
args.push(t)
}
type.function.args.forEach((a) => {
let t = parsedToString(a)
if (a.optional) t += '='
args.push(t)
})
if (type.function.variableArgs) {
let t = '...'
t += parsedToString(type.function.variableArgs)
args.push(t)
}
const argsJoined = args.join(', ')
s += argsJoined + ')'
if (type.function.return) {
s += ': ' + parsedToString(type.function.return)
}
} else if (type.record) {
s += '{ '
const rs = Object.keys(type.record).map((key) => {
const val = type.record[key]
if (!val) return key
const v = parsedToString(val)
return `${key}: ${v}`
})
s += rs.join(', ')
s += ' }'
} else if (type.application) {
if (type.name == 'Promise') {
const otherThanVoid = type.application.some(t => t.name != 'void')
if (!otherThanVoid) return s + 'Promise'
}
s += type.name + '<'
const apps = type.application.map((a) => {
return parsedToString(a)
})
s += apps.join(', ')
s += '>'
} else if (type.union) {
s += '('
const union = type.union.map((u) => {
return parsedToString(u)
})
s += union.join('|')
s += ')'
} else {
const name = type.name == 'any' ? '*' : type.name
s += name
}
return s
}
module.exports = Property
const extractTags = require('rexml');
const parse = require('@typedefs/parser');
const Property = require('./Property');
const Arg = require('./Arg');
const { addSuppress, makeBlock, getExternDeclaration, makeOptional } = require('./');

@@ -107,7 +108,33 @@ const { getLink, trimD } = require('./');

const fnProps = fn.map(({ content: c, props: p }) => {
const { 'async': async, 'args': args = '', 'return': ret = 'void', ...rest } = p
let r = async ? `!Promise<${ret}>` : ret
let ai = c.lastIndexOf('</arg>')
let argsArgs = []
if (ai != -1) {
ai = ai + '</arg>'.length
const pre = c.slice(0, ai)
c = c.slice(ai)
argsArgs = extractTags('arg', pre)
argsArgs = argsArgs.map(({ content: ac, props: ap }) => {
const ar = new Arg()
ar.fromXML(ac, ap)
return ar
})
}
const { 'async': async, 'return': ret = 'void', ...rest } = p
let { 'args': args = '' } = p
if (!args && argsArgs.length) {
args = argsArgs.map(({ type: at, optional }) => {
// optional can also just be set in type, e.g., type="string=",
// so check for null and not truthy
if (optional !== null) return `${at}=`
return at
}).join(',')
}
let r = ret.replace(/\n\s*/g, ' ')
r = async ? `!Promise<${r}>` : r
const fnType = `function(${args}): ${r}`
rest['type'] = fnType
const pr = new Property()
const pr = new Property(argsArgs)
pr.fromXML(c, rest)

@@ -224,2 +251,3 @@ return pr

s = s + getExternDeclaration(this.namespace, this.name, constr)
/** @type {!Array<!Property>} */
const properties = this.properties.reduce((acc, p) => {

@@ -236,2 +264,12 @@ acc.push(p)

/** @type {string} */ (p.name))
if (p.parsed && p.parsed.name == 'function') {
const { function: { args } } = p.parsed
const a = args.map((_, i) => {
const { name = `arg${i}` } = p.args[i] || {}
return name
})
r += ` = function(${a.join(', ')}) {}`
} else if (p.type.startsWith('function(')) {
r += ' = function() {}'
}
return r

@@ -273,2 +311,3 @@ })

/**
* Converts a type to a markdown string.
* @param {!Array<!Type>} [allTypes]

@@ -279,5 +318,8 @@ * @param {!Object} [opts]

* @param {function()} [opts.link] A function to call for extra processing of links.
* @param {!Array<string>} [opts.details] An array of types that should be displayed as details.
* @todo open-details
*/
toMarkdown(allTypes = [], opts = {}) {
const { narrow, flatten, preprocessDesc, link } = opts
const { narrow, flatten, preprocessDesc, link, details = [] } = opts
const displayInDetails = details.includes(this.name)
const t = this.type ? `\`${this.type}\`` : ''

@@ -344,5 +386,5 @@ let typeWithLink = t, useCode = false

})
if (narrow) return { LINE, table }
const r = `${LINE}${table}`
return r
return { LINE, table, displayInDetails } // delegate rendering to typal
// const r = `${LINE}${table}`
// return r
}

@@ -397,3 +439,3 @@ }

try {
parsed = parse(type)
parsed = parse(type) // should parse type when added
if (!parsed) {

@@ -602,2 +644,3 @@ console.log('Could not parse %s', type)

module.exports.getLinks = getLinks
module.exports.parsedToString = parsedToString
module.exports.makePropsTable = makePropsTable

14

build/lib/typedef/rule.js

@@ -1,2 +0,1 @@

let read = require('@wrote/read'); if (read && read.__esModule) read = read.default;
const { makeBlock } = require('../');

@@ -6,3 +5,3 @@ const Type = require('../Type'); // eslint-disable-line

const Import = require('../Import'); // eslint-disable-line
const parseFile = require('../parse');
const { readTypesFile } = require('../parse');
const { closureJoinTypes, externsJoinTypes } = require('../closure');

@@ -37,12 +36,3 @@

this.LOG('Detected type marker: %s', location)
const xml = await read(loc)
let { namespace = null, types, imports } = parseFile(xml)
types = types.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
imports = imports.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
const { types, imports, namespace } = await readTypesFile(loc, ignore)

@@ -49,0 +39,0 @@ this.emit('types', types) // remember types for js-replace-stream

@@ -0,1 +1,19 @@

## 31 July 2019
### [1.18.0](https://github.com/artdecocode/typal/compare/v1.17.0...v1.18.0)
- [feature] Generate source code from template
- [feature] Update XML schema to specify properties which are functions and their args with `<args>`.
- [feature] Create externs in form of
```js
/**
* Fn desc.
* @param {string} param1 Arg1 Desc
* @param {boolean} param2 Arg2 Desc
*/
_ns.Type.prototype.fn = function(param1, param2)
```
- [doc] Move some documentation to wiki.
- [API] `Type.toMarkdown` now always returns _{ LINE, table }_.
## 29 July 2019

@@ -2,0 +20,0 @@

@@ -7,8 +7,8 @@ #!/usr/bin/env node

const path = require('path');
var aa = "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);
}, ba = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this;
function ca(a, b) {
}, da = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this;
function ea(a, b) {
if (b) {
var c = ba;
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 && aa(c, a, {configurable:!0, writable:!0, value:b});
b != d && null != b && ca(c, a, {configurable:!0, writable:!0, value:b});
}
}
ca("String.prototype.trimRight", function(a) {
ea("String.prototype.trimRight", function(a) {
function b() {

@@ -33,3 +33,3 @@ return this.replace(/[\s\xa0]+$/, "");

});
const w = (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)]};
}, da = a => {
}, ha = a => {
const b = [];

@@ -63,4 +63,4 @@ for (let c = 0; c < a.length; c++) {

return b;
}, ea = () => {
var a = x;
}, ja = () => {
var a = ia;
return Object.keys(a).reduce((b, c) => {

@@ -79,8 +79,9 @@ const d = a[c];

};
const x = {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"}, 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"}}, A = function(a, b) {
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) {
a = void 0 === a ? {} : a;
b = void 0 === b ? process.argv : b;
[, , ...b] = b;
const c = da(b);
const c = ha(b);
b = b.slice(c.length);

@@ -90,6 +91,6 @@ let d = !c.length;

var g = Object.assign({}, e);
e = e.m;
g = (delete g.m, g);
e = e.s;
g = (delete g.s, g);
if (0 == e.length && d) {
return Object.assign({}, {m:e}, g);
return Object.assign({}, {s:e}, g);
}

@@ -99,19 +100,19 @@ const h = a[f];

if ("string" == typeof h) {
({value:k, argv:e} = w(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} = w(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) {
return Object.assign({}, {m:e}, g);
return Object.assign({}, {s:e}, g);
}
}
return void 0 === k ? Object.assign({}, {m:e}, g) : Object.assign({}, {m:e}, g, {[f]:k});
}, {m:b});
}(x), C = A.source, D = A.output, fa = A.closure, ha = A.externs, ia = A.types, ja = A.migrate, ka = A.help, la = A.version;
function ma(a = {usage:{}}) {
return void 0 === k ? Object.assign({}, {s:e}, g) : Object.assign({}, {s:e}, g, {[f]:k});
}, {s:b});
}(ia), w = v.source, ka = v.output, la = v.closure, ma = v.externs, na = v.types, oa = v.template, pa = v.migrate, qa = v.help, ra = v.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);

@@ -129,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];

@@ -144,6 +145,6 @@ }, []).map(l => `\t${l}`);

}
;const {createReadStream:na, createWriteStream:oa, lstat:E, readdir:pa} = fs;
var qa = stream;
const {Transform:F, Writable:ra} = stream;
const G = (a, b = 0, c = !1) => {
;const {createReadStream:ta, createWriteStream:ua, lstat:x, readdir:va} = fs;
var wa = stream;
const {Transform:y, Writable:xa} = stream;
const ya = (a, b = 0, c = !1) => {
if (0 === b && !c) {

@@ -154,11 +155,11 @@ return a;

return c ? a[a.length - 1] : a.slice(b).join("\n");
}, sa = (a, b = !1) => G(a, 2 + (b ? 1 : 0)), H = a => {
}, za = (a, b = !1) => ya(a, 2 + (b ? 1 : 0)), Aa = a => {
({callee:{caller:a}} = a);
return a;
};
const {homedir:ta} = os;
const J = /\s+at.*(?:\(|\s)(.*)\)?/, ua = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/, va = ta(), K = a => {
const {pretty:b = !1, ignoredModules:c = ["pirates"]} = {}, d = c.join("|"), e = new RegExp(ua.source.replace("IGNORED_MODULES", d));
const {homedir:Ba} = os;
const Ca = /\s+at.*(?:\(|\s)(.*)\)?/, Da = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/, Ea = Ba(), B = a => {
const {pretty:b = !1, ignoredModules:c = ["pirates"]} = {}, d = c.join("|"), e = new RegExp(Da.source.replace("IGNORED_MODULES", d));
return a.replace(/\\/g, "/").split("\n").filter(f => {
f = f.match(J);
f = f.match(Ca);
if (null === f || !f[1]) {

@@ -169,20 +170,20 @@ return !0;

return f.includes(".app/Contents/Resources/electron.asar") || f.includes(".app/Contents/Resources/default_app.asar") ? !1 : !e.test(f);
}).filter(f => f.trim()).map(f => b ? f.replace(J, (g, h) => g.replace(h, h.replace(va, "~"))) : f).join("\n");
}).filter(f => f.trim()).map(f => b ? f.replace(Ca, (g, h) => g.replace(h, h.replace(Ea, "~"))) : f).join("\n");
};
function wa(a, b, c = !1) {
function Fa(a, b, c = !1) {
return function(d) {
var e = H(arguments), {stack:f} = Error();
const g = G(f, 2, !0), h = (f = d instanceof Error) ? d.message : d;
var e = Aa(arguments), {stack:f} = Error();
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");
e = K(e);
e = B(e);
return Object.assign(f ? d : Error(), {message:h, stack:e});
};
}
;function L(a) {
;function F(a) {
var {stack:b} = Error();
const c = H(arguments);
b = sa(b, a);
return wa(c, b, a);
const c = Aa(arguments);
b = za(b, a);
return Fa(c, b, a);
}
;const xa = (a, b) => {
;const Ga = (a, b) => {
b.once("error", c => {

@@ -193,3 +194,3 @@ a.emit("error", c);

};
class ya extends ra {
class Ha extends xa {
constructor(a) {

@@ -199,6 +200,6 @@ var b = a || {}, c = Object.assign({}, b);

b = (delete c.binary, delete c.rs, c);
const {O:f = L(!0), proxyError:g} = a || {}, h = (k, l) => f(l);
const {P:f = F(!0), proxyError:g} = a || {}, h = (k, l) => f(l);
super(b);
this.b = [];
this.M = new Promise((k, l) => {
this.N = new Promise((k, l) => {
this.on("finish", () => {

@@ -214,3 +215,3 @@ let m;

} else {
const n = K(m.stack);
const n = B(m.stack);
m.stack = n;

@@ -221,3 +222,3 @@ g && h`${m}`;

});
e && xa(this, e).pipe(this);
e && Ga(this, e).pipe(this);
});

@@ -229,20 +230,20 @@ }

}
get i() {
return this.M;
get g() {
return this.N;
}
}
const M = async a => {
const G = async a => {
var b = void 0 === b ? {} : b;
({i:a} = new ya(Object.assign({}, {rs:a}, b, {O:L(!0)})));
({g:a} = new Ha(Object.assign({}, {rs:a}, b, {P:F(!0)})));
return await a;
};
async function N(a) {
a = na(a);
return await M(a);
async function H(a) {
a = ta(a);
return await G(a);
}
;async function O(a, b) {
;async function I(a, b) {
if (!a) {
throw Error("No path is given.");
}
const c = L(!0), d = oa(a);
const c = F(!0), d = ua(a);
await new Promise((e, f) => {

@@ -255,3 +256,3 @@ d.on("error", g => {

}
;function za(a, b) {
;function Ia(a, b) {
if (b > a - 2) {

@@ -261,4 +262,4 @@ throw Error("Function does not accept that many arguments.");

}
async function P(a, b, c) {
const d = L(!0);
async function J(a, b, c) {
const d = F(!0);
if ("function" !== typeof a) {

@@ -275,27 +276,27 @@ throw Error("Function must be passed.");

Array.isArray(b) ? (b.forEach((l, m) => {
za(e, m);
}), k = [...b, h]) : 1 < Array.from(arguments).length && (za(e, 0), k = [b, h]);
Ia(e, m);
}), k = [...b, h]) : 1 < Array.from(arguments).length && (Ia(e, 0), k = [b, h]);
a(...k);
});
}
;const {join:Q} = path;
async function Aa(a, b) {
;const {join:K} = path;
async function Ja(a, b) {
b = b.map(async c => {
const d = Q(a, c);
return {lstat:await P(E, d), path:d, relativePath:c};
const d = K(a, c);
return {lstat:await J(x, d), path:d, relativePath:c};
});
return await Promise.all(b);
}
const Ba = a => a.lstat.isDirectory(), Ca = a => !a.lstat.isDirectory();
async function Da(a) {
const Ka = a => a.lstat.isDirectory(), La = a => !a.lstat.isDirectory();
async function L(a) {
if (!a) {
throw Error("Please specify a path to the directory");
}
if (!(await P(E, a)).isDirectory()) {
if (!(await J(x, a)).isDirectory()) {
throw a = Error("Path is not a directory"), a.code = "ENOTDIR", a;
}
var b = await P(pa, a);
b = await Aa(a, b);
a = b.filter(Ba);
b = b.filter(Ca).reduce((c, d) => {
var b = await J(va, a);
b = await Ja(a, b);
a = b.filter(Ka);
b = b.filter(La).reduce((c, d) => {
var e = d.lstat.isDirectory() ? "Directory" : d.lstat.isFile() ? "File" : d.lstat.isSymbolicLink() ? "SymbolicLink" : void 0;

@@ -307,3 +308,3 @@ return Object.assign({}, c, {[d.relativePath]:{type:e}});

c = await c;
d = await Da(e);
d = await L(e);
return Object.assign({}, c, {[f]:d});

@@ -313,11 +314,11 @@ }, {});

}
const Ea = (a, b) => {
const M = (a, b) => {
let c = [], d = [];
Object.keys(a).forEach(f => {
const {type:g} = a[f];
"File" == g ? c.push(Q(b, f)) : "Directory" == g && d.push(f);
"File" == g ? c.push(K(b, f)) : "Directory" == g && d.push(f);
});
const e = d.reduce((f, g) => {
const {content:h} = a[g];
g = Ea(h, Q(b, g));
g = M(h, K(b, g));
return [...f, ...g];

@@ -327,3 +328,161 @@ }, []);

};
const S = (a, b, c, d) => {
function Ma(a) {
if ("object" != typeof a) {
return !1;
}
const {re:b, replacement:c} = a;
a = b instanceof RegExp;
const d = -1 != ["string", "function"].indexOf(typeof c);
return a && d;
}
const N = (a, b) => {
if (!(b instanceof Error)) {
throw b;
}
[, , a] = a.stack.split("\n", 3);
a = b.stack.indexOf(a);
if (-1 == a) {
throw b;
}
a = b.stack.substr(0, a - 1);
const c = a.lastIndexOf("\n");
b.stack = a.substr(0, c);
throw b;
};
function Na(a, b) {
function c() {
return b.filter(Ma).reduce((d, {re:e, replacement:f}) => {
if (this.o) {
return d;
}
if ("string" == typeof f) {
return d = d.replace(e, f);
}
{
let g;
return d.replace(e, (h, ...k) => {
g = Error();
try {
return this.o ? h : f.call(this, h, ...k);
} catch (l) {
N(g, l);
}
});
}
}, `${a}`);
}
c.b = () => {
c.o = !0;
};
return c.call(c);
}
;const Oa = a => new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`, "g"), Pa = (a, b) => `%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`, Qa = () => {
var a = {R:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg};
return Object.keys(a).reduce((b, c) => {
{
var d = a[c];
const {getReplacement:e = Pa, getRegex:f = Oa} = {}, g = f(c);
d = {name:c, re:d, regExp:g, getReplacement:e, map:{}, lastIndex:0};
}
return Object.assign({}, b, {[c]:d});
}, {});
}, Ra = a => {
var b = void 0 === b ? [] : b;
const {regExp:c, map:d} = a;
return {re:c, replacement(e, f) {
e = d[f];
delete d[f];
return Na(e, Array.isArray(b) ? b : [b]);
}};
}, Sa = a => {
const {re:b, map:c, getReplacement:d, name:e} = a;
return {re:b, replacement(f) {
const {lastIndex:g} = a;
c[g] = f;
a.lastIndex += 1;
return d(e, g);
}};
};
async function Ta(a, b) {
b instanceof wa ? b.pipe(a) : a.end(b);
return await G(a);
}
class O extends y {
constructor(a, b) {
super(b);
this.g = (Array.isArray(a) ? a : [a]).filter(Ma);
this.o = !1;
this.A = b;
}
async replace(a, b) {
const c = new O(this.g, this.A);
b && Object.assign(c, b);
a = await Ta(c, a);
c.o && (this.o = !0);
b && Object.keys(b).forEach(d => {
b[d] = c[d];
});
return a;
}
async reduce(a) {
return await this.g.reduce(async(b, {re:c, replacement:d}) => {
b = await b;
if (this.o) {
return b;
}
if ("string" == typeof d) {
b = b.replace(c, d);
} else {
const e = [];
let f;
const g = b.replace(c, (h, ...k) => {
f = Error();
try {
if (this.o) {
return e.length ? e.push(Promise.resolve(h)) : h;
}
const l = d.call(this, h, ...k);
l instanceof Promise && e.push(l);
return l;
} catch (l) {
N(f, l);
}
});
if (e.length) {
try {
const h = await Promise.all(e);
b = b.replace(c, () => h.shift());
} catch (h) {
N(f, h);
}
} else {
b = g;
}
}
return b;
}, `${a}`);
}
async _transform(a, b, c) {
try {
const d = await this.reduce(a);
this.push(d);
c();
} catch (d) {
a = B(d.stack), d.stack = a, c(d);
}
}
}
;function Ua() {
var a = Va;
let b = "";
const c = new y({transform(d, e, f) {
let g;
for (b += d.toString(); (d = a.exec(b)) && (c.push(d), g = d, a.global);) {
}
g && (b = b.slice(g.index + g[0].length));
f();
}, objectMode:!0});
return c;
}
;const S = (a, b, c, d) => {
if (!a) {

@@ -338,3 +497,3 @@ throw Error("The name of the property is not given");

return `${a}=${b}`;
}, Fa = ({number:a, S:b, boolean:c, type:d}) => b ? "string" : a ? "number" : c ? "boolean" : d ? d : "*", Ga = a => `${/[^\w\d._]/.test(a) ? `(${a})` : a}|undefined`, Ha = a => `/**
}, Wa = ({number:a, M:b, boolean:c, type:d}) => b ? "string" : a ? "number" : c ? "boolean" : d ? d : "*", Xa = a => `${/[^\w\d._]/.test(a) ? `(${a})` : a}|undefined`, Ya = a => `/**
${a}

@@ -385,9 +544,9 @@ */

}
;const Ia = new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`, "g"), Ja = new RegExp(`\\s*((?:${Ia.source}\\s*)*)`);
const X = (a, b) => W(new RegExp(`<${a}${Ja.source}?(?:${/\s*\/>/.source}|${(new RegExp(`>([\\s\\S]+?)?</${a}>`)).source})`, "g"), b, ["a", "v", "v1", "v2", "c"]).map(({a:c = "", c:d = ""}) => {
;const Za = new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`, "g"), $a = new RegExp(`\\s*((?:${Za.source}\\s*)*)`);
const X = (a, b) => W(new RegExp(`<${a}${$a.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 = Ka(c);
return {content:d, w:c};
}), Ka = a => W(Ia, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => {
if (!d) {
c = ab(c);
return {content:d, v:c};
}), ab = a => W(Za, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => {
if (void 0 === d) {
return b[c] = !0, b;

@@ -398,3 +557,3 @@ }

}, {});
const La = a => a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b => /\S/.test(b)).map(b => {
const bb = a => a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b => /\S/.test(b)).map(b => {
switch(b) {

@@ -416,3 +575,3 @@ case "function":

});
function Ma(a) {
function cb(a) {
let b = 0;

@@ -565,8 +724,25 @@ const c = (d, e) => {

}
;function Na(a) {
a = La(a);
return Ma(a);
;function db(a) {
a = bb(a);
return cb(a);
}
;function Oa(a, b, {name:c, string:d, "boolean":e, opt:f, number:g, type:h, "default":k, closure:l, alias:m, aliases:n}) {
;function eb(a, b, {name:c, string:d, "boolean":e, opt:f, number:g, type:h}) {
if (!c) {
throw Error("Argument does not have a name.");
}
a.name = c;
b && (a.description = V(b));
a.type = Wa({number:g, M:d, boolean:e, type:h});
f && (a.optional = !0);
}
class fb {
constructor() {
this.name = null;
this.type = "";
this.optional = null;
this.description = "";
}
}
;function gb(a, b, {name:c, string:d, "boolean":e, opt:f, number:g, type:h, "default":k, closure:l, alias:m, aliases:n, noParams:p}) {
if (!c) {
throw Error("Property does not have a name.");

@@ -576,13 +752,20 @@ }

b && (a.description = V(b));
a.type = Fa({number:g, S:d, boolean:e, type:h});
a.type = Wa({number:g, M:d, boolean:e, type:h});
l ? a.f = l : a.f = a.type;
void 0 !== k && (a.b = !0);
a.b && (a.default = k);
if (f || a.b) {
void 0 !== k && (a.g = !0);
a.g && (a.default = k);
if (f || a.g) {
a.optional = !0;
}
m && (a.v = [m]);
n && (a.v = n.split(/\s*,\s*/));
m && (a.w = [m]);
n && (a.w = n.split(/\s*,\s*/));
p && (a.l = p);
if (!a.optional && !a.l) {
try {
a.b = db(a.f);
} catch (q) {
}
}
}
function Pa(a, b = null, c = !1) {
function hb(a, b = null, c = !1) {
if (!a.name) {

@@ -592,9 +775,31 @@ throw Error("Property does not have a name. Has it been constructed using fromXML?");

b = S(a.name, a.default, a.type, b);
return `{${c ? a.f : a.type}} ${a.optional ? `[${b}]` : b}${`${a.description ? ` ${a.description}` : ""}${a.b ? ` Default \`${a.default}\`.` : ""}`}`;
return `{${c ? a.f : a.type}} ${a.optional ? `[${b}]` : b}${`${a.description ? ` ${a.description}` : ""}${a.g ? ` Default \`${a.default}\`.` : ""}`}`;
}
function Qa(a, b = !1) {
a = Pa(a, null, b);
return ` * @prop ${Ra(a, !0)}`;
function ib(a, b = !1) {
a = hb(a, null, b);
return ` * @prop ${jb(a, !0)}`;
}
function Sa(a, b) {
function kb(a) {
const b = [], {function:{args:c, return:d}} = a.b;
c.map(Y).forEach((e, f) => {
const {optional:g} = c[f], {name:h = `arg${f}`, description:k} = a.args[f] || {};
b.push(` * @param {${e}${g ? "=" : ""}} ${g ? `[${h}]` : h}${k ? ` ${k}` : ""}`);
});
if ("void" != d.name) {
const e = Y(d);
b.push(` * @return {${e}}`);
}
return b;
}
function lb(a, b = "") {
const c = [];
if (a.description) {
let d = jb(a.description);
a.default && (d += ` Default \`${a.default}\`.`);
c.push(d);
}
a.b && "function" == a.b.name ? (a = kb(a), c.push(...a)) : c.push(` * @type {${a.optional ? Xa(a.f) : a.f}}`);
return c.map(d => `${b}${d}`).join("\n");
}
function mb(a, b) {
const c = Object.assign(Object.create(Object.getPrototypeOf(a)), a);

@@ -605,28 +810,21 @@ c.description = `An alias for \`${a.name}\`.`;

}
class Ta {
constructor() {
class nb {
constructor(a = []) {
this.description = this.name = null;
this.type = "*";
this.f = "";
this.b = !1;
this.g = !1;
this.default = null;
this.optional = !1;
this.v = [];
this.w = [];
this.l = !1;
this.b = null;
this.args = a;
}
I() {
const a = [];
if (this.description) {
let b = Ra(this.description);
this.default && (b += ` Default \`${this.default}\`.`);
a.push(b);
}
a.push(` * @type {${this.optional ? Ga(this.f) : this.f}}`);
return a.join("\n");
}
J(a, b = "", c = !1) {
a = Pa(this, a, c);
I(a, b = "", c = !1) {
a = hb(this, a, c);
return `${b} * @param ${a}`;
}
}
const Ra = (a, b = !1) => a.split("\n").map((c, d) => {
const jb = (a, b = !1) => a.split("\n").map((c, d) => {
if (b && !d) {

@@ -638,5 +836,50 @@ return c;

return d + c;
}).join("\n");
function Ua(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:v} = c;
}).join("\n"), Y = a => {
var b = "";
a.nullable ? b = "?" : !1 === a.nullable && (b = "!");
if (a.function) {
b += a.name + "(";
const d = [];
if (a.function.this) {
var c = "this: " + Y(a.function.this);
d.push(c);
}
a.function.new && (c = "new: " + Y(a.function.new), d.push(c));
a.function.args.forEach(e => {
let f = Y(e);
e.optional && (f += "=");
d.push(f);
});
a.function.variableArgs && (c = "..." + Y(a.function.variableArgs), d.push(c));
c = d.join(", ");
b += c + ")";
a.function.return && (b += ": " + Y(a.function.return));
} else {
if (a.record) {
b += "{ ", c = Object.keys(a.record).map(d => {
var e = a.record[d];
if (!e) {
return d;
}
e = Y(e);
return `${d}: ${e}`;
}), b += c.join(", "), b += " }";
} else {
if (a.application) {
if ("Promise" == a.name && !a.application.some(d => "void" != d.name)) {
return b + "Promise";
}
b += a.name + "<";
c = a.application.map(d => Y(d));
b += c.join(", ");
b += ">";
} else {
a.union ? (b += "(", c = a.union.map(d => Y(d)), b += c.join("|"), b += ")") : b += "any" == a.name ? "*" : a.name;
}
}
}
return b;
};
function ob(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":t, "interface":u, record:P} = c;
if (!e) {

@@ -651,39 +894,51 @@ throw Error("Type does not have a name.");

a.K = !!k;
a.C = !!l;
a.J = !!l;
a.import = !!m;
n && (a.link = n);
!0 === q && (a.isConstructor = q);
!0 === t && (a.o = t);
!0 === v && (a.s = v);
r && (a.extends = r);
!0 === u && (a.l = u);
!0 === P && (a.A = P);
t && (a.extends = t);
if (b) {
c = X("prop", b).map(u => {
var {content:R, w:y} = u;
u = new Ta;
Oa(u, R, y);
return u;
c = X("prop", b).map(r => {
var {content:z, v:A} = r;
r = new nb;
gb(r, z, A);
return r;
});
const B = X("function", b);
const Ab = X("function", b);
b = X("fn", b);
b = [...B, ...b].map(u => {
var {content:R, w:y} = u, z = Object.assign({}, y);
u = y.async;
const eb = void 0 === y.args ? "" : y.args;
var I = void 0 === y["return"] ? "void" : y["return"];
z = (delete z.async, delete z.args, delete z["return"], z);
I = I.replace(/\n\s*/g, " ");
z.type = `function(${eb}): ${u ? `!Promise<${I}>` : I}`;
u = new Ta;
Oa(u, R, z);
return u;
b = [...Ab, ...b].map(r => {
var {content:z, v:A} = r, C = z.lastIndexOf("</arg>");
r = [];
-1 != C && (C += 6, r = z.slice(0, C), z = z.slice(C), r = X("arg", r), r = r.map(D => {
var {content:Q, v:aa} = D;
D = new fb;
eb(D, Q, aa);
return D;
}));
var E = Object.assign({}, A);
C = A.async;
var R = void 0 === A["return"] ? "void" : A["return"];
E = (delete E.async, delete E["return"], E);
let {args:ba = ""} = A;
!ba && r.length && (ba = r.map(D => {
var {type:Q, optional:aa} = D;
return null !== aa ? `${Q}=` : Q;
}).join(","));
R = R.replace(/\n\s*/g, " ");
E.type = `function(${ba}): ${C ? `!Promise<${R}>` : R}`;
r = new nb(r);
gb(r, z, E);
return r;
});
a.h = [...c, ...b];
a.i = [...c, ...b];
}
d && (a.l = d);
d && (a.j = d);
}
function Va(a) {
function pb(a) {
var b = [];
a.description && b.push(` * ${a.description}`);
a.extends && b.push(` * @extends {${a.extends}}`);
b.push(` * @${a.P}`);
b.push(` * @${a.S}`);
b = `/**

@@ -693,29 +948,40 @@ ${b.join("\n")}

`;
b += U(a.l, a.name, void 0);
const c = a.h.reduce((d, e) => {
b += U(a.j, a.name, void 0);
const c = a.i.reduce((d, e) => {
d.push(e);
const f = e.v.map(g => Sa(e, g));
const f = e.w.map(g => mb(e, g));
d.push(...f);
return d;
}, []).map(d => {
let e = d.I();
return e = `/**
let e = lb(d);
e = `/**
${e}
*/
` + U(`${a.g}.prototype`, d.name);
` + U(`${a.h}.prototype`, d.name);
if (d.b && "function" == d.b.name) {
var {function:{args:f}} = d.b;
f = f.map((g, h) => {
({name:g = `arg${h}`} = d.args[h] || {});
return g;
});
e += ` = function(${f.join(", ")}) {}`;
} else {
d.type.startsWith("function(") && (e += " = function() {}");
}
return e;
});
return [b, ...c].join("\n");
}
function Wa(a, b) {
function qb(a, b) {
const c = `${a.extends ? "$" : ""}${a.name}`;
return b ? `${a.u}${c}` : c;
}
function Xa(a, b, c) {
var d = ` * @typedef {${(b ? a.f : a.type) || "Object"}}${` ${Wa(a, b)}${a.i}`}`;
a = (a.h ? a.h.reduce((e, f) => {
function rb(a, b, c) {
var d = ` * @typedef {${(b ? a.f : a.type) || "Object"}}${` ${qb(a, b)}${a.g}`}`;
a = (a.i ? a.i.reduce((e, f) => {
e.push(f);
const g = f.v.map(h => Sa(f, h));
const g = f.w.map(h => mb(f, h));
e.push(...g);
return e;
}, []) : []).map(e => Qa(e, b));
}, []) : []).map(e => ib(e, b));
d = [d, ...a].join("\n");

@@ -728,8 +994,8 @@ b && !c && (d = T(d));

}
function Ya(a, b, c) {
function sb(a, b, c) {
b = void 0 === b ? !1 : b;
c = void 0 === c ? !1 : c;
const d = !!a.extends, e = Xa(a, b, c), f = [];
if (a.l && b) {
let g = ` * @typedef {${a.g}} ${a.name}${a.i}`;
const d = !!a.extends, e = rb(a, b, c), f = [];
if (a.j && b) {
let g = ` * @typedef {${a.h}} ${a.name}${a.g}`;
b && !c && (g = T(g));

@@ -742,3 +1008,3 @@ g = `/**

}
d && (a = ` * @typedef {${a.extends} & ${Wa(a, b)}} ${b ? a.g : a.name}${a.i}`, b && !c && (a = T(a)), a = `/**
d && (a = ` * @typedef {${a.extends} & ${qb(a, b)}} ${b ? a.h : a.name}${a.g}`, b && !c && (a = T(a)), a = `/**
${a}

@@ -750,26 +1016,18 @@ */

}
class Y {
class tb {
constructor() {
this.name = "";
this.link = this.C = this.import = this.K = this.L = this.description = this.f = this.type = null;
this.h = [];
this.l = null;
this.s = this.o = this.isConstructor = !1;
this.link = this.J = this.import = this.K = this.L = this.description = this.f = this.type = null;
this.i = [];
this.j = null;
this.A = this.l = this.isConstructor = !1;
this.extends = null;
}
get R() {
return this.isConstructor || this.o || this.s;
get T() {
return this.isConstructor || this.l || this.A;
}
I() {
let a;
this.f ? a = ` * @typedef {${this.f}}` : this.R || (a = ` * @typedef {${Za(this.h, !0)}}`);
return a ? (this.description && (a = ` * ${this.description}\n${a}`), a = `/**
${a}
*/
` + U(this.l, this.name)) : Va(this);
}
get i() {
get g() {
return `${this.b ? ` \`\uff20${this.b}\`` : ""}${this.description ? ` ${this.description}` : ""}`;
}
get P() {
get S() {
const a = this.b;

@@ -782,11 +1040,11 @@ if (!a) {

get b() {
return this.isConstructor ? "constructor" : this.o ? "interface" : this.s ? "record" : "";
return this.isConstructor ? "constructor" : this.l ? "interface" : this.A ? "record" : "";
}
get u() {
return this.l ? `${this.l}.` : "";
return this.j ? `${this.j}.` : "";
}
get g() {
get h() {
return `${this.u}${this.name}`;
}
J(a, b, c, d, e) {
I(a, b, c, d, e) {
e = void 0 === e ? !1 : e;

@@ -796,9 +1054,9 @@ var f = "";

d = this.description ? ` ${this.description}` : "";
const g = this.K ? Za(this.h) : e ? this.g : this.name;
const g = this.K ? ub(this.i) : e ? this.h : this.name;
b = `${c || ""} * @param {${f}${g}} ${b ? `[${a}]` : a}${d}`;
f = this.h && !this.C ? this.h.map(h => h.J(a, c, e)) : [];
f = this.i && !this.J ? this.i.map(h => h.I(a, c, e)) : [];
return [b, ...f].join("\n");
}
}
const Za = (a, b) => {
const ub = (a, b) => {
a = void 0 === a ? [] : a;

@@ -808,3 +1066,3 @@ b = void 0 === b ? !1 : b;

c.push(d);
const e = d.v.map(f => Object.assign({}, d, {name:f}));
const e = d.w.map(f => Object.assign({}, d, {name:f}));
c.push(...e);

@@ -816,150 +1074,43 @@ return c;

let e = c.name, f = d;
c.optional && !b ? e = `${c.name}?` : c.optional && b && (f = `(${Ga(d)})`);
c.optional && !b ? e = `${c.name}?` : c.optional && b && (f = `(${Xa(d)})`);
return `${e}: ${f}`;
}).join(", ")} }`;
};
function $a(a) {
if ("object" != typeof a) {
return !1;
}
const {re:b, replacement:c} = a;
a = b instanceof RegExp;
const d = -1 != ["string", "function"].indexOf(typeof c);
return a && d;
}
const ab = (a, b) => {
if (!(b instanceof Error)) {
throw b;
}
[, , a] = a.stack.split("\n", 3);
a = b.stack.indexOf(a);
if (-1 == a) {
throw b;
}
a = b.stack.substr(0, a - 1);
const c = a.lastIndexOf("\n");
b.stack = a.substr(0, c);
throw b;
};
async function bb(a, b) {
b instanceof qa ? b.pipe(a) : a.end(b);
return await M(a);
}
class cb extends F {
constructor(a, b) {
super(b);
this.o = (Array.isArray(a) ? a : [a]).filter($a);
this.b = !1;
this.C = b;
}
async replace(a, b) {
const c = new cb(this.o, this.C);
b && Object.assign(c, b);
a = await bb(c, a);
c.b && this.brake();
b && Object.keys(b).forEach(d => {
b[d] = c[d];
});
return a;
}
brake() {
this.b = !0;
}
async reduce(a) {
return await this.o.reduce(async(b, {re:c, replacement:d}) => {
b = await b;
if (this.b) {
return b;
}
if ("string" == typeof d) {
b = b.replace(c, d);
} else {
const e = [];
let f;
const g = b.replace(c, (h, ...k) => {
f = Error();
try {
if (this.b) {
return e.length ? e.push(Promise.resolve(h)) : h;
}
const l = d.call(this, h, ...k);
l instanceof Promise && e.push(l);
return l;
} catch (l) {
ab(f, l);
}
});
if (e.length) {
try {
const h = await Promise.all(e);
b = b.replace(c, () => h.shift());
} catch (h) {
ab(f, h);
}
} else {
b = g;
}
}
return b;
}, `${a}`);
}
async _transform(a, b, c) {
try {
const d = await this.reduce(a);
this.push(d);
c();
} catch (d) {
a = K(d.stack), d.stack = a, c(d);
}
}
}
;function db() {
var a = fb;
let b = "";
const c = new F({transform(d, e, f) {
let g;
for (b += d.toString(); (d = a.exec(b)) && (c.push(d), g = d, a.global);) {
}
g && (b = b.slice(g.index + g[0].length));
f();
}, objectMode:!0});
return c;
}
;function gb(a, {name:b, from:c, desc:d, link:e, ns:f}) {
function vb(a, {name:b, from:c, desc:d, link:e, ns:f}) {
a.name = b;
a.from = c;
a.F = d;
a.G = d;
a.link = e;
a.u = f || a.from;
}
function hb(a, b = !0) {
return ` * @typedef {import('${a.from}').${a.name}} ${b ? a.g : a.name}`;
function wb(a, b = !0) {
return ` * @typedef {import('${a.from}').${a.name}} ${b ? a.h : a.name}`;
}
class ib {
class xb {
constructor() {
this.from = this.name = this.u = "";
this.link = this.F = null;
this.link = this.G = null;
}
get g() {
get h() {
return `${this.u}.${this.name}`;
}
}
;function jb(a, b) {
b = b.reduce((c, d) => Object.assign({}, c, {[d.g]:d}), {});
a.D = Object.assign({}, a.D, b);
;function yb(a, b) {
b = b.reduce((c, d) => Object.assign({}, c, {[d.h]:d}), {});
a.F = Object.assign({}, a.F, b);
}
class kb extends cb {
class zb extends O {
constructor(a, b) {
b = void 0 === b ? {} : b;
super(a);
this.D = {};
this.F = {};
this.on("types", c => {
jb(this, c);
yb(this, c);
});
this.on("namespace", c => {
this.i.includes(c) || this.i.push(c);
this.b.includes(c) || this.b.push(c);
});
this.s = b;
this.i = [];
this.j = console.log;
this.l = b;
this.b = [];
this.m = console.log;
this.file = null;

@@ -969,12 +1120,12 @@ this.lines = [];

static get Type() {
return Y;
return tb;
}
static get b() {
return ib;
return xb;
}
get types() {
return this.D;
return this.F;
}
}
;const lb = a => {
;const Bb = a => {
a = X("types", a);

@@ -984,24 +1135,30 @@ if (!a.length) {

}
const [{content:b, w:{namespace:c, ns:d = c}}] = a, e = void 0 == d ? void 0 : d;
a = X("type", b).map(({content:h, w:k}) => {
const l = new Y;
Ua(l, h, k, e);
const [{content:b, v:{namespace:c, ns:d = c}}] = a, e = void 0 == d ? void 0 : d;
a = X("type", b).map(({content:h, v:k}) => {
const l = new tb;
ob(l, h, k, e);
return l;
});
const f = X("import", b).map(({w:h, content:k}) => {
const l = new ib;
const f = X("import", b).map(({v:h, content:k}) => {
const l = new xb;
k && (h.desc = V(k));
gb(l, h);
vb(l, h);
return l;
}), g = f.map(({name:h, from:k, F:l, link:m, u:n}) => {
const p = new Y;
Ua(p, "", {name:h, type:`import('${k}').${h}`, L:!0, import:!0, F:l, link:m}, void 0 == n ? void 0 : n);
}), g = f.map(({name:h, from:k, G:l, link:m, u:n}) => {
const p = new tb;
ob(p, "", {name:h, type:`import('${k}').${h}`, L:!0, import:!0, G:l, link:m}, void 0 == n ? void 0 : n);
return p;
});
return {l:d, types:a, imports:f, T:g};
return {j:d, types:a, imports:f, U:g};
}, Cb = async(a, b = []) => {
a = await H(a);
let {j:c = null, types:d, imports:e} = Bb(a);
d = d.filter(({h:f}) => b.includes(f) ? !1 : !0);
e = e.filter(({h:f}) => b.includes(f) ? !1 : !0);
return {types:d, imports:e, j:c};
};
const mb = (a, b, c) => {
b = b.map(d => Ya(d, !0, c));
const Db = (a, b, c) => {
b = b.map(d => sb(d, !0, c));
a = a.map(d => {
d = hb(d);
d = wb(d);
return `/**

@@ -1013,4 +1170,14 @@ ${c ? d : T(d)}

return [...b, ...a].join("");
}, nb = (a, b, c, d = !1) => {
a = [...a.map(e => e.I())].join("\n");
}, Eb = (a, b, c, d = !1) => {
a = [...a.map(e => {
{
let f;
e.f ? f = ` * @typedef {${e.f}}` : e.T || (f = ` * @typedef {${ub(e.i, !0)}}`);
f ? (e.description && (f = ` * ${e.description}\n${f}`), f = `/**
${f}
*/
`, e = f += U(e.j, e.name)) : e = pb(e);
}
return e;
})].join("\n");
return `${!b || d || c.includes(b) ? "" : `/** @const */

@@ -1020,32 +1187,29 @@ var ${b} = {}

};
const pb = {re:/^\/\*\*? (documentary|typal) (.+?) \*\/\n(?:([^\n][\s\S]+?\n))?$/mg, replacement:async function(a, b, c) {
const Gb = {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");
let l = e.find(p => p.startsWith("ignore:"));
l = l ? l.replace("ignore:", "").split(",") : [];
let {B:m, G:n} = this.s;
let {D:m, H:n} = this.l;
f && (m = !0);
g && (n = !0);
try {
this.j("Detected type marker: %s", c);
const p = await N(d);
let {l:q = null, types:r, imports:t} = lb(p);
r = r.filter(({g:B}) => l.includes(B) ? !1 : !0);
t = t.filter(({g:B}) => l.includes(B) ? !1 : !0);
this.emit("types", r);
this.emit("types", t);
let v;
m ? v = mb(t, r, h) : n ? (v = nb(r, q, this.i, k) + "\n", q && this.emit("namespace", q)) : v = ob(t, r);
return `/* ${b} ${c} */\n${v}`;
this.m("Detected type marker: %s", c);
const {types:p, imports:q, j:t} = await Cb(d, l);
this.emit("types", p);
this.emit("types", q);
let u;
m ? u = Db(q, p, h) : n ? (u = Eb(p, t, this.b, k) + "\n", t && this.emit("namespace", t)) : u = Fb(q, p);
return `/* ${b} ${c} */\n${u}`;
} catch (p) {
return this.j("(%s) Could not process typedef-js: %s", c, p.message), process.env.b && console.error(p.stack), a;
return this.m("(%s) Could not process typedef-js: %s", c, p.message), process.env.b && console.error(p.stack), a;
}
}}, ob = (a, b) => {
b = b.map(c => Ya(c));
a = a.map(c => hb(c, !1)).map(Ha).join("");
}}, Fb = (a, b) => {
b = b.map(c => sb(c));
a = a.map(c => wb(c, !1)).map(Ya).join("");
b = b.join("");
return `${a}${b}`.replace(qb, " * @typedef");
}, qb = / \*\/\n\/\*\*\n \* @typedef/g;
const sb = {re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\n(?: +)\* @param {(?:.+?)} \[?\4\]?.*)*)/gm, replacement:rb};
function rb(a, b, c, d, e, f, g) {
const {B:h} = this.s;
return `${a}${b}`.replace(Hb, " * @typedef");
}, Hb = / \*\/\n\/\*\*\n \* @typedef/g;
const Jb = {re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\n(?: +)\* @param {(?:.+?)} \[?\4\]?.*)*)/gm, replacement:Ib};
function Ib(a, b, c, d, e, f, g) {
const {D:h} = this.l;
let k;

@@ -1060,22 +1224,22 @@ f = () => {

}
m = {line:m, N:b.length + 11};
m = {line:m, O:b.length + 11};
}
const {line:n, N:p} = m;
this.j("%s:%s:%s", this.file, n, p);
const {line:n, O:p} = m;
this.m("%s:%s:%s", this.file, n, p);
}
};
try {
k = Na(c);
k = db(c);
} catch (m) {
return this.j("Error while parsing the type %s", c), this.j(process.env.DEBUG ? m.stack : m.message), f(), a;
return this.m("Error while parsing the type %s", c), this.m(process.env.DEBUG ? m.stack : m.message), f(), a;
}
if (!k) {
return this.j("Could not parse the type %s", c), f(), a;
return this.m("Could not parse the type %s", c), f(), a;
}
const l = Object.values(this.types).map(({name:m, g:n}) => h ? n : m);
if (!Z(k, l, this.j, c, f)) {
const l = Object.values(this.types).map(({name:m, h:n}) => h ? n : m);
if (!Z(k, l, this.m, c, f)) {
return a;
}
c = Object.values(this.types).find(({name:m, g:n}) => h ? n == k.name : m == k.name);
return !c || c instanceof kb.b ? a : c.J(e, d, b, k.nullable, h);
c = Object.values(this.types).find(({name:m, h:n}) => h ? n == k.name : m == k.name);
return !c || c instanceof zb.b ? a : c.I(e, d, b, k.nullable, h);
}

@@ -1088,3 +1252,3 @@ const Z = (a, b, c, d, e) => {

let h = b.includes(f);
h || (h = tb.includes(f));
h || (h = Kb.includes(f));
if (h) {

@@ -1108,36 +1272,42 @@ return !0;

}
}, tb = "String Boolean Object Date Number Symbol Buffer Function".split(" ");
var vb = async() => {
const {B:a = !1, G:b = !1, H:c, types:d} = {B:fa, G:ha, H:D, types:ia};
await Promise.all(C.map(async e => {
var f = await P(E, e);
}, Kb = "String Boolean Object Date Number Symbol Buffer Function".split(" ");
var Lb = (a, b = !1) => {
var {R:c} = Qa();
const d = Sa(c);
c = Ra(c);
return new zb(b ? [Gb] : [Gb, d, Jb, c], a);
};
var Nb = async() => {
const {D:a = !1, H:b = !1, B:c, types:d} = {D:la, H:ma, B:ka, types:na};
await Promise.all(w.map(async e => {
var f = await J(x, e);
let g;
f.isFile() ? g = [e] : f.isDirectory() && (f = await Da(e), g = Ea(f.content, e));
await ub(g, a, b, c, d);
f.isFile() ? g = [e] : f.isDirectory() && (f = await L(e), g = M(f.content, e));
await Mb(g, a, b, c, d);
}));
};
const ub = async(a, b = !1, c = !1, d = null, e = null) => {
const Mb = async(a, b = !1, c = !1, d = null, e = null) => {
const f = [];
e && await Promise.all(e.split(",").map(async g => {
g = await N(g);
const {types:h, imports:k} = lb(g);
g = await H(g);
const {types:h, imports:k} = Bb(g);
f.push(h, k);
}));
await Promise.all(a.map(async g => {
var h = await N(g);
const k = new kb([pb, sb], {B:b, G:c});
var h = await H(g);
const k = Lb({D:b, H:c}, c);
f.forEach(l => k.emit("types", l));
k.file = g;
k.j = console.error;
k.m = console.error;
k.lines = h.split("\n");
k.end(h);
h = await M(k);
"-" == d ? console.log(h) : d ? await O(d, h) : await O(g, h);
h = await G(k);
"-" == d ? console.log(h) : d ? await I(d, h) : await I(g, h);
}));
};
const wb = a => {
const Ob = a => {
let b;
"true" == a ? b = !0 : "false" == a ? b = !1 : /^\d+$/.test(a) && (b = parseInt(a, 10));
return void 0 !== b ? b : a;
}, xb = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, yb = "type opt name quote defaultValue description Default".split(" "), fb = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), zb = (a, b, c, d) => {
}, Pb = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, Qb = "type opt name quote defaultValue description Default".split(" "), Va = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), Rb = (a, b, c, d) => {
d = d.length;

@@ -1148,3 +1318,3 @@ a = a && "Object" != a ? ` type="${a}"` : "";

};
class Ab extends F {
class Sb extends y {
constructor() {

@@ -1154,4 +1324,4 @@ super({writableObjectMode:!0});

_transform(a, b, c) {
var {type:d, name:e, description:f, h:g} = a;
a = d && d.startsWith("import") ? Bb(d, e) : zb(d, e, f, g);
var {type:d, name:e, description:f, i:g} = a;
a = d && d.startsWith("import") ? Tb(d, e) : Rb(d, e, f, g);
this.push(a);

@@ -1163,6 +1333,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), v = " ".repeat(6);
h = `${t}<prop${q}${h} name="${l}"${r}${n ? `>\n${v}${n}\n${t}</prop>` : "/>"}\n`;
const u = " ".repeat(4), P = " ".repeat(6);
h = `${u}<prop${q}${h} name="${l}"${t}${n ? `>\n${P}${n}\n${u}</prop>` : "/>"}\n`;
}

@@ -1175,3 +1345,3 @@ this.push(h);

}
const Bb = (a, b) => {
const Tb = (a, b) => {
const c = /import\((['"])(.+?)\1\)/.exec(a);

@@ -1184,3 +1354,3 @@ if (!c) {

};
class Cb extends F {
class Ub extends y {
constructor() {

@@ -1191,3 +1361,3 @@ super({objectMode:!0});

var [, d, e, f, g] = a;
a = W(xb, g, yb).map(h => {
a = W(Pb, g, Qb).map(h => {
var k = Object.assign({}, h), l = h.defaultValue;

@@ -1199,14 +1369,14 @@ 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:wb(l)} : {}, m ? {A:wb(m)} : {}, n ? {optional:!0} : {});
n = Object.assign({}, k, {name:p, type:h}, l ? {defaultValue:Ob(l)} : {}, m ? {C:Ob(m)} : {}, n ? {optional:!0} : {});
if (l || m) {
l ? l !== m && void 0 !== n.A && (l = S(p, m, h), console.error("%s[%s] does not match Default `%s`.", e, l, n.A)) : (l = S(p, m, h), console.error("%s[%s] got from Default.", e, l)), n.default = "defaultValue" in n ? n.defaultValue : n.A, delete n.defaultValue, delete n.A;
l ? l !== m && void 0 !== n.C && (l = S(p, m, h), console.error("%s[%s] does not match Default `%s`.", e, l, n.C)) : (l = S(p, m, h), console.error("%s[%s] got from Default.", e, l)), n.default = "defaultValue" in n ? n.defaultValue : n.C, delete n.defaultValue, delete n.C;
}
return n;
});
this.push({type:d, name:e, description:f, h:a});
this.push({type:d, name:e, description:f, i:a});
c();
}
}
async function Db(a) {
const b = db(), c = new Cb, d = new Ab;
async function Vb(a) {
const b = Ua(), c = new Ub, d = new Sb;
b.pipe(c).pipe(d);

@@ -1227,23 +1397,91 @@ b.end(a);

return `<types>
${(await M(d)).trim()}
${(await G(d)).trim()}
</types>`;
}
;var Eb = async() => {
const {H:a} = {H:D};
await Promise.all(C.map(async b => {
b = await N(b);
b = await Db(b);
a ? await O(a, b) : console.log(b);
;var Wb = async() => {
const {B:a} = {B:ka};
await Promise.all(w.map(async b => {
b = await H(b);
b = await Vb(b);
a ? await I(a, b) : console.log(b);
}));
};
if (ka) {
const a = ea();
console.log(ma({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"}));
const Xb = /( *) \* @fnType {(.+?)}/gm;
class Yb extends O {
constructor(a, b) {
super([{re:Xb, async replacement(c, d, e) {
e = e.split(".");
let f, g;
if (2 == e.length) {
[f, g] = e;
} else {
if (3 == e.length) {
f = `${e[0]}.${e[1]}`, g = e[2];
} else {
throw Error("The @fnType should consist of _namespace.Type.propName or Type.propName");
}
}
e = a.find(({h}) => h == f);
if (!e) {
return console.error("Type %s in %s not found", f, b), c;
}
e = e.i.find(({name:h}) => h == g);
return e ? e.b ? e.b.function ? lb(e, d) : (console.error("Property %s of type %s in %s is not a function.", g, f, b), c) : (console.error("Property %s of type %s in %s wasn't parsed, possibly parser bug.", g, f, b), c) : (console.error("Property %s of type %s in %s not found", g, f, b), c);
}}]);
}
}
;const Zb = async a => {
if (!a) {
return [];
}
const b = await J(x, a);
if (b.isFile()) {
var c = [a];
} else {
b.isDirectory() && (c = await L(a), c = M(c.content, a), c = c.filter(d => d.endsWith(".xml")));
}
return c;
}, $b = async a => (await Promise.all(a.map(async b => {
const c = await Cb(b);
return Object.assign({}, c, {location:b});
}))).reduce((b, c) => {
var {imports:d, types:e} = c;
b.push(...d);
b.push(...e);
return b;
}, []);
async function ac() {
var a = {B:oa, types:na};
a = void 0 === a ? {} : a;
const {B:b, types:c} = a;
a = await Zb(c);
const d = await $b(a);
await Promise.all(w.map(async e => {
var f = await J(x, e);
let g;
f.isFile() ? g = [e] : f.isDirectory() && (f = await L(e), g = M(f.content, e));
await bc(g, d, b);
}));
}
const bc = 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 H(d);
const f = new Yb(b, d);
f.end(e);
e = await G(f);
"-" == c ? console.log(e) : c ? await I(c, e) : await I(d, e);
}));
};
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 {
la && (console.log(require("../../package.json").version), process.exit());
ra && (console.log(require("../../package.json").version), process.exit());
}
(async() => {
try {
return ja ? await Eb() : await vb();
return pa ? await Wb() : oa ? await ac() : await Nb();
} catch (a) {

@@ -1250,0 +1488,0 @@ process.env.DEBUG ? console.log(a.stack) : console.log(a.message);

{
"name": "typal",
"version": "1.17.0",
"version": "1.18.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.",

@@ -18,3 +18,4 @@ "main": "build/index.js",

"doc": "NODE_DEBUG=doc doc -o README.md",
"b": "alamode src -o build -s -i bin",
"wiki": "DEPACK_MAX_COLUMNS=80 NODE_DEBUG=doc doc wiki -W ../typal.wiki",
"b": "alamode src -o build -s",
"compile": "depack-dev src/bin/typal -c -o compile/bin -a -p -s",

@@ -72,6 +73,6 @@ "depack1": "depack-dev depack/t.js -c -o t/tt.js -a -p",

"@zoroaster/mask": "^2.2.0",
"alamode": "^2.3.4",
"alamode": "^2.3.6",
"argufy": "^1.7.1",
"catchment": "^3.3.0",
"documentary": "^1.27.7",
"documentary": "^1.28.2",
"erotic": "^2.1.1",

@@ -90,4 +91,4 @@ "eslint-config-artdeco": "1.0.1",

"mismatch": "^1.2.0",
"rexml": "^2.0.2"
"rexml": "^2.0.3"
}
}

@@ -41,3 +41,3 @@ import read from '@wrote/read'

const content = await read(file)
const js = makeJSTypal({ closure, externs })
const js = makeJSTypal({ closure, externs }, externs)
existingTypes.forEach(type => js.emit('types', type))

@@ -44,0 +44,0 @@ js.file = file

@@ -27,2 +27,6 @@ import argufy from 'argufy'

},
'template': {
description: 'Scans the input file for `@type` comment in functions\' JSDoc, and inserts the annotations from types\' files.',
short: 'T',
},
'migrate': {

@@ -74,2 +78,7 @@ description: 'Extracts types from JavaScript source code and saves them\ninto the types.xml file specified in the output option.',

/**
* Scans the input file for `@type` comment in functions' JSDoc, and inserts the annotations from types' files.
*/
export const _template = /** @type {string} */ (args['template'])
/**
* Extracts types from JavaScript source code and saves them

@@ -76,0 +85,0 @@ into the types.xml file specified in the output option.

import { _source, _closure, _externs, _output, _help, _version, _migrate, _types,
argsConfig } from './get-args'
argsConfig, _template } from './get-args'
import usually from 'usually'

@@ -7,2 +7,3 @@ import { reduceUsage } from 'argufy'

import extract from './commands/extract'
import templ from './commands/template'

@@ -30,2 +31,7 @@ if (_help) {

})
} else if (_template) {
return await templ(_source, {
output: _template,
types: _types,
})
}

@@ -32,0 +38,0 @@ return await generate(_source, {

@@ -0,1 +1,2 @@

import { makeMarkers, makeCutRule, makePasteRule } from 'restream'
import typedefJsRule from './typedef/rule'

@@ -6,5 +7,15 @@ import JSDocRule from './typedef/jsdoc'

export default (conf, onlyTypedef = false) => {
const rules = onlyTypedef ? [typedefJsRule] : [typedefJsRule, JSDocRule]
const { externsTypedef } = makeMarkers({
externsTypedef: /^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg,
})
// to exclude @params in externs block from JSDoc warnings
const cr = makeCutRule(externsTypedef)
const pr = makePasteRule(externsTypedef)
const rules = onlyTypedef ? [typedefJsRule] : [typedefJsRule,
cr,
JSDocRule,
pr,
]
const jsTypal = new JSTypal(rules, conf)
return jsTypal
}

@@ -5,2 +5,3 @@ import extractTags from 'rexml'

import { trimD } from './'
import read from '@wrote/read'

@@ -67,2 +68,19 @@ /**

export default parseFile
export default parseFile
/**
* @param {string} path
*/
export const readTypesFile = async (path, ignore = []) => {
const xml = await read(path)
let { namespace = null, types, imports } = parseFile(xml)
types = types.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
imports = imports.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
return { types, imports, namespace }
}

@@ -0,2 +1,4 @@

import parse from '@typedefs/parser'
import { getPropType, getNameWithDefault, makeOptional, trimD } from './'
import Arg from './Arg' // eslint-disable-line

@@ -7,3 +9,7 @@ /**

export default class Property {
constructor() {
/**
* @param {!Array<!Arg>} [args] If a property was written as a function with inner
* <arg> elements, this array will contain parsed entries.
*/
constructor(args = []) {
/**

@@ -49,2 +55,15 @@ * The name of the property.

this.aliases = []
/**
* The parsed type.
*/
this.parsed = undefined
/**
* Whether to skip function params serialisation (e.g., in case it's working incorrectly).
*/
this.noParams = false
this.parsed = null
this.args = args
}

@@ -57,3 +76,3 @@ static fromXML(...args) {

fromXML(content,
{ 'name': name, 'string': string, 'boolean': boolean, 'opt': opt, 'number': number, 'type': type, 'default': def, 'closure': closure, 'alias': alias, 'aliases': aliases },
{ 'name': name, 'string': string, 'boolean': boolean, 'opt': opt, 'number': number, 'type': type, 'default': def, 'closure': closure, 'alias': alias, 'aliases': aliases, 'noParams': noParams },
) {

@@ -72,2 +91,12 @@ if (!name) throw new Error('Property does not have a name.')

if (aliases) this.aliases = aliases.split(/\s*,\s*/)
if (noParams) this.noParams = noParams
// if optional, we want to keep "| undefined" on records
if (!this.optional && !this.noParams) {
try {
this.parsed = parse(this.closureType)
} catch (err) { /* ok */
}
}
}

@@ -90,4 +119,22 @@ toJSDoc(parentParam = null, closure = false) {

}
toExtern() {
toFunctionJsDoc() {
const pp = []
const { function: { args, return: ret } } = this.parsed
const a = args.map(parsedToString)
a.forEach((s, i) => {
const { optional } = args[i]
const { name = `arg${i}`, description } = this.args[i] || {}
const arg = optional ? `[${name}]` : name
const d = description ? ` ${description}` : ''
pp.push(` * @param {${s}${optional ? '=' : ''}} ${arg}${d}`)
})
if (ret.name != 'void') {
const r = parsedToString(ret)
pp.push(` * @return {${r}}`)
}
return pp
}
toExtern(ws = '') {
const pp = []
if (this.description) {

@@ -98,5 +145,10 @@ let d = indentWithAster(this.description)

}
const t = this.optional ? makeOptional(this.closureType) : this.closureType
pp.push(` * @type {${t}}`)
return pp.join('\n')
if (this.parsed && this.parsed.name == 'function') {
const lines = this.toFunctionJsDoc()
pp.push(...lines)
} else {
const t = this.optional ? makeOptional(this.closureType) : this.closureType
pp.push(` * @type {${t}}`)
}
return pp.map(p => `${ws}${p}`).join('\n')
}

@@ -125,2 +177,76 @@ toParam(parentParam, ws = '', closure = false) {

return d
}
/**
* @param {!_typedefsParser.Type} type
*/
const parsedToString = (type) => {
let s = ''
let nullable = ''
if (type.nullable) nullable = '?'
else if (type.nullable === false) nullable = '!'
s += nullable
if (type.function) {
s += type.name + '(' // Function or function
const args = []
if (type.function.this) {
let t = 'this: '
t += parsedToString(type.function.this)
args.push(t)
}
if (type.function.new) {
let t = 'new: '
t += parsedToString(type.function.new)
args.push(t)
}
type.function.args.forEach((a) => {
let t = parsedToString(a)
if (a.optional) t += '='
args.push(t)
})
if (type.function.variableArgs) {
let t = '...'
t += parsedToString(type.function.variableArgs)
args.push(t)
}
const argsJoined = args.join(', ')
s += argsJoined + ')'
if (type.function.return) {
s += ': ' + parsedToString(type.function.return)
}
} else if (type.record) {
s += '{ '
const rs = Object.keys(type.record).map((key) => {
const val = type.record[key]
if (!val) return key
const v = parsedToString(val)
return `${key}: ${v}`
})
s += rs.join(', ')
s += ' }'
} else if (type.application) {
if (type.name == 'Promise') {
const otherThanVoid = type.application.some(t => t.name != 'void')
if (!otherThanVoid) return s + 'Promise'
}
s += type.name + '<'
const apps = type.application.map((a) => {
return parsedToString(a)
})
s += apps.join(', ')
s += '>'
} else if (type.union) {
s += '('
const union = type.union.map((u) => {
return parsedToString(u)
})
s += union.join('|')
s += ')'
} else {
const name = type.name == 'any' ? '*' : type.name
s += name
}
return s
}
import extractTags from 'rexml'
import parse from '@typedefs/parser'
import Property from './Property'
import Arg from './Arg'
import { addSuppress, makeBlock, getExternDeclaration, makeOptional } from './'

@@ -107,3 +108,27 @@ import { getLink, trimD } from './'

const fnProps = fn.map(({ content: c, props: p }) => {
const { 'async': async, 'args': args = '', 'return': ret = 'void', ...rest } = p
let ai = c.lastIndexOf('</arg>')
let argsArgs = []
if (ai != -1) {
ai = ai + '</arg>'.length
const pre = c.slice(0, ai)
c = c.slice(ai)
argsArgs = extractTags('arg', pre)
argsArgs = argsArgs.map(({ content: ac, props: ap }) => {
const ar = new Arg()
ar.fromXML(ac, ap)
return ar
})
}
const { 'async': async, 'return': ret = 'void', ...rest } = p
let { 'args': args = '' } = p
if (!args && argsArgs.length) {
args = argsArgs.map(({ type: at, optional }) => {
// optional can also just be set in type, e.g., type="string=",
// so check for null and not truthy
if (optional !== null) return `${at}=`
return at
}).join(',')
}
let r = ret.replace(/\n\s*/g, ' ')

@@ -113,3 +138,4 @@ r = async ? `!Promise<${r}>` : r

rest['type'] = fnType
const pr = new Property()
const pr = new Property(argsArgs)
pr.fromXML(c, rest)

@@ -226,2 +252,3 @@ return pr

s = s + getExternDeclaration(this.namespace, this.name, constr)
/** @type {!Array<!Property>} */
const properties = this.properties.reduce((acc, p) => {

@@ -238,2 +265,12 @@ acc.push(p)

/** @type {string} */ (p.name))
if (p.parsed && p.parsed.name == 'function') {
const { function: { args } } = p.parsed
const a = args.map((_, i) => {
const { name = `arg${i}` } = p.args[i] || {}
return name
})
r += ` = function(${a.join(', ')}) {}`
} else if (p.type.startsWith('function(')) {
r += ' = function() {}'
}
return r

@@ -275,2 +312,3 @@ })

/**
* Converts a type to a markdown string.
* @param {!Array<!Type>} [allTypes]

@@ -281,5 +319,8 @@ * @param {!Object} [opts]

* @param {function()} [opts.link] A function to call for extra processing of links.
* @param {!Array<string>} [opts.details] An array of types that should be displayed as details.
* @todo open-details
*/
toMarkdown(allTypes = [], opts = {}) {
const { narrow, flatten, preprocessDesc, link } = opts
const { narrow, flatten, preprocessDesc, link, details = [] } = opts
const displayInDetails = details.includes(this.name)
const t = this.type ? `\`${this.type}\`` : ''

@@ -346,5 +387,5 @@ let typeWithLink = t, useCode = false

})
if (narrow) return { LINE, table }
const r = `${LINE}${table}`
return r
return { LINE, table, displayInDetails } // delegate rendering to typal
// const r = `${LINE}${table}`
// return r
}

@@ -399,3 +440,3 @@ }

try {
parsed = parse(type)
parsed = parse(type) // should parse type when added
if (!parsed) {

@@ -419,3 +460,3 @@ console.log('Could not parse %s', type)

*/
const parsedToString = (type, allTypes, opts = {}) => {
export const parsedToString = (type, allTypes, opts = {}) => {
const { escapePipe = true } = opts

@@ -422,0 +463,0 @@ let s = ''

@@ -1,2 +0,1 @@

import read from '@wrote/read'
import { makeBlock } from '../'

@@ -6,3 +5,3 @@ import Type from '../Type' // eslint-disable-line

import Import from '../Import' // eslint-disable-line
import parseFile from '../parse'
import { readTypesFile } from '../parse'
import { closureJoinTypes, externsJoinTypes } from '../closure'

@@ -37,12 +36,3 @@

this.LOG('Detected type marker: %s', location)
const xml = await read(loc)
let { namespace = null, types, imports } = parseFile(xml)
types = types.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
imports = imports.filter(({ fullName }) => {
if (ignore.includes(fullName)) return false
return true
})
const { types, imports, namespace } = await readTypesFile(loc, ignore)

@@ -49,0 +39,0 @@ this.emit('types', types) // remember types for js-replace-stream

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc