Skip to content

Commit

Permalink
Merge pull request microsoft#16122 from Microsoft/master-fix16092
Browse files Browse the repository at this point in the history
[Master] ts-style @Property
  • Loading branch information
yuit authored May 30, 2017
2 parents 2c3c4dd + 27078f9 commit d82a57e
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 89 deletions.
33 changes: 8 additions & 25 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6510,7 +6510,7 @@ namespace ts {
case "arg":
case "argument":
case "param":
tag = parseParamTag(atToken, tagName);
tag = parseParameterOrPropertyTag(atToken, tagName, /*shouldParseParamTag*/ true);
break;
case "return":
case "returns":
Expand Down Expand Up @@ -6655,11 +6655,12 @@ namespace ts {
return { name, isBracketed };
}

function parseParamTag(atToken: AtToken, tagName: Identifier) {
function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, shouldParseParamTag: boolean): JSDocPropertyTag | JSDocParameterTag {
let typeExpression = tryParseTypeExpression();
skipWhitespace();

const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
skipWhitespace();

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

const result = <JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos);
const result = shouldParseParamTag ?
<JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos) :
<JSDocPropertyTag>createNode(SyntaxKind.JSDocPropertyTag, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.preParameterName = preName;
result.typeExpression = typeExpression;
result.postParameterName = postName;
result.parameterName = postName || preName;
result.name = postName || preName;
result.isBracketed = isBracketed;
return finishNode(result);
}
Expand Down Expand Up @@ -6713,26 +6716,6 @@ namespace ts {
return finishNode(result);
}

function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
const typeExpression = tryParseTypeExpression();
skipWhitespace();
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
skipWhitespace();

if (!name) {
parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected);
return undefined;
}

const result = <JSDocPropertyTag>createNode(SyntaxKind.JSDocPropertyTag, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.name = name;
result.typeExpression = typeExpression;
result.isBracketed = isBracketed;
return finishNode(result);
}

function parseAugmentsTag(atToken: AtToken, tagName: Identifier): JSDocAugmentsTag {
const typeExpression = tryParseTypeExpression();

Expand Down Expand Up @@ -6869,7 +6852,7 @@ namespace ts {
return true;
case "prop":
case "property":
const propertyTag = parsePropertyTag(atToken, tagName);
const propertyTag = parseParameterOrPropertyTag(atToken, tagName, /*shouldParseParamTag*/ false) as JSDocPropertyTag;
if (propertyTag) {
if (!parentTag.jsDocPropertyTags) {
parentTag.jsDocPropertyTags = <NodeArray<JSDocPropertyTag>>[];
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,10 @@ namespace ts {
parent: JSDoc;
kind: SyntaxKind.JSDocPropertyTag;
name: Identifier;
/** the parameter name, if provided *before* the type (TypeScript-style) */
preParameterName?: Identifier;
/** the parameter name, if provided *after* the type (JSDoc-standard) */
postParameterName?: Identifier;
typeExpression: JSDocTypeExpression;
isBracketed: boolean;
}
Expand All @@ -2163,7 +2167,7 @@ namespace ts {
/** the parameter name, if provided *after* the type (JSDoc-standard) */
postParameterName?: Identifier;
/** the parameter name, regardless of the location it was provided */
parameterName: Identifier;
name: Identifier;
isBracketed: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ namespace ts {
}
else if (param.name.kind === SyntaxKind.Identifier) {
const name = (param.name as Identifier).text;
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name);
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.name.text === name);
}
else {
// TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines
Expand All @@ -1646,7 +1646,7 @@ namespace ts {

/** Does the opposite of `getJSDocParameterTags`: given a JSDoc parameter, finds the parameter corresponding to it. */
export function getParameterFromJSDoc(node: JSDocParameterTag): ParameterDeclaration | undefined {
const name = node.parameterName.text;
const name = node.name.text;
const grandParent = node.parent!.parent!;
Debug.assert(node.parent!.kind === SyntaxKind.JSDocComment);
if (!isFunctionLike(grandParent)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 27,
"end": 28,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand Down Expand Up @@ -34,7 +34,7 @@
"end": 27,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 22,
"end": 27,
Expand All @@ -44,6 +44,6 @@
},
"length": 1,
"pos": 8,
"end": 27
"end": 28
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 32,
"end": 33,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand Down Expand Up @@ -34,7 +34,7 @@
"end": 32,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 27,
"end": 32,
Expand All @@ -44,6 +44,6 @@
},
"length": 1,
"pos": 8,
"end": 32
"end": 33
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 29,
"end": 30,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand Down Expand Up @@ -34,7 +34,7 @@
"end": 29,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 24,
"end": 29,
Expand All @@ -44,6 +44,6 @@
},
"length": 1,
"pos": 8,
"end": 29
"end": 30
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 29,
"end": 30,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand Down Expand Up @@ -34,7 +34,7 @@
"end": 29,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 24,
"end": 29,
Expand All @@ -44,6 +44,6 @@
},
"length": 1,
"pos": 8,
"end": 29
"end": 30
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"end": 30,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 25,
"end": 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"end": 31,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 26,
"end": 31,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"end": 28
}
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 15,
"end": 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"end": 28
}
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 15,
"end": 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 18,
"end": 19,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand All @@ -24,7 +24,7 @@
"end": 18,
"text": "foo"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 15,
"end": 18,
Expand All @@ -34,6 +34,6 @@
},
"length": 1,
"pos": 8,
"end": 18
"end": 19
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 29,
"end": 32,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand Down Expand Up @@ -34,7 +34,7 @@
"end": 29,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 24,
"end": 29,
Expand All @@ -45,7 +45,7 @@
"1": {
"kind": "JSDocParameterTag",
"pos": 34,
"end": 55,
"end": 56,
"atToken": {
"kind": "AtToken",
"pos": 34,
Expand Down Expand Up @@ -73,7 +73,7 @@
"end": 55,
"text": "name2"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 50,
"end": 55,
Expand All @@ -83,6 +83,6 @@
},
"length": 2,
"pos": 8,
"end": 55
"end": 56
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocParameterTag",
"pos": 8,
"end": 29,
"end": 30,
"atToken": {
"kind": "AtToken",
"pos": 8,
Expand Down Expand Up @@ -34,7 +34,7 @@
"end": 29,
"text": "name1"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 24,
"end": 29,
Expand All @@ -45,7 +45,7 @@
"1": {
"kind": "JSDocParameterTag",
"pos": 30,
"end": 51,
"end": 52,
"atToken": {
"kind": "AtToken",
"pos": 30,
Expand Down Expand Up @@ -73,7 +73,7 @@
"end": 51,
"text": "name2"
},
"parameterName": {
"name": {
"kind": "Identifier",
"pos": 46,
"end": 51,
Expand All @@ -83,6 +83,6 @@
},
"length": 2,
"pos": 8,
"end": 51
"end": 52
}
}
Loading

0 comments on commit d82a57e

Please sign in to comment.