Comparing version 1.18.0 to 1.19.0
@@ -0,1 +1,2 @@ | ||
const extractTags = require('rexml'); | ||
const { trimD, getPropType } = require('./'); | ||
@@ -26,3 +27,25 @@ | ||
/** | ||
* @param {string} content | ||
*/ | ||
const extractArgs = (content) => { | ||
let ai = content.lastIndexOf('</arg>') | ||
let newContent = content | ||
/** @type {!Array<!Arg>} */ | ||
let argsArgs = [] | ||
if (ai != -1) { | ||
ai = ai + '</arg>'.length | ||
const pre = content.slice(0, ai) | ||
newContent = content.slice(ai) | ||
argsArgs = extractTags('arg', pre) | ||
argsArgs = argsArgs.map(({ content: ac, props: ap }) => { | ||
const ar = new Arg() | ||
ar.fromXML(ac, ap) | ||
return ar | ||
}) | ||
} | ||
return { newContent, argsArgs } | ||
} | ||
module.exports = Arg | ||
module.exports = Arg | ||
module.exports.extractArgs = extractArgs |
@@ -83,3 +83,3 @@ /** | ||
* @param {string} name | ||
* @param {string} [constr] The signature of the constructor for constructors and interfaces. | ||
* @param {?string} [constr] The signature of the constructor for constructors and interfaces. | ||
*/ | ||
@@ -86,0 +86,0 @@ const getExternDeclaration = (namespace, name, constr) => { |
@@ -6,4 +6,18 @@ const extractTags = require('rexml'); | ||
let read = require('@wrote/read'); if (read && read.__esModule) read = read.default; | ||
const { extractArgs } = require('./Arg'); | ||
/** | ||
* @param {string} namespace | ||
* @param {Type} type | ||
*/ | ||
const removeNamespace = (namespace, type) => { | ||
const s = new RegExp(`([!?])?${namespace}\\.`, 'g') | ||
type.properties.forEach((p) => { | ||
p.type = p.type.replace(s, '$1') | ||
}) | ||
if (type.type) type.type = type.type.replace(s, '$1') | ||
if (type.extends) type.extends = type.extends.replace(s, '$1') | ||
} | ||
/** | ||
* Parse the types.xml file. | ||
@@ -29,12 +43,35 @@ * @param {string} xml The content of the `xml` file. | ||
type.fromXML(content, props, ns) | ||
if (rootNamespace) { | ||
const s = new RegExp(`([!?])?${rootNamespace}\\.`, 'g') | ||
type.properties.forEach((p) => { | ||
p.type = p.type.replace(s, '$1') | ||
}) | ||
if (type.type) type.type = type.type.replace(s, '$1') | ||
if (type.extends) type.extends = type.extends.replace(s, '$1') | ||
return type | ||
}) | ||
const interfaceTags = extractTags('interface', Root) | ||
const interfaces = interfaceTags.map(({ content, props }) => { | ||
const type = new Type() | ||
const i = content.search(/<(prop|function|fn|static) /) | ||
let prebody = '', body = content | ||
if (i != 1) { | ||
prebody = content.slice(0, i) | ||
body = content.slice(i) | ||
} | ||
const { argsArgs } = extractArgs(prebody) | ||
// let { 'args': args = '', ...rest } = props | ||
// if (!args && argsArgs.length) { | ||
// args = argsArgs.map(({ type: at, optional }) => { | ||
// if (optional !== null) return `${at}=` | ||
// return at | ||
// }).join(',') | ||
// } | ||
// const assignment = `function(${args})` | ||
type.fromXML(body, props, ns) | ||
type.setAssignment(argsArgs) | ||
type.isInterface = true | ||
return type | ||
}) | ||
let allTypes = [...types, ...interfaces] | ||
if (rootNamespace) allTypes.forEach(t => removeNamespace( | ||
/** @type {string} */ (rootNamespace), t | ||
)) | ||
@@ -66,3 +103,3 @@ const imports = extractTags('import', Root) | ||
return { namespace, types, imports, Imports } | ||
return { namespace, types: allTypes, imports, Imports } | ||
} | ||
@@ -69,0 +106,0 @@ |
@@ -67,2 +67,7 @@ const parse = require('@typedefs/parser'); | ||
this.args = args | ||
/** | ||
* Whether this property is a static method. | ||
*/ | ||
this.staticMethod = false | ||
} | ||
@@ -69,0 +74,0 @@ static fromXML(...args) { |
const extractTags = require('rexml'); | ||
const parse = require('@typedefs/parser'); | ||
const Property = require('./Property'); | ||
const Arg = require('./Arg'); | ||
const { addSuppress, makeBlock, getExternDeclaration, makeOptional } = require('./'); | ||
const { getLink, trimD } = require('./'); | ||
const Arg = require('./Arg'); const { extractArgs } = Arg; | ||
@@ -72,2 +72,12 @@ /** | ||
this.extends = null | ||
// /** | ||
// * The assignment arguments for constructors, interfaces, e.g., "string, number=" | ||
// * @type {?string} | ||
// */ | ||
// this._assignmentString = null | ||
/** | ||
* @type {Array<!Arg>} | ||
*/ | ||
this._args = null | ||
} | ||
@@ -106,21 +116,14 @@ /** | ||
const fns = extractTags('fn', content) | ||
const fn = [...functions, ...fns] | ||
const staticMethods = extractTags('static', content).map(a => { | ||
a['isStatic'] = true | ||
return a | ||
}) | ||
const fn = [...functions, ...fns, ...staticMethods] | ||
const fnProps = fn.map(({ content: c, props: 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 fnProps = fn.map(({ content: c, props: p, 'isStatic': isStatic }) => { | ||
const { newContent, argsArgs } = extractArgs(c) | ||
const { 'async': async, 'return': ret = 'void', ...rest } = p | ||
let { 'args': args = '' } = p | ||
if (!args && argsArgs.length) { | ||
@@ -138,6 +141,7 @@ args = argsArgs.map(({ type: at, optional }) => { | ||
const fnType = `function(${args}): ${r}` | ||
rest['type'] = fnType | ||
rest['type'] = fnType // e.g., a prop will have type `function()` | ||
const pr = new Property(argsArgs) | ||
pr.fromXML(c, rest) | ||
pr.fromXML(newContent, rest) | ||
if (isStatic) pr.staticMethod = true | ||
return pr | ||
@@ -152,2 +156,14 @@ }) | ||
} | ||
/** | ||
* When printing to externs, this is the right-hand part. | ||
* Used in constructors, interfaces. | ||
* @example | ||
* _ns.Type = function(paramA, paramB) | ||
* @param {!Array<!Arg>} array The parsed arguments | ||
*/ | ||
// * @param {string} string The inner arguments part as string | ||
setAssignment(array) { | ||
// this._assignmentString = string | ||
this._args = array | ||
} | ||
toExtern() { | ||
@@ -247,8 +263,12 @@ let s | ||
if (this.extends) pp.push(` * @extends {${this.extends}}`) | ||
if (this._args) this._args.forEach((s) => { | ||
const { name, description, optional, type } = s | ||
const arg = optional ? `[${name}]` : name | ||
const d = description ? ` ${description}` : '' | ||
pp.push(` * @param {${type}${optional ? '=' : ''}} ${arg}${d}`) | ||
}) | ||
const constr = this._args ? `function(${this._args.map(({ name }) => name)}) {}` : null | ||
pp.push(` * @${this.prototypeAnnotation}`) | ||
let s = makeBlock(pp.join('\n')) | ||
let constr | ||
// if (this.isConstructor || this.isInterface) { | ||
// constr = 'function() {}' | ||
// } | ||
s = s + getExternDeclaration(this.namespace, this.name, constr) | ||
@@ -265,3 +285,4 @@ /** @type {!Array<!Property>} */ | ||
r = makeBlock(r) | ||
r = r + getExternDeclaration(`${this.fullName}.prototype`, | ||
const prototype = p.staticMethod ? '' : '.prototype' | ||
r = r + getExternDeclaration(`${this.fullName}${prototype}`, | ||
/** @type {string} */ (p.name)) | ||
@@ -268,0 +289,0 @@ if (p.parsed && p.parsed.name == 'function') { |
@@ -0,1 +1,7 @@ | ||
## 1 August 2019 | ||
### [1.19.0](https://github.com/artdecocode/typal/compare/v1.18.0...v1.19.0) | ||
- [feature] Static methods and interfaces in schema. | ||
## 31 July 2019 | ||
@@ -2,0 +8,0 @@ |
@@ -7,8 +7,8 @@ #!/usr/bin/env node | ||
const path = require('path'); | ||
var ca = "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) { | ||
var ba = "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) { | ||
a != Array.prototype && a != Object.prototype && (a[b] = c.value); | ||
}, da = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this; | ||
function ea(a, b) { | ||
}, ca = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this; | ||
function da(a, b) { | ||
if (b) { | ||
var c = da; | ||
var c = ca; | ||
a = a.split("."); | ||
@@ -23,6 +23,6 @@ for (var d = 0; d < a.length - 1; d++) { | ||
b = b(d); | ||
b != d && null != b && ca(c, a, {configurable:!0, writable:!0, value:b}); | ||
b != d && null != b && ba(c, a, {configurable:!0, writable:!0, value:b}); | ||
} | ||
} | ||
ea("String.prototype.trimRight", function(a) { | ||
da("String.prototype.trimRight", function(a) { | ||
function b() { | ||
@@ -33,3 +33,3 @@ return this.replace(/[\s\xa0]+$/, ""); | ||
}); | ||
const fa = (a, b, c, d, e) => { | ||
const ea = (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)]}; | ||
}, ha = a => { | ||
}, fa = a => { | ||
const b = []; | ||
@@ -63,4 +63,4 @@ for (let c = 0; c < a.length; c++) { | ||
return b; | ||
}, ja = () => { | ||
var a = ia; | ||
}, ia = () => { | ||
var a = ha; | ||
return Object.keys(a).reduce((b, c) => { | ||
@@ -79,3 +79,3 @@ const d = a[c]; | ||
}; | ||
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_.", | ||
const ha = {source:{description:"The path to the source file or directory with files to embed types into. Can specify multiple values, e.g., `typal types/index.js types/vendor.js`.", command:!0, multiple:!0}, output:{description:"The destination where to save output.\nIf not passed, the file will be overwritten.\nIf `-` is passed, prints to stdout.", short:"o"}, closure:{description:"Whether to generate types in _Closure_ mode.", boolean:!0, short:"c"}, 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"}, | ||
@@ -86,3 +86,3 @@ version:{description:"Show the version's number and exit.", boolean:!0, short:"v"}}, v = function(a, b) { | ||
[, , ...b] = b; | ||
const c = ha(b); | ||
const c = fa(b); | ||
b = b.slice(c.length); | ||
@@ -92,6 +92,6 @@ let d = !c.length; | ||
var g = Object.assign({}, e); | ||
e = e.s; | ||
g = (delete g.s, g); | ||
e = e.v; | ||
g = (delete g.v, g); | ||
if (0 == e.length && d) { | ||
return Object.assign({}, {s:e}, g); | ||
return Object.assign({}, {v:e}, g); | ||
} | ||
@@ -101,15 +101,15 @@ const h = a[f]; | ||
if ("string" == typeof h) { | ||
({value:k, argv:e} = fa(e, f, h)); | ||
({value:k, argv:e} = ea(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} = fa(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} = ea(e, f, l, m, n); | ||
} catch (l) { | ||
return Object.assign({}, {s:e}, g); | ||
return Object.assign({}, {v:e}, g); | ||
} | ||
} | ||
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:{}}) { | ||
return void 0 === k ? Object.assign({}, {v:e}, g) : Object.assign({}, {v:e}, g, {[f]:k}); | ||
}, {v:b}); | ||
}(ha), w = v.source, ja = v.output, ka = v.closure, la = v.externs, ma = v.types, na = v.template, oa = v.migrate, pa = v.help, qa = v.version; | ||
function ra(a = {usage:{}}) { | ||
const {usage:b = {}, description:c, line:d, example:e} = a; | ||
@@ -145,5 +145,5 @@ a = Object.keys(b); | ||
} | ||
;const {createReadStream:ta, createWriteStream:ua, lstat:x, readdir:va} = fs; | ||
var wa = stream; | ||
const {Transform:y, Writable:xa} = stream; | ||
;const {createReadStream:sa, createWriteStream:ta, lstat:x, readdir:ua} = fs; | ||
var va = stream; | ||
const {Transform:y, Writable:wa} = stream; | ||
const ya = (a, b = 0, c = !1) => { | ||
@@ -160,3 +160,3 @@ if (0 === b && !c) { | ||
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 Ca = /\s+at.*(?:\(|\s)(.*)\)?/, Da = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/, Ea = Ba(), A = a => { | ||
const {pretty:b = !1, ignoredModules:c = ["pirates"]} = {}, d = c.join("|"), e = new RegExp(Da.source.replace("IGNORED_MODULES", d)); | ||
@@ -177,7 +177,7 @@ return a.replace(/\\/g, "/").split("\n").filter(f => { | ||
e = [`Error: ${h}`, ...null !== e && a === e || c ? [b] : [g, b]].join("\n"); | ||
e = B(e); | ||
e = A(e); | ||
return Object.assign(f ? d : Error(), {message:h, stack:e}); | ||
}; | ||
} | ||
;function F(a) { | ||
;function C(a) { | ||
var {stack:b} = Error(); | ||
@@ -194,3 +194,3 @@ const c = Aa(arguments); | ||
}; | ||
class Ha extends xa { | ||
class Ha extends wa { | ||
constructor(a) { | ||
@@ -200,6 +200,6 @@ var b = a || {}, c = Object.assign({}, b); | ||
b = (delete c.binary, delete c.rs, c); | ||
const {P:f = F(!0), proxyError:g} = a || {}, h = (k, l) => f(l); | ||
const {S:f = C(!0), proxyError:g} = a || {}, h = (k, l) => f(l); | ||
super(b); | ||
this.b = []; | ||
this.N = new Promise((k, l) => { | ||
this.P = new Promise((k, l) => { | ||
this.on("finish", () => { | ||
@@ -215,3 +215,3 @@ let m; | ||
} else { | ||
const n = B(m.stack); | ||
const n = A(m.stack); | ||
m.stack = n; | ||
@@ -229,20 +229,20 @@ g && h`${m}`; | ||
} | ||
get g() { | ||
return this.N; | ||
get f() { | ||
return this.P; | ||
} | ||
} | ||
const G = async a => { | ||
const D = async a => { | ||
var b = void 0 === b ? {} : b; | ||
({g:a} = new Ha(Object.assign({}, {rs:a}, b, {P:F(!0)}))); | ||
({f:a} = new Ha(Object.assign({}, {rs:a}, b, {S:C(!0)}))); | ||
return await a; | ||
}; | ||
async function H(a) { | ||
a = ta(a); | ||
return await G(a); | ||
async function E(a) { | ||
a = sa(a); | ||
return await D(a); | ||
} | ||
;async function I(a, b) { | ||
;async function F(a, b) { | ||
if (!a) { | ||
throw Error("No path is given."); | ||
} | ||
const c = F(!0), d = ua(a); | ||
const c = C(!0), d = ta(a); | ||
await new Promise((e, f) => { | ||
@@ -260,4 +260,4 @@ d.on("error", g => { | ||
} | ||
async function J(a, b, c) { | ||
const d = F(!0); | ||
async function G(a, b, c) { | ||
const d = C(!0); | ||
if ("function" !== typeof a) { | ||
@@ -279,7 +279,7 @@ throw Error("Function must be passed."); | ||
} | ||
;const {join:K} = path; | ||
;const {join:H} = path; | ||
async function Ja(a, b) { | ||
b = b.map(async c => { | ||
const d = K(a, c); | ||
return {lstat:await J(x, d), path:d, relativePath:c}; | ||
const d = H(a, c); | ||
return {lstat:await G(x, d), path:d, relativePath:c}; | ||
}); | ||
@@ -289,10 +289,10 @@ return await Promise.all(b); | ||
const Ka = a => a.lstat.isDirectory(), La = a => !a.lstat.isDirectory(); | ||
async function L(a) { | ||
async function I(a) { | ||
if (!a) { | ||
throw Error("Please specify a path to the directory"); | ||
} | ||
if (!(await J(x, a)).isDirectory()) { | ||
if (!(await G(x, a)).isDirectory()) { | ||
throw a = Error("Path is not a directory"), a.code = "ENOTDIR", a; | ||
} | ||
var b = await J(va, a); | ||
var b = await G(ua, a); | ||
b = await Ja(a, b); | ||
@@ -307,3 +307,3 @@ a = b.filter(Ka); | ||
c = await c; | ||
d = await L(e); | ||
d = await I(e); | ||
return Object.assign({}, c, {[f]:d}); | ||
@@ -313,11 +313,11 @@ }, {}); | ||
} | ||
const M = (a, b) => { | ||
const J = (a, b) => { | ||
let c = [], d = []; | ||
Object.keys(a).forEach(f => { | ||
const {type:g} = a[f]; | ||
"File" == g ? c.push(K(b, f)) : "Directory" == g && d.push(f); | ||
"File" == g ? c.push(H(b, f)) : "Directory" == g && d.push(f); | ||
}); | ||
const e = d.reduce((f, g) => { | ||
const {content:h} = a[g]; | ||
g = M(h, K(b, g)); | ||
g = J(h, H(b, g)); | ||
return [...f, ...g]; | ||
@@ -336,3 +336,3 @@ }, []); | ||
} | ||
const N = (a, b) => { | ||
const K = (a, b) => { | ||
if (!(b instanceof Error)) { | ||
@@ -354,3 +354,3 @@ throw b; | ||
return b.filter(Ma).reduce((d, {re:e, replacement:f}) => { | ||
if (this.o) { | ||
if (this.s) { | ||
return d; | ||
@@ -366,5 +366,5 @@ } | ||
try { | ||
return this.o ? h : f.call(this, h, ...k); | ||
return this.s ? h : f.call(this, h, ...k); | ||
} catch (l) { | ||
N(g, l); | ||
K(g, l); | ||
} | ||
@@ -376,3 +376,3 @@ }); | ||
c.b = () => { | ||
c.o = !0; | ||
c.s = !0; | ||
}; | ||
@@ -382,3 +382,3 @@ 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}; | ||
var a = {T:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\n(?:([^\n][\s\S]+?\n))?$/mg}; | ||
return Object.keys(a).reduce((b, c) => { | ||
@@ -410,17 +410,17 @@ { | ||
async function Ta(a, b) { | ||
b instanceof wa ? b.pipe(a) : a.end(b); | ||
return await G(a); | ||
b instanceof va ? b.pipe(a) : a.end(b); | ||
return await D(a); | ||
} | ||
class O extends y { | ||
class L extends y { | ||
constructor(a, b) { | ||
super(b); | ||
this.g = (Array.isArray(a) ? a : [a]).filter(Ma); | ||
this.o = !1; | ||
this.A = b; | ||
this.f = (Array.isArray(a) ? a : [a]).filter(Ma); | ||
this.s = !1; | ||
this.o = b; | ||
} | ||
async replace(a, b) { | ||
const c = new O(this.g, this.A); | ||
const c = new L(this.f, this.o); | ||
b && Object.assign(c, b); | ||
a = await Ta(c, a); | ||
c.o && (this.o = !0); | ||
c.s && (this.s = !0); | ||
b && Object.keys(b).forEach(d => { | ||
@@ -432,5 +432,5 @@ b[d] = c[d]; | ||
async reduce(a) { | ||
return await this.g.reduce(async(b, {re:c, replacement:d}) => { | ||
return await this.f.reduce(async(b, {re:c, replacement:d}) => { | ||
b = await b; | ||
if (this.o) { | ||
if (this.s) { | ||
return b; | ||
@@ -446,3 +446,3 @@ } | ||
try { | ||
if (this.o) { | ||
if (this.s) { | ||
return e.length ? e.push(Promise.resolve(h)) : h; | ||
@@ -454,3 +454,3 @@ } | ||
} catch (l) { | ||
N(f, l); | ||
K(f, l); | ||
} | ||
@@ -463,3 +463,3 @@ }); | ||
} catch (h) { | ||
N(f, h); | ||
K(f, h); | ||
} | ||
@@ -479,3 +479,3 @@ } else { | ||
} catch (d) { | ||
a = B(d.stack), d.stack = a, c(d); | ||
a = A(d.stack), d.stack = a, c(d); | ||
} | ||
@@ -496,3 +496,3 @@ } | ||
} | ||
;const S = (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}`; | ||
}, 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 => `/** | ||
}, Wa = ({number:a, O: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} | ||
*/ | ||
`, T = a => ` * @suppress {nonStandardJsDocs} | ||
${a}`, U = (a, b, c) => { | ||
`, P = a => ` * @suppress {nonStandardJsDocs} | ||
${a}`, Q = (a, b, c) => { | ||
a = `${a ? "" : "var "}${a ? `${a}.` : ""}${b}`; | ||
c && (a += ` = ${c}`); | ||
return a; | ||
}, V = a => { | ||
}, R = a => { | ||
a = a.trimRight(); | ||
@@ -539,3 +539,3 @@ var b = /\S/.exec(a); | ||
}; | ||
function W(a, b, c) { | ||
function S(a, b, c) { | ||
const d = []; | ||
@@ -556,7 +556,7 @@ b.replace(a, (e, ...f) => { | ||
;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 = ""}) => { | ||
const T = (a, b) => S(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 = ab(c); | ||
return {content:d, v:c}; | ||
}), ab = a => W(Za, a, ["key", "val", "def", "f"]).reduce((b, {key:c, val:d}) => { | ||
return {content:d, u:c}; | ||
}), ab = a => S(Za, 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 = V(b)); | ||
a.type = Wa({number:g, M:d, boolean:e, type:h}); | ||
b && (a.description = R(b)); | ||
a.type = Wa({number:g, O:d, boolean:e, type:h}); | ||
f && (a.optional = !0); | ||
@@ -755,3 +755,13 @@ } | ||
} | ||
;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}) { | ||
const gb = a => { | ||
let b = a.lastIndexOf("</arg>"), c = a; | ||
var d = []; | ||
-1 != b && (b += 6, d = a.slice(0, b), c = a.slice(b), d = T("arg", d), d = d.map(({content:e, u:f}) => { | ||
const g = new fb; | ||
eb(g, e, f); | ||
return g; | ||
})); | ||
return {V:c, K:d}; | ||
}; | ||
function hb(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) { | ||
@@ -761,16 +771,16 @@ throw Error("Property does not have a name."); | ||
a.name = c; | ||
b && (a.description = V(b)); | ||
a.type = Wa({number:g, M:d, boolean:e, type:h}); | ||
l ? a.f = l : a.f = a.type; | ||
void 0 !== k && (a.g = !0); | ||
a.g && (a.default = k); | ||
if (f || a.g) { | ||
b && (a.description = R(b)); | ||
a.type = Wa({number:g, O:d, boolean:e, type:h}); | ||
l ? a.g = l : a.g = a.type; | ||
void 0 !== k && (a.f = !0); | ||
a.f && (a.default = k); | ||
if (f || a.f) { | ||
a.optional = !0; | ||
} | ||
m && (a.w = [m]); | ||
n && (a.w = n.split(/\s*,\s*/)); | ||
m && (a.A = [m]); | ||
n && (a.A = n.split(/\s*,\s*/)); | ||
p && (a.l = p); | ||
if (!a.optional && !a.l) { | ||
try { | ||
a.b = db(a.f); | ||
a.b = db(a.g); | ||
} catch (q) { | ||
@@ -780,16 +790,16 @@ } | ||
} | ||
function hb(a, b = null, c = !1) { | ||
function ib(a, b = null, c = !1) { | ||
if (!a.name) { | ||
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.g ? ` Default \`${a.default}\`.` : ""}`}`; | ||
b = O(a.name, a.default, a.type, b); | ||
return `{${c ? a.g : a.type}} ${a.optional ? `[${b}]` : b}${`${a.description ? ` ${a.description}` : ""}${a.f ? ` Default \`${a.default}\`.` : ""}`}`; | ||
} | ||
function ib(a, b = !1) { | ||
a = hb(a, null, b); | ||
return ` * @prop ${jb(a, !0)}`; | ||
function jb(a, b = !1) { | ||
a = ib(a, null, b); | ||
return ` * @prop ${kb(a, !0)}`; | ||
} | ||
function kb(a) { | ||
function lb(a) { | ||
const b = [], {function:{args:c, return:d}} = a.b; | ||
c.map(Y).forEach((e, f) => { | ||
c.map(U).forEach((e, f) => { | ||
const {optional:g} = c[f], {name:h = `arg${f}`, description:k} = a.args[f] || {}; | ||
@@ -799,3 +809,3 @@ b.push(` * @param {${e}${g ? "=" : ""}} ${g ? `[${h}]` : h}${k ? ` ${k}` : ""}`); | ||
if ("void" != d.name) { | ||
const e = Y(d); | ||
const e = U(d); | ||
b.push(` * @return {${e}}`); | ||
@@ -805,13 +815,13 @@ } | ||
} | ||
function lb(a, b = "") { | ||
function mb(a, b = "") { | ||
const c = []; | ||
if (a.description) { | ||
let d = jb(a.description); | ||
let d = kb(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}}`); | ||
a.b && "function" == a.b.name ? (a = lb(a), c.push(...a)) : c.push(` * @type {${a.optional ? Xa(a.g) : a.g}}`); | ||
return c.map(d => `${b}${d}`).join("\n"); | ||
} | ||
function mb(a, b) { | ||
function nb(a, b) { | ||
const c = Object.assign(Object.create(Object.getPrototypeOf(a)), a); | ||
@@ -822,21 +832,22 @@ c.description = `An alias for \`${a.name}\`.`; | ||
} | ||
class nb { | ||
class ob { | ||
constructor(a = []) { | ||
this.description = this.name = null; | ||
this.type = "*"; | ||
this.f = ""; | ||
this.g = !1; | ||
this.g = ""; | ||
this.f = !1; | ||
this.default = null; | ||
this.optional = !1; | ||
this.w = []; | ||
this.A = []; | ||
this.l = !1; | ||
this.b = null; | ||
this.args = a; | ||
this.o = !1; | ||
} | ||
I(a, b = "", c = !1) { | ||
a = hb(this, a, c); | ||
J(a, b = "", c = !1) { | ||
a = ib(this, a, c); | ||
return `${b} * @param ${a}`; | ||
} | ||
} | ||
const jb = (a, b = !1) => a.split("\n").map((c, d) => { | ||
const kb = (a, b = !1) => a.split("\n").map((c, d) => { | ||
if (b && !d) { | ||
@@ -848,3 +859,3 @@ return c; | ||
return d + c; | ||
}).join("\n"), Y = a => { | ||
}).join("\n"), U = a => { | ||
var b = ""; | ||
@@ -856,15 +867,15 @@ a.nullable ? b = "?" : !1 === a.nullable && (b = "!"); | ||
if (a.function.this) { | ||
var c = "this: " + Y(a.function.this); | ||
var c = "this: " + U(a.function.this); | ||
d.push(c); | ||
} | ||
a.function.new && (c = "new: " + Y(a.function.new), d.push(c)); | ||
a.function.new && (c = "new: " + U(a.function.new), d.push(c)); | ||
a.function.args.forEach(e => { | ||
let f = Y(e); | ||
let f = U(e); | ||
e.optional && (f += "="); | ||
d.push(f); | ||
}); | ||
a.function.variableArgs && (c = "..." + Y(a.function.variableArgs), d.push(c)); | ||
a.function.variableArgs && (c = "..." + U(a.function.variableArgs), d.push(c)); | ||
c = d.join(", "); | ||
b += c + ")"; | ||
a.function.return && (b += ": " + Y(a.function.return)); | ||
a.function.return && (b += ": " + U(a.function.return)); | ||
} else { | ||
@@ -877,3 +888,3 @@ if (a.record) { | ||
} | ||
e = Y(e); | ||
e = U(e); | ||
return `${d}: ${e}`; | ||
@@ -887,7 +898,7 @@ }), b += c.join(", "), b += " }"; | ||
b += a.name + "<"; | ||
c = a.application.map(d => Y(d)); | ||
c = a.application.map(d => U(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; | ||
a.union ? (b += "(", c = a.union.map(d => U(d)), b += c.join("|"), b += ")") : b += "any" == a.name ? "*" : a.name; | ||
} | ||
@@ -898,4 +909,4 @@ } | ||
}; | ||
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; | ||
function V(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:M} = c; | ||
if (!e) { | ||
@@ -906,44 +917,42 @@ throw Error("Type does not have a name."); | ||
f && (a.type = f); | ||
p ? a.f = p : a.f = a.type; | ||
g && (a.description = V(g)); | ||
a.L = !!h; | ||
a.K = !!k; | ||
a.J = !!l; | ||
p ? a.g = p : a.g = a.type; | ||
g && (a.description = R(g)); | ||
a.N = !!h; | ||
a.M = !!k; | ||
a.L = !!l; | ||
a.import = !!m; | ||
n && (a.link = n); | ||
!0 === q && (a.isConstructor = q); | ||
!0 === u && (a.l = u); | ||
!0 === P && (a.A = P); | ||
!0 === u && (a.f = u); | ||
!0 === M && (a.I = M); | ||
t && (a.extends = t); | ||
if (b) { | ||
c = X("prop", b).map(r => { | ||
var {content:z, v:A} = r; | ||
r = new nb; | ||
gb(r, z, A); | ||
c = T("prop", b).map(r => { | ||
var {content:Y, u:z} = r; | ||
r = new ob; | ||
hb(r, Y, z); | ||
return r; | ||
}); | ||
const Ab = X("function", b); | ||
b = X("fn", b); | ||
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; | ||
const zb = T("function", b), Ab = T("fn", b); | ||
b = T("static", b).map(r => { | ||
r.isStatic = !0; | ||
return r; | ||
}); | ||
b = [...zb, ...Ab, ...b].map(r => { | ||
var {content:Y, u:z, isStatic:Bb} = r; | ||
const {V:Cb, K:Z} = gb(Y); | ||
var B = Object.assign({}, z); | ||
r = z.async; | ||
var N = void 0 === z["return"] ? "void" : z["return"]; | ||
B = (delete B.async, delete B["return"], B); | ||
let {args:aa = ""} = z; | ||
!aa && Z.length && (aa = Z.map(Db => { | ||
var {type:xa, optional:Eb} = Db; | ||
return null !== Eb ? `${xa}=` : xa; | ||
}).join(",")); | ||
R = R.replace(/\n\s*/g, " "); | ||
E.type = `function(${ba}): ${C ? `!Promise<${R}>` : R}`; | ||
r = new nb(r); | ||
gb(r, z, E); | ||
N = N.replace(/\n\s*/g, " "); | ||
B.type = `function(${aa}): ${r ? `!Promise<${N}>` : N}`; | ||
r = new ob(Z); | ||
hb(r, Cb, B); | ||
Bb && (r.o = !0); | ||
return r; | ||
@@ -956,50 +965,58 @@ }); | ||
function pb(a) { | ||
var b = []; | ||
const b = []; | ||
a.description && b.push(` * ${a.description}`); | ||
a.extends && b.push(` * @extends {${a.extends}}`); | ||
b.push(` * @${a.S}`); | ||
b = `/** | ||
a.b && a.b.forEach(e => { | ||
const {name:f, description:g, optional:h, type:k} = e; | ||
b.push(` * @param {${k}${h ? "=" : ""}} ${h ? `[${f}]` : f}${g ? ` ${g}` : ""}`); | ||
}); | ||
var c = a.b ? `function(${a.b.map(e => { | ||
({name:e} = e); | ||
return e; | ||
})}) {}` : null; | ||
b.push(` * @${a.U}`); | ||
let d = `/** | ||
${b.join("\n")} | ||
*/ | ||
`; | ||
b += U(a.j, a.name, void 0); | ||
const c = a.i.reduce((d, e) => { | ||
d.push(e); | ||
const f = e.w.map(g => mb(e, g)); | ||
d.push(...f); | ||
return d; | ||
}, []).map(d => { | ||
let e = lb(d); | ||
e = `/** | ||
${e} | ||
d += Q(a.j, a.name, c); | ||
c = a.i.reduce((e, f) => { | ||
e.push(f); | ||
const g = f.A.map(h => nb(f, h)); | ||
e.push(...g); | ||
return e; | ||
}, []).map(e => { | ||
let f = mb(e); | ||
f = `/** | ||
${f} | ||
*/ | ||
` + 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; | ||
` + Q(`${a.h}${e.o ? "" : ".prototype"}`, e.name); | ||
if (e.b && "function" == e.b.name) { | ||
var {function:{args:g}} = e.b; | ||
g = g.map((h, k) => { | ||
({name:h = `arg${k}`} = e.args[k] || {}); | ||
return h; | ||
}); | ||
e += ` = function(${f.join(", ")}) {}`; | ||
f += ` = function(${g.join(", ")}) {}`; | ||
} else { | ||
d.type.startsWith("function(") && (e += " = function() {}"); | ||
e.type.startsWith("function(") && (f += " = function() {}"); | ||
} | ||
return e; | ||
return f; | ||
}); | ||
return [b, ...c].join("\n"); | ||
return [d, ...c].join("\n"); | ||
} | ||
function qb(a, b) { | ||
const c = `${a.extends ? "$" : ""}${a.name}`; | ||
return b ? `${a.u}${c}` : c; | ||
return b ? `${a.w}${c}` : c; | ||
} | ||
function rb(a, b, c) { | ||
var d = ` * @typedef {${(b ? a.f : a.type) || "Object"}}${` ${qb(a, b)}${a.g}`}`; | ||
var d = ` * @typedef {${(b ? a.g : a.type) || "Object"}}${` ${qb(a, b)}${a.o}`}`; | ||
a = (a.i ? a.i.reduce((e, f) => { | ||
e.push(f); | ||
const g = f.w.map(h => mb(f, h)); | ||
const g = f.A.map(h => nb(f, h)); | ||
e.push(...g); | ||
return e; | ||
}, []) : []).map(e => ib(e, b)); | ||
}, []) : []).map(e => jb(e, b)); | ||
d = [d, ...a].join("\n"); | ||
b && !c && (d = T(d)); | ||
b && !c && (d = P(d)); | ||
return `/** | ||
@@ -1015,4 +1032,4 @@ ${d} | ||
if (a.j && b) { | ||
let g = ` * @typedef {${a.h}} ${a.name}${a.g}`; | ||
b && !c && (g = T(g)); | ||
let g = ` * @typedef {${a.h}} ${a.name}${a.o}`; | ||
b && !c && (g = P(g)); | ||
g = `/** | ||
@@ -1024,3 +1041,3 @@ ${g} | ||
} | ||
d && (a = ` * @typedef {${a.extends} & ${qb(a, b)}} ${b ? a.h : a.name}${a.g}`, b && !c && (a = T(a)), a = `/** | ||
d && (a = ` * @typedef {${a.extends} & ${qb(a, b)}} ${b ? a.h : a.name}${a.o}`, b && !c && (a = P(a)), a = `/** | ||
${a} | ||
@@ -1032,19 +1049,19 @@ */ | ||
} | ||
class tb { | ||
class W { | ||
constructor() { | ||
this.name = ""; | ||
this.link = this.J = this.import = this.K = this.L = this.description = this.f = this.type = null; | ||
this.link = this.L = this.import = this.M = this.N = this.description = this.g = this.type = null; | ||
this.i = []; | ||
this.j = null; | ||
this.A = this.l = this.isConstructor = !1; | ||
this.extends = null; | ||
this.I = this.f = this.isConstructor = !1; | ||
this.b = this.extends = null; | ||
} | ||
get T() { | ||
return this.isConstructor || this.l || this.A; | ||
get W() { | ||
return this.isConstructor || this.f || this.I; | ||
} | ||
get g() { | ||
return `${this.b ? ` \`\uff20${this.b}\`` : ""}${this.description ? ` ${this.description}` : ""}`; | ||
get o() { | ||
return `${this.l ? ` \`\uff20${this.l}\`` : ""}${this.description ? ` ${this.description}` : ""}`; | ||
} | ||
get S() { | ||
const a = this.b; | ||
get U() { | ||
const a = this.l; | ||
if (!a) { | ||
@@ -1055,12 +1072,12 @@ throw Error("Unknown prototype type (not constructor or interface)."); | ||
} | ||
get b() { | ||
return this.isConstructor ? "constructor" : this.l ? "interface" : this.A ? "record" : ""; | ||
get l() { | ||
return this.isConstructor ? "constructor" : this.f ? "interface" : this.I ? "record" : ""; | ||
} | ||
get u() { | ||
get w() { | ||
return this.j ? `${this.j}.` : ""; | ||
} | ||
get h() { | ||
return `${this.u}${this.name}`; | ||
return `${this.w}${this.name}`; | ||
} | ||
I(a, b, c, d, e) { | ||
J(a, b, c, d, e) { | ||
e = void 0 === e ? !1 : e; | ||
@@ -1070,9 +1087,9 @@ var f = ""; | ||
d = this.description ? ` ${this.description}` : ""; | ||
const g = this.K ? ub(this.i) : e ? this.h : this.name; | ||
const g = this.M ? tb(this.i) : e ? this.h : this.name; | ||
b = `${c || ""} * @param {${f}${g}} ${b ? `[${a}]` : a}${d}`; | ||
f = this.i && !this.J ? this.i.map(h => h.I(a, c, e)) : []; | ||
f = this.i && !this.L ? this.i.map(h => h.J(a, c, e)) : []; | ||
return [b, ...f].join("\n"); | ||
} | ||
} | ||
const ub = (a, b) => { | ||
const tb = (a, b) => { | ||
a = void 0 === a ? [] : a; | ||
@@ -1082,3 +1099,3 @@ b = void 0 === b ? !1 : b; | ||
c.push(d); | ||
const e = d.w.map(f => Object.assign({}, d, {name:f})); | ||
const e = d.A.map(f => Object.assign({}, d, {name:f})); | ||
c.push(...e); | ||
@@ -1088,3 +1105,3 @@ return c; | ||
return `{ ${a.map(c => { | ||
const d = b ? c.f : c.type; | ||
const d = b ? c.g : c.type; | ||
let e = c.name, f = d; | ||
@@ -1095,3 +1112,3 @@ c.optional && !b ? e = `${c.name}?` : c.optional && b && (f = `(${Xa(d)})`); | ||
}; | ||
function vb(a, {name:b, from:c, desc:d, link:e, ns:f}) { | ||
function ub(a, {name:b, from:c, desc:d, link:e, ns:f}) { | ||
a.name = b; | ||
@@ -1101,21 +1118,21 @@ a.from = c; | ||
a.link = e; | ||
a.u = f || a.from; | ||
a.w = f || a.from; | ||
} | ||
function wb(a, b = !0) { | ||
function vb(a, b = !0) { | ||
return ` * @typedef {import('${a.from}').${a.name}} ${b ? a.h : a.name}`; | ||
} | ||
class xb { | ||
class wb { | ||
constructor() { | ||
this.from = this.name = this.u = ""; | ||
this.from = this.name = this.w = ""; | ||
this.link = this.G = null; | ||
} | ||
get h() { | ||
return `${this.u}.${this.name}`; | ||
return `${this.w}.${this.name}`; | ||
} | ||
} | ||
;function yb(a, b) { | ||
;function xb(a, b) { | ||
b = b.reduce((c, d) => Object.assign({}, c, {[d.h]:d}), {}); | ||
a.F = Object.assign({}, a.F, b); | ||
} | ||
class zb extends O { | ||
class yb extends L { | ||
constructor(a, b) { | ||
@@ -1126,3 +1143,3 @@ b = void 0 === b ? {} : b; | ||
this.on("types", c => { | ||
yb(this, c); | ||
xb(this, c); | ||
}); | ||
@@ -1139,6 +1156,6 @@ this.on("namespace", c => { | ||
static get Type() { | ||
return tb; | ||
return W; | ||
} | ||
static get b() { | ||
return xb; | ||
return wb; | ||
} | ||
@@ -1149,27 +1166,39 @@ get types() { | ||
} | ||
;const Bb = a => { | ||
a = X("types", a); | ||
;const Fb = a => { | ||
a = T("types", a); | ||
if (!a.length) { | ||
throw Error("XML file should contain root types element."); | ||
} | ||
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); | ||
const [{content:b, u:{namespace:c, ns:d = c}}] = a, e = void 0 == d ? void 0 : d; | ||
a = T("type", b).map(({content:h, u:k}) => { | ||
const l = new W; | ||
V(l, h, k, e); | ||
return l; | ||
}); | ||
const f = X("import", b).map(({v:h, content:k}) => { | ||
const l = new xb; | ||
k && (h.desc = V(k)); | ||
vb(l, h); | ||
var f = T("interface", b).map(({content:h, u:k}) => { | ||
const l = new W, m = h.search(/<(prop|function|fn|static) /); | ||
let n = "", p = h; | ||
1 != m && (n = h.slice(0, m), p = h.slice(m)); | ||
({K:h} = gb(n)); | ||
V(l, p, k, e); | ||
l.b = h; | ||
l.f = !0; | ||
return l; | ||
}), 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); | ||
}); | ||
a = [...a, ...f]; | ||
f = T("import", b).map(({u:h, content:k}) => { | ||
const l = new wb; | ||
k && (h.desc = R(k)); | ||
ub(l, h); | ||
return l; | ||
}); | ||
const g = f.map(({name:h, from:k, G:l, link:m, w:n}) => { | ||
const p = new W; | ||
V(p, "", {name:h, type:`import('${k}').${h}`, N:!0, import:!0, G:l, link:m}, void 0 == n ? void 0 : n); | ||
return p; | ||
}); | ||
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); | ||
return {j:d, types:a, imports:f, X:g}; | ||
}, Gb = async(a, b = []) => { | ||
a = await E(a); | ||
let {j:c = null, types:d, imports:e} = Fb(a); | ||
d = d.filter(({h:f}) => b.includes(f) ? !1 : !0); | ||
@@ -1179,8 +1208,8 @@ e = e.filter(({h:f}) => b.includes(f) ? !1 : !0); | ||
}; | ||
const Db = (a, b, c) => { | ||
const Hb = (a, b, c) => { | ||
b = b.map(d => sb(d, !0, c)); | ||
a = a.map(d => { | ||
d = wb(d); | ||
d = vb(d); | ||
return `/** | ||
${c ? d : T(d)} | ||
${c ? d : P(d)} | ||
*/ | ||
@@ -1190,11 +1219,11 @@ `; | ||
return [...b, ...a].join(""); | ||
}, Eb = (a, b, c, d = !1) => { | ||
}, Ib = (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)}}`); | ||
e.g ? f = ` * @typedef {${e.g}}` : e.W || (f = ` * @typedef {${tb(e.i, !0)}}`); | ||
f ? (e.description && (f = ` * ${e.description}\n${f}`), f = `/** | ||
${f} | ||
*/ | ||
`, e = f += U(e.j, e.name)) : e = pb(e); | ||
`, e = f += Q(e.j, e.name)) : e = pb(e); | ||
} | ||
@@ -1207,3 +1236,3 @@ return e; | ||
}; | ||
const Gb = {re:/^\/\*\*? (documentary|typal) (.+?) \*\/\n(?:([^\n][\s\S]+?\n))?$/mg, replacement:async function(a, b, c) { | ||
const Kb = {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"); | ||
@@ -1217,7 +1246,7 @@ let l = e.find(p => p.startsWith("ignore:")); | ||
this.m("Detected type marker: %s", c); | ||
const {types:p, imports:q, j:t} = await Cb(d, l); | ||
const {types:p, imports:q, j:t} = await Gb(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); | ||
m ? u = Hb(q, p, h) : n ? (u = Ib(p, t, this.b, k) + "\n", t && this.emit("namespace", t)) : u = Jb(q, p); | ||
return `/* ${b} ${c} */\n${u}`; | ||
@@ -1227,10 +1256,10 @@ } catch (p) { | ||
} | ||
}}, Fb = (a, b) => { | ||
}}, Jb = (a, b) => { | ||
b = b.map(c => sb(c)); | ||
a = a.map(c => wb(c, !1)).map(Ya).join(""); | ||
a = a.map(c => vb(c, !1)).map(Ya).join(""); | ||
b = b.join(""); | ||
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) { | ||
return `${a}${b}`.replace(Lb, " * @typedef"); | ||
}, Lb = / \*\/\n\/\*\*\n \* @typedef/g; | ||
const Nb = {re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\n(?: +)\* @param {(?:.+?)} \[?\4\]?.*)*)/gm, replacement:Mb}; | ||
function Mb(a, b, c, d, e, f, g) { | ||
const {D:h} = this.l; | ||
@@ -1246,5 +1275,5 @@ let k; | ||
} | ||
m = {line:m, O:b.length + 11}; | ||
m = {line:m, R:b.length + 11}; | ||
} | ||
const {line:n, O:p} = m; | ||
const {line:n, R:p} = m; | ||
this.m("%s:%s:%s", this.file, n, p); | ||
@@ -1262,9 +1291,9 @@ } | ||
const l = Object.values(this.types).map(({name:m, h:n}) => h ? n : m); | ||
if (!Z(k, l, this.m, c, f)) { | ||
if (!X(k, l, this.m, 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 zb.b ? a : c.I(e, d, b, k.nullable, h); | ||
return !c || c instanceof yb.b ? a : c.J(e, d, b, k.nullable, h); | ||
} | ||
const Z = (a, b, c, d, e) => { | ||
const X = (a, b, c, d, e) => { | ||
if (a) { | ||
@@ -1275,3 +1304,3 @@ var f = a.name; | ||
let h = b.includes(f); | ||
h || (h = Kb.includes(f)); | ||
h || (h = Ob.includes(f)); | ||
if (h) { | ||
@@ -1285,38 +1314,38 @@ return !0; | ||
a.application ? a.application.forEach(h => { | ||
Z(h, ...g); | ||
X(h, ...g); | ||
}) : a.record ? Object.keys(a.record).forEach(h => { | ||
Z(a.record[h], ...g); | ||
X(a.record[h], ...g); | ||
}) : a.union ? a.union.forEach(h => { | ||
Z(h, ...g); | ||
}) : a.function && (Z(a.function.this, ...g), Z(a.function.new, ...g), a.function.args.forEach(h => { | ||
Z(h, ...g); | ||
}), Z(a.function.variableArgs, ...g), Z(a.function.return, ...g)); | ||
X(h, ...g); | ||
}) : a.function && (X(a.function.this, ...g), X(a.function.new, ...g), a.function.args.forEach(h => { | ||
X(h, ...g); | ||
}), X(a.function.variableArgs, ...g), X(a.function.return, ...g)); | ||
} | ||
} | ||
}, Kb = "String Boolean Object Date Number Symbol Buffer Function".split(" "); | ||
var Lb = (a, b = !1) => { | ||
var {R:c} = Qa(); | ||
}, Ob = "String Boolean Object Date Number Symbol Buffer Function".split(" "); | ||
var Pb = (a, b = !1) => { | ||
var {T:c} = Qa(); | ||
const d = Sa(c); | ||
c = Ra(c); | ||
return new zb(b ? [Gb] : [Gb, d, Jb, c], a); | ||
return new yb(b ? [Kb] : [Kb, d, Nb, c], a); | ||
}; | ||
var Nb = async() => { | ||
const {D:a = !1, H:b = !1, B:c, types:d} = {D:la, H:ma, B:ka, types:na}; | ||
var Rb = async() => { | ||
const {D:a = !1, H:b = !1, B:c, types:d} = {D:ka, H:la, B:ja, types:ma}; | ||
await Promise.all(w.map(async e => { | ||
var f = await J(x, e); | ||
var f = await G(x, e); | ||
let g; | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await L(e), g = M(f.content, e)); | ||
await Mb(g, a, b, c, d); | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await I(e), g = J(f.content, e)); | ||
await Qb(g, a, b, c, d); | ||
})); | ||
}; | ||
const Mb = async(a, b = !1, c = !1, d = null, e = null) => { | ||
const Qb = async(a, b = !1, c = !1, d = null, e = null) => { | ||
const f = []; | ||
e && await Promise.all(e.split(",").map(async g => { | ||
g = await H(g); | ||
const {types:h, imports:k} = Bb(g); | ||
g = await E(g); | ||
const {types:h, imports:k} = Fb(g); | ||
f.push(h, k); | ||
})); | ||
await Promise.all(a.map(async g => { | ||
var h = await H(g); | ||
const k = Lb({D:b, H:c}, c); | ||
var h = await E(g); | ||
const k = Pb({D:b, H:c}, c); | ||
f.forEach(l => k.emit("types", l)); | ||
@@ -1327,11 +1356,11 @@ k.file = g; | ||
k.end(h); | ||
h = await G(k); | ||
"-" == d ? console.log(h) : d ? await I(d, h) : await I(g, h); | ||
h = await D(k); | ||
"-" == d ? console.log(h) : d ? await F(d, h) : await F(g, h); | ||
})); | ||
}; | ||
const Ob = a => { | ||
const Sb = a => { | ||
let b; | ||
"true" == a ? b = !0 : "false" == a ? b = !1 : /^\d+$/.test(a) && (b = parseInt(a, 10)); | ||
return void 0 !== b ? b : a; | ||
}, 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) => { | ||
}, Tb = /^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm, Ub = "type opt name quote defaultValue description Default".split(" "), Va = new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\n((?:${/ \* @prop(?:erty)? .+\n/.source})*)`, "gm"), Vb = (a, b, c, d) => { | ||
d = d.length; | ||
@@ -1342,3 +1371,3 @@ a = a && "Object" != a ? ` type="${a}"` : ""; | ||
}; | ||
class Sb extends y { | ||
class Wb extends y { | ||
constructor() { | ||
@@ -1349,3 +1378,3 @@ super({writableObjectMode:!0}); | ||
var {type:d, name:e, description:f, i:g} = a; | ||
a = d && d.startsWith("import") ? Tb(d, e) : Rb(d, e, f, g); | ||
a = d && d.startsWith("import") ? Xb(d, e) : Vb(d, e, f, g); | ||
this.push(a); | ||
@@ -1359,4 +1388,4 @@ g.forEach(h => { | ||
q = p && !q ? " opt" : ""; | ||
const u = " ".repeat(4), P = " ".repeat(6); | ||
h = `${u}<prop${q}${h} name="${l}"${t}${n ? `>\n${P}${n}\n${u}</prop>` : "/>"}\n`; | ||
const u = " ".repeat(4), M = " ".repeat(6); | ||
h = `${u}<prop${q}${h} name="${l}"${t}${n ? `>\n${M}${n}\n${u}</prop>` : "/>"}\n`; | ||
} | ||
@@ -1369,3 +1398,3 @@ this.push(h); | ||
} | ||
const Tb = (a, b) => { | ||
const Xb = (a, b) => { | ||
const c = /import\((['"])(.+?)\1\)/.exec(a); | ||
@@ -1378,3 +1407,3 @@ if (!c) { | ||
}; | ||
class Ub extends y { | ||
class Yb extends y { | ||
constructor() { | ||
@@ -1385,3 +1414,3 @@ super({objectMode:!0}); | ||
var [, d, e, f, g] = a; | ||
a = W(Pb, g, Qb).map(h => { | ||
a = S(Tb, g, Ub).map(h => { | ||
var k = Object.assign({}, h), l = h.defaultValue; | ||
@@ -1393,5 +1422,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:Ob(l)} : {}, m ? {C:Ob(m)} : {}, n ? {optional:!0} : {}); | ||
n = Object.assign({}, k, {name:p, type:h}, l ? {defaultValue:Sb(l)} : {}, m ? {C:Sb(m)} : {}, n ? {optional:!0} : {}); | ||
if (l || m) { | ||
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; | ||
l ? l !== m && void 0 !== n.C && (l = O(p, m, h), console.error("%s[%s] does not match Default `%s`.", e, l, n.C)) : (l = O(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; | ||
} | ||
@@ -1404,4 +1433,4 @@ return n; | ||
} | ||
async function Vb(a) { | ||
const b = Ua(), c = new Ub, d = new Sb; | ||
async function Zb(a) { | ||
const b = Ua(), c = new Yb, d = new Wb; | ||
b.pipe(c).pipe(d); | ||
@@ -1422,17 +1451,17 @@ b.end(a); | ||
return `<types> | ||
${(await G(d)).trim()} | ||
${(await D(d)).trim()} | ||
</types>`; | ||
} | ||
;var Wb = async() => { | ||
const {B:a} = {B:ka}; | ||
;var $b = async() => { | ||
const {B:a} = {B:ja}; | ||
await Promise.all(w.map(async b => { | ||
b = await H(b); | ||
b = await Vb(b); | ||
a ? await I(a, b) : console.log(b); | ||
b = await E(b); | ||
b = await Zb(b); | ||
a ? await F(a, b) : console.log(b); | ||
})); | ||
}; | ||
const Xb = /( *) \* @fnType {(.+?)}/gm; | ||
class Yb extends O { | ||
const ac = /( *) \* @fnType {(.+?)}/gm; | ||
class bc extends L { | ||
constructor(a, b) { | ||
super([{re:Xb, async replacement(c, d, e) { | ||
super([{re:ac, async replacement(c, d, e) { | ||
e = e.split("."); | ||
@@ -1454,19 +1483,19 @@ let f, g; | ||
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); | ||
return e ? e.b ? e.b.function ? mb(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 => { | ||
;const cc = async a => { | ||
if (!a) { | ||
return []; | ||
} | ||
const b = await J(x, a); | ||
const b = await G(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"))); | ||
b.isDirectory() && (c = await I(a), c = J(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); | ||
}, dc = async a => (await Promise.all(a.map(async b => { | ||
const c = await Gb(b); | ||
return Object.assign({}, c, {location:b}); | ||
@@ -1479,36 +1508,36 @@ }))).reduce((b, c) => { | ||
}, []); | ||
async function ac() { | ||
var a = {B:oa, types:na}; | ||
async function ec() { | ||
var a = {B:na, types:ma}; | ||
a = void 0 === a ? {} : a; | ||
const {B:b, types:c} = a; | ||
a = await Zb(c); | ||
const d = await $b(a); | ||
a = await cc(c); | ||
const d = await dc(a); | ||
await Promise.all(w.map(async e => { | ||
var f = await J(x, e); | ||
var f = await G(x, e); | ||
let g; | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await L(e), g = M(f.content, e)); | ||
await bc(g, d, b); | ||
f.isFile() ? g = [e] : f.isDirectory() && (f = await I(e), g = J(f.content, e)); | ||
await fc(g, d, b); | ||
})); | ||
} | ||
const bc = async(a, b, c) => { | ||
const fc = 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); | ||
var e = await E(d); | ||
const f = new bc(b, d); | ||
f.end(e); | ||
e = await G(f); | ||
"-" == c ? console.log(e) : c ? await I(c, e) : await I(d, e); | ||
e = await D(f); | ||
"-" == c ? console.log(e) : c ? await F(c, e) : await F(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"})); | ||
if (pa) { | ||
const a = ia(); | ||
console.log(ra({usage:a, description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.", line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]", example:"typal src/index.js -c"})); | ||
process.exit(); | ||
} else { | ||
ra && (console.log(require("../../package.json").version), process.exit()); | ||
qa && (console.log(require("../../package.json").version), process.exit()); | ||
} | ||
(async() => { | ||
try { | ||
return pa ? await Wb() : oa ? await ac() : await Nb(); | ||
return oa ? await $b() : na ? await ec() : await Rb(); | ||
} catch (a) { | ||
@@ -1515,0 +1544,0 @@ process.env.DEBUG ? console.log(a.stack) : console.log(a.message); |
{ | ||
"name": "typal", | ||
"version": "1.18.0", | ||
"version": "1.19.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", |
@@ -0,1 +1,2 @@ | ||
import extractTags from 'rexml' | ||
import { trimD, getPropType } from './' | ||
@@ -25,1 +26,23 @@ | ||
} | ||
/** | ||
* @param {string} content | ||
*/ | ||
export const extractArgs = (content) => { | ||
let ai = content.lastIndexOf('</arg>') | ||
let newContent = content | ||
/** @type {!Array<!Arg>} */ | ||
let argsArgs = [] | ||
if (ai != -1) { | ||
ai = ai + '</arg>'.length | ||
const pre = content.slice(0, ai) | ||
newContent = content.slice(ai) | ||
argsArgs = extractTags('arg', pre) | ||
argsArgs = argsArgs.map(({ content: ac, props: ap }) => { | ||
const ar = new Arg() | ||
ar.fromXML(ac, ap) | ||
return ar | ||
}) | ||
} | ||
return { newContent, argsArgs } | ||
} |
@@ -83,3 +83,3 @@ /** | ||
* @param {string} name | ||
* @param {string} [constr] The signature of the constructor for constructors and interfaces. | ||
* @param {?string} [constr] The signature of the constructor for constructors and interfaces. | ||
*/ | ||
@@ -86,0 +86,0 @@ export const getExternDeclaration = (namespace, name, constr) => { |
@@ -6,4 +6,18 @@ import extractTags from 'rexml' | ||
import read from '@wrote/read' | ||
import { extractArgs } from './Arg' | ||
/** | ||
* @param {string} namespace | ||
* @param {Type} type | ||
*/ | ||
const removeNamespace = (namespace, type) => { | ||
const s = new RegExp(`([!?])?${namespace}\\.`, 'g') | ||
type.properties.forEach((p) => { | ||
p.type = p.type.replace(s, '$1') | ||
}) | ||
if (type.type) type.type = type.type.replace(s, '$1') | ||
if (type.extends) type.extends = type.extends.replace(s, '$1') | ||
} | ||
/** | ||
* Parse the types.xml file. | ||
@@ -29,12 +43,35 @@ * @param {string} xml The content of the `xml` file. | ||
type.fromXML(content, props, ns) | ||
if (rootNamespace) { | ||
const s = new RegExp(`([!?])?${rootNamespace}\\.`, 'g') | ||
type.properties.forEach((p) => { | ||
p.type = p.type.replace(s, '$1') | ||
}) | ||
if (type.type) type.type = type.type.replace(s, '$1') | ||
if (type.extends) type.extends = type.extends.replace(s, '$1') | ||
return type | ||
}) | ||
const interfaceTags = extractTags('interface', Root) | ||
const interfaces = interfaceTags.map(({ content, props }) => { | ||
const type = new Type() | ||
const i = content.search(/<(prop|function|fn|static) /) | ||
let prebody = '', body = content | ||
if (i != 1) { | ||
prebody = content.slice(0, i) | ||
body = content.slice(i) | ||
} | ||
const { argsArgs } = extractArgs(prebody) | ||
// let { 'args': args = '', ...rest } = props | ||
// if (!args && argsArgs.length) { | ||
// args = argsArgs.map(({ type: at, optional }) => { | ||
// if (optional !== null) return `${at}=` | ||
// return at | ||
// }).join(',') | ||
// } | ||
// const assignment = `function(${args})` | ||
type.fromXML(body, props, ns) | ||
type.setAssignment(argsArgs) | ||
type.isInterface = true | ||
return type | ||
}) | ||
let allTypes = [...types, ...interfaces] | ||
if (rootNamespace) allTypes.forEach(t => removeNamespace( | ||
/** @type {string} */ (rootNamespace), t | ||
)) | ||
@@ -66,3 +103,3 @@ const imports = extractTags('import', Root) | ||
return { namespace, types, imports, Imports } | ||
return { namespace, types: allTypes, imports, Imports } | ||
} | ||
@@ -69,0 +106,0 @@ |
@@ -67,2 +67,7 @@ import parse from '@typedefs/parser' | ||
this.args = args | ||
/** | ||
* Whether this property is a static method. | ||
*/ | ||
this.staticMethod = false | ||
} | ||
@@ -69,0 +74,0 @@ static fromXML(...args) { |
import extractTags from 'rexml' | ||
import parse from '@typedefs/parser' | ||
import Property from './Property' | ||
import Arg from './Arg' | ||
import { addSuppress, makeBlock, getExternDeclaration, makeOptional } from './' | ||
import { getLink, trimD } from './' | ||
import Arg, { extractArgs } from './Arg' | ||
@@ -72,2 +72,12 @@ /** | ||
this.extends = null | ||
// /** | ||
// * The assignment arguments for constructors, interfaces, e.g., "string, number=" | ||
// * @type {?string} | ||
// */ | ||
// this._assignmentString = null | ||
/** | ||
* @type {Array<!Arg>} | ||
*/ | ||
this._args = null | ||
} | ||
@@ -106,21 +116,14 @@ /** | ||
const fns = extractTags('fn', content) | ||
const fn = [...functions, ...fns] | ||
const staticMethods = extractTags('static', content).map(a => { | ||
a['isStatic'] = true | ||
return a | ||
}) | ||
const fn = [...functions, ...fns, ...staticMethods] | ||
const fnProps = fn.map(({ content: c, props: 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 fnProps = fn.map(({ content: c, props: p, 'isStatic': isStatic }) => { | ||
const { newContent, argsArgs } = extractArgs(c) | ||
const { 'async': async, 'return': ret = 'void', ...rest } = p | ||
let { 'args': args = '' } = p | ||
if (!args && argsArgs.length) { | ||
@@ -138,6 +141,7 @@ args = argsArgs.map(({ type: at, optional }) => { | ||
const fnType = `function(${args}): ${r}` | ||
rest['type'] = fnType | ||
rest['type'] = fnType // e.g., a prop will have type `function()` | ||
const pr = new Property(argsArgs) | ||
pr.fromXML(c, rest) | ||
pr.fromXML(newContent, rest) | ||
if (isStatic) pr.staticMethod = true | ||
return pr | ||
@@ -152,2 +156,14 @@ }) | ||
} | ||
/** | ||
* When printing to externs, this is the right-hand part. | ||
* Used in constructors, interfaces. | ||
* @example | ||
* _ns.Type = function(paramA, paramB) | ||
* @param {!Array<!Arg>} array The parsed arguments | ||
*/ | ||
// * @param {string} string The inner arguments part as string | ||
setAssignment(array) { | ||
// this._assignmentString = string | ||
this._args = array | ||
} | ||
toExtern() { | ||
@@ -247,8 +263,12 @@ let s | ||
if (this.extends) pp.push(` * @extends {${this.extends}}`) | ||
if (this._args) this._args.forEach((s) => { | ||
const { name, description, optional, type } = s | ||
const arg = optional ? `[${name}]` : name | ||
const d = description ? ` ${description}` : '' | ||
pp.push(` * @param {${type}${optional ? '=' : ''}} ${arg}${d}`) | ||
}) | ||
const constr = this._args ? `function(${this._args.map(({ name }) => name)}) {}` : null | ||
pp.push(` * @${this.prototypeAnnotation}`) | ||
let s = makeBlock(pp.join('\n')) | ||
let constr | ||
// if (this.isConstructor || this.isInterface) { | ||
// constr = 'function() {}' | ||
// } | ||
s = s + getExternDeclaration(this.namespace, this.name, constr) | ||
@@ -265,3 +285,4 @@ /** @type {!Array<!Property>} */ | ||
r = makeBlock(r) | ||
r = r + getExternDeclaration(`${this.fullName}.prototype`, | ||
const prototype = p.staticMethod ? '' : '.prototype' | ||
r = r + getExternDeclaration(`${this.fullName}${prototype}`, | ||
/** @type {string} */ (p.name)) | ||
@@ -268,0 +289,0 @@ if (p.parsed && p.parsed.name == 'function') { |
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
300414
5499