Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 324cff9127c897db2fa0234de6f5d8172aee9c31 1 parent 3b22b64
Jeff Williams authored March 21, 2013
2  README.md
Source Rendered
@@ -143,6 +143,8 @@ pull request, please contact me in advance so I can help things go smoothly.
143 143
 
144 144
 ## Changelog ##
145 145
 
  146
++ 0.5.2 (March 2013): The `parse()` method now correctly parses function types when JSDoc-style type
  147
+expressions are enabled.
146 148
 + 0.5.1 (March 2013): Newlines and extra spaces are now removed from type expressions before they
147 149
 are parsed.
148 150
 + 0.5.0 (March 2013):
9  bin/parseType.js
@@ -9,10 +9,15 @@ var util = require('util');
9 9
 
10 10
 var command = path.basename(process.argv[1]);
11 11
 var typeExpression = process.argv[2];
  12
+var jsdoc = process.argv[3] === '--jsdoc' ? true : false;
12 13
 var parsedType;
13 14
 
  15
+var opts = {
  16
+	jsdoc: jsdoc
  17
+};
  18
+
14 19
 function usage() {
15  
-	console.log(util.format('Usage:\n    %s [typeExpression]', command));
  20
+	console.log(util.format('Usage:\n    %s typeExpression [--jsdoc]', command));
16 21
 }
17 22
 
18 23
 if (!typeExpression) {
@@ -20,7 +25,7 @@ if (!typeExpression) {
20 25
 	process.exit(1);
21 26
 } else {
22 27
 	try {
23  
-		parsedType = catharsis.parse(typeExpression);
  28
+		parsedType = catharsis.parse(typeExpression, opts);
24 29
 	} catch (e) {
25 30
 		console.error(util.format('Unable to parse "%s" (exception follows):', typeExpression));
26 31
 		console.error(e.stack || e.message);
4  lib/parser.js
2 additions, 2 deletions not shown
14  lib/parser.pegjs
@@ -177,7 +177,7 @@ FunctionType
177 177
 				params: []
178 178
 			};
179 179
 		}
180  
-
  180
+		
181 181
 		var result = {
182 182
 			type: Types.FunctionType
183 183
 		};
@@ -213,12 +213,7 @@ FunctionSignatureType
213 213
 	}
214 214
 
215 215
 FunctionSignature
216  
-	= params:ParametersType {
217  
-		return {
218  
-			params: params
219  
-		};
220  
-	}
221  
-	/ funcNew:FunctionSignatureNew funcThis:(_ ',' _ FunctionSignatureThis)?
  216
+	= funcNew:FunctionSignatureNew funcThis:(_ ',' _ FunctionSignatureThis)?
222 217
 		params:(_ ',' _ ParametersType)? {
223 218
 		var result = {
224 219
 			params: params !== '' ? params[3] : [],
@@ -242,6 +237,11 @@ FunctionSignature
242 237
 
243 238
 		return result;
244 239
 	}
  240
+	/ params:ParametersType {
  241
+		return {
  242
+			params: params
  243
+		};
  244
+	}
245 245
 
246 246
 FunctionSignatureNew
247 247
 	= 'new' _ ':' _ expr:TypeExpression { return expr; }
2  package.json
... ...
@@ -1,5 +1,5 @@
1 1
 {
2  
-	"version": "0.5.1",
  2
+	"version": "0.5.2",
3 3
 	"name": "catharsis",
4 4
 	"description": "A JavaScript parser for Google Closure Compiler and JSDoc type expressions.",
5 5
 	"author": "Jeff Williams <jeffrey.l.williams@gmail.com>",
18  test/specs/jsdoc/jsdoc.js
@@ -168,5 +168,23 @@ module.exports = [
168 168
 			type: Types.FunctionType,
169 169
 			params: []
170 170
 		}
  171
+	},
  172
+	{
  173
+		description: 'standard function type (should still parse if JSDoc expressions are allowed)',
  174
+		expression: 'function(this:my.namespace.Class, my.Class)=',
  175
+		parsed: {
  176
+			type: Types.FunctionType,
  177
+			params: [
  178
+				{
  179
+					type: Types.NameExpression,
  180
+					name: 'my.Class'
  181
+				}
  182
+			],
  183
+			'this': {
  184
+				type: Types.NameExpression,
  185
+				name: 'my.namespace.Class'
  186
+			},
  187
+			optional: true
  188
+		}
171 189
 	}
172 190
 ];

0 notes on commit 324cff9

Please sign in to comment.
Something went wrong with that request. Please try again.