Comparing version 0.6.0 to 0.7.0
@@ -59,3 +59,3 @@ /** | ||
if (cache && cache[expr]) { | ||
if (cache && Object.prototype.hasOwnProperty.call(cache, expr)) { | ||
return cache[expr]; | ||
@@ -62,0 +62,0 @@ } else { |
@@ -69,3 +69,2 @@ 'use strict'; | ||
Stringifier.prototype.optional = function(optional) { | ||
/*jshint boss: true */ // TODO: remove after JSHint releases the fix for jshint/jshint#878 | ||
if (optional === true) { | ||
@@ -115,14 +114,14 @@ return '='; | ||
// TODO: refactor for clarity | ||
Stringifier.prototype.type = function(type) { | ||
var result = ''; | ||
if (!type) { | ||
return ''; | ||
return result; | ||
} | ||
// nullable comes first | ||
var result = this.nullable(type.nullable); | ||
// next portion varies by type | ||
switch(type.type) { | ||
case Types.AllLiteral: | ||
result += this._formatNameAndType(type, '*'); | ||
result += this._formatRepeatableAndNullable(type, '', | ||
this._formatNameAndType(type, '*')); | ||
break; | ||
@@ -133,22 +132,25 @@ case Types.FunctionType: | ||
case Types.NullLiteral: | ||
result += this._formatNameAndType(type, 'null'); | ||
result += this._formatRepeatableAndNullable(type, '', | ||
this._formatNameAndType(type, 'null')); | ||
break; | ||
case Types.RecordType: | ||
result += this._record(type); | ||
result += this._formatRepeatableAndNullable(type, '', this._record(type)); | ||
break; | ||
case Types.TypeApplication: | ||
result += this.type(type.expression); | ||
result += this._formatRepeatableAndNullable(type, '', this.type(type.expression)); | ||
result += this.applications(type.applications); | ||
break; | ||
case Types.UndefinedLiteral: | ||
result += this._formatNameAndType(type, 'undefined'); | ||
result += this._formatRepeatableAndNullable(type, '', | ||
this._formatNameAndType(type, 'undefined')); | ||
break; | ||
case Types.TypeUnion: | ||
result += this.elements(type.elements); | ||
result += this._formatRepeatableAndNullable(type, '', this.elements(type.elements)); | ||
break; | ||
case Types.UnknownLiteral: | ||
result += this._formatNameAndType(type, '?'); | ||
result += this._formatRepeatableAndNullable(type, '', | ||
this._formatNameAndType(type, '?')); | ||
break; | ||
default: | ||
result += this._formatNameAndType(type); | ||
result += this._formatRepeatableAndNullable(type, '', this._formatNameAndType(type)); | ||
} | ||
@@ -196,10 +198,19 @@ | ||
var separator = (nameString && typeString) ? ':' : ''; | ||
return nameString + separator + typeString; | ||
} | ||
Stringifier.prototype._formatRepeatable = function(nameString, typeString) { | ||
var open = this._inFunctionSignatureParams ? '...[' : '...'; | ||
var close = this._inFunctionSignatureParams ? ']' : ''; | ||
Stringifier.prototype._formatRepeatableAndNullable = function(type, nameString, typeString) { | ||
var open = ''; | ||
var close = ''; | ||
var combined; | ||
return open + combineNameAndType(nameString, typeString) + close; | ||
if (type.repeatable) { | ||
open = this._inFunctionSignatureParams ? '...[' : '...'; | ||
close = this._inFunctionSignatureParams ? ']' : ''; | ||
} | ||
combined = this.nullable(type.nullable) + combineNameAndType(nameString, typeString); | ||
return open + combined + close; | ||
}; | ||
@@ -222,7 +233,3 @@ | ||
if (type.repeatable === true) { | ||
return this._formatRepeatable(nameString, typeString); | ||
} else { | ||
return combineNameAndType(nameString, typeString); | ||
} | ||
return combineNameAndType(nameString, typeString); | ||
}; | ||
@@ -234,2 +241,3 @@ | ||
var result; | ||
var signatureBase; | ||
@@ -254,3 +262,4 @@ // these go within the signature's parens, in this order | ||
result = 'function(' + params.join(', ') + ')'; | ||
signatureBase = 'function(' + params.join(', ') + ')'; | ||
result = this._formatRepeatableAndNullable(type, '', signatureBase); | ||
result += this.result(type.result); | ||
@@ -257,0 +266,0 @@ |
{ | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"name": "catharsis", | ||
@@ -23,4 +23,4 @@ "description": "A JavaScript parser for Google Closure Compiler and JSDoc type expressions.", | ||
"scripts": { | ||
"build": "pegjs ./lib/parser.pegjs", | ||
"prepublish": "pegjs ./lib/parser.pegjs; uglifyjs ./lib/parser.js -o ./lib/parser.js", | ||
"build": "./node_modules/.bin/pegjs ./lib/parser.pegjs", | ||
"prepublish": "./node_modules/.bin/pegjs ./lib/parser.pegjs; ./node_modules/.bin/uglifyjs ./lib/parser.js -o ./lib/parser.js", | ||
"test": "mocha" | ||
@@ -34,2 +34,2 @@ }, | ||
] | ||
} | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
187934
8
877
0
240