From 348fc7e51e1df2136b815c7d2847ede78983bccc Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 24 May 2017 16:37:02 -0700 Subject: [PATCH 1/4] Take into account optional property in parameter --- src/compiler/binder.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 204a979d928..8870757999f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1,4 +1,4 @@ -/// +/// /// /* @internal */ @@ -2178,7 +2178,11 @@ namespace ts { case SyntaxKind.JSDocRecordMember: return bindPropertyWorker(node as JSDocRecordMember); case SyntaxKind.JSDocPropertyTag: - return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + let optionalType = 0; + if ((node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType) { + optionalType = SymbolFlags.Optional; + } + return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property | optionalType, SymbolFlags.PropertyExcludes); case SyntaxKind.JSDocFunctionType: return bindFunctionOrConstructorType(node); case SyntaxKind.JSDocTypeLiteral: From cabe4d36060750d742a62f6cd3b27234ee83caf4 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 May 2017 19:49:04 -0700 Subject: [PATCH 2/4] Address PR --- src/compiler/binder.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8870757999f..80bdeae6df5 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2178,11 +2178,10 @@ namespace ts { case SyntaxKind.JSDocRecordMember: return bindPropertyWorker(node as JSDocRecordMember); case SyntaxKind.JSDocPropertyTag: - let optionalType = 0; - if ((node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType) { - optionalType = SymbolFlags.Optional; - } - return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property | optionalType, SymbolFlags.PropertyExcludes); + return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, + (node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? + SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property, + SymbolFlags.PropertyExcludes); case SyntaxKind.JSDocFunctionType: return bindFunctionOrConstructorType(node); case SyntaxKind.JSDocTypeLiteral: From 4f791040fc7fa467dec2ae66bf9b0cc1b688e5e8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 May 2017 20:16:52 -0700 Subject: [PATCH 3/4] Add tests and baselines --- .../reference/checkJsdocTypedefInParamTag1.js | 24 +++++++++++++++++++ .../checkJsdocTypedefInParamTag1.symbols | 17 +++++++++++++ .../checkJsdocTypedefInParamTag1.types | 20 ++++++++++++++++ .../jsdoc/checkJsdocTypedefInParamTag1.ts | 15 ++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 tests/baselines/reference/checkJsdocTypedefInParamTag1.js create mode 100644 tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols create mode 100644 tests/baselines/reference/checkJsdocTypedefInParamTag1.types create mode 100644 tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts diff --git a/tests/baselines/reference/checkJsdocTypedefInParamTag1.js b/tests/baselines/reference/checkJsdocTypedefInParamTag1.js new file mode 100644 index 00000000000..28d6a96b3f9 --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefInParamTag1.js @@ -0,0 +1,24 @@ +//// [0.js] +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} + +foo({x: 'abc'}); + +//// [0.js] +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) { } +foo({ x: 'abc' }); diff --git a/tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols b/tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols new file mode 100644 index 00000000000..19672d6e52c --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/jsdoc/0.js === +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} +>foo : Symbol(foo, Decl(0.js, 0, 0)) +>opts : Symbol(opts, Decl(0.js, 8, 13)) + +foo({x: 'abc'}); +>foo : Symbol(foo, Decl(0.js, 0, 0)) +>x : Symbol(x, Decl(0.js, 10, 5)) + diff --git a/tests/baselines/reference/checkJsdocTypedefInParamTag1.types b/tests/baselines/reference/checkJsdocTypedefInParamTag1.types new file mode 100644 index 00000000000..ff30e8da8a8 --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefInParamTag1.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/0.js === +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} +>foo : (opts: { x: string; y?: string; }) => void +>opts : { x: string; y?: string; } + +foo({x: 'abc'}); +>foo({x: 'abc'}) : void +>foo : (opts: { x: string; y?: string; }) => void +>{x: 'abc'} : { x: string; } +>x : string +>'abc' : "abc" + diff --git a/tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts b/tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts new file mode 100644 index 00000000000..261ce070cf2 --- /dev/null +++ b/tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts @@ -0,0 +1,15 @@ +// @allowJS: true +// @suppressOutputPathCheck: true + +// @filename: 0.js +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} + +foo({x: 'abc'}); \ No newline at end of file From 23be471def7c30dd5b2ce7959986b2259c7fb723 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 May 2017 21:52:23 -0700 Subject: [PATCH 4/4] Fix linting --- src/compiler/binder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 80bdeae6df5..ec3e8157589 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1,4 +1,4 @@ -/// +/// /// /* @internal */ @@ -3596,4 +3596,4 @@ namespace ts { return TransformFlags.NodeExcludes; } } -} +} \ No newline at end of file