diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index db2c09e34b..4e1d4ccd9b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6132,16 +6132,14 @@ namespace ts { } // Parses out a JSDoc type expression. - export function parseJSDocTypeExpression(): JSDocTypeExpression; - export function parseJSDocTypeExpression(requireBraces: true): JSDocTypeExpression | undefined; - export function parseJSDocTypeExpression(requireBraces?: boolean): JSDocTypeExpression | undefined { + export function parseJSDocTypeExpression(mayOmitBraces?: boolean): JSDocTypeExpression { const result = createNode(SyntaxKind.JSDocTypeExpression, scanner.getTokenPos()); - if (!parseExpected(SyntaxKind.OpenBraceToken) && requireBraces) { - return undefined; - } + const hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(SyntaxKind.OpenBraceToken); result.type = doInsideOfContext(NodeFlags.JSDoc, parseType); - parseExpected(SyntaxKind.CloseBraceToken); + if (!mayOmitBraces || hasBrace) { + parseExpected(SyntaxKind.CloseBraceToken); + } fixupParentReferences(result); return finishNode(result); @@ -6597,7 +6595,7 @@ namespace ts { const result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; - result.typeExpression = parseJSDocTypeExpression(/*requireBraces*/ true); + result.typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true); return finishNode(result); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 8dc5a10c62..78df166633 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -1873,7 +1873,17 @@ namespace ts { return token = SyntaxKind.CommaToken; case CharacterCodes.dot: pos++; + if (text.substr(tokenPos, pos + 2) === "...") { + pos += 2; + return token = SyntaxKind.DotDotDotToken; + } return token = SyntaxKind.DotToken; + case CharacterCodes.exclamation: + pos++; + return token = SyntaxKind.ExclamationToken; + case CharacterCodes.question: + pos++; + return token = SyntaxKind.QuestionToken; } if (isIdentifierStart(ch, ScriptTarget.Latest)) { @@ -1881,6 +1891,7 @@ namespace ts { while (isIdentifierPart(text.charCodeAt(pos), ScriptTarget.Latest) && pos < end) { pos++; } + tokenValue = text.substring(tokenPos, pos); return token = SyntaxKind.Identifier; } else { diff --git a/tests/baselines/reference/jsdocTypedefMissingType.errors.txt b/tests/baselines/reference/jsdocTypedefMissingType.errors.txt index b5b29a47ed..ef1141a8e8 100644 --- a/tests/baselines/reference/jsdocTypedefMissingType.errors.txt +++ b/tests/baselines/reference/jsdocTypedefMissingType.errors.txt @@ -1,8 +1,7 @@ /a.js(2,14): error TS8021: JSDoc '@typedef' tag should either have a type annotation or be followed by '@property' or '@member' tags. -/a.js(12,11): error TS1005: '{' expected. -==== /a.js (2 errors) ==== +==== /a.js (1 errors) ==== // Bad: missing a type /** @typedef T */ ~ @@ -17,7 +16,5 @@ */ /** @type Person */ - ~~~~~~ -!!! error TS1005: '{' expected. const person = { name: "" }; \ No newline at end of file diff --git a/tests/baselines/reference/jsdocTypedefMissingType.types b/tests/baselines/reference/jsdocTypedefMissingType.types index 4a3f796ccb..18cd68abfc 100644 --- a/tests/baselines/reference/jsdocTypedefMissingType.types +++ b/tests/baselines/reference/jsdocTypedefMissingType.types @@ -14,8 +14,8 @@ const t = 0; /** @type Person */ const person = { name: "" }; ->person : { [x: string]: any; name: string; } ->{ name: "" } : { [x: string]: any; name: string; } +>person : { name: string; } +>{ name: "" } : { name: string; } >name : string >"" : "" diff --git a/tests/baselines/reference/malformedTags.types b/tests/baselines/reference/malformedTags.types index b4f7daecd8..c3af959586 100644 --- a/tests/baselines/reference/malformedTags.types +++ b/tests/baselines/reference/malformedTags.types @@ -5,7 +5,7 @@ * @type Function */ var isArray = Array.isArray; ->isArray : (arg: any) => arg is any[] +>isArray : Function >Array.isArray : (arg: any) => arg is any[] >Array : ArrayConstructor >isArray : (arg: any) => arg is any[] diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index de98c4f608..cfe2154c33 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -50,9 +50,10 @@ node_modules/chrome-devtools-frontend/front_end/Runtime.js(478,17): error TS2503 node_modules/chrome-devtools-frontend/front_end/Runtime.js(488,17): error TS2503: Cannot find namespace 'Runtime'. node_modules/chrome-devtools-frontend/front_end/Runtime.js(489,17): error TS2503: Cannot find namespace 'Runtime'. node_modules/chrome-devtools-frontend/front_end/Runtime.js(502,16): error TS2503: Cannot find namespace 'Runtime'. -node_modules/chrome-devtools-frontend/front_end/Runtime.js(527,9): error TS2322: Type 'Window' is not assignable to type 'new () => any'. - Type 'Window' provides no match for the signature 'new (): any'. -node_modules/chrome-devtools-frontend/front_end/Runtime.js(527,55): error TS1005: '{' expected. +node_modules/chrome-devtools-frontend/front_end/Runtime.js(527,9): error TS2322: Type 'Function' is not assignable to type 'new () => any'. + Type 'Function' provides no match for the signature 'new (): any'. +node_modules/chrome-devtools-frontend/front_end/Runtime.js(527,49): error TS2352: Type 'Window' cannot be converted to type 'Function'. + Property 'apply' is missing in type 'Window'. node_modules/chrome-devtools-frontend/front_end/Runtime.js(539,20): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. node_modules/chrome-devtools-frontend/front_end/Runtime.js(577,10): error TS2339: Property 'name' does not exist on type '(Anonymous class)'. node_modules/chrome-devtools-frontend/front_end/Runtime.js(582,10): error TS2339: Property 'extensions' does not exist on type '(Anonymous class)'. @@ -332,7 +333,7 @@ node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane. node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(301,5): error TS2304: Cannot find name 'UI'. node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(302,23): error TS2339: Property 'tabIndex' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(311,5): error TS2304: Cannot find name 'UI'. -node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(314,15): error TS1005: '{' expected. +node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(314,23): error TS2503: Cannot find namespace 'Accessibility'. node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(323,23): error TS2339: Property 'style' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(330,27): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/accessibility/AXBreadcrumbsPane.js(357,15): error TS2503: Cannot find namespace 'Accessibility'. @@ -8542,7 +8543,7 @@ node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManag node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(247,15): error TS2503: Cannot find namespace 'Coverage'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(248,15): error TS2503: Cannot find namespace 'Coverage'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(255,15): error TS2503: Cannot find namespace 'Common'. -node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(258,34): error TS1005: '{' expected. +node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(258,35): error TS2503: Cannot find namespace 'Workspace'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(259,39): error TS2304: Cannot find name 'Coverage'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(263,1): error TS2304: Cannot find name 'Coverage'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageDecorationManager.js(268,1): error TS2304: Cannot find name 'Coverage'. @@ -8744,7 +8745,7 @@ node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(220,1): node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(223,15): error TS2503: Cannot find namespace 'UI'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(229,5): error TS2304: Cannot find name 'UI'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(230,21): error TS2304: Cannot find name 'UI'. -node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(231,59): error TS1005: '{' expected. +node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(231,60): error TS2503: Cannot find namespace 'Coverage'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageView.js(237,15): error TS2503: Cannot find namespace 'Coverage'. node_modules/chrome-devtools-frontend/front_end/coverage_test_runner/CoverageTestRunner.js(10,1): error TS2304: Cannot find name 'CoverageTestRunner'. node_modules/chrome-devtools-frontend/front_end/coverage_test_runner/CoverageTestRunner.js(11,3): error TS2304: Cannot find name 'UI'. @@ -13261,7 +13262,6 @@ node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(46,81): error TS2708: Cannot use namespace 'FormatterWorker' as a value. node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(51,3): error TS2322: Type '(line: string, callback: (arg0: string, arg1: string, arg2: number, arg3: number) => any) => void' is not assignable to type '(arg0: string) => any'. node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(54,1): error TS2708: Cannot use namespace 'FormatterWorker' as a value. -node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(58,26): error TS1005: '{' expected. node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(64,7): error TS2708: Cannot use namespace 'FormatterWorker' as a value. node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(67,7): error TS2708: Cannot use namespace 'FormatterWorker' as a value. node_modules/chrome-devtools-frontend/front_end/formatter_worker/FormatterWorker.js(70,7): error TS2708: Cannot use namespace 'FormatterWorker' as a value. @@ -14928,7 +14928,6 @@ node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(49, node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(51,9): error TS2304: Cannot find name 'LayerViewer'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(54,32): error TS2339: Property 'contentElement' does not exist on type '(Anonymous class)'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(66,32): error TS2304: Cannot find name 'LayerViewer'. -node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(68,15): error TS1005: '{' expected. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(76,15): error TS2503: Cannot find namespace 'SDK'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(89,15): error TS2503: Cannot find namespace 'SDK'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(98,5): error TS2304: Cannot find name 'UI'. @@ -15008,7 +15007,11 @@ node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(547 node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(548,33): error TS2304: Cannot find name 'LayerViewer'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(552,74): error TS2304: Cannot find name 'LayerViewer'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(557,28): error TS2304: Cannot find name 'LayerViewer'. +node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(559,48): error TS2339: Property 'image' does not exist on type 'WebGLTexture'. +node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(561,49): error TS2339: Property 'image' does not exist on type 'WebGLTexture'. +node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(561,94): error TS2339: Property 'image' does not exist on type 'WebGLTexture'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(565,25): error TS2304: Cannot find name 'LayerViewer'. +node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(566,97): error TS2339: Property 'image' does not exist on type 'WebGLTexture'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(576,15): error TS2503: Cannot find namespace 'LayerViewer'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(590,15): error TS2339: Property 'isShowing' does not exist on type '(Anonymous class)'. node_modules/chrome-devtools-frontend/front_end/layer_viewer/Layers3DView.js(595,34): error TS2339: Property 'contentElement' does not exist on type '(Anonymous class)'. @@ -18482,9 +18485,8 @@ node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(847,29): e node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(859,25): error TS2304: Cannot find name 'UI'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(870,27): error TS2304: Cannot find name 'UI'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(903,42): error TS2503: Cannot find namespace 'PerfUI'. -node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(907,17): error TS1005: '{' expected. -node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(915,27): error TS2339: Property 'peekLast' does not exist on type '{ [x: string]: any; nestingLevel: number; visible: boolean; }[]'. -node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(919,45): error TS2339: Property 'peekLast' does not exist on type '{ [x: string]: any; nestingLevel: number; visible: boolean; }[]'. +node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(915,27): error TS2339: Property 'peekLast' does not exist on type '{ nestingLevel: number; visible: boolean; }[]'. +node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(919,45): error TS2339: Property 'peekLast' does not exist on type '{ nestingLevel: number; visible: boolean; }[]'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(931,15): error TS2503: Cannot find namespace 'PerfUI'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(935,12): error TS2304: Cannot find name 'UI'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(940,15): error TS2503: Cannot find namespace 'PerfUI'. @@ -18496,9 +18498,8 @@ node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1004,18): node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1090,18): error TS2304: Cannot find name 'PerfUI'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1117,15): error TS2503: Cannot find namespace 'PerfUI'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1165,46): error TS2304: Cannot find name 'PerfUI'. -node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1167,15): error TS1005: '{' expected. -node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1176,27): error TS2339: Property 'peekLast' does not exist on type '{ [x: string]: any; nestingLevel: number; visible: boolean; }[]'. -node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1182,43): error TS2339: Property 'peekLast' does not exist on type '{ [x: string]: any; nestingLevel: number; visible: boolean; }[]'. +node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1176,27): error TS2339: Property 'peekLast' does not exist on type '{ nestingLevel: number; visible: boolean; }[]'. +node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1182,43): error TS2339: Property 'peekLast' does not exist on type '{ nestingLevel: number; visible: boolean; }[]'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1273,25): error TS2339: Property 'style' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1286,19): error TS2339: Property 'constrain' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/perf_ui/FlameChart.js(1376,1): error TS2304: Cannot find name 'PerfUI'. @@ -31622,7 +31623,7 @@ node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js( node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(24,20): error TS2304: Cannot find name 'Timeline'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(26,38): error TS2304: Cannot find name 'UI'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(31,37): error TS2304: Cannot find name 'Common'. -node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(34,15): error TS1005: '{' expected. +node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(34,27): error TS2503: Cannot find namespace 'Timeline'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(38,32): error TS2304: Cannot find name 'Timeline'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(39,40): error TS2304: Cannot find name 'Common'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineDetailsView.js(42,32): error TS2304: Cannot find name 'Timeline'. @@ -34041,7 +34042,7 @@ node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilt node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(40,14): error TS2304: Cannot find name 'TimelineModel'. node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(41,27): error TS2304: Cannot find name 'TimelineModel'. node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(42,14): error TS2304: Cannot find name 'TimelineModel'. -node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(43,22): error TS1005: '{' expected. +node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(43,23): error TS2503: Cannot find namespace 'TimelineModel'. node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(47,1): error TS2304: Cannot find name 'TimelineModel'. node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(47,61): error TS2304: Cannot find name 'TimelineModel'. node_modules/chrome-devtools-frontend/front_end/timeline_model/TimelineModelFilter.js(58,15): error TS2503: Cannot find namespace 'SDK'.