protobufjs
Advanced tools
Comparing version 6.10.0-beta.0 to 6.10.0-beta.1
@@ -197,5 +197,4 @@ "use strict"; | ||
// Use es6 syntax if not explicitly specified on the command line and the es6 wrapper is used | ||
if (argv.wrap === "es6" || argv.es6) { | ||
argv.wrap = "es6"; | ||
// `--wrap es6` implies `--es6` but not the other way around. You can still use e.g. `--es6 --wrap commonjs` | ||
if (argv.wrap === "es6") { | ||
argv.es6 = true; | ||
@@ -202,0 +201,0 @@ } |
{ | ||
"name": "protobufjs", | ||
"version": "6.10.0-beta.0", | ||
"version": "6.10.0-beta.1", | ||
"versionScheme": "~", | ||
@@ -5,0 +5,0 @@ "description": "Protocol Buffers for JavaScript (& TypeScript).", |
@@ -22,3 +22,3 @@ "use strict"; | ||
("r=Reader.create(r)") | ||
("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k" : "")) | ||
("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : "")) | ||
("while(r.pos<c){") | ||
@@ -41,19 +41,41 @@ ("var t=r.uint32()"); | ||
if (field.map) { gen | ||
("r.skip().pos++") // assumes id 1 + key wireType | ||
("if(%s===util.emptyObject)", ref) | ||
("%s={}", ref) | ||
("k=r.%s()", field.keyType) | ||
("r.pos++"); // assumes id 2 + value wireType | ||
if (types.long[field.keyType] !== undefined) { | ||
if (types.basic[type] === undefined) gen | ||
("%s[typeof k===\"object\"?util.longToHash(k):k]=types[%i].decode(r,r.uint32())", ref, i); // can't be groups | ||
else gen | ||
("%s[typeof k===\"object\"?util.longToHash(k):k]=r.%s()", ref, type); | ||
} else { | ||
if (types.basic[type] === undefined) gen | ||
("%s[k]=types[%i].decode(r,r.uint32())", ref, i); // can't be groups | ||
else gen | ||
("%s[k]=r.%s()", ref, type); | ||
} | ||
("var c2 = r.uint32()+r.pos"); | ||
if (types.defaults[field.keyType] !== undefined) gen | ||
("k=%j", types.defaults[field.keyType]); | ||
else gen | ||
("k=null"); | ||
if (types.defaults[type] !== undefined) gen | ||
("value=%j", types.defaults[type]); | ||
else gen | ||
("value=null"); | ||
gen | ||
("while(r.pos<c2){") | ||
("var tag2=r.uint32()") | ||
("switch(tag2>>>3){") | ||
("case 1: k=r.%s(); break", field.keyType) | ||
("case 2:"); | ||
if (types.basic[type] === undefined) gen | ||
("value=types[%i].decode(r,r.uint32())", i); // can't be groups | ||
else gen | ||
("value=r.%s()", type); | ||
gen | ||
("break") | ||
("default:") | ||
("r.skipType(tag2&7)") | ||
("break") | ||
("}") | ||
("}"); | ||
if (types.long[field.keyType] !== undefined) gen | ||
("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref); | ||
else gen | ||
("%s[k]=value", ref); | ||
// Repeated fields | ||
@@ -60,0 +82,0 @@ } else if (field.repeated) { gen |
@@ -33,2 +33,8 @@ "use strict"; | ||
/** | ||
* Parsed Options. | ||
* @type {Array.<Object.<string,*>>|undefined} | ||
*/ | ||
this.parsedOptions = null; | ||
/** | ||
* Unique name within its namespace. | ||
@@ -174,2 +180,39 @@ * @type {string} | ||
/** | ||
* Sets a parsed option. | ||
* @param {string} name parsed Option name | ||
* @param {*} value Option value | ||
* @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value | ||
* @returns {ReflectionObject} `this` | ||
*/ | ||
ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) { | ||
if (!this.parsedOptions) { | ||
this.parsedOptions = []; | ||
} | ||
var parsedOptions = this.parsedOptions; | ||
if (propName) { | ||
// If setting a sub property of an option then try to merge it | ||
// with an existing option | ||
var opt = parsedOptions.find(function (opt) { | ||
return Object.prototype.hasOwnProperty.call(opt, name); | ||
}); | ||
if (opt) { | ||
// If we found an existing option - just merge the property value | ||
var newValue = opt[name]; | ||
util.setProperty(newValue, propName, value); | ||
} else { | ||
// otherwise, create a new option, set it's property and add it to the list | ||
opt = {}; | ||
opt[name] = util.setProperty({}, propName, value); | ||
parsedOptions.push(opt); | ||
} | ||
} else { | ||
// Always create a new option when setting the value of the option itself | ||
var newOpt = {}; | ||
newOpt[name] = value; | ||
parsedOptions.push(newOpt); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Sets multiple options. | ||
@@ -176,0 +219,0 @@ * @param {Object.<string,*>} options Options to set |
@@ -45,2 +45,3 @@ "use strict"; | ||
* @property {boolean} [alternateCommentMode=false] Recognize double-slash comments in addition to doc-block comments. | ||
* @property {boolean} [preferTrailingComment=false] Use trailing comment when both leading comment and trailing comment exist. | ||
*/ | ||
@@ -72,2 +73,3 @@ | ||
var preferTrailingComment = options.preferTrailingComment || false; | ||
var tn = tokenize(source, options.alternateCommentMode || false), | ||
@@ -296,4 +298,4 @@ next = tn.next, | ||
skip(";"); | ||
if (obj && typeof obj.comment !== "string") | ||
obj.comment = cmnt(trailingLine); // try line-type comment if no block | ||
if (obj && (typeof obj.comment !== "string" || preferTrailingComment)) | ||
obj.comment = cmnt(trailingLine) || obj.comment; // try line-type comment | ||
} | ||
@@ -546,7 +548,12 @@ } | ||
var name = token; | ||
var option = name; | ||
var propName; | ||
if (isCustom) { | ||
skip(")"); | ||
name = "(" + name + ")"; | ||
option = name; | ||
token = peek(); | ||
if (fqTypeRefRe.test(token)) { | ||
propName = token.substr(1); //remove '.' before property name | ||
name += token; | ||
@@ -557,3 +564,4 @@ next(); | ||
skip("="); | ||
parseOptionValue(parent, name); | ||
var optionValue = parseOptionValue(parent, name); | ||
setParsedOption(parent, option, optionValue, propName); | ||
} | ||
@@ -563,2 +571,3 @@ | ||
if (skip("{", true)) { // { a: "foo" b { c: "bar" } } | ||
var result = {}; | ||
while (!skip("}", true)) { | ||
@@ -569,15 +578,27 @@ /* istanbul ignore if */ | ||
var value; | ||
var propName = token; | ||
if (peek() === "{") | ||
parseOptionValue(parent, name + "." + token); | ||
value = parseOptionValue(parent, name + "." + token); | ||
else { | ||
skip(":"); | ||
if (peek() === "{") | ||
parseOptionValue(parent, name + "." + token); | ||
else | ||
setOption(parent, name + "." + token, readValue(true)); | ||
value = parseOptionValue(parent, name + "." + token); | ||
else { | ||
value = readValue(true); | ||
setOption(parent, name + "." + token, value); | ||
} | ||
} | ||
var prevValue = result[propName]; | ||
if (prevValue) | ||
value = [].concat(prevValue).concat(value); | ||
result[propName] = value; | ||
skip(",", true); | ||
} | ||
} else | ||
setOption(parent, name, readValue(true)); | ||
return result; | ||
} | ||
var simpleValue = readValue(true); | ||
setOption(parent, name, simpleValue); | ||
return simpleValue; | ||
// Does not enforce a delimiter to be universal | ||
@@ -591,2 +612,7 @@ } | ||
function setParsedOption(parent, name, value, propName) { | ||
if (parent.setParsedOption) | ||
parent.setParsedOption(name, value, propName); | ||
} | ||
function parseInlineOptions(parent) { | ||
@@ -593,0 +619,0 @@ if (skip("[", true)) { |
@@ -109,3 +109,4 @@ "use strict"; | ||
commentLine = 0, | ||
commentLineEmpty = false; | ||
commentLineEmpty = false, | ||
commentIsLeading = false; | ||
@@ -158,9 +159,11 @@ var stack = []; | ||
* @param {number} end End offset | ||
* @param {boolean} isLeading set if a leading comment | ||
* @returns {undefined} | ||
* @inner | ||
*/ | ||
function setComment(start, end) { | ||
function setComment(start, end, isLeading) { | ||
commentType = source.charAt(start++); | ||
commentLine = line; | ||
commentLineEmpty = false; | ||
commentIsLeading = isLeading; | ||
var lookback; | ||
@@ -227,3 +230,4 @@ if (alternateCommentMode) { | ||
start, | ||
isDoc; | ||
isDoc, | ||
isLeadingComment = offset === 0; | ||
do { | ||
@@ -234,4 +238,6 @@ if (offset === length) | ||
while (whitespaceRe.test(curr = charAt(offset))) { | ||
if (curr === "\n") | ||
if (curr === "\n") { | ||
isLeadingComment = true; | ||
++line; | ||
} | ||
if (++offset === length) | ||
@@ -257,3 +263,3 @@ return null; | ||
if (isDoc) { | ||
setComment(start, offset - 1); | ||
setComment(start, offset - 1, isLeadingComment); | ||
} | ||
@@ -279,3 +285,3 @@ ++line; | ||
if (isDoc) { | ||
setComment(start, offset); | ||
setComment(start, offset, isLeadingComment); | ||
} | ||
@@ -301,3 +307,3 @@ line++; | ||
if (isDoc) { | ||
setComment(start, offset - 2); | ||
setComment(start, offset - 2, isLeadingComment); | ||
} | ||
@@ -380,3 +386,3 @@ repeat = true; | ||
if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) { | ||
ret = commentText; | ||
ret = commentIsLeading ? commentText : null; | ||
} | ||
@@ -389,3 +395,3 @@ } else { | ||
if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) { | ||
ret = commentText; | ||
ret = commentIsLeading ? null : commentText; | ||
} | ||
@@ -392,0 +398,0 @@ } |
@@ -168,3 +168,34 @@ "use strict"; | ||
/** | ||
* Sets the value of a property by property path. If a value already exists, it is turned to an array | ||
* @param {Object.<string,*>} dst Destination object | ||
* @param {string} path dot '.' delimited path of the property to set | ||
* @param {Object} value the value to set | ||
* @returns {Object.<string,*>} Destination object | ||
*/ | ||
util.setProperty = function setProperty(dst, path, value) { | ||
function setProp(dst, path, value) { | ||
var part = path.shift(); | ||
if (path.length > 0) { | ||
dst[part] = setProp(dst[part] || {}, path, value); | ||
} else { | ||
var prevValue = dst[part]; | ||
if (prevValue) | ||
value = [].concat(prevValue).concat(value); | ||
dst[part] = value; | ||
} | ||
return dst; | ||
} | ||
if (typeof dst !== "object") | ||
throw TypeError("dst must be an object"); | ||
if (!path) | ||
throw TypeError("path must be specified"); | ||
path = path.split("."); | ||
return setProp(dst, path, value); | ||
}; | ||
/** | ||
* Decorator root (TypeScript). | ||
@@ -171,0 +202,0 @@ * @name util.decorateRoot |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
3214838
39900