Skip to content

Commit d68038a

Browse files
author
Yui T
committed
Support bracket for optional property
1 parent 068256b commit d68038a

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ namespace ts {
21792179
return bindPropertyWorker(node as JSDocRecordMember);
21802180
case SyntaxKind.JSDocPropertyTag:
21812181
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag,
2182-
(node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType ?
2182+
(node as JSDocPropertyTag).isBracketed || ((node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType) ?
21832183
SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property,
21842184
SymbolFlags.PropertyExcludes);
21852185
case SyntaxKind.JSDocFunctionType:

src/compiler/parser.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6631,10 +6631,7 @@ namespace ts {
66316631
});
66326632
}
66336633

6634-
function parseParamTag(atToken: AtToken, tagName: Identifier) {
6635-
let typeExpression = tryParseTypeExpression();
6636-
skipWhitespace();
6637-
6634+
function parseBracketNameInPropertyAndParamTag() {
66386635
let name: Identifier;
66396636
let isBracketed: boolean;
66406637
// Looking for something like '[foo]' or 'foo'
@@ -6653,6 +6650,14 @@ namespace ts {
66536650
else if (tokenIsIdentifierOrKeyword(token())) {
66546651
name = parseJSDocIdentifierName();
66556652
}
6653+
return { name, isBracketed };
6654+
}
6655+
6656+
function parseParamTag(atToken: AtToken, tagName: Identifier) {
6657+
let typeExpression = tryParseTypeExpression();
6658+
skipWhitespace();
6659+
6660+
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
66566661

66576662
if (!name) {
66586663
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
@@ -6709,8 +6714,9 @@ namespace ts {
67096714
function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
67106715
const typeExpression = tryParseTypeExpression();
67116716
skipWhitespace();
6712-
const name = parseJSDocIdentifierName();
6717+
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
67136718
skipWhitespace();
6719+
67146720
if (!name) {
67156721
parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected);
67166722
return undefined;
@@ -6721,6 +6727,7 @@ namespace ts {
67216727
result.tagName = tagName;
67226728
result.name = name;
67236729
result.typeExpression = typeExpression;
6730+
result.isBracketed = isBracketed;
67246731
return finishNode(result);
67256732
}
67266733

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,7 @@ namespace ts {
21432143
kind: SyntaxKind.JSDocPropertyTag;
21442144
name: Identifier;
21452145
typeExpression: JSDocTypeExpression;
2146+
isBracketed: boolean;
21462147
}
21472148

21482149
export interface JSDocTypeLiteral extends JSDocType {

0 commit comments

Comments
 (0)