Skip to content

Commit

Permalink
fix(destructuring): escape parameter names containing curly brace.
Browse files Browse the repository at this point in the history
not sure if this is the right way to annotate destructured params, have asked on js-compiler-users
  • Loading branch information
alexeagle committed Mar 14, 2016
1 parent 7d8e017 commit bb806ec
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sickle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ class Annotator {
newDoc.tags.push(tag);
}

const escapeParameterName = (name: string) => {
if (name.indexOf('{') > -1) {
return `'${name}'`;
}
return name;
};

// Parameters.
if (fnDecl.parameters.length) {
for (let param of fnDecl.parameters) {
Expand All @@ -352,7 +359,7 @@ class Annotator {
}
newDoc.tags.push({
tagName: 'param',
parameterName: name,
parameterName: escapeParameterName(name),

This comment has been minimized.

Copy link
@evmar

evmar Mar 14, 2016

Contributor

I think the escaping should happen when emitting, rather than when reading, so that the "newDoc" data structure contains the platonic ideal of the doc tag.

Concretely this means moving this escapeParameterName call down to the this.emit(... tag.parameterName) spot, a few lines down.

This comment has been minimized.

Copy link
@alexeagle

alexeagle via email Mar 14, 2016

Author Contributor
type: param.type,
optional: param.initializer != null || param.questionToken != null,
text: paramDoc,
Expand Down
1 change: 1 addition & 0 deletions test_files/functions.in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ function FunctionsTest1(a: number): string {
function FunctionsTest2(a: number, b: number) {}
/** @ngInject */
function FunctionsTest3(a: number, b: number) {}
function Destructuring({a,b}:{a:number, b:number}) {}
4 changes: 4 additions & 0 deletions test_files/functions.sickle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ function FunctionsTest2(a: number, b: number) {}
* @param { number} b
*/
function FunctionsTest3(a: number, b: number) {}
/**
* @param {{a:number, b:number}} '{a,b}'
*/
function Destructuring({a,b}:{a:number, b:number}) {}
4 changes: 4 additions & 0 deletions test_files/functions.tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ function FunctionsTest2(a, b) { }
* @param { number} b
*/
function FunctionsTest3(a, b) { }
/**
* @param {{a:number, b:number}} '{a,b}'
*/
function Destructuring({ a, b }) { }

0 comments on commit bb806ec

Please sign in to comment.