Skip to content

Commit d82a57e

Browse files
authored
Merge pull request #16122 from Microsoft/master-fix16092
[Master] ts-style @Property
2 parents 2c3c4dd + 27078f9 commit d82a57e

19 files changed

+170
-89
lines changed

src/compiler/parser.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6510,7 +6510,7 @@ namespace ts {
65106510
case "arg":
65116511
case "argument":
65126512
case "param":
6513-
tag = parseParamTag(atToken, tagName);
6513+
tag = parseParameterOrPropertyTag(atToken, tagName, /*shouldParseParamTag*/ true);
65146514
break;
65156515
case "return":
65166516
case "returns":
@@ -6655,11 +6655,12 @@ namespace ts {
66556655
return { name, isBracketed };
66566656
}
66576657

6658-
function parseParamTag(atToken: AtToken, tagName: Identifier) {
6658+
function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, shouldParseParamTag: boolean): JSDocPropertyTag | JSDocParameterTag {
66596659
let typeExpression = tryParseTypeExpression();
66606660
skipWhitespace();
66616661

66626662
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
6663+
skipWhitespace();
66636664

66646665
if (!name) {
66656666
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
@@ -6678,13 +6679,15 @@ namespace ts {
66786679
typeExpression = tryParseTypeExpression();
66796680
}
66806681

6681-
const result = <JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos);
6682+
const result = shouldParseParamTag ?
6683+
<JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos) :
6684+
<JSDocPropertyTag>createNode(SyntaxKind.JSDocPropertyTag, atToken.pos);
66826685
result.atToken = atToken;
66836686
result.tagName = tagName;
66846687
result.preParameterName = preName;
66856688
result.typeExpression = typeExpression;
66866689
result.postParameterName = postName;
6687-
result.parameterName = postName || preName;
6690+
result.name = postName || preName;
66886691
result.isBracketed = isBracketed;
66896692
return finishNode(result);
66906693
}
@@ -6713,26 +6716,6 @@ namespace ts {
67136716
return finishNode(result);
67146717
}
67156718

