Comparing version 0.6.0 to 0.6.1
@@ -27,2 +27,3 @@ | ||
this._isRepeated = false | ||
this._oneofIndex = -1 | ||
this._options = {} | ||
@@ -49,2 +50,4 @@ } | ||
isRepeated: this._isRepeated, | ||
hasOneofIndex: this.hasOneofIndex(), | ||
oneofIndex: this._oneofIndex, | ||
options: this._options | ||
@@ -101,2 +104,3 @@ } | ||
FieldDescriptor.prototype.getCamelName = function () { | ||
@@ -106,2 +110,3 @@ return helper.toCamelCase(this._name) | ||
FieldDescriptor.prototype.getTitleName = function () { | ||
@@ -111,2 +116,3 @@ return helper.toTitleCase(this._name) | ||
FieldDescriptor.prototype.getTag = function () { | ||
@@ -139,2 +145,18 @@ return this._tag | ||
FieldDescriptor.prototype.setOneofIndex = function (oneofIndex) { | ||
this._oneofIndex = oneofIndex | ||
return this | ||
} | ||
FieldDescriptor.prototype.getOneofIndex = function () { | ||
return this._oneofIndex | ||
} | ||
FieldDescriptor.prototype.hasOneofIndex = function () { | ||
return this._oneofIndex != -1 | ||
} | ||
FieldDescriptor.prototype.addOption = function (name, value) { | ||
@@ -141,0 +163,0 @@ this._options[name] = value |
@@ -8,2 +8,3 @@ | ||
var Descriptor = require('./Descriptor') | ||
var OneofDescriptor = require('./OneofDescriptor') | ||
var helper = require('../helper') | ||
@@ -26,2 +27,4 @@ | ||
this._fieldNames = {} | ||
this._oneofs = [] | ||
this._oneofNames = {} | ||
this._package = '' | ||
@@ -53,2 +56,3 @@ } | ||
obj.fields = helper.values(this._fields, helper.toTemplateObject), | ||
obj.oneofs = this._oneofs.map(helper.toTemplateObject), | ||
obj.messages = helper.values(this._messages, helper.toTemplateObject), | ||
@@ -99,2 +103,3 @@ obj.enums = helper.values(this._enums, helper.toTemplateObject) | ||
/** | ||
@@ -143,2 +148,23 @@ * @param {string} name | ||
MessageDescriptor.prototype.addOneof = function (oneofName) { | ||
var oneof = new OneofDescriptor(oneofName, this._oneofs.length) | ||
this._oneofs.push(oneof) | ||
this._oneofNames[oneofName] = oneof | ||
oneof.setParent(this) | ||
return oneof | ||
} | ||
MessageDescriptor.prototype.getOneof = function (name) { | ||
return this._oneofNames[name] || this._oneofNames[helper.toProtoCase(name)] || null | ||
} | ||
MessageDescriptor.prototype.getOneofByIndex = function (index) { | ||
return this._oneofs[index] || null | ||
} | ||
MessageDescriptor.prototype.addMessage = function (message) { | ||
@@ -145,0 +171,0 @@ this._messages[message.getName()] = message |
@@ -28,3 +28,3 @@ | ||
this._rescursing = false | ||
this._recursing = false | ||
} | ||
@@ -31,0 +31,0 @@ util.inherits(ProtoDescriptor, Descriptor) |
@@ -134,2 +134,5 @@ | ||
break | ||
case 'oneof': | ||
parseOneof(message) | ||
break | ||
case 'extensions': | ||
@@ -240,2 +243,31 @@ parseExtensions(proto) | ||
// Parses oneof: oneof oneofName {protoType fieldName = 1;} | ||
function parseOneof(parent) { | ||
var oneofName = expect(Token.Type.WORD).content | ||
if (parent.getOneof(oneofName)) { | ||
throw new ParseError( | ||
identifier, oneofName, 'duplicate oneof name in "' + parent.getName() + '"') | ||
} | ||
var oneof = parent.addOneof(oneofName) | ||
var oneofIndex = oneof.getOneofIndex() | ||
parseBlock(function (token) { | ||
if (token.content == 'required' || | ||
token.content == 'optional' || | ||
token.content == 'repeated') { | ||
throw new Error('Fields in oneof blocks cannot have labels (required/optional/repeated).') | ||
} | ||
// Add the token back so parseField can function properly. | ||
tokens.unshift(token) | ||
var field = parseField(parent) | ||
field.setOneofIndex(oneofIndex) | ||
field.setOptional(true) | ||
expect(Token.Type.TERMINATOR) | ||
}) | ||
} | ||
// Parses field options: [ name1 = value1, name2 = value2, (name3) = value3 ] | ||
@@ -282,6 +314,6 @@ function parseFieldOptions(parent) { | ||
function isComment(token) { | ||
return isOneOf(token, [Token.Type.LINE_COMMENT, Token.Type.BLOCK_COMMENT]) | ||
return isInArray(token, [Token.Type.LINE_COMMENT, Token.Type.BLOCK_COMMENT]) | ||
} | ||
function isOneOf(token, types) { | ||
function isInArray(token, types) { | ||
for (var i = 0; i < types.length; i++) { | ||
@@ -302,3 +334,3 @@ if (token.type == types[i]) return true | ||
if (!Array.isArray(types)) types = [types] | ||
if (!isOneOf(token, types)) { | ||
if (!isInArray(token, types)) { | ||
throw new ParseError(identifier, token, 'expected ' + types.map(Token.toErrorString) + '.') | ||
@@ -305,0 +337,0 @@ } |
{ | ||
"name": "pbnj", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"keywords": ["protocol", "buffer", "proto", "protobuf", "parser", "codegen"], | ||
"description": "JavaScript protocol buffer schema parser and template based code generator", | ||
"homepage": "https://github.com/dpup/pbnj", | ||
"homepage": "https://github.com/Medium/pbnj", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/dpup/pbnj.git" | ||
"url": "git://github.com/Medium/pbnj.git" | ||
}, | ||
@@ -11,0 +11,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
90670
23
1671
1