Merge pull request #16122 from Microsoft/master-fix16092
[Master] ts-style @property
This commit is contained in:
commit
d82a57ea5d
|
@ -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":
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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>>[];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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)) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 27,
|
||||
"end": 28,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -34,7 +34,7 @@
|
|||
"end": 27,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 22,
|
||||
"end": 27,
|
||||
|
@ -44,6 +44,6 @@
|
|||
},
|
||||
"length": 1,
|
||||
"pos": 8,
|
||||
"end": 27
|
||||
"end": 28
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 32,
|
||||
"end": 33,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -34,7 +34,7 @@
|
|||
"end": 32,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 27,
|
||||
"end": 32,
|
||||
|
@ -44,6 +44,6 @@
|
|||
},
|
||||
"length": 1,
|
||||
"pos": 8,
|
||||
"end": 32
|
||||
"end": 33
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 29,
|
||||
"end": 30,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -34,7 +34,7 @@
|
|||
"end": 29,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 24,
|
||||
"end": 29,
|
||||
|
@ -44,6 +44,6 @@
|
|||
},
|
||||
"length": 1,
|
||||
"pos": 8,
|
||||
"end": 29
|
||||
"end": 30
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 29,
|
||||
"end": 30,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -34,7 +34,7 @@
|
|||
"end": 29,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 24,
|
||||
"end": 29,
|
||||
|
@ -44,6 +44,6 @@
|
|||
},
|
||||
"length": 1,
|
||||
"pos": 8,
|
||||
"end": 29
|
||||
"end": 30
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@
|
|||
"end": 30,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 25,
|
||||
"end": 30,
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"end": 31,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 26,
|
||||
"end": 31,
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"end": 28
|
||||
}
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 15,
|
||||
"end": 20,
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"end": 28
|
||||
}
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 15,
|
||||
"end": 20,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 18,
|
||||
"end": 19,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -24,7 +24,7 @@
|
|||
"end": 18,
|
||||
"text": "foo"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 15,
|
||||
"end": 18,
|
||||
|
@ -34,6 +34,6 @@
|
|||
},
|
||||
"length": 1,
|
||||
"pos": 8,
|
||||
"end": 18
|
||||
"end": 19
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 29,
|
||||
"end": 32,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -34,7 +34,7 @@
|
|||
"end": 29,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 24,
|
||||
"end": 29,
|
||||
|
@ -45,7 +45,7 @@
|
|||
"1": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 34,
|
||||
"end": 55,
|
||||
"end": 56,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 34,
|
||||
|
@ -73,7 +73,7 @@
|
|||
"end": 55,
|
||||
"text": "name2"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 50,
|
||||
"end": 55,
|
||||
|
@ -83,6 +83,6 @@
|
|||
},
|
||||
"length": 2,
|
||||
"pos": 8,
|
||||
"end": 55
|
||||
"end": 56
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"0": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 8,
|
||||
"end": 29,
|
||||
"end": 30,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 8,
|
||||
|
@ -34,7 +34,7 @@
|
|||
"end": 29,
|
||||
"text": "name1"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 24,
|
||||
"end": 29,
|
||||
|
@ -45,7 +45,7 @@
|
|||
"1": {
|
||||
"kind": "JSDocParameterTag",
|
||||
"pos": 30,
|
||||
"end": 51,
|
||||
"end": 52,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 30,
|
||||
|
@ -73,7 +73,7 @@
|
|||
"end": 51,
|
||||
"text": "name2"
|
||||
},
|
||||
"parameterName": {
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 46,
|
||||
"end": 51,
|
||||
|
@ -83,6 +83,6 @@
|
|||
},
|
||||
"length": 2,
|
||||
"pos": 8,
|
||||
"end": 51
|
||||
"end": 52
|
||||
}
|
||||
}
|
|
@ -82,12 +82,6 @@
|
|||
"end": 56,
|
||||
"text": "property"
|
||||
},
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 66,
|
||||
"end": 69,
|
||||
"text": "age"
|
||||
},
|
||||
"typeExpression": {
|
||||
"kind": "JSDocTypeExpression",
|
||||
"pos": 57,
|
||||
|
@ -97,6 +91,18 @@
|
|||
"pos": 58,
|
||||
"end": 64
|
||||
}
|
||||
},
|
||||
"postParameterName": {
|
||||
"kind": "Identifier",
|
||||
"pos": 66,
|
||||
"end": 69,
|
||||
"text": "age"
|
||||
},
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 66,
|
||||
"end": 69,
|
||||
"text": "age"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -114,12 +120,6 @@
|
|||
"end": 83,
|
||||
"text": "property"
|
||||
},
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 93,
|
||||
"end": 97,
|
||||
"text": "name"
|
||||
},
|
||||
"typeExpression": {
|
||||
"kind": "JSDocTypeExpression",
|
||||
"pos": 84,
|
||||
|
@ -129,6 +129,18 @@
|
|||
"pos": 85,
|
||||
"end": 91
|
||||
}
|
||||
},
|
||||
"postParameterName": {
|
||||
"kind": "Identifier",
|
||||
"pos": 93,
|
||||
"end": 97,
|
||||
"text": "name"
|
||||
},
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"pos": 93,
|
||||
"end": 97,
|
||||
"text": "name"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -15,6 +15,19 @@ function foo(opts) {
|
|||
|
||||
foo({x: 'abc'});
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnotherOpts
|
||||
* @property anotherX {string}
|
||||
* @property anotherY {string=}
|
||||
*
|
||||
* @param {AnotherOpts} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
opts.anotherX;
|
||||
}
|
||||
|
||||
foo1({anotherX: "world"});
|
||||
|
||||
/**
|
||||
* @typedef {object} Opts1
|
||||
* @property {string} x
|
||||
|
@ -24,10 +37,10 @@ foo({x: 'abc'});
|
|||
*
|
||||
* @param {Opts1} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
function foo2(opts) {
|
||||
opts.x;
|
||||
}
|
||||
foo1({x: 'abc'});
|
||||
foo2({x: 'abc'});
|
||||
|
||||
|
||||
//// [0.js]
|
||||
|
@ -45,6 +58,17 @@ function foo(opts) {
|
|||
opts.x;
|
||||
}
|
||||
foo({ x: 'abc' });
|
||||
/**
|
||||
* @typedef {Object} AnotherOpts
|
||||
* @property anotherX {string}
|
||||
* @property anotherY {string=}
|
||||
*
|
||||
* @param {AnotherOpts} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
opts.anotherX;
|
||||
}
|
||||
foo1({ anotherX: "world" });
|
||||
/**
|
||||
* @typedef {object} Opts1
|
||||
* @property {string} x
|
||||
|
@ -54,7 +78,7 @@ foo({ x: 'abc' });
|
|||
*
|
||||
* @param {Opts1} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
function foo2(opts) {
|
||||
opts.x;
|
||||
}
|
||||
foo1({ x: 'abc' });
|
||||
foo2({ x: 'abc' });
|
||||
|
|
|
@ -23,6 +23,27 @@ foo({x: 'abc'});
|
|||
>foo : Symbol(foo, Decl(0.js, 0, 0))
|
||||
>x : Symbol(x, Decl(0.js, 14, 5))
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnotherOpts
|
||||
* @property anotherX {string}
|
||||
* @property anotherY {string=}
|
||||
*
|
||||
* @param {AnotherOpts} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
>foo1 : Symbol(foo1, Decl(0.js, 14, 16))
|
||||
>opts : Symbol(opts, Decl(0.js, 23, 14))
|
||||
|
||||
opts.anotherX;
|
||||
>opts.anotherX : Symbol(anotherX, Decl(0.js, 18, 3))
|
||||
>opts : Symbol(opts, Decl(0.js, 23, 14))
|
||||
>anotherX : Symbol(anotherX, Decl(0.js, 18, 3))
|
||||
}
|
||||
|
||||
foo1({anotherX: "world"});
|
||||
>foo1 : Symbol(foo1, Decl(0.js, 14, 16))
|
||||
>anotherX : Symbol(anotherX, Decl(0.js, 27, 6))
|
||||
|
||||
/**
|
||||
* @typedef {object} Opts1
|
||||
* @property {string} x
|
||||
|
@ -32,16 +53,16 @@ foo({x: 'abc'});
|
|||
*
|
||||
* @param {Opts1} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
>foo1 : Symbol(foo1, Decl(0.js, 14, 16))
|
||||
>opts : Symbol(opts, Decl(0.js, 25, 14))
|
||||
function foo2(opts) {
|
||||
>foo2 : Symbol(foo2, Decl(0.js, 27, 26))
|
||||
>opts : Symbol(opts, Decl(0.js, 38, 14))
|
||||
|
||||
opts.x;
|
||||
>opts.x : Symbol(x, Decl(0.js, 18, 3))
|
||||
>opts : Symbol(opts, Decl(0.js, 25, 14))
|
||||
>x : Symbol(x, Decl(0.js, 18, 3))
|
||||
>opts.x : Symbol(x, Decl(0.js, 31, 3))
|
||||
>opts : Symbol(opts, Decl(0.js, 38, 14))
|
||||
>x : Symbol(x, Decl(0.js, 31, 3))
|
||||
}
|
||||
foo1({x: 'abc'});
|
||||
>foo1 : Symbol(foo1, Decl(0.js, 14, 16))
|
||||
>x : Symbol(x, Decl(0.js, 28, 6))
|
||||
foo2({x: 'abc'});
|
||||
>foo2 : Symbol(foo2, Decl(0.js, 27, 26))
|
||||
>x : Symbol(x, Decl(0.js, 41, 6))
|
||||
|
||||
|
|
|
@ -26,6 +26,30 @@ foo({x: 'abc'});
|
|||
>x : string
|
||||
>'abc' : "abc"
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnotherOpts
|
||||
* @property anotherX {string}
|
||||
* @property anotherY {string=}
|
||||
*
|
||||
* @param {AnotherOpts} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
>foo1 : (opts: { anotherX: string; anotherY?: string; }) => void
|
||||
>opts : { anotherX: string; anotherY?: string; }
|
||||
|
||||
opts.anotherX;
|
||||
>opts.anotherX : string
|
||||
>opts : { anotherX: string; anotherY?: string; }
|
||||
>anotherX : string
|
||||
}
|
||||
|
||||
foo1({anotherX: "world"});
|
||||
>foo1({anotherX: "world"}) : void
|
||||
>foo1 : (opts: { anotherX: string; anotherY?: string; }) => void
|
||||
>{anotherX: "world"} : { anotherX: string; }
|
||||
>anotherX : string
|
||||
>"world" : "world"
|
||||
|
||||
/**
|
||||
* @typedef {object} Opts1
|
||||
* @property {string} x
|
||||
|
@ -35,8 +59,8 @@ foo({x: 'abc'});
|
|||
*
|
||||
* @param {Opts1} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
>foo1 : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
|
||||
function foo2(opts) {
|
||||
>foo2 : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
|
||||
>opts : { x: string; y?: string; z?: string; w?: string; }
|
||||
|
||||
opts.x;
|
||||
|
@ -44,9 +68,9 @@ function foo1(opts) {
|
|||
>opts : { x: string; y?: string; z?: string; w?: string; }
|
||||
>x : string
|
||||
}
|
||||
foo1({x: 'abc'});
|
||||
>foo1({x: 'abc'}) : void
|
||||
>foo1 : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
|
||||
foo2({x: 'abc'});
|
||||
>foo2({x: 'abc'}) : void
|
||||
>foo2 : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
|
||||
>{x: 'abc'} : { x: string; }
|
||||
>x : string
|
||||
>'abc' : "abc"
|
||||
|
|
|
@ -18,6 +18,19 @@ function foo(opts) {
|
|||
|
||||
foo({x: 'abc'});
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnotherOpts
|
||||
* @property anotherX {string}
|
||||
* @property anotherY {string=}
|
||||
*
|
||||
* @param {AnotherOpts} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
opts.anotherX;
|
||||
}
|
||||
|
||||
foo1({anotherX: "world"});
|
||||
|
||||
/**
|
||||
* @typedef {object} Opts1
|
||||
* @property {string} x
|
||||
|
@ -27,7 +40,7 @@ foo({x: 'abc'});
|
|||
*
|
||||
* @param {Opts1} opts
|
||||
*/
|
||||
function foo1(opts) {
|
||||
function foo2(opts) {
|
||||
opts.x;
|
||||
}
|
||||
foo1({x: 'abc'});
|
||||
foo2({x: 'abc'});
|
||||
|
|
Loading…
Reference in a new issue