Permalink
Browse files

0.5.2 fix: parse function types correctly when JSDoc parsing is enabled

  • Loading branch information...
1 parent 3b22b64 commit 324cff9127c897db2fa0234de6f5d8172aee9c31 @hegemonic committed Mar 21, 2013
Showing with 37 additions and 12 deletions.
  1. +2 −0 README.md
  2. +7 −2 bin/parseType.js
  3. +2 −2 lib/parser.js
  4. +7 −7 lib/parser.pegjs
  5. +1 −1 package.json
  6. +18 −0 test/specs/jsdoc/jsdoc.js
View
@@ -143,6 +143,8 @@ pull request, please contact me in advance so I can help things go smoothly.
## Changelog ##
++ 0.5.2 (March 2013): The `parse()` method now correctly parses function types when JSDoc-style type
+expressions are enabled.
+ 0.5.1 (March 2013): Newlines and extra spaces are now removed from type expressions before they
are parsed.
+ 0.5.0 (March 2013):
View
@@ -9,18 +9,23 @@ var util = require('util');
var command = path.basename(process.argv[1]);
var typeExpression = process.argv[2];
+var jsdoc = process.argv[3] === '--jsdoc' ? true : false;
var parsedType;
+var opts = {
+ jsdoc: jsdoc
+};
+
function usage() {
- console.log(util.format('Usage:\n %s [typeExpression]', command));
+ console.log(util.format('Usage:\n %s typeExpression [--jsdoc]', command));
}
if (!typeExpression) {
usage();
process.exit(1);
} else {
try {
- parsedType = catharsis.parse(typeExpression);
+ parsedType = catharsis.parse(typeExpression, opts);
} catch (e) {
console.error(util.format('Unable to parse "%s" (exception follows):', typeExpression));
console.error(e.stack || e.message);
View
View
@@ -177,7 +177,7 @@ FunctionType
params: []
};
}
-
+
var result = {
type: Types.FunctionType
};
@@ -213,12 +213,7 @@ FunctionSignatureType
}
FunctionSignature
- = params:ParametersType {
- return {
- params: params
- };
- }
- / funcNew:FunctionSignatureNew funcThis:(_ ',' _ FunctionSignatureThis)?
+ = funcNew:FunctionSignatureNew funcThis:(_ ',' _ FunctionSignatureThis)?
params:(_ ',' _ ParametersType)? {
var result = {
params: params !== '' ? params[3] : [],
@@ -242,6 +237,11 @@ FunctionSignature
return result;
}
+ / params:ParametersType {
+ return {
+ params: params
+ };
+ }
FunctionSignatureNew
= 'new' _ ':' _ expr:TypeExpression { return expr; }
View
@@ -1,5 +1,5 @@
{
- "version": "0.5.1",
+ "version": "0.5.2",
"name": "catharsis",
"description": "A JavaScript parser for Google Closure Compiler and JSDoc type expressions.",
"author": "Jeff Williams <jeffrey.l.williams@gmail.com>",
@@ -168,5 +168,23 @@ module.exports = [
type: Types.FunctionType,
params: []
}
+ },
+ {
+ description: 'standard function type (should still parse if JSDoc expressions are allowed)',
+ expression: 'function(this:my.namespace.Class, my.Class)=',
+ parsed: {
+ type: Types.FunctionType,
+ params: [
+ {
+ type: Types.NameExpression,
+ name: 'my.Class'
+ }
+ ],
+ 'this': {
+ type: Types.NameExpression,
+ name: 'my.namespace.Class'
+ },
+ optional: true
+ }
}
];

0 comments on commit 324cff9

Please sign in to comment.