protobufjs 6.11.2 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -174
- package/dist/light/protobuf.js +77 -29
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +27 -10
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +163 -61
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +9 -7
- package/package.json +14 -33
- package/scripts/postinstall.js +0 -3
- package/src/converter.js +10 -4
- package/src/decoder.js +4 -3
- package/src/enum.js +24 -7
- package/src/field.js +6 -3
- package/src/namespace.js +3 -3
- package/src/parse.js +55 -16
- package/src/roots.js +1 -1
- package/src/tokenize.js +31 -16
- package/src/util/minimal.js +24 -7
- package/src/util.js +3 -0
- package/src/wrappers.js +2 -2
- package/tsconfig.json +2 -1
- package/CHANGELOG.md +0 -1019
- package/bin/pbjs +0 -6
- package/bin/pbts +0 -6
- package/cli/LICENSE +0 -33
- package/cli/README.md +0 -174
- package/cli/bin/pbjs +0 -6
- package/cli/bin/pbts +0 -6
- package/cli/index.d.ts +0 -3
- package/cli/index.js +0 -3
- package/cli/lib/tsd-jsdoc/LICENSE +0 -21
- package/cli/lib/tsd-jsdoc/README.md +0 -23
- package/cli/lib/tsd-jsdoc/plugin.js +0 -21
- package/cli/lib/tsd-jsdoc/publish.js +0 -705
- package/cli/lib/tsd-jsdoc.json +0 -18
- package/cli/node_modules/.package-lock.json +0 -256
- package/cli/node_modules/acorn/CHANGELOG.md +0 -620
- package/cli/node_modules/acorn/LICENSE +0 -21
- package/cli/node_modules/acorn/README.md +0 -269
- package/cli/node_modules/acorn/bin/acorn +0 -4
- package/cli/node_modules/acorn/dist/acorn.d.ts +0 -209
- package/cli/node_modules/acorn/dist/acorn.js +0 -5186
- package/cli/node_modules/acorn/dist/acorn.js.map +0 -1
- package/cli/node_modules/acorn/dist/acorn.mjs +0 -5155
- package/cli/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
- package/cli/node_modules/acorn/dist/acorn.mjs.map +0 -1
- package/cli/node_modules/acorn/dist/bin.js +0 -64
- package/cli/node_modules/acorn/package.json +0 -35
- package/cli/node_modules/acorn-jsx/LICENSE +0 -19
- package/cli/node_modules/acorn-jsx/README.md +0 -40
- package/cli/node_modules/acorn-jsx/index.js +0 -488
- package/cli/node_modules/acorn-jsx/package.json +0 -27
- package/cli/node_modules/acorn-jsx/xhtml.js +0 -255
- package/cli/node_modules/balanced-match/.npmignore +0 -5
- package/cli/node_modules/balanced-match/LICENSE.md +0 -21
- package/cli/node_modules/balanced-match/README.md +0 -91
- package/cli/node_modules/balanced-match/index.js +0 -59
- package/cli/node_modules/balanced-match/package.json +0 -49
- package/cli/node_modules/brace-expansion/LICENSE +0 -21
- package/cli/node_modules/brace-expansion/README.md +0 -129
- package/cli/node_modules/brace-expansion/index.js +0 -201
- package/cli/node_modules/brace-expansion/package.json +0 -47
- package/cli/node_modules/concat-map/.travis.yml +0 -4
- package/cli/node_modules/concat-map/LICENSE +0 -18
- package/cli/node_modules/concat-map/README.markdown +0 -62
- package/cli/node_modules/concat-map/example/map.js +0 -6
- package/cli/node_modules/concat-map/index.js +0 -13
- package/cli/node_modules/concat-map/package.json +0 -43
- package/cli/node_modules/concat-map/test/map.js +0 -39
- package/cli/node_modules/deep-is/.npmignore +0 -1
- package/cli/node_modules/deep-is/.travis.yml +0 -6
- package/cli/node_modules/deep-is/LICENSE +0 -22
- package/cli/node_modules/deep-is/README.markdown +0 -70
- package/cli/node_modules/deep-is/example/cmp.js +0 -11
- package/cli/node_modules/deep-is/index.js +0 -102
- package/cli/node_modules/deep-is/package.json +0 -61
- package/cli/node_modules/deep-is/test/NaN.js +0 -16
- package/cli/node_modules/deep-is/test/cmp.js +0 -23
- package/cli/node_modules/deep-is/test/neg-vs-pos-0.js +0 -15
- package/cli/node_modules/escodegen/LICENSE.BSD +0 -21
- package/cli/node_modules/escodegen/README.md +0 -84
- package/cli/node_modules/escodegen/bin/escodegen.js +0 -77
- package/cli/node_modules/escodegen/bin/esgenerate.js +0 -64
- package/cli/node_modules/escodegen/escodegen.js +0 -2647
- package/cli/node_modules/escodegen/package.json +0 -62
- package/cli/node_modules/eslint-visitor-keys/CHANGELOG.md +0 -25
- package/cli/node_modules/eslint-visitor-keys/LICENSE +0 -201
- package/cli/node_modules/eslint-visitor-keys/README.md +0 -98
- package/cli/node_modules/eslint-visitor-keys/lib/index.js +0 -81
- package/cli/node_modules/eslint-visitor-keys/lib/visitor-keys.json +0 -284
- package/cli/node_modules/eslint-visitor-keys/package.json +0 -40
- package/cli/node_modules/espree/CHANGELOG.md +0 -509
- package/cli/node_modules/espree/LICENSE +0 -25
- package/cli/node_modules/espree/README.md +0 -233
- package/cli/node_modules/espree/espree.js +0 -177
- package/cli/node_modules/espree/lib/ast-node-types.js +0 -96
- package/cli/node_modules/espree/lib/espree.js +0 -286
- package/cli/node_modules/espree/lib/features.js +0 -29
- package/cli/node_modules/espree/lib/options.js +0 -106
- package/cli/node_modules/espree/lib/token-translator.js +0 -263
- package/cli/node_modules/espree/lib/visitor-keys.js +0 -123
- package/cli/node_modules/espree/package.json +0 -64
- package/cli/node_modules/esprima/ChangeLog +0 -235
- package/cli/node_modules/esprima/LICENSE.BSD +0 -21
- package/cli/node_modules/esprima/README.md +0 -46
- package/cli/node_modules/esprima/bin/esparse.js +0 -139
- package/cli/node_modules/esprima/bin/esvalidate.js +0 -236
- package/cli/node_modules/esprima/dist/esprima.js +0 -6709
- package/cli/node_modules/esprima/package.json +0 -112
- package/cli/node_modules/estraverse/.jshintrc +0 -16
- package/cli/node_modules/estraverse/LICENSE.BSD +0 -19
- package/cli/node_modules/estraverse/README.md +0 -153
- package/cli/node_modules/estraverse/estraverse.js +0 -801
- package/cli/node_modules/estraverse/gulpfile.js +0 -70
- package/cli/node_modules/estraverse/package.json +0 -40
- package/cli/node_modules/esutils/LICENSE.BSD +0 -19
- package/cli/node_modules/esutils/README.md +0 -174
- package/cli/node_modules/esutils/lib/ast.js +0 -144
- package/cli/node_modules/esutils/lib/code.js +0 -135
- package/cli/node_modules/esutils/lib/keyword.js +0 -165
- package/cli/node_modules/esutils/lib/utils.js +0 -33
- package/cli/node_modules/esutils/package.json +0 -44
- package/cli/node_modules/fast-levenshtein/LICENSE.md +0 -25
- package/cli/node_modules/fast-levenshtein/README.md +0 -104
- package/cli/node_modules/fast-levenshtein/levenshtein.js +0 -136
- package/cli/node_modules/fast-levenshtein/package.json +0 -39
- package/cli/node_modules/fs.realpath/LICENSE +0 -43
- package/cli/node_modules/fs.realpath/README.md +0 -33
- package/cli/node_modules/fs.realpath/index.js +0 -66
- package/cli/node_modules/fs.realpath/old.js +0 -303
- package/cli/node_modules/fs.realpath/package.json +0 -26
- package/cli/node_modules/glob/LICENSE +0 -21
- package/cli/node_modules/glob/README.md +0 -375
- package/cli/node_modules/glob/changelog.md +0 -67
- package/cli/node_modules/glob/common.js +0 -240
- package/cli/node_modules/glob/glob.js +0 -790
- package/cli/node_modules/glob/package.json +0 -46
- package/cli/node_modules/glob/sync.js +0 -486
- package/cli/node_modules/inflight/LICENSE +0 -15
- package/cli/node_modules/inflight/README.md +0 -37
- package/cli/node_modules/inflight/inflight.js +0 -54
- package/cli/node_modules/inflight/package.json +0 -29
- package/cli/node_modules/inherits/LICENSE +0 -16
- package/cli/node_modules/inherits/README.md +0 -42
- package/cli/node_modules/inherits/inherits.js +0 -9
- package/cli/node_modules/inherits/inherits_browser.js +0 -27
- package/cli/node_modules/inherits/package.json +0 -29
- package/cli/node_modules/levn/LICENSE +0 -22
- package/cli/node_modules/levn/README.md +0 -196
- package/cli/node_modules/levn/lib/cast.js +0 -298
- package/cli/node_modules/levn/lib/coerce.js +0 -285
- package/cli/node_modules/levn/lib/index.js +0 -22
- package/cli/node_modules/levn/lib/parse-string.js +0 -113
- package/cli/node_modules/levn/lib/parse.js +0 -102
- package/cli/node_modules/levn/package.json +0 -47
- package/cli/node_modules/minimatch/LICENSE +0 -15
- package/cli/node_modules/minimatch/README.md +0 -209
- package/cli/node_modules/minimatch/minimatch.js +0 -923
- package/cli/node_modules/minimatch/package.json +0 -30
- package/cli/node_modules/once/LICENSE +0 -15
- package/cli/node_modules/once/README.md +0 -79
- package/cli/node_modules/once/once.js +0 -42
- package/cli/node_modules/once/package.json +0 -33
- package/cli/node_modules/optionator/CHANGELOG.md +0 -56
- package/cli/node_modules/optionator/LICENSE +0 -22
- package/cli/node_modules/optionator/README.md +0 -238
- package/cli/node_modules/optionator/lib/help.js +0 -260
- package/cli/node_modules/optionator/lib/index.js +0 -465
- package/cli/node_modules/optionator/lib/util.js +0 -54
- package/cli/node_modules/optionator/package.json +0 -44
- package/cli/node_modules/path-is-absolute/index.js +0 -20
- package/cli/node_modules/path-is-absolute/license +0 -21
- package/cli/node_modules/path-is-absolute/package.json +0 -43
- package/cli/node_modules/path-is-absolute/readme.md +0 -59
- package/cli/node_modules/prelude-ls/CHANGELOG.md +0 -99
- package/cli/node_modules/prelude-ls/LICENSE +0 -22
- package/cli/node_modules/prelude-ls/README.md +0 -15
- package/cli/node_modules/prelude-ls/lib/Func.js +0 -65
- package/cli/node_modules/prelude-ls/lib/List.js +0 -686
- package/cli/node_modules/prelude-ls/lib/Num.js +0 -130
- package/cli/node_modules/prelude-ls/lib/Obj.js +0 -154
- package/cli/node_modules/prelude-ls/lib/Str.js +0 -92
- package/cli/node_modules/prelude-ls/lib/index.js +0 -178
- package/cli/node_modules/prelude-ls/package.json +0 -52
- package/cli/node_modules/rimraf/CHANGELOG.md +0 -65
- package/cli/node_modules/rimraf/LICENSE +0 -15
- package/cli/node_modules/rimraf/README.md +0 -101
- package/cli/node_modules/rimraf/bin.js +0 -68
- package/cli/node_modules/rimraf/package.json +0 -32
- package/cli/node_modules/rimraf/rimraf.js +0 -360
- package/cli/node_modules/source-map/CHANGELOG.md +0 -301
- package/cli/node_modules/source-map/LICENSE +0 -28
- package/cli/node_modules/source-map/README.md +0 -742
- package/cli/node_modules/source-map/dist/source-map.debug.js +0 -3234
- package/cli/node_modules/source-map/dist/source-map.js +0 -3233
- package/cli/node_modules/source-map/dist/source-map.min.js +0 -2
- package/cli/node_modules/source-map/dist/source-map.min.js.map +0 -1
- package/cli/node_modules/source-map/lib/array-set.js +0 -121
- package/cli/node_modules/source-map/lib/base64-vlq.js +0 -140
- package/cli/node_modules/source-map/lib/base64.js +0 -67
- package/cli/node_modules/source-map/lib/binary-search.js +0 -111
- package/cli/node_modules/source-map/lib/mapping-list.js +0 -79
- package/cli/node_modules/source-map/lib/quick-sort.js +0 -114
- package/cli/node_modules/source-map/lib/source-map-consumer.js +0 -1145
- package/cli/node_modules/source-map/lib/source-map-generator.js +0 -425
- package/cli/node_modules/source-map/lib/source-node.js +0 -413
- package/cli/node_modules/source-map/lib/util.js +0 -488
- package/cli/node_modules/source-map/package.json +0 -73
- package/cli/node_modules/source-map/source-map.d.ts +0 -98
- package/cli/node_modules/source-map/source-map.js +0 -8
- package/cli/node_modules/tmp/CHANGELOG.md +0 -288
- package/cli/node_modules/tmp/LICENSE +0 -21
- package/cli/node_modules/tmp/README.md +0 -365
- package/cli/node_modules/tmp/lib/tmp.js +0 -780
- package/cli/node_modules/tmp/package.json +0 -58
- package/cli/node_modules/type-check/LICENSE +0 -22
- package/cli/node_modules/type-check/README.md +0 -210
- package/cli/node_modules/type-check/lib/check.js +0 -126
- package/cli/node_modules/type-check/lib/index.js +0 -16
- package/cli/node_modules/type-check/lib/parse-type.js +0 -196
- package/cli/node_modules/type-check/package.json +0 -40
- package/cli/node_modules/word-wrap/LICENSE +0 -21
- package/cli/node_modules/word-wrap/README.md +0 -182
- package/cli/node_modules/word-wrap/index.d.ts +0 -50
- package/cli/node_modules/word-wrap/index.js +0 -46
- package/cli/node_modules/word-wrap/package.json +0 -77
- package/cli/node_modules/wrappy/LICENSE +0 -15
- package/cli/node_modules/wrappy/README.md +0 -36
- package/cli/node_modules/wrappy/package.json +0 -29
- package/cli/node_modules/wrappy/wrappy.js +0 -33
- package/cli/package.json +0 -8
- package/cli/package.standalone.json +0 -32
- package/cli/pbjs.d.ts +0 -9
- package/cli/pbjs.js +0 -330
- package/cli/pbts.d.ts +0 -9
- package/cli/pbts.js +0 -197
- package/cli/targets/json-module.js +0 -38
- package/cli/targets/json.js +0 -8
- package/cli/targets/proto.js +0 -326
- package/cli/targets/proto2.js +0 -10
- package/cli/targets/proto3.js +0 -10
- package/cli/targets/static-module.js +0 -29
- package/cli/targets/static.js +0 -711
- package/cli/util.js +0 -183
- package/cli/wrappers/amd.js +0 -7
- package/cli/wrappers/closure.js +0 -7
- package/cli/wrappers/commonjs.js +0 -7
- package/cli/wrappers/default.js +0 -15
- package/cli/wrappers/es6.js +0 -5
- package/dist/README.md +0 -31
- package/dist/light/README.md +0 -31
- package/dist/minimal/README.md +0 -31
|
@@ -1,705 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var fs = require("fs");
|
|
4
|
-
|
|
5
|
-
// output stream
|
|
6
|
-
var out = null;
|
|
7
|
-
|
|
8
|
-
// documentation data
|
|
9
|
-
var data = null;
|
|
10
|
-
|
|
11
|
-
// already handled objects, by name
|
|
12
|
-
var seen = {};
|
|
13
|
-
|
|
14
|
-
// indentation level
|
|
15
|
-
var indent = 0;
|
|
16
|
-
|
|
17
|
-
// whether indent has been written for the current line yet
|
|
18
|
-
var indentWritten = false;
|
|
19
|
-
|
|
20
|
-
// provided options
|
|
21
|
-
var options = {};
|
|
22
|
-
|
|
23
|
-
// queued interfaces
|
|
24
|
-
var queuedInterfaces = [];
|
|
25
|
-
|
|
26
|
-
// whether writing the first line
|
|
27
|
-
var firstLine = true;
|
|
28
|
-
|
|
29
|
-
// JSDoc hook
|
|
30
|
-
exports.publish = function publish(taffy, opts) {
|
|
31
|
-
options = opts || {};
|
|
32
|
-
|
|
33
|
-
// query overrides options
|
|
34
|
-
if (options.query)
|
|
35
|
-
Object.keys(options.query).forEach(function(key) {
|
|
36
|
-
if (key !== "query")
|
|
37
|
-
switch (options[key] = options.query[key]) {
|
|
38
|
-
case "true":
|
|
39
|
-
options[key] = true;
|
|
40
|
-
break;
|
|
41
|
-
case "false":
|
|
42
|
-
options[key] = false;
|
|
43
|
-
break;
|
|
44
|
-
case "null":
|
|
45
|
-
options[key] = null;
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// remove undocumented
|
|
51
|
-
taffy({ undocumented: true }).remove();
|
|
52
|
-
taffy({ ignore: true }).remove();
|
|
53
|
-
taffy({ inherited: true }).remove();
|
|
54
|
-
|
|
55
|
-
// remove private
|
|
56
|
-
if (!options.private)
|
|
57
|
-
taffy({ access: "private" }).remove();
|
|
58
|
-
|
|
59
|
-
// setup output
|
|
60
|
-
out = options.destination
|
|
61
|
-
? fs.createWriteStream(options.destination)
|
|
62
|
-
: process.stdout;
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
// setup environment
|
|
66
|
-
data = taffy().get();
|
|
67
|
-
indent = 0;
|
|
68
|
-
indentWritten = false;
|
|
69
|
-
firstLine = true;
|
|
70
|
-
|
|
71
|
-
// wrap everything in a module if configured
|
|
72
|
-
if (options.module) {
|
|
73
|
-
writeln("export = ", options.module, ";");
|
|
74
|
-
writeln();
|
|
75
|
-
writeln("declare namespace ", options.module, " {");
|
|
76
|
-
writeln();
|
|
77
|
-
++indent;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// handle all
|
|
81
|
-
getChildrenOf(undefined).forEach(function(child) {
|
|
82
|
-
handleElement(child, null);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// process queued
|
|
86
|
-
while (queuedInterfaces.length) {
|
|
87
|
-
var element = queuedInterfaces.shift();
|
|
88
|
-
begin(element);
|
|
89
|
-
writeInterface(element);
|
|
90
|
-
writeln(";");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// end wrap
|
|
94
|
-
if (options.module) {
|
|
95
|
-
--indent;
|
|
96
|
-
writeln("}");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// close file output
|
|
100
|
-
if (out !== process.stdout)
|
|
101
|
-
out.end();
|
|
102
|
-
|
|
103
|
-
} finally {
|
|
104
|
-
// gc environment objects
|
|
105
|
-
out = data = null;
|
|
106
|
-
seen = options = {};
|
|
107
|
-
queuedInterfaces = [];
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
// Utility
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
// writes one or multiple strings
|
|
116
|
-
function write() {
|
|
117
|
-
var s = Array.prototype.slice.call(arguments).join("");
|
|
118
|
-
if (!indentWritten) {
|
|
119
|
-
for (var i = 0; i < indent; ++i)
|
|
120
|
-
s = " " + s;
|
|
121
|
-
indentWritten = true;
|
|
122
|
-
}
|
|
123
|
-
out.write(s);
|
|
124
|
-
firstLine = false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// writes zero or multiple strings, followed by a new line
|
|
128
|
-
function writeln() {
|
|
129
|
-
var s = Array.prototype.slice.call(arguments).join("");
|
|
130
|
-
if (s.length)
|
|
131
|
-
write(s, "\n");
|
|
132
|
-
else if (!firstLine)
|
|
133
|
-
out.write("\n");
|
|
134
|
-
indentWritten = false;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
var keepTags = [
|
|
138
|
-
"param",
|
|
139
|
-
"returns",
|
|
140
|
-
"throws",
|
|
141
|
-
"see"
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
// parses a comment into text and tags
|
|
145
|
-
function parseComment(comment) {
|
|
146
|
-
var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n|\r/g); // property.description has just "\r" ?!
|
|
147
|
-
var desc;
|
|
148
|
-
var text = [];
|
|
149
|
-
var tags = null;
|
|
150
|
-
for (var i = 0; i < lines.length; ++i) {
|
|
151
|
-
var match = /^@(\w+)\b/.exec(lines[i]);
|
|
152
|
-
if (match) {
|
|
153
|
-
if (!tags) {
|
|
154
|
-
tags = [];
|
|
155
|
-
desc = text;
|
|
156
|
-
}
|
|
157
|
-
text = [];
|
|
158
|
-
tags.push({ name: match[1], text: text });
|
|
159
|
-
lines[i] = lines[i].substring(match[1].length + 1).trim();
|
|
160
|
-
}
|
|
161
|
-
if (lines[i].length || text.length)
|
|
162
|
-
text.push(lines[i]);
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
text: desc || text,
|
|
166
|
-
tags: tags || []
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// writes a comment
|
|
171
|
-
function writeComment(comment, otherwiseNewline) {
|
|
172
|
-
if (!comment || options.comments === false) {
|
|
173
|
-
if (otherwiseNewline)
|
|
174
|
-
writeln();
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (typeof comment !== "object")
|
|
178
|
-
comment = parseComment(comment);
|
|
179
|
-
comment.tags = comment.tags.filter(function(tag) {
|
|
180
|
-
return keepTags.indexOf(tag.name) > -1 && (tag.name !== "returns" || tag.text[0] !== "{undefined}");
|
|
181
|
-
});
|
|
182
|
-
writeln();
|
|
183
|
-
if (!comment.tags.length && comment.text.length < 2) {
|
|
184
|
-
writeln("/** " + comment.text[0] + " */");
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
writeln("/**");
|
|
188
|
-
comment.text.forEach(function(line) {
|
|
189
|
-
if (line.length)
|
|
190
|
-
writeln(" * ", line);
|
|
191
|
-
else
|
|
192
|
-
writeln(" *");
|
|
193
|
-
});
|
|
194
|
-
comment.tags.forEach(function(tag) {
|
|
195
|
-
var started = false;
|
|
196
|
-
if (tag.text.length) {
|
|
197
|
-
tag.text.forEach(function(line, i) {
|
|
198
|
-
if (i > 0)
|
|
199
|
-
write(" * ");
|
|
200
|
-
else if (tag.name !== "throws")
|
|
201
|
-
line = line.replace(/^\{[^\s]*} ?/, "");
|
|
202
|
-
if (!line.length)
|
|
203
|
-
return;
|
|
204
|
-
if (!started) {
|
|
205
|
-
write(" * @", tag.name, " ");
|
|
206
|
-
started = true;
|
|
207
|
-
}
|
|
208
|
-
writeln(line);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
writeln(" */");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// recursively replaces all occurencies of re's match
|
|
216
|
-
function replaceRecursive(name, re, fn) {
|
|
217
|
-
var found;
|
|
218
|
-
|
|
219
|
-
function replacer() {
|
|
220
|
-
found = true;
|
|
221
|
-
return fn.apply(null, arguments);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
do {
|
|
225
|
-
found = false;
|
|
226
|
-
name = name.replace(re, replacer);
|
|
227
|
-
} while (found);
|
|
228
|
-
return name;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// tests if an element is considered to be a class or class-like
|
|
232
|
-
function isClassLike(element) {
|
|
233
|
-
return isClass(element) || isInterface(element);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// tests if an element is considered to be a class
|
|
237
|
-
function isClass(element) {
|
|
238
|
-
return element && element.kind === "class";
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// tests if an element is considered to be an interface
|
|
242
|
-
function isInterface(element) {
|
|
243
|
-
return element && (element.kind === "interface" || element.kind === "mixin");
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// tests if an element is considered to be a namespace
|
|
247
|
-
function isNamespace(element) {
|
|
248
|
-
return element && (element.kind === "namespace" || element.kind === "module");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// gets all children of the specified parent
|
|
252
|
-
function getChildrenOf(parent) {
|
|
253
|
-
var memberof = parent ? parent.longname : undefined;
|
|
254
|
-
return data.filter(function(element) {
|
|
255
|
-
return element.memberof === memberof;
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// gets the literal type of an element
|
|
260
|
-
function getTypeOf(element) {
|
|
261
|
-
if (element.tsType)
|
|
262
|
-
return element.tsType.replace(/\r?\n|\r/g, "\n");
|
|
263
|
-
var name = "any";
|
|
264
|
-
var type = element.type;
|
|
265
|
-
if (type && type.names && type.names.length) {
|
|
266
|
-
if (type.names.length === 1)
|
|
267
|
-
name = element.type.names[0].trim();
|
|
268
|
-
else
|
|
269
|
-
name = "(" + element.type.names.join("|") + ")";
|
|
270
|
-
} else
|
|
271
|
-
return name;
|
|
272
|
-
|
|
273
|
-
// Replace catchalls with any
|
|
274
|
-
name = name.replace(/\*|\bmixed\b/g, "any");
|
|
275
|
-
|
|
276
|
-
// Ensure upper case Object for map expressions below
|
|
277
|
-
name = name.replace(/\bobject\b/g, "Object");
|
|
278
|
-
|
|
279
|
-
// Correct Something.<Something> to Something<Something>
|
|
280
|
-
name = replaceRecursive(name, /\b(?!Object|Array)([\w$]+)\.<([^>]*)>/gi, function($0, $1, $2) {
|
|
281
|
-
return $1 + "<" + $2 + ">";
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
// Replace Array.<string> with string[]
|
|
285
|
-
name = replaceRecursive(name, /\bArray\.?<([^>]*)>/gi, function($0, $1) {
|
|
286
|
-
return $1 + "[]";
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// Replace Object.<string,number> with { [k: string]: number }
|
|
290
|
-
name = replaceRecursive(name, /\bObject\.?<([^,]*), *([^>]*)>/gi, function($0, $1, $2) {
|
|
291
|
-
return "{ [k: " + $1 + "]: " + $2 + " }";
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// Replace functions (there are no signatures) with Function
|
|
295
|
-
name = name.replace(/\bfunction(?:\(\))?\b/g, "Function");
|
|
296
|
-
|
|
297
|
-
// Convert plain Object back to just object
|
|
298
|
-
name = name.replace(/\b(Object\b(?!\.))/g, function($0, $1) {
|
|
299
|
-
return $1.toLowerCase();
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
return name;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// begins writing the definition of the specified element
|
|
306
|
-
function begin(element, is_interface) {
|
|
307
|
-
if (!seen[element.longname]) {
|
|
308
|
-
if (isClass(element)) {
|
|
309
|
-
var comment = parseComment(element.comment);
|
|
310
|
-
var classdesc = comment.tags.find(function(tag) { return tag.name === "classdesc"; });
|
|
311
|
-
if (classdesc) {
|
|
312
|
-
comment.text = classdesc.text;
|
|
313
|
-
comment.tags = [];
|
|
314
|
-
}
|
|
315
|
-
writeComment(comment, true);
|
|
316
|
-
} else
|
|
317
|
-
writeComment(element.comment, is_interface || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
|
|
318
|
-
seen[element.longname] = element;
|
|
319
|
-
} else
|
|
320
|
-
writeln();
|
|
321
|
-
// ????: something changed in JSDoc 3.6.0? so that @exports + @enum does
|
|
322
|
-
// no longer yield a 'global' scope, but is some sort of unscoped module
|
|
323
|
-
// element now. The additional condition added below works around this.
|
|
324
|
-
if ((element.scope === "global" || element.isEnum && element.scope === undefined) && !options.module)
|
|
325
|
-
write("export ");
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// writes the function signature describing element
|
|
329
|
-
function writeFunctionSignature(element, isConstructor, isTypeDef) {
|
|
330
|
-
write("(");
|
|
331
|
-
|
|
332
|
-
var params = {};
|
|
333
|
-
|
|
334
|
-
// this type
|
|
335
|
-
if (element.this)
|
|
336
|
-
params["this"] = {
|
|
337
|
-
type: element.this.replace(/^{|}$/g, ""),
|
|
338
|
-
optional: false
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// parameter types
|
|
342
|
-
if (element.params)
|
|
343
|
-
element.params.forEach(function(param) {
|
|
344
|
-
var path = param.name.split(/\./g);
|
|
345
|
-
if (path.length === 1)
|
|
346
|
-
params[param.name] = {
|
|
347
|
-
type: getTypeOf(param),
|
|
348
|
-
variable: param.variable === true,
|
|
349
|
-
optional: param.optional === true,
|
|
350
|
-
defaultValue: param.defaultvalue // Not used yet (TODO)
|
|
351
|
-
};
|
|
352
|
-
else // Property syntax (TODO)
|
|
353
|
-
params[path[0]].type = "{ [k: string]: any }";
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
var paramNames = Object.keys(params);
|
|
357
|
-
paramNames.forEach(function(name, i) {
|
|
358
|
-
var param = params[name];
|
|
359
|
-
var type = param.type;
|
|
360
|
-
if (param.variable) {
|
|
361
|
-
name = "..." + name;
|
|
362
|
-
type = param.type.charAt(0) === "(" ? "any[]" : param.type + "[]";
|
|
363
|
-
}
|
|
364
|
-
write(name, !param.variable && param.optional ? "?: " : ": ", type);
|
|
365
|
-
if (i < paramNames.length - 1)
|
|
366
|
-
write(", ");
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
write(")");
|
|
370
|
-
|
|
371
|
-
// return type
|
|
372
|
-
if (!isConstructor) {
|
|
373
|
-
write(isTypeDef ? " => " : ": ");
|
|
374
|
-
var typeName;
|
|
375
|
-
if (element.returns && element.returns.length && (typeName = getTypeOf(element.returns[0])) !== "undefined")
|
|
376
|
-
write(typeName);
|
|
377
|
-
else
|
|
378
|
-
write("void");
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// writes (a typedef as) an interface
|
|
383
|
-
function writeInterface(element) {
|
|
384
|
-
write("interface ", element.name);
|
|
385
|
-
writeInterfaceBody(element);
|
|
386
|
-
writeln();
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function writeInterfaceBody(element) {
|
|
390
|
-
writeln("{");
|
|
391
|
-
++indent;
|
|
392
|
-
if (element.tsType)
|
|
393
|
-
writeln(element.tsType.replace(/\r?\n|\r/g, "\n"));
|
|
394
|
-
else if (element.properties && element.properties.length)
|
|
395
|
-
element.properties.forEach(writeProperty);
|
|
396
|
-
--indent;
|
|
397
|
-
write("}");
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function writeProperty(property, declare) {
|
|
401
|
-
writeComment(property.description);
|
|
402
|
-
if (declare)
|
|
403
|
-
write("let ");
|
|
404
|
-
write(property.name);
|
|
405
|
-
if (property.optional)
|
|
406
|
-
write("?");
|
|
407
|
-
writeln(": ", getTypeOf(property), ";");
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
//
|
|
411
|
-
// Handlers
|
|
412
|
-
//
|
|
413
|
-
|
|
414
|
-
// handles a single element of any understood type
|
|
415
|
-
function handleElement(element, parent) {
|
|
416
|
-
if (element.scope === "inner")
|
|
417
|
-
return false;
|
|
418
|
-
|
|
419
|
-
if (element.optional !== true && element.type && element.type.names && element.type.names.length) {
|
|
420
|
-
for (var i = 0; i < element.type.names.length; i++) {
|
|
421
|
-
if (element.type.names[i].toLowerCase() === "undefined") {
|
|
422
|
-
// This element is actually optional. Set optional to true and
|
|
423
|
-
// remove the 'undefined' type
|
|
424
|
-
element.optional = true;
|
|
425
|
-
element.type.names.splice(i, 1);
|
|
426
|
-
i--;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (seen[element.longname])
|
|
432
|
-
return true;
|
|
433
|
-
if (isClassLike(element))
|
|
434
|
-
handleClass(element, parent);
|
|
435
|
-
else switch (element.kind) {
|
|
436
|
-
case "module":
|
|
437
|
-
if (element.isEnum) {
|
|
438
|
-
handleEnum(element, parent);
|
|
439
|
-
break;
|
|
440
|
-
}
|
|
441
|
-
// eslint-disable-line no-fallthrough
|
|
442
|
-
case "namespace":
|
|
443
|
-
handleNamespace(element, parent);
|
|
444
|
-
break;
|
|
445
|
-
case "constant":
|
|
446
|
-
case "member":
|
|
447
|
-
handleMember(element, parent);
|
|
448
|
-
break;
|
|
449
|
-
case "function":
|
|
450
|
-
handleFunction(element, parent);
|
|
451
|
-
break;
|
|
452
|
-
case "typedef":
|
|
453
|
-
handleTypeDef(element, parent);
|
|
454
|
-
break;
|
|
455
|
-
case "package":
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
seen[element.longname] = element;
|
|
459
|
-
return true;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// handles (just) a namespace
|
|
463
|
-
function handleNamespace(element/*, parent*/) {
|
|
464
|
-
var children = getChildrenOf(element);
|
|
465
|
-
if (!children.length)
|
|
466
|
-
return;
|
|
467
|
-
var first = true;
|
|
468
|
-
if (element.properties)
|
|
469
|
-
element.properties.forEach(function(property) {
|
|
470
|
-
if (!/^[$\w]+$/.test(property.name)) // incompatible in namespace
|
|
471
|
-
return;
|
|
472
|
-
if (first) {
|
|
473
|
-
begin(element);
|
|
474
|
-
writeln("namespace ", element.name, " {");
|
|
475
|
-
++indent;
|
|
476
|
-
first = false;
|
|
477
|
-
}
|
|
478
|
-
writeProperty(property, true);
|
|
479
|
-
});
|
|
480
|
-
children.forEach(function(child) {
|
|
481
|
-
if (child.scope === "inner" || seen[child.longname])
|
|
482
|
-
return;
|
|
483
|
-
if (first) {
|
|
484
|
-
begin(element);
|
|
485
|
-
writeln("namespace ", element.name, " {");
|
|
486
|
-
++indent;
|
|
487
|
-
first = false;
|
|
488
|
-
}
|
|
489
|
-
handleElement(child, element);
|
|
490
|
-
});
|
|
491
|
-
if (!first) {
|
|
492
|
-
--indent;
|
|
493
|
-
writeln("}");
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// a filter function to remove any module references
|
|
498
|
-
function notAModuleReference(ref) {
|
|
499
|
-
return ref.indexOf("module:") === -1;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// handles a class or class-like
|
|
503
|
-
function handleClass(element, parent) {
|
|
504
|
-
var is_interface = isInterface(element);
|
|
505
|
-
begin(element, is_interface);
|
|
506
|
-
if (is_interface)
|
|
507
|
-
write("interface ");
|
|
508
|
-
else {
|
|
509
|
-
if (element.virtual)
|
|
510
|
-
write("abstract ");
|
|
511
|
-
write("class ");
|
|
512
|
-
}
|
|
513
|
-
write(element.name);
|
|
514
|
-
if (element.templates && element.templates.length)
|
|
515
|
-
write("<", element.templates.join(", "), ">");
|
|
516
|
-
write(" ");
|
|
517
|
-
|
|
518
|
-
// extended classes
|
|
519
|
-
if (element.augments) {
|
|
520
|
-
var augments = element.augments.filter(notAModuleReference);
|
|
521
|
-
if (augments.length)
|
|
522
|
-
write("extends ", augments[0], " ");
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// implemented interfaces
|
|
526
|
-
var impls = [];
|
|
527
|
-
if (element.implements)
|
|
528
|
-
Array.prototype.push.apply(impls, element.implements);
|
|
529
|
-
if (element.mixes)
|
|
530
|
-
Array.prototype.push.apply(impls, element.mixes);
|
|
531
|
-
impls = impls.filter(notAModuleReference);
|
|
532
|
-
if (impls.length)
|
|
533
|
-
write("implements ", impls.join(", "), " ");
|
|
534
|
-
|
|
535
|
-
writeln("{");
|
|
536
|
-
++indent;
|
|
537
|
-
|
|
538
|
-
if (element.tsType)
|
|
539
|
-
writeln(element.tsType.replace(/\r?\n|\r/g, "\n"));
|
|
540
|
-
|
|
541
|
-
// constructor
|
|
542
|
-
if (!is_interface && !element.virtual)
|
|
543
|
-
handleFunction(element, parent, true);
|
|
544
|
-
|
|
545
|
-
// properties
|
|
546
|
-
if (is_interface && element.properties)
|
|
547
|
-
element.properties.forEach(function(property) {
|
|
548
|
-
writeProperty(property);
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
// class-compatible members
|
|
552
|
-
var incompatible = [];
|
|
553
|
-
getChildrenOf(element).forEach(function(child) {
|
|
554
|
-
if (isClassLike(child) || child.kind === "module" || child.kind === "typedef" || child.isEnum) {
|
|
555
|
-
incompatible.push(child);
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
handleElement(child, element);
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
--indent;
|
|
562
|
-
writeln("}");
|
|
563
|
-
|
|
564
|
-
// class-incompatible members
|
|
565
|
-
if (incompatible.length) {
|
|
566
|
-
writeln();
|
|
567
|
-
if (element.scope === "global" && !options.module)
|
|
568
|
-
write("export ");
|
|
569
|
-
writeln("namespace ", element.name, " {");
|
|
570
|
-
++indent;
|
|
571
|
-
incompatible.forEach(function(child) {
|
|
572
|
-
handleElement(child, element);
|
|
573
|
-
});
|
|
574
|
-
--indent;
|
|
575
|
-
writeln("}");
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
// handles an enum
|
|
580
|
-
function handleEnum(element) {
|
|
581
|
-
begin(element);
|
|
582
|
-
|
|
583
|
-
var stringEnum = false;
|
|
584
|
-
element.properties.forEach(function(property) {
|
|
585
|
-
if (isNaN(property.defaultvalue)) {
|
|
586
|
-
stringEnum = true;
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
if (stringEnum) {
|
|
590
|
-
writeln("type ", element.name, " =");
|
|
591
|
-
++indent;
|
|
592
|
-
element.properties.forEach(function(property, i) {
|
|
593
|
-
write(i === 0 ? "" : "| ", JSON.stringify(property.defaultvalue));
|
|
594
|
-
});
|
|
595
|
-
--indent;
|
|
596
|
-
writeln(";");
|
|
597
|
-
} else {
|
|
598
|
-
writeln("enum ", element.name, " {");
|
|
599
|
-
++indent;
|
|
600
|
-
element.properties.forEach(function(property, i) {
|
|
601
|
-
write(property.name);
|
|
602
|
-
if (property.defaultvalue !== undefined)
|
|
603
|
-
write(" = ", JSON.stringify(property.defaultvalue));
|
|
604
|
-
if (i < element.properties.length - 1)
|
|
605
|
-
writeln(",");
|
|
606
|
-
else
|
|
607
|
-
writeln();
|
|
608
|
-
});
|
|
609
|
-
--indent;
|
|
610
|
-
writeln("}");
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// handles a namespace or class member
|
|
615
|
-
function handleMember(element, parent) {
|
|
616
|
-
if (element.isEnum) {
|
|
617
|
-
handleEnum(element);
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
begin(element);
|
|
621
|
-
|
|
622
|
-
var inClass = isClassLike(parent);
|
|
623
|
-
if (inClass) {
|
|
624
|
-
write(element.access || "public", " ");
|
|
625
|
-
if (element.scope === "static")
|
|
626
|
-
write("static ");
|
|
627
|
-
if (element.readonly)
|
|
628
|
-
write("readonly ");
|
|
629
|
-
} else
|
|
630
|
-
write(element.kind === "constant" ? "const " : "let ");
|
|
631
|
-
|
|
632
|
-
write(element.name);
|
|
633
|
-
if (element.optional)
|
|
634
|
-
write("?");
|
|
635
|
-
write(": ");
|
|
636
|
-
|
|
637
|
-
if (element.type && element.type.names && /^Object\b/i.test(element.type.names[0]) && element.properties) {
|
|
638
|
-
writeln("{");
|
|
639
|
-
++indent;
|
|
640
|
-
element.properties.forEach(function(property, i) {
|
|
641
|
-
writeln(JSON.stringify(property.name), ": ", getTypeOf(property), i < element.properties.length - 1 ? "," : "");
|
|
642
|
-
});
|
|
643
|
-
--indent;
|
|
644
|
-
writeln("};");
|
|
645
|
-
} else
|
|
646
|
-
writeln(getTypeOf(element), ";");
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// handles a function or method
|
|
650
|
-
function handleFunction(element, parent, isConstructor) {
|
|
651
|
-
var insideClass = true;
|
|
652
|
-
if (isConstructor) {
|
|
653
|
-
writeComment(element.comment);
|
|
654
|
-
write("constructor");
|
|
655
|
-
} else {
|
|
656
|
-
begin(element);
|
|
657
|
-
insideClass = isClassLike(parent);
|
|
658
|
-
if (insideClass) {
|
|
659
|
-
write(element.access || "public", " ");
|
|
660
|
-
if (element.scope === "static")
|
|
661
|
-
write("static ");
|
|
662
|
-
} else
|
|
663
|
-
write("function ");
|
|
664
|
-
write(element.name);
|
|
665
|
-
if (element.templates && element.templates.length)
|
|
666
|
-
write("<", element.templates.join(", "), ">");
|
|
667
|
-
}
|
|
668
|
-
writeFunctionSignature(element, isConstructor, false);
|
|
669
|
-
writeln(";");
|
|
670
|
-
if (!insideClass)
|
|
671
|
-
handleNamespace(element);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// handles a type definition (not a real type)
|
|
675
|
-
function handleTypeDef(element, parent) {
|
|
676
|
-
if (isInterface(element)) {
|
|
677
|
-
if (isClassLike(parent))
|
|
678
|
-
queuedInterfaces.push(element);
|
|
679
|
-
else {
|
|
680
|
-
begin(element);
|
|
681
|
-
writeInterface(element);
|
|
682
|
-
}
|
|
683
|
-
} else {
|
|
684
|
-
writeComment(element.comment, true);
|
|
685
|
-
write("type ", element.name);
|
|
686
|
-
if (element.templates && element.templates.length)
|
|
687
|
-
write("<", element.templates.join(", "), ">");
|
|
688
|
-
write(" = ");
|
|
689
|
-
if (element.tsType)
|
|
690
|
-
write(element.tsType.replace(/\r?\n|\r/g, "\n"));
|
|
691
|
-
else {
|
|
692
|
-
var type = getTypeOf(element);
|
|
693
|
-
if (element.type && element.type.names.length === 1 && element.type.names[0] === "function")
|
|
694
|
-
writeFunctionSignature(element, false, true);
|
|
695
|
-
else if (type === "object") {
|
|
696
|
-
if (element.properties && element.properties.length)
|
|
697
|
-
writeInterfaceBody(element);
|
|
698
|
-
else
|
|
699
|
-
write("{}");
|
|
700
|
-
} else
|
|
701
|
-
write(type);
|
|
702
|
-
}
|
|
703
|
-
writeln(";");
|
|
704
|
-
}
|
|
705
|
-
}
|