@depup/apollo__protobufjs 1.2.7-depup.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/LICENSE +39 -0
- package/README.md +32 -0
- package/bin/pbjs +6 -0
- package/bin/pbts +6 -0
- package/changes.json +14 -0
- package/cli/LICENSE +33 -0
- package/cli/README.md +11 -0
- package/cli/bin/pbjs +6 -0
- package/cli/bin/pbts +6 -0
- package/cli/index.d.ts +3 -0
- package/cli/index.js +3 -0
- package/cli/lib/tsd-jsdoc/LICENSE +21 -0
- package/cli/lib/tsd-jsdoc/README.md +23 -0
- package/cli/lib/tsd-jsdoc/plugin.js +21 -0
- package/cli/lib/tsd-jsdoc/publish.js +693 -0
- package/cli/lib/tsd-jsdoc.json +18 -0
- package/cli/package.json +7 -0
- package/cli/package.standalone.json +32 -0
- package/cli/pbjs.d.ts +9 -0
- package/cli/pbjs.js +331 -0
- package/cli/pbts.d.ts +9 -0
- package/cli/pbts.js +198 -0
- package/cli/targets/json-module.js +38 -0
- package/cli/targets/json.js +8 -0
- package/cli/targets/proto.js +326 -0
- package/cli/targets/proto2.js +10 -0
- package/cli/targets/proto3.js +10 -0
- package/cli/targets/static-module.js +29 -0
- package/cli/targets/static.js +709 -0
- package/cli/util.js +183 -0
- package/cli/wrappers/amd.js +7 -0
- package/cli/wrappers/closure.js +7 -0
- package/cli/wrappers/commonjs.js +7 -0
- package/cli/wrappers/default.js +15 -0
- package/cli/wrappers/es6.js +5 -0
- package/dist/README.md +31 -0
- package/dist/light/README.md +31 -0
- package/dist/light/protobuf.js +7198 -0
- package/dist/light/protobuf.js.map +1 -0
- package/dist/light/protobuf.min.js +7 -0
- package/dist/light/protobuf.min.js.map +1 -0
- package/dist/minimal/README.md +31 -0
- package/dist/minimal/protobuf.js +2675 -0
- package/dist/minimal/protobuf.js.map +1 -0
- package/dist/minimal/protobuf.min.js +7 -0
- package/dist/minimal/protobuf.min.js.map +1 -0
- package/dist/protobuf.js +8775 -0
- package/dist/protobuf.js.map +1 -0
- package/dist/protobuf.min.js +7 -0
- package/dist/protobuf.min.js.map +1 -0
- package/ext/debug/README.md +4 -0
- package/ext/debug/index.js +71 -0
- package/ext/descriptor/README.md +72 -0
- package/ext/descriptor/index.d.ts +191 -0
- package/ext/descriptor/index.js +1052 -0
- package/ext/descriptor/test.js +54 -0
- package/google/LICENSE +27 -0
- package/google/README.md +1 -0
- package/google/api/annotations.json +83 -0
- package/google/api/annotations.proto +11 -0
- package/google/api/http.json +86 -0
- package/google/api/http.proto +31 -0
- package/google/protobuf/api.json +118 -0
- package/google/protobuf/api.proto +34 -0
- package/google/protobuf/descriptor.json +739 -0
- package/google/protobuf/descriptor.proto +286 -0
- package/google/protobuf/source_context.json +20 -0
- package/google/protobuf/source_context.proto +7 -0
- package/google/protobuf/type.json +202 -0
- package/google/protobuf/type.proto +89 -0
- package/index.d.ts +2628 -0
- package/index.js +4 -0
- package/light.d.ts +2 -0
- package/light.js +4 -0
- package/minimal.d.ts +2 -0
- package/minimal.js +4 -0
- package/package.json +147 -0
- package/scripts/postinstall.js +35 -0
- package/src/common.js +399 -0
- package/src/converter.js +304 -0
- package/src/decoder.js +106 -0
- package/src/encoder.js +119 -0
- package/src/enum.js +181 -0
- package/src/field.js +379 -0
- package/src/index-light.js +104 -0
- package/src/index-minimal.js +36 -0
- package/src/index.js +12 -0
- package/src/mapfield.js +126 -0
- package/src/message.js +139 -0
- package/src/method.js +151 -0
- package/src/namespace.js +433 -0
- package/src/object.js +200 -0
- package/src/oneof.js +203 -0
- package/src/parse.js +761 -0
- package/src/reader.js +405 -0
- package/src/reader_buffer.js +44 -0
- package/src/root.js +353 -0
- package/src/roots.js +18 -0
- package/src/rpc/service.js +142 -0
- package/src/rpc.js +36 -0
- package/src/service.js +167 -0
- package/src/tokenize.js +397 -0
- package/src/type.js +589 -0
- package/src/types.js +196 -0
- package/src/typescript.jsdoc +22 -0
- package/src/util/longbits.js +200 -0
- package/src/util/minimal.js +406 -0
- package/src/util.js +178 -0
- package/src/verifier.js +191 -0
- package/src/wrappers.js +83 -0
- package/src/writer.js +459 -0
- package/src/writer_buffer.js +81 -0
- package/tsconfig.json +7 -0
package/src/service.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = Service;
|
|
3
|
+
|
|
4
|
+
// extends Namespace
|
|
5
|
+
var Namespace = require("./namespace");
|
|
6
|
+
((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
|
|
7
|
+
|
|
8
|
+
var Method = require("./method"),
|
|
9
|
+
util = require("./util"),
|
|
10
|
+
rpc = require("./rpc");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new service instance.
|
|
14
|
+
* @classdesc Reflected service.
|
|
15
|
+
* @extends NamespaceBase
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {string} name Service name
|
|
18
|
+
* @param {Object.<string,*>} [options] Service options
|
|
19
|
+
* @throws {TypeError} If arguments are invalid
|
|
20
|
+
*/
|
|
21
|
+
function Service(name, options) {
|
|
22
|
+
Namespace.call(this, name, options);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Service methods.
|
|
26
|
+
* @type {Object.<string,Method>}
|
|
27
|
+
*/
|
|
28
|
+
this.methods = {}; // toJSON, marker
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Cached methods as an array.
|
|
32
|
+
* @type {Method[]|null}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
this._methodsArray = null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Service descriptor.
|
|
40
|
+
* @interface IService
|
|
41
|
+
* @extends INamespace
|
|
42
|
+
* @property {Object.<string,IMethod>} methods Method descriptors
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Constructs a service from a service descriptor.
|
|
47
|
+
* @param {string} name Service name
|
|
48
|
+
* @param {IService} json Service descriptor
|
|
49
|
+
* @returns {Service} Created service
|
|
50
|
+
* @throws {TypeError} If arguments are invalid
|
|
51
|
+
*/
|
|
52
|
+
Service.fromJSON = function fromJSON(name, json) {
|
|
53
|
+
var service = new Service(name, json.options);
|
|
54
|
+
/* istanbul ignore else */
|
|
55
|
+
if (json.methods)
|
|
56
|
+
for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
|
|
57
|
+
service.add(Method.fromJSON(names[i], json.methods[names[i]]));
|
|
58
|
+
if (json.nested)
|
|
59
|
+
service.addJSON(json.nested);
|
|
60
|
+
service.comment = json.comment;
|
|
61
|
+
return service;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts this service to a service descriptor.
|
|
66
|
+
* @param {IToJSONOptions} [toJSONOptions] JSON conversion options
|
|
67
|
+
* @returns {IService} Service descriptor
|
|
68
|
+
*/
|
|
69
|
+
Service.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
70
|
+
var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
|
|
71
|
+
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
|
|
72
|
+
return util.toObject([
|
|
73
|
+
"options" , inherited && inherited.options || undefined,
|
|
74
|
+
"methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
|
|
75
|
+
"nested" , inherited && inherited.nested || undefined,
|
|
76
|
+
"comment" , keepComments ? this.comment : undefined
|
|
77
|
+
]);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Methods of this service as an array for iteration.
|
|
82
|
+
* @name Service#methodsArray
|
|
83
|
+
* @type {Method[]}
|
|
84
|
+
* @readonly
|
|
85
|
+
*/
|
|
86
|
+
Object.defineProperty(Service.prototype, "methodsArray", {
|
|
87
|
+
get: function() {
|
|
88
|
+
return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
function clearCache(service) {
|
|
93
|
+
service._methodsArray = null;
|
|
94
|
+
return service;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @override
|
|
99
|
+
*/
|
|
100
|
+
Service.prototype.get = function get(name) {
|
|
101
|
+
return this.methods[name]
|
|
102
|
+
|| Namespace.prototype.get.call(this, name);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @override
|
|
107
|
+
*/
|
|
108
|
+
Service.prototype.resolveAll = function resolveAll() {
|
|
109
|
+
var methods = this.methodsArray;
|
|
110
|
+
for (var i = 0; i < methods.length; ++i)
|
|
111
|
+
methods[i].resolve();
|
|
112
|
+
return Namespace.prototype.resolve.call(this);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @override
|
|
117
|
+
*/
|
|
118
|
+
Service.prototype.add = function add(object) {
|
|
119
|
+
|
|
120
|
+
/* istanbul ignore if */
|
|
121
|
+
if (this.get(object.name))
|
|
122
|
+
throw Error("duplicate name '" + object.name + "' in " + this);
|
|
123
|
+
|
|
124
|
+
if (object instanceof Method) {
|
|
125
|
+
this.methods[object.name] = object;
|
|
126
|
+
object.parent = this;
|
|
127
|
+
return clearCache(this);
|
|
128
|
+
}
|
|
129
|
+
return Namespace.prototype.add.call(this, object);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @override
|
|
134
|
+
*/
|
|
135
|
+
Service.prototype.remove = function remove(object) {
|
|
136
|
+
if (object instanceof Method) {
|
|
137
|
+
|
|
138
|
+
/* istanbul ignore if */
|
|
139
|
+
if (this.methods[object.name] !== object)
|
|
140
|
+
throw Error(object + " is not a member of " + this);
|
|
141
|
+
|
|
142
|
+
delete this.methods[object.name];
|
|
143
|
+
object.parent = null;
|
|
144
|
+
return clearCache(this);
|
|
145
|
+
}
|
|
146
|
+
return Namespace.prototype.remove.call(this, object);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Creates a runtime service using the specified rpc implementation.
|
|
151
|
+
* @param {RPCImpl} rpcImpl RPC implementation
|
|
152
|
+
* @param {boolean} [requestDelimited=false] Whether requests are length-delimited
|
|
153
|
+
* @param {boolean} [responseDelimited=false] Whether responses are length-delimited
|
|
154
|
+
* @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
|
|
155
|
+
*/
|
|
156
|
+
Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
|
|
157
|
+
var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
|
|
158
|
+
for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
|
|
159
|
+
var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
|
|
160
|
+
rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
|
|
161
|
+
m: method,
|
|
162
|
+
q: method.resolvedRequestType.ctor,
|
|
163
|
+
s: method.resolvedResponseType.ctor
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return rpcService;
|
|
167
|
+
};
|
package/src/tokenize.js
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = tokenize;
|
|
3
|
+
|
|
4
|
+
var delimRe = /[\s{}=;:[\],'"()<>]/g,
|
|
5
|
+
stringDoubleRe = /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,
|
|
6
|
+
stringSingleRe = /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g;
|
|
7
|
+
|
|
8
|
+
var setCommentRe = /^ *[*/]+ */,
|
|
9
|
+
setCommentAltRe = /^\s*\*?\/*/,
|
|
10
|
+
setCommentSplitRe = /\n/g,
|
|
11
|
+
whitespaceRe = /\s/,
|
|
12
|
+
unescapeRe = /\\(.?)/g;
|
|
13
|
+
|
|
14
|
+
var unescapeMap = {
|
|
15
|
+
"0": "\0",
|
|
16
|
+
"r": "\r",
|
|
17
|
+
"n": "\n",
|
|
18
|
+
"t": "\t"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unescapes a string.
|
|
23
|
+
* @param {string} str String to unescape
|
|
24
|
+
* @returns {string} Unescaped string
|
|
25
|
+
* @property {Object.<string,string>} map Special characters map
|
|
26
|
+
* @memberof tokenize
|
|
27
|
+
*/
|
|
28
|
+
function unescape(str) {
|
|
29
|
+
return str.replace(unescapeRe, function($0, $1) {
|
|
30
|
+
switch ($1) {
|
|
31
|
+
case "\\":
|
|
32
|
+
case "":
|
|
33
|
+
return $1;
|
|
34
|
+
default:
|
|
35
|
+
return unescapeMap[$1] || "";
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
tokenize.unescape = unescape;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets the next token and advances.
|
|
44
|
+
* @typedef TokenizerHandleNext
|
|
45
|
+
* @type {function}
|
|
46
|
+
* @returns {string|null} Next token or `null` on eof
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Peeks for the next token.
|
|
51
|
+
* @typedef TokenizerHandlePeek
|
|
52
|
+
* @type {function}
|
|
53
|
+
* @returns {string|null} Next token or `null` on eof
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Pushes a token back to the stack.
|
|
58
|
+
* @typedef TokenizerHandlePush
|
|
59
|
+
* @type {function}
|
|
60
|
+
* @param {string} token Token
|
|
61
|
+
* @returns {undefined}
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Skips the next token.
|
|
66
|
+
* @typedef TokenizerHandleSkip
|
|
67
|
+
* @type {function}
|
|
68
|
+
* @param {string} expected Expected token
|
|
69
|
+
* @param {boolean} [optional=false] If optional
|
|
70
|
+
* @returns {boolean} Whether the token matched
|
|
71
|
+
* @throws {Error} If the token didn't match and is not optional
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets the comment on the previous line or, alternatively, the line comment on the specified line.
|
|
76
|
+
* @typedef TokenizerHandleCmnt
|
|
77
|
+
* @type {function}
|
|
78
|
+
* @param {number} [line] Line number
|
|
79
|
+
* @returns {string|null} Comment text or `null` if none
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Handle object returned from {@link tokenize}.
|
|
84
|
+
* @interface ITokenizerHandle
|
|
85
|
+
* @property {TokenizerHandleNext} next Gets the next token and advances (`null` on eof)
|
|
86
|
+
* @property {TokenizerHandlePeek} peek Peeks for the next token (`null` on eof)
|
|
87
|
+
* @property {TokenizerHandlePush} push Pushes a token back to the stack
|
|
88
|
+
* @property {TokenizerHandleSkip} skip Skips a token, returns its presence and advances or, if non-optional and not present, throws
|
|
89
|
+
* @property {TokenizerHandleCmnt} cmnt Gets the comment on the previous line or the line comment on the specified line, if any
|
|
90
|
+
* @property {number} line Current line number
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Tokenizes the given .proto source and returns an object with useful utility functions.
|
|
95
|
+
* @param {string} source Source contents
|
|
96
|
+
* @param {boolean} alternateCommentMode Whether we should activate alternate comment parsing mode.
|
|
97
|
+
* @returns {ITokenizerHandle} Tokenizer handle
|
|
98
|
+
*/
|
|
99
|
+
function tokenize(source, alternateCommentMode) {
|
|
100
|
+
/* eslint-disable callback-return */
|
|
101
|
+
source = source.toString();
|
|
102
|
+
|
|
103
|
+
var offset = 0,
|
|
104
|
+
length = source.length,
|
|
105
|
+
line = 1,
|
|
106
|
+
commentType = null,
|
|
107
|
+
commentText = null,
|
|
108
|
+
commentLine = 0,
|
|
109
|
+
commentLineEmpty = false;
|
|
110
|
+
|
|
111
|
+
var stack = [];
|
|
112
|
+
|
|
113
|
+
var stringDelim = null;
|
|
114
|
+
|
|
115
|
+
/* istanbul ignore next */
|
|
116
|
+
/**
|
|
117
|
+
* Creates an error for illegal syntax.
|
|
118
|
+
* @param {string} subject Subject
|
|
119
|
+
* @returns {Error} Error created
|
|
120
|
+
* @inner
|
|
121
|
+
*/
|
|
122
|
+
function illegal(subject) {
|
|
123
|
+
return Error("illegal " + subject + " (line " + line + ")");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Reads a string till its end.
|
|
128
|
+
* @returns {string} String read
|
|
129
|
+
* @inner
|
|
130
|
+
*/
|
|
131
|
+
function readString() {
|
|
132
|
+
var re = stringDelim === "'" ? stringSingleRe : stringDoubleRe;
|
|
133
|
+
re.lastIndex = offset - 1;
|
|
134
|
+
var match = re.exec(source);
|
|
135
|
+
if (!match)
|
|
136
|
+
throw illegal("string");
|
|
137
|
+
offset = re.lastIndex;
|
|
138
|
+
push(stringDelim);
|
|
139
|
+
stringDelim = null;
|
|
140
|
+
return unescape(match[1]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Gets the character at `pos` within the source.
|
|
145
|
+
* @param {number} pos Position
|
|
146
|
+
* @returns {string} Character
|
|
147
|
+
* @inner
|
|
148
|
+
*/
|
|
149
|
+
function charAt(pos) {
|
|
150
|
+
return source.charAt(pos);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sets the current comment text.
|
|
155
|
+
* @param {number} start Start offset
|
|
156
|
+
* @param {number} end End offset
|
|
157
|
+
* @returns {undefined}
|
|
158
|
+
* @inner
|
|
159
|
+
*/
|
|
160
|
+
function setComment(start, end) {
|
|
161
|
+
commentType = source.charAt(start++);
|
|
162
|
+
commentLine = line;
|
|
163
|
+
commentLineEmpty = false;
|
|
164
|
+
var lookback;
|
|
165
|
+
if (alternateCommentMode) {
|
|
166
|
+
lookback = 2; // alternate comment parsing: "//" or "/*"
|
|
167
|
+
} else {
|
|
168
|
+
lookback = 3; // "///" or "/**"
|
|
169
|
+
}
|
|
170
|
+
var commentOffset = start - lookback,
|
|
171
|
+
c;
|
|
172
|
+
do {
|
|
173
|
+
if (--commentOffset < 0 ||
|
|
174
|
+
(c = source.charAt(commentOffset)) === "\n") {
|
|
175
|
+
commentLineEmpty = true;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
} while (c === " " || c === "\t");
|
|
179
|
+
var lines = source
|
|
180
|
+
.substring(start, end)
|
|
181
|
+
.split(setCommentSplitRe);
|
|
182
|
+
for (var i = 0; i < lines.length; ++i)
|
|
183
|
+
lines[i] = lines[i]
|
|
184
|
+
.replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")
|
|
185
|
+
.trim();
|
|
186
|
+
commentText = lines
|
|
187
|
+
.join("\n")
|
|
188
|
+
.trim();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function isDoubleSlashCommentLine(startOffset) {
|
|
192
|
+
var endOffset = findEndOfLine(startOffset);
|
|
193
|
+
|
|
194
|
+
// see if remaining line matches comment pattern
|
|
195
|
+
var lineText = source.substring(startOffset, endOffset);
|
|
196
|
+
// look for 1 or 2 slashes since startOffset would already point past
|
|
197
|
+
// the first slash that started the comment.
|
|
198
|
+
var isComment = /^\s*\/{1,2}/.test(lineText);
|
|
199
|
+
return isComment;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function findEndOfLine(cursor) {
|
|
203
|
+
// find end of cursor's line
|
|
204
|
+
var endOffset = cursor;
|
|
205
|
+
while (endOffset < length && charAt(endOffset) !== "\n") {
|
|
206
|
+
endOffset++;
|
|
207
|
+
}
|
|
208
|
+
return endOffset;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Obtains the next token.
|
|
213
|
+
* @returns {string|null} Next token or `null` on eof
|
|
214
|
+
* @inner
|
|
215
|
+
*/
|
|
216
|
+
function next() {
|
|
217
|
+
if (stack.length > 0)
|
|
218
|
+
return stack.shift();
|
|
219
|
+
if (stringDelim)
|
|
220
|
+
return readString();
|
|
221
|
+
var repeat,
|
|
222
|
+
prev,
|
|
223
|
+
curr,
|
|
224
|
+
start,
|
|
225
|
+
isDoc;
|
|
226
|
+
do {
|
|
227
|
+
if (offset === length)
|
|
228
|
+
return null;
|
|
229
|
+
repeat = false;
|
|
230
|
+
while (whitespaceRe.test(curr = charAt(offset))) {
|
|
231
|
+
if (curr === "\n")
|
|
232
|
+
++line;
|
|
233
|
+
if (++offset === length)
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (charAt(offset) === "/") {
|
|
238
|
+
if (++offset === length) {
|
|
239
|
+
throw illegal("comment");
|
|
240
|
+
}
|
|
241
|
+
if (charAt(offset) === "/") { // Line
|
|
242
|
+
if (!alternateCommentMode) {
|
|
243
|
+
// check for triple-slash comment
|
|
244
|
+
isDoc = charAt(start = offset + 1) === "/";
|
|
245
|
+
|
|
246
|
+
while (charAt(++offset) !== "\n") {
|
|
247
|
+
if (offset === length) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
++offset;
|
|
252
|
+
if (isDoc) {
|
|
253
|
+
setComment(start, offset - 1);
|
|
254
|
+
}
|
|
255
|
+
++line;
|
|
256
|
+
repeat = true;
|
|
257
|
+
} else {
|
|
258
|
+
// check for double-slash comments, consolidating consecutive lines
|
|
259
|
+
start = offset;
|
|
260
|
+
isDoc = false;
|
|
261
|
+
if (isDoubleSlashCommentLine(offset)) {
|
|
262
|
+
isDoc = true;
|
|
263
|
+
do {
|
|
264
|
+
offset = findEndOfLine(offset);
|
|
265
|
+
if (offset === length) {
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
offset++;
|
|
269
|
+
} while (isDoubleSlashCommentLine(offset));
|
|
270
|
+
} else {
|
|
271
|
+
offset = Math.min(length, findEndOfLine(offset) + 1);
|
|
272
|
+
}
|
|
273
|
+
if (isDoc) {
|
|
274
|
+
setComment(start, offset);
|
|
275
|
+
}
|
|
276
|
+
line++;
|
|
277
|
+
repeat = true;
|
|
278
|
+
}
|
|
279
|
+
} else if ((curr = charAt(offset)) === "*") { /* Block */
|
|
280
|
+
// check for /** (regular comment mode) or /* (alternate comment mode)
|
|
281
|
+
start = offset + 1;
|
|
282
|
+
isDoc = alternateCommentMode || charAt(start) === "*";
|
|
283
|
+
do {
|
|
284
|
+
if (curr === "\n") {
|
|
285
|
+
++line;
|
|
286
|
+
}
|
|
287
|
+
if (++offset === length) {
|
|
288
|
+
throw illegal("comment");
|
|
289
|
+
}
|
|
290
|
+
prev = curr;
|
|
291
|
+
curr = charAt(offset);
|
|
292
|
+
} while (prev !== "*" || curr !== "/");
|
|
293
|
+
++offset;
|
|
294
|
+
if (isDoc) {
|
|
295
|
+
setComment(start, offset - 2);
|
|
296
|
+
}
|
|
297
|
+
repeat = true;
|
|
298
|
+
} else {
|
|
299
|
+
return "/";
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} while (repeat);
|
|
303
|
+
|
|
304
|
+
// offset !== length if we got here
|
|
305
|
+
|
|
306
|
+
var end = offset;
|
|
307
|
+
delimRe.lastIndex = 0;
|
|
308
|
+
var delim = delimRe.test(charAt(end++));
|
|
309
|
+
if (!delim)
|
|
310
|
+
while (end < length && !delimRe.test(charAt(end)))
|
|
311
|
+
++end;
|
|
312
|
+
var token = source.substring(offset, offset = end);
|
|
313
|
+
if (token === "\"" || token === "'")
|
|
314
|
+
stringDelim = token;
|
|
315
|
+
return token;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Pushes a token back to the stack.
|
|
320
|
+
* @param {string} token Token
|
|
321
|
+
* @returns {undefined}
|
|
322
|
+
* @inner
|
|
323
|
+
*/
|
|
324
|
+
function push(token) {
|
|
325
|
+
stack.push(token);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Peeks for the next token.
|
|
330
|
+
* @returns {string|null} Token or `null` on eof
|
|
331
|
+
* @inner
|
|
332
|
+
*/
|
|
333
|
+
function peek() {
|
|
334
|
+
if (!stack.length) {
|
|
335
|
+
var token = next();
|
|
336
|
+
if (token === null)
|
|
337
|
+
return null;
|
|
338
|
+
push(token);
|
|
339
|
+
}
|
|
340
|
+
return stack[0];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Skips a token.
|
|
345
|
+
* @param {string} expected Expected token
|
|
346
|
+
* @param {boolean} [optional=false] Whether the token is optional
|
|
347
|
+
* @returns {boolean} `true` when skipped, `false` if not
|
|
348
|
+
* @throws {Error} When a required token is not present
|
|
349
|
+
* @inner
|
|
350
|
+
*/
|
|
351
|
+
function skip(expected, optional) {
|
|
352
|
+
var actual = peek(),
|
|
353
|
+
equals = actual === expected;
|
|
354
|
+
if (equals) {
|
|
355
|
+
next();
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
if (!optional)
|
|
359
|
+
throw illegal("token '" + actual + "', '" + expected + "' expected");
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Gets a comment.
|
|
365
|
+
* @param {number} [trailingLine] Line number if looking for a trailing comment
|
|
366
|
+
* @returns {string|null} Comment text
|
|
367
|
+
* @inner
|
|
368
|
+
*/
|
|
369
|
+
function cmnt(trailingLine) {
|
|
370
|
+
var ret = null;
|
|
371
|
+
if (trailingLine === undefined) {
|
|
372
|
+
if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) {
|
|
373
|
+
ret = commentText;
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
/* istanbul ignore else */
|
|
377
|
+
if (commentLine < trailingLine) {
|
|
378
|
+
peek();
|
|
379
|
+
}
|
|
380
|
+
if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) {
|
|
381
|
+
ret = commentText;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return ret;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return Object.defineProperty({
|
|
388
|
+
next: next,
|
|
389
|
+
peek: peek,
|
|
390
|
+
push: push,
|
|
391
|
+
skip: skip,
|
|
392
|
+
cmnt: cmnt
|
|
393
|
+
}, "line", {
|
|
394
|
+
get: function() { return line; }
|
|
395
|
+
});
|
|
396
|
+
/* eslint-enable callback-return */
|
|
397
|
+
}
|