6716-
function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
6717-
const typeExpression = tryParseTypeExpression();
6718-
skipWhitespace();
6719-
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
6720-
skipWhitespace();
6721-
6722-
if (!name) {
6723-
parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected);
6724-
return undefined;
6725-
}
6726-
6727-
const result = <JSDocPropertyTag>createNode(SyntaxKind.JSDocPropertyTag, atToken.pos);
6728-
result.atToken = atToken;
6729-
result.tagName = tagName;
6730-
result.name = name;
6731-
result.typeExpression = typeExpression;
6732-
result.isBracketed = isBracketed;
6733-
return finishNode(result);
6734-
}
6735-
67366719
function parseAugmentsTag(atToken: AtToken, tagName: Identifier): JSDocAugmentsTag {
67376720
const typeExpression = tryParseTypeExpression();
67386721

@@ -6869,7 +6852,7 @@ namespace ts {
68696852
return true;
68706853
case "prop":
68716854
case "property":
6872-
const propertyTag = parsePropertyTag(atToken, tagName);
6855+
const propertyTag = parseParameterOrPropertyTag(atToken, tagName, /*shouldParseParamTag*/ false) as JSDocPropertyTag;
68736856
if (propertyTag) {
68746857
if (!parentTag.jsDocPropertyTags) {
68756858
parentTag.jsDocPropertyTags = <NodeArray<JSDocPropertyTag>>[];

src/compiler/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,10 @@ namespace ts {
21452145
parent: JSDoc;
21462146
kind: SyntaxKind.JSDocPropertyTag;
21472147
name: Identifier;
2148+
/** the parameter name, if provided *before* the type (TypeScript-style) */
2149+
preParameterName?: Identifier;
2150+
/** the parameter name, if provided *after* the type (JSDoc-standard) */
2151+
postParameterName?: Identifier;
21482152
typeExpression: JSDocTypeExpression;
21492153
isBracketed: boolean;
21502154
}
@@ -2163,7 +2167,7 @@ namespace ts {
21632167
/** the parameter name, if provided *after* the type (JSDoc-standard) */
21642168
postParameterName?: Identifier;
21652169
/** the parameter name, regardless of the location it was provided */
2166-
parameterName: Identifier;
2170+
name: Identifier;
21672171
isBracketed: boolean;
21682172
}
21692173

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ namespace ts {
16351635
}
16361636
else if (param.name.kind === SyntaxKind.Identifier) {
16371637
const name = (param.name as Identifier).text;
1638-
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name);
1638+
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.name.text === name);
16391639
}
16401640
else {
16411641
// TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines
@@ -1646,7 +1646,7 @@ namespace ts {
16461646

16471647
/** Does the opposite of `getJSDocParameterTags`: given a JSDoc parameter, finds the parameter corresponding to it. */
16481648
export function getParameterFromJSDoc(node: JSDocParameterTag): ParameterDeclaration | undefined {
1649-
const name = node.parameterName.text;
1649+
const name = node.name.text;
16501650
const grandParent = node.parent!.parent!;
16511651
Debug.assert(node.parent!.kind === SyntaxKind.JSDocComment);
16521652
if (!isFunctionLike(grandParent)) {

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argSynonymForParamTag.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 27,
9+
"end": 28,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 27,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 22,
4040
"end": 27,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 27
47+
"end": 28
4848
}
4949
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argumentSynonymForParamTag.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 32,
9+
"end": 33,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 32,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 27,
4040
"end": 32,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 32
47+
"end": 33
4848
}
4949
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 29,
9+
"end": 30,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 29,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 24,
4040
"end": 29,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 29
47+
"end": 30
4848
}
4949
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTag1.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 29,
9+
"end": 30,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 29,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 24,
4040
"end": 29,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 29
47+
"end": 30
4848
}
4949
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"end": 30,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 25,
4040
"end": 30,

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"end": 31,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 26,
4040
"end": 31,

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"end": 28
3535
}
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 15,
4040
"end": 20,

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"end": 28
3535
}
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 15,
4040
"end": 20,

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 18,
9+
"end": 19,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -24,7 +24,7 @@
2424
"end": 18,
2525
"text": "foo"
2626
},
27-
"parameterName": {
27+
"name": {
2828
"kind": "Identifier",
2929
"pos": 15,
3030
"end": 18,
@@ -34,6 +34,6 @@
3434
},
3535
"length": 1,
3636
"pos": 8,
37-
"end": 18
37+
"end": 19
3838
}
3939
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 29,
9+
"end": 32,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 29,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 24,
4040
"end": 29,
@@ -45,7 +45,7 @@
4545
"1": {
4646
"kind": "JSDocParameterTag",
4747
"pos": 34,
48-
"end": 55,
48+
"end": 56,
4949
"atToken": {
5050
"kind": "AtToken",
5151
"pos": 34,
@@ -73,7 +73,7 @@
7373
"end": 55,
7474
"text": "name2"
7575
},
76-
"parameterName": {
76+
"name": {
7777
"kind": "Identifier",
7878
"pos": 50,
7979
"end": 55,
@@ -83,6 +83,6 @@
8383
},
8484
"length": 2,
8585
"pos": 8,
86-
"end": 55
86+
"end": 56
8787
}
8888
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 29,
9+
"end": 30,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 29,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 24,
4040
"end": 29,
@@ -45,7 +45,7 @@
4545
"1": {
4646
"kind": "JSDocParameterTag",
4747
"pos": 30,
48-
"end": 51,
48+
"end": 52,
4949
"atToken": {
5050
"kind": "AtToken",
5151
"pos": 30,
@@ -73,7 +73,7 @@
7373
"end": 51,
7474
"text": "name2"
7575
},
76-
"parameterName": {
76+
"name": {
7777
"kind": "Identifier",
7878
"pos": 46,
7979
"end": 51,
@@ -83,6 +83,6 @@
8383
},
8484
"length": 2,
8585
"pos": 8,
86-
"end": 51
86+
"end": 52
8787
}
8888
}

0 commit comments

Comments
 (0)