Merge pull request #16094 from Microsoft/master-@propWithBracket

[Master] @prop with bracket for optional property
This commit is contained in:
Yui 2017-05-26 10:55:43 -07:00 committed by GitHub
commit 3186fc4897
7 changed files with 29 additions and 11 deletions

View file

@ -2179,7 +2179,7 @@ namespace ts {
return bindPropertyWorker(node as JSDocRecordMember); return bindPropertyWorker(node as JSDocRecordMember);
case SyntaxKind.JSDocPropertyTag: case SyntaxKind.JSDocPropertyTag:
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag,
(node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? (node as JSDocPropertyTag).isBracketed || ((node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType) ?
SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property, SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property,
SymbolFlags.PropertyExcludes); SymbolFlags.PropertyExcludes);
case SyntaxKind.JSDocFunctionType: case SyntaxKind.JSDocFunctionType:

View file

@ -6631,10 +6631,7 @@ namespace ts {
}); });
} }
function parseParamTag(atToken: AtToken, tagName: Identifier) { function parseBracketNameInPropertyAndParamTag() {
let typeExpression = tryParseTypeExpression();
skipWhitespace();
let name: Identifier; let name: Identifier;
let isBracketed: boolean; let isBracketed: boolean;
// Looking for something like '[foo]' or 'foo' // Looking for something like '[foo]' or 'foo'
@ -6653,6 +6650,14 @@ namespace ts {
else if (tokenIsIdentifierOrKeyword(token())) { else if (tokenIsIdentifierOrKeyword(token())) {
name = parseJSDocIdentifierName(); name = parseJSDocIdentifierName();
} }
return { name, isBracketed };
}
function parseParamTag(atToken: AtToken, tagName: Identifier) {
let typeExpression = tryParseTypeExpression();
skipWhitespace();
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
if (!name) { if (!name) {
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected); parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
@ -6709,8 +6714,9 @@ namespace ts {
function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag { function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
const typeExpression = tryParseTypeExpression(); const typeExpression = tryParseTypeExpression();
skipWhitespace(); skipWhitespace();
const name = parseJSDocIdentifierName(); const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
skipWhitespace(); skipWhitespace();
if (!name) { if (!name) {
parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected); parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected);
return undefined; return undefined;
@ -6721,6 +6727,7 @@ namespace ts {
result.tagName = tagName; result.tagName = tagName;
result.name = name; result.name = name;
result.typeExpression = typeExpression; result.typeExpression = typeExpression;
result.isBracketed = isBracketed;
return finishNode(result); return finishNode(result);
} }

View file

@ -2146,6 +2146,7 @@ namespace ts {
kind: SyntaxKind.JSDocPropertyTag; kind: SyntaxKind.JSDocPropertyTag;
name: Identifier; name: Identifier;
typeExpression: JSDocTypeExpression; typeExpression: JSDocTypeExpression;
isBracketed: boolean;
} }
export interface JSDocTypeLiteral extends JSDocType { export interface JSDocTypeLiteral extends JSDocType {

View file

@ -4,6 +4,8 @@
* @typedef {Object} Opts * @typedef {Object} Opts
* @property {string} x * @property {string} x
* @property {string=} y * @property {string=} y
* @property {string} [z]
* @property {string} [w="hi"]
* *
* @param {Opts} opts * @param {Opts} opts
*/ */
@ -17,6 +19,8 @@ foo({x: 'abc'});
* @typedef {Object} Opts * @typedef {Object} Opts
* @property {string} x * @property {string} x
* @property {string=} y * @property {string=} y
* @property {string} [z]
* @property {string} [w="hi"]
* *
* @param {Opts} opts * @param {Opts} opts
*/ */

View file

@ -4,14 +4,16 @@
* @typedef {Object} Opts * @typedef {Object} Opts
* @property {string} x * @property {string} x
* @property {string=} y * @property {string=} y
* @property {string} [z]
* @property {string} [w="hi"]
* *
* @param {Opts} opts * @param {Opts} opts
*/ */
function foo(opts) {} function foo(opts) {}
>foo : Symbol(foo, Decl(0.js, 0, 0)) >foo : Symbol(foo, Decl(0.js, 0, 0))
>opts : Symbol(opts, Decl(0.js, 8, 13)) >opts : Symbol(opts, Decl(0.js, 10, 13))
foo({x: 'abc'}); foo({x: 'abc'});
>foo : Symbol(foo, Decl(0.js, 0, 0)) >foo : Symbol(foo, Decl(0.js, 0, 0))
>x : Symbol(x, Decl(0.js, 10, 5)) >x : Symbol(x, Decl(0.js, 12, 5))

View file

@ -4,16 +4,18 @@
* @typedef {Object} Opts * @typedef {Object} Opts
* @property {string} x * @property {string} x
* @property {string=} y * @property {string=} y
* @property {string} [z]
* @property {string} [w="hi"]
* *
* @param {Opts} opts * @param {Opts} opts
*/ */
function foo(opts) {} function foo(opts) {}
>foo : (opts: { x: string; y?: string; }) => void >foo : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
>opts : { x: string; y?: string; } >opts : { x: string; y?: string; z?: string; w?: string; }
foo({x: 'abc'}); foo({x: 'abc'});
>foo({x: 'abc'}) : void >foo({x: 'abc'}) : void
>foo : (opts: { x: string; y?: string; }) => void >foo : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
>{x: 'abc'} : { x: string; } >{x: 'abc'} : { x: string; }
>x : string >x : string
>'abc' : "abc" >'abc' : "abc"

View file

@ -7,6 +7,8 @@
* @typedef {Object} Opts * @typedef {Object} Opts
* @property {string} x * @property {string} x
* @property {string=} y * @property {string=} y
* @property {string} [z]
* @property {string} [w="hi"]
* *
* @param {Opts} opts * @param {Opts} opts
*/ */