-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(destructuring): escape parameter names containing curly brace.
not sure if this is the right way to annotate destructured params, have asked on js-compiler-users
- Loading branch information
Showing
4 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -352,7 +359,7 @@ class Annotator { | |
} | ||
newDoc.tags.push({ | ||
tagName: 'param', | ||
parameterName: name, | ||
parameterName: escapeParameterName(name), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alexeagle
via email
Author
Contributor
|
||
type: param.type, | ||
optional: param.initializer != null || param.questionToken != null, | ||
text: paramDoc, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.