From 52d32e55972d1c918fd7586d217efbf2bca6b904 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 21 Apr 2020 12:57:26 +0300 Subject: [PATCH 01/43] Add outlining spans for object destructuring elements --- src/services/outliningElementsCollector.ts | 1 + .../getOutliningForObjectDestructuring.ts | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/cases/fourslash/getOutliningForObjectDestructuring.ts diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index dd71b48c49c..3d35f78343e 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -199,6 +199,7 @@ namespace ts.OutliningElementsCollector { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.CaseBlock: + case SyntaxKind.ObjectBindingPattern: return spanForNode(n); case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: diff --git a/tests/cases/fourslash/getOutliningForObjectDestructuring.ts b/tests/cases/fourslash/getOutliningForObjectDestructuring.ts new file mode 100644 index 00000000000..bc9ce6ba2cd --- /dev/null +++ b/tests/cases/fourslash/getOutliningForObjectDestructuring.ts @@ -0,0 +1,39 @@ +/// + +////const[| { +//// a, +//// b, +//// c +////}|] =[| { +//// a: 1, +//// b: 2, +//// c: 3 +////}|] + +////const[| { +//// a:[| { +//// a_1, +//// a_2, +//// a_3:[| { +//// a_3_1, +//// a_3_2, +//// a_3_3, +//// }|], +//// }|], +//// b, +//// c +////}|] =[| { +//// a:[| { +//// a_1: 1, +//// a_2: 2, +//// a_3:[| { +//// a_3_1: 1, +//// a_3_2: 1, +//// a_3_3: 1 +//// }|], +//// }|], +//// b: 2, +//// c: 3 +////}|] + +verify.outliningSpansInCurrentFile(test.ranges(), "code"); From 57f161eaa8eaf08de3ebf6b14645e50c9ce3e782 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 28 Apr 2020 10:44:36 +0300 Subject: [PATCH 02/43] feat(38225): change diagnostic message for remove braces from arrow function body --- src/compiler/diagnosticMessages.json | 6 +++--- src/services/codefixes/returnValueCorrect.ts | 12 ++++++------ tests/cases/fourslash/codeFixCorrectReturnValue10.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue12.ts | 6 +++--- tests/cases/fourslash/codeFixCorrectReturnValue13.ts | 6 +++--- tests/cases/fourslash/codeFixCorrectReturnValue18.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue20.ts | 6 +++--- tests/cases/fourslash/codeFixCorrectReturnValue21.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue22.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue23.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue25.ts | 2 +- tests/cases/fourslash/codeFixCorrectReturnValue7.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue8.ts | 4 ++-- tests/cases/fourslash/codeFixCorrectReturnValue9.ts | 4 ++-- .../fourslash/codeFixCorrectReturnValue_all2.ts | 4 ++-- 15 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 03f42608454..a93ea04141c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5633,7 +5633,7 @@ "category": "Message", "code": 95111 }, - "Remove block body braces": { + "Remove braces from arrow function body": { "category": "Message", "code": 95112 }, @@ -5645,7 +5645,7 @@ "category": "Message", "code": 95114 }, - "Remove all incorrect body block braces": { + "Remove braces from all arrow function bodies with relevant issues": { "category": "Message", "code": 95115 }, @@ -5653,7 +5653,7 @@ "category": "Message", "code": 95116 }, - + "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", "code": 18004 diff --git a/src/services/codefixes/returnValueCorrect.ts b/src/services/codefixes/returnValueCorrect.ts index 947b9933e30..fb80e296a97 100644 --- a/src/services/codefixes/returnValueCorrect.ts +++ b/src/services/codefixes/returnValueCorrect.ts @@ -2,7 +2,7 @@ namespace ts.codefix { const fixId = "returnValueCorrect"; const fixIdAddReturnStatement = "fixAddReturnStatement"; - const fixIdRemoveBlockBodyBrace = "fixRemoveBlockBodyBrace"; + const fixRemoveBracesFromArrowFunctionBody = "fixRemoveBracesFromArrowFunctionBody"; const fixIdWrapTheBlockWithParen = "fixWrapTheBlockWithParen"; const errorCodes = [ Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code, @@ -35,7 +35,7 @@ namespace ts.codefix { registerCodeFix({ errorCodes, - fixIds: [fixIdAddReturnStatement, fixIdRemoveBlockBodyBrace, fixIdWrapTheBlockWithParen], + fixIds: [fixIdAddReturnStatement, fixRemoveBracesFromArrowFunctionBody, fixIdWrapTheBlockWithParen], getCodeActions: context => { const { program, sourceFile, span: { start }, errorCode } = context; const info = getInfo(program.getTypeChecker(), sourceFile, start, errorCode); @@ -44,7 +44,7 @@ namespace ts.codefix { if (info.kind === ProblemKind.MissingReturnStatement) { return append( [getActionForfixAddReturnStatement(context, info.expression, info.statement)], - isArrowFunction(info.declaration) ? getActionForfixRemoveBlockBodyBrace(context, info.declaration, info.expression, info.commentSource): undefined); + isArrowFunction(info.declaration) ? getActionForFixRemoveBracesFromArrowFunctionBody(context, info.declaration, info.expression, info.commentSource): undefined); } else { return [getActionForfixWrapTheBlockWithParen(context, info.declaration, info.expression)]; @@ -58,7 +58,7 @@ namespace ts.codefix { case fixIdAddReturnStatement: addReturnStatement(changes, diag.file, info.expression, info.statement); break; - case fixIdRemoveBlockBodyBrace: + case fixRemoveBracesFromArrowFunctionBody: if (!isArrowFunction(info.declaration)) return undefined; removeBlockBodyBrace(changes, diag.file, info.declaration, info.expression, info.commentSource, /* withParen */ false); break; @@ -196,9 +196,9 @@ namespace ts.codefix { return createCodeFixAction(fixId, changes, Diagnostics.Add_a_return_statement, fixIdAddReturnStatement, Diagnostics.Add_all_missing_return_statement); } - function getActionForfixRemoveBlockBodyBrace(context: CodeFixContext, declaration: ArrowFunction, expression: Expression, commentSource: Node) { + function getActionForFixRemoveBracesFromArrowFunctionBody(context: CodeFixContext, declaration: ArrowFunction, expression: Expression, commentSource: Node) { const changes = textChanges.ChangeTracker.with(context, t => removeBlockBodyBrace(t, context.sourceFile, declaration, expression, commentSource, /* withParen */ false)); - return createCodeFixAction(fixId, changes, Diagnostics.Remove_block_body_braces, fixIdRemoveBlockBodyBrace, Diagnostics.Remove_all_incorrect_body_block_braces); + return createCodeFixAction(fixId, changes, Diagnostics.Remove_braces_from_arrow_function_body, fixRemoveBracesFromArrowFunctionBody, Diagnostics.Remove_braces_from_all_arrow_function_bodies_with_relevant_issues); } function getActionForfixWrapTheBlockWithParen(context: CodeFixContext, declaration: ArrowFunction, expression: Expression) { diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue10.ts b/tests/cases/fourslash/codeFixCorrectReturnValue10.ts index cdbf416984d..61523d804b1 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue10.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue10.ts @@ -3,6 +3,6 @@ //// const a: ((() => number) | (() => undefined)) = () => { 1 } verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' } + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue12.ts b/tests/cases/fourslash/codeFixCorrectReturnValue12.ts index d242e4f4cf8..8a4c0dbf923 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue12.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue12.ts @@ -9,7 +9,7 @@ //// }) verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' }, - { description: 'Remove unused label' }, + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }, + { description: ts.Diagnostics.Remove_unused_label.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue13.ts b/tests/cases/fourslash/codeFixCorrectReturnValue13.ts index a1e2cc553cc..cdc7c51982a 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue13.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue13.ts @@ -8,9 +8,9 @@ //// } verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' }, - { description: 'Remove unused label' }, + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }, + { description: ts.Diagnostics.Remove_unused_label.message } ]); interface A { diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue18.ts b/tests/cases/fourslash/codeFixCorrectReturnValue18.ts index ffa038a48fc..633a0096003 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue18.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue18.ts @@ -11,7 +11,7 @@ //// var x = { 1 }} />; verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' }, + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }, { description: `Infer type of 'props' from usage` } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue20.ts b/tests/cases/fourslash/codeFixCorrectReturnValue20.ts index f552edaee67..a9b9a6cd1ce 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue20.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue20.ts @@ -16,8 +16,8 @@ //// }} />; verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' }, + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }, { description: `Infer type of 'props' from usage` }, - { description: 'Remove unused label' }, + { description: ts.Diagnostics.Remove_unused_label.message }, ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue21.ts b/tests/cases/fourslash/codeFixCorrectReturnValue21.ts index 1a248f77909..fc0fef8872b 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue21.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue21.ts @@ -9,6 +9,6 @@ //// } verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' }, + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue22.ts b/tests/cases/fourslash/codeFixCorrectReturnValue22.ts index 372513592af..59f1e9cc4b6 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue22.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue22.ts @@ -11,6 +11,6 @@ //// } verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' }, + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue23.ts b/tests/cases/fourslash/codeFixCorrectReturnValue23.ts index 14fde025337..859749e754b 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue23.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue23.ts @@ -5,6 +5,6 @@ //// } verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' } + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue25.ts b/tests/cases/fourslash/codeFixCorrectReturnValue25.ts index 3d7f7503673..1cb93bf3ecf 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue25.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue25.ts @@ -4,7 +4,7 @@ //// Foo(() => { /* leading */ 1 /* trailing */ }) verify.codeFix({ - description: "Remove block body braces", + description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message, index: 1, newFileContent: `function Foo (a: () => number) { a() } diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue7.ts b/tests/cases/fourslash/codeFixCorrectReturnValue7.ts index bd0bfd3b343..0125238c8a4 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue7.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue7.ts @@ -4,6 +4,6 @@ //// Foo(() => { 1 }) verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' } + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue8.ts b/tests/cases/fourslash/codeFixCorrectReturnValue8.ts index cde3ab2e42f..640f84af4d0 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue8.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue8.ts @@ -4,6 +4,6 @@ //// Foo(() => { 1 }) verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' } + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue9.ts b/tests/cases/fourslash/codeFixCorrectReturnValue9.ts index 104fd785f00..97e684b0c0f 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue9.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue9.ts @@ -3,6 +3,6 @@ //// const a: () => number = () => { 1 } verify.codeFixAvailable([ - { description: 'Add a return statement' }, - { description: 'Remove block body braces' } + { description: ts.Diagnostics.Add_a_return_statement.message }, + { description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message } ]); diff --git a/tests/cases/fourslash/codeFixCorrectReturnValue_all2.ts b/tests/cases/fourslash/codeFixCorrectReturnValue_all2.ts index e3b0d1c0b1d..34b889849ac 100644 --- a/tests/cases/fourslash/codeFixCorrectReturnValue_all2.ts +++ b/tests/cases/fourslash/codeFixCorrectReturnValue_all2.ts @@ -58,8 +58,8 @@ //// const test: { a: () => A } = { a: () => { bar: '1' } } verify.codeFixAll({ - fixId: "fixRemoveBlockBodyBrace", - fixAllDescription: "Remove all incorrect body block braces", + fixId: "fixRemoveBracesFromArrowFunctionBody", + fixAllDescription: ts.Diagnostics.Remove_braces_from_all_arrow_function_bodies_with_relevant_issues.message, newFileContent: `interface A { bar: string From 946abeadb053d0c0bce2ca00142b33432f2211ba Mon Sep 17 00:00:00 2001 From: lissein Date: Sat, 9 May 2020 04:53:14 +0200 Subject: [PATCH 03/43] Changed template strings to emit void 0 instead of undefined (#38430) undefined is not a keyword in es5 and es3 so we now emit void 0 instead in template strings. --- src/compiler/transformers/taggedTemplate.ts | 2 +- ...dTemplateEscapeSequences(target=es2015).js | 22 +++--- ...ggedTemplateEscapeSequences(target=es5).js | 22 +++--- .../invalidTaggedTemplateEscapeSequences.js | 70 +++++++++---------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/compiler/transformers/taggedTemplate.ts b/src/compiler/transformers/taggedTemplate.ts index ea3e529b752..8dc0fe1a964 100644 --- a/src/compiler/transformers/taggedTemplate.ts +++ b/src/compiler/transformers/taggedTemplate.ts @@ -63,7 +63,7 @@ namespace ts { } function createTemplateCooked(template: TemplateHead | TemplateMiddle | TemplateTail | NoSubstitutionTemplateLiteral) { - return template.templateFlags ? createIdentifier("undefined") : createLiteral(template.text); + return template.templateFlags ? createVoidZero() : createLiteral(template.text); } /** diff --git a/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es2015).js b/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es2015).js index 1ad643d360d..bed4ca912d8 100644 --- a/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es2015).js +++ b/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es2015).js @@ -35,20 +35,20 @@ function tag(str, ...args) { } const a = tag `123`; const b = tag `123 ${100}`; -const x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300); +const x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300); const y = `\u{hello} ${100} \xtraordinary ${200} wonderful ${300} \uworld`; // should error with NoSubstitutionTemplate -const z = tag(__makeTemplateObject([undefined], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate +const z = tag(__makeTemplateObject([void 0], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate const a1 = tag `${100}\0`; // \0 -const a2 = tag(__makeTemplateObject(["", undefined], ["", "\\00"]), 100); // \\00 -const a3 = tag(__makeTemplateObject(["", undefined], ["", "\\u"]), 100); // \\u -const a4 = tag(__makeTemplateObject(["", undefined], ["", "\\u0"]), 100); // \\u0 -const a5 = tag(__makeTemplateObject(["", undefined], ["", "\\u00"]), 100); // \\u00 -const a6 = tag(__makeTemplateObject(["", undefined], ["", "\\u000"]), 100); // \\u000 +const a2 = tag(__makeTemplateObject(["", void 0], ["", "\\00"]), 100); // \\00 +const a3 = tag(__makeTemplateObject(["", void 0], ["", "\\u"]), 100); // \\u +const a4 = tag(__makeTemplateObject(["", void 0], ["", "\\u0"]), 100); // \\u0 +const a5 = tag(__makeTemplateObject(["", void 0], ["", "\\u00"]), 100); // \\u00 +const a6 = tag(__makeTemplateObject(["", void 0], ["", "\\u000"]), 100); // \\u000 const a7 = tag `${100}\u0000`; // \u0000 -const a8 = tag(__makeTemplateObject(["", undefined], ["", "\\u{"]), 100); // \\u{ +const a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{ const a9 = tag `${100}\u{10FFFF}`; // \\u{10FFFF -const a10 = tag(__makeTemplateObject(["", undefined], ["", "\\u{1f622"]), 100); // \\u{1f622 +const a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622 const a11 = tag `${100}\u{1f622}`; // \u{1f622} -const a12 = tag(__makeTemplateObject(["", undefined], ["", "\\x"]), 100); // \\x -const a13 = tag(__makeTemplateObject(["", undefined], ["", "\\x0"]), 100); // \\x0 +const a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x +const a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0 const a14 = tag `${100}\x00`; // \x00 diff --git a/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es5).js b/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es5).js index 362e2cf175c..6e0c375edb2 100644 --- a/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es5).js +++ b/tests/baselines/reference/invalidTaggedTemplateEscapeSequences(target=es5).js @@ -39,20 +39,20 @@ function tag(str) { } var a = tag(__makeTemplateObject(["123"], ["123"])); var b = tag(__makeTemplateObject(["123 ", ""], ["123 ", ""]), 100); -var x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300); +var x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300); var y = "hello} " + 100 + " traordinary " + 200 + " wonderful " + 300 + " world"; // should error with NoSubstitutionTemplate -var z = tag(__makeTemplateObject([undefined], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate +var z = tag(__makeTemplateObject([void 0], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate var a1 = tag(__makeTemplateObject(["", "\0"], ["", "\\0"]), 100); // \0 -var a2 = tag(__makeTemplateObject(["", undefined], ["", "\\00"]), 100); // \\00 -var a3 = tag(__makeTemplateObject(["", undefined], ["", "\\u"]), 100); // \\u -var a4 = tag(__makeTemplateObject(["", undefined], ["", "\\u0"]), 100); // \\u0 -var a5 = tag(__makeTemplateObject(["", undefined], ["", "\\u00"]), 100); // \\u00 -var a6 = tag(__makeTemplateObject(["", undefined], ["", "\\u000"]), 100); // \\u000 +var a2 = tag(__makeTemplateObject(["", void 0], ["", "\\00"]), 100); // \\00 +var a3 = tag(__makeTemplateObject(["", void 0], ["", "\\u"]), 100); // \\u +var a4 = tag(__makeTemplateObject(["", void 0], ["", "\\u0"]), 100); // \\u0 +var a5 = tag(__makeTemplateObject(["", void 0], ["", "\\u00"]), 100); // \\u00 +var a6 = tag(__makeTemplateObject(["", void 0], ["", "\\u000"]), 100); // \\u000 var a7 = tag(__makeTemplateObject(["", "\0"], ["", "\\u0000"]), 100); // \u0000 -var a8 = tag(__makeTemplateObject(["", undefined], ["", "\\u{"]), 100); // \\u{ +var a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{ var a9 = tag(__makeTemplateObject(["", "\uDBFF\uDFFF"], ["", "\\u{10FFFF}"]), 100); // \\u{10FFFF -var a10 = tag(__makeTemplateObject(["", undefined], ["", "\\u{1f622"]), 100); // \\u{1f622 +var a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622 var a11 = tag(__makeTemplateObject(["", "\uD83D\uDE22"], ["", "\\u{1f622}"]), 100); // \u{1f622} -var a12 = tag(__makeTemplateObject(["", undefined], ["", "\\x"]), 100); // \\x -var a13 = tag(__makeTemplateObject(["", undefined], ["", "\\x0"]), 100); // \\x0 +var a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x +var a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0 var a14 = tag(__makeTemplateObject(["", "\0"], ["", "\\x00"]), 100); // \x00 diff --git a/tests/baselines/reference/invalidTaggedTemplateEscapeSequences.js b/tests/baselines/reference/invalidTaggedTemplateEscapeSequences.js index 362e2cf175c..58984b3018c 100644 --- a/tests/baselines/reference/invalidTaggedTemplateEscapeSequences.js +++ b/tests/baselines/reference/invalidTaggedTemplateEscapeSequences.js @@ -1,28 +1,28 @@ //// [invalidTaggedTemplateEscapeSequences.ts] -function tag (str: any, ...args: any[]): any { - return str -} - -const a = tag`123` -const b = tag`123 ${100}` -const x = tag`\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`; -const y = `\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`; // should error with NoSubstitutionTemplate -const z = tag`\u{hello} \xtraordinary wonderful \uworld` // should work with Tagged NoSubstitutionTemplate - -const a1 = tag`${ 100 }\0` // \0 -const a2 = tag`${ 100 }\00` // \\00 -const a3 = tag`${ 100 }\u` // \\u -const a4 = tag`${ 100 }\u0` // \\u0 -const a5 = tag`${ 100 }\u00` // \\u00 -const a6 = tag`${ 100 }\u000` // \\u000 -const a7 = tag`${ 100 }\u0000` // \u0000 -const a8 = tag`${ 100 }\u{` // \\u{ -const a9 = tag`${ 100 }\u{10FFFF}` // \\u{10FFFF -const a10 = tag`${ 100 }\u{1f622` // \\u{1f622 -const a11 = tag`${ 100 }\u{1f622}` // \u{1f622} -const a12 = tag`${ 100 }\x` // \\x -const a13 = tag`${ 100 }\x0` // \\x0 -const a14 = tag`${ 100 }\x00` // \x00 +function tag (str: any, ...args: any[]): any { + return str +} + +const a = tag`123` +const b = tag`123 ${100}` +const x = tag`\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`; +const y = `\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`; // should error with NoSubstitutionTemplate +const z = tag`\u{hello} \xtraordinary wonderful \uworld` // should work with Tagged NoSubstitutionTemplate + +const a1 = tag`${ 100 }\0` // \0 +const a2 = tag`${ 100 }\00` // \\00 +const a3 = tag`${ 100 }\u` // \\u +const a4 = tag`${ 100 }\u0` // \\u0 +const a5 = tag`${ 100 }\u00` // \\u00 +const a6 = tag`${ 100 }\u000` // \\u000 +const a7 = tag`${ 100 }\u0000` // \u0000 +const a8 = tag`${ 100 }\u{` // \\u{ +const a9 = tag`${ 100 }\u{10FFFF}` // \\u{10FFFF +const a10 = tag`${ 100 }\u{1f622` // \\u{1f622 +const a11 = tag`${ 100 }\u{1f622}` // \u{1f622} +const a12 = tag`${ 100 }\x` // \\x +const a13 = tag`${ 100 }\x0` // \\x0 +const a14 = tag`${ 100 }\x00` // \x00 //// [invalidTaggedTemplateEscapeSequences.js] @@ -39,20 +39,20 @@ function tag(str) { } var a = tag(__makeTemplateObject(["123"], ["123"])); var b = tag(__makeTemplateObject(["123 ", ""], ["123 ", ""]), 100); -var x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300); +var x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300); var y = "hello} " + 100 + " traordinary " + 200 + " wonderful " + 300 + " world"; // should error with NoSubstitutionTemplate -var z = tag(__makeTemplateObject([undefined], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate +var z = tag(__makeTemplateObject([void 0], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate var a1 = tag(__makeTemplateObject(["", "\0"], ["", "\\0"]), 100); // \0 -var a2 = tag(__makeTemplateObject(["", undefined], ["", "\\00"]), 100); // \\00 -var a3 = tag(__makeTemplateObject(["", undefined], ["", "\\u"]), 100); // \\u -var a4 = tag(__makeTemplateObject(["", undefined], ["", "\\u0"]), 100); // \\u0 -var a5 = tag(__makeTemplateObject(["", undefined], ["", "\\u00"]), 100); // \\u00 -var a6 = tag(__makeTemplateObject(["", undefined], ["", "\\u000"]), 100); // \\u000 +var a2 = tag(__makeTemplateObject(["", void 0], ["", "\\00"]), 100); // \\00 +var a3 = tag(__makeTemplateObject(["", void 0], ["", "\\u"]), 100); // \\u +var a4 = tag(__makeTemplateObject(["", void 0], ["", "\\u0"]), 100); // \\u0 +var a5 = tag(__makeTemplateObject(["", void 0], ["", "\\u00"]), 100); // \\u00 +var a6 = tag(__makeTemplateObject(["", void 0], ["", "\\u000"]), 100); // \\u000 var a7 = tag(__makeTemplateObject(["", "\0"], ["", "\\u0000"]), 100); // \u0000 -var a8 = tag(__makeTemplateObject(["", undefined], ["", "\\u{"]), 100); // \\u{ +var a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{ var a9 = tag(__makeTemplateObject(["", "\uDBFF\uDFFF"], ["", "\\u{10FFFF}"]), 100); // \\u{10FFFF -var a10 = tag(__makeTemplateObject(["", undefined], ["", "\\u{1f622"]), 100); // \\u{1f622 +var a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622 var a11 = tag(__makeTemplateObject(["", "\uD83D\uDE22"], ["", "\\u{1f622}"]), 100); // \u{1f622} -var a12 = tag(__makeTemplateObject(["", undefined], ["", "\\x"]), 100); // \\x -var a13 = tag(__makeTemplateObject(["", undefined], ["", "\\x0"]), 100); // \\x0 +var a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x +var a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0 var a14 = tag(__makeTemplateObject(["", "\0"], ["", "\\x00"]), 100); // \x00 From 4109bba9e15717fee2c0d34ec2c24561a59919f3 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Mon, 11 May 2020 11:05:15 -0700 Subject: [PATCH 04/43] Update user baselines (#38472) Co-authored-by: typescript-bot --- .../reference/docker/office-ui-fabric.log | 58 +++++++++---------- tests/baselines/reference/docker/vue-next.log | 8 +-- .../reference/user/eventemitter3.log | 13 +---- 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/tests/baselines/reference/docker/office-ui-fabric.log b/tests/baselines/reference/docker/office-ui-fabric.log index 3a8ae0d4b9b..69f3f4e63a1 100644 --- a/tests/baselines/reference/docker/office-ui-fabric.log +++ b/tests/baselines/reference/docker/office-ui-fabric.log @@ -19,36 +19,36 @@ Standard output: Standard error: info cli using local version of lerna -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency @uifabric/tslint-rules: (Use `node --trace-warnings ...` to show where the warning was created) -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'find' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'head' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'set' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'test' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'to' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency -@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'which' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'find' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'head' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'set' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'test' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'to' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency +@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'which' of module exports inside circular dependency @uifabric/tslint-rules: [XX:XX:XX XM] ▲ One of these [node-sass, postcss, autoprefixer] is not installed, so this task has no effect @fluentui/ability-attributes: npm WARN lifecycle The node binary used for scripts is but npm is using /usr/local/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with. @fluentui/ability-attributes: internal/modules/cjs/loader.js:491 diff --git a/tests/baselines/reference/docker/vue-next.log b/tests/baselines/reference/docker/vue-next.log index 96c3e8730f4..ddb045b9940 100644 --- a/tests/baselines/reference/docker/vue-next.log +++ b/tests/baselines/reference/docker/vue-next.log @@ -106,16 +106,16 @@ created packages/reactivity/dist/reactivity.global.prod.js in ?s packages/runtime-core/src/apiInject.ts Error: /vue-next/packages/runtime-core/src/apiInject.ts(40,9): semantic error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. at error (/vue-next/node_modules/rollup/dist/shared/rollup.js:161:30) - at throwPluginError (/vue-next/node_modules/rollup/dist/shared/rollup.js:16925:12) - at Object.error (/vue-next/node_modules/rollup/dist/shared/rollup.js:17944:24) - at Object.error (/vue-next/node_modules/rollup/dist/shared/rollup.js:17098:38) + at throwPluginError (/vue-next/node_modules/rollup/dist/shared/rollup.js:16989:12) + at Object.error (/vue-next/node_modules/rollup/dist/shared/rollup.js:18021:24) + at Object.error (/vue-next/node_modules/rollup/dist/shared/rollup.js:17162:38) at RollupContext.error (/vue-next/node_modules/rollup-plugin-typescript2/src/rollupcontext.ts:37:18) at /vue-next/node_modules/rollup-plugin-typescript2/src/print-diagnostics.ts:41:11 at arrayEach (/vue-next/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:516:11) at forEach (/vue-next/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:9342:14) at _.each (/vue-next/node_modules/rollup-plugin-typescript2/src/print-diagnostics.ts:9:2) at Object.transform (/vue-next/node_modules/rollup-plugin-typescript2/src/index.ts:242:5) -(node:17) UnhandledPromiseRejectionWarning: Error: Command failed with exit code 1 (EPERM): rollup -c --environment COMMIT:b725b63,NODE_ENV:production,TARGET:runtime-core,TYPES:true +(node:17) UnhandledPromiseRejectionWarning: Error: Command failed with exit code 1 (EPERM): rollup -c --environment COMMIT:9d111f5,NODE_ENV:production,TARGET:runtime-core,TYPES:true at makeError (/vue-next/node_modules/execa/lib/error.js:59:11) at handlePromise (/vue-next/node_modules/execa/index.js:112:26) at processTicksAndRejections (internal/process/task_queues.js:97:5) diff --git a/tests/baselines/reference/user/eventemitter3.log b/tests/baselines/reference/user/eventemitter3.log index 5bd4bedd9f6..6d255ed9eec 100644 --- a/tests/baselines/reference/user/eventemitter3.log +++ b/tests/baselines/reference/user/eventemitter3.log @@ -1,17 +1,6 @@ Exit Code: 1 Standard output: -node_modules/eventemitter3/index.d.ts(22,13): error TS2344: Type 'T[K]' does not satisfy the constraint 'any[] | ((...args: any[]) => void)'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'any[] | ((...args: any[]) => void)'. - Type 'T[string]' is not assignable to type 'any[] | ((...args: any[]) => void)'. - Type 'T[string]' is not assignable to type 'any[]'. - Type 'T[K]' is not assignable to type 'any[]'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'any[]'. - Type 'T[string]' is not assignable to type 'any[]'. -node_modules/eventemitter3/index.d.ts(122,62): error TS2344: Type 'EventTypes' does not satisfy the constraint 'string | symbol | {} | { [K in keyof EventTypes]: any[] | ((...args: any[]) => void); }'. - Type 'unknown' is not assignable to type 'string | symbol | {} | { [K in keyof EventTypes]: any[] | ((...args: any[]) => void); }'. - Type 'unknown' is not assignable to type '{ [K in keyof EventTypes]: any[] | ((...args: any[]) => void); }'. - Type 'EventTypes' is not assignable to type '{ [K in keyof EventTypes]: any[] | ((...args: any[]) => void); }'. - Type 'unknown' is not assignable to type '{ [K in keyof EventTypes]: any[] | ((...args: any[]) => void); }'. +node_modules/eventemitter3/index.d.ts(117,17): error TS2536: Type 'K' cannot be used to index type 'ArgumentMap'. From 738b6b5b685f291dc8d8658b5e6aaa43f4e47ab9 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 11 May 2020 22:25:25 +0300 Subject: [PATCH 05/43] fix(38073): hide 'Extract to function in global scope' action for arrow functions which use 'this' (#38107) --- src/services/refactors/extractSymbol.ts | 30 +++++++++++------------ tests/cases/fourslash/extract-method38.ts | 14 +++++++++++ tests/cases/fourslash/extract-method39.ts | 14 +++++++++++ 3 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 tests/cases/fourslash/extract-method38.ts create mode 100644 tests/cases/fourslash/extract-method39.ts diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 64e9bb6f3a2..0e5034ff843 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -405,24 +405,24 @@ namespace ts.refactor.extractSymbol { rangeFacts |= RangeFacts.UsesThis; } break; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.FunctionDeclaration: + if (isSourceFile(node.parent) && node.parent.externalModuleIndicator === undefined) { + // You cannot extract global declarations + (errors || (errors = [] as Diagnostic[])).push(createDiagnosticForNode(node, Messages.functionWillNotBeVisibleInTheNewScope)); + } + // falls through + case SyntaxKind.ClassExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + // do not dive into functions (except arrow functions) or classes + return false; } - if (isFunctionLikeDeclaration(node) || isClassLike(node)) { - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.ClassDeclaration: - if (isSourceFile(node.parent) && node.parent.externalModuleIndicator === undefined) { - // You cannot extract global declarations - (errors || (errors = [] as Diagnostic[])).push(createDiagnosticForNode(node, Messages.functionWillNotBeVisibleInTheNewScope)); - } - break; - } - - // do not dive into functions or classes - return false; - } const savedPermittedJumps = permittedJumps; - switch (node.kind) { case SyntaxKind.IfStatement: permittedJumps = PermittedJumps.None; diff --git a/tests/cases/fourslash/extract-method38.ts b/tests/cases/fourslash/extract-method38.ts new file mode 100644 index 00000000000..075f08ec7f9 --- /dev/null +++ b/tests/cases/fourslash/extract-method38.ts @@ -0,0 +1,14 @@ +/// + +////function bar(fn: () => void) {} +//// +////class Foo { +//// x: number; +//// foo() { +//// /*start*/bar(() => { this.x });/*end*/ +//// } +////} + +goTo.select("start", "end"); +verify.refactorAvailable("Extract Symbol", "function_scope_1"); +verify.not.refactorAvailable("Extract Symbol", "function_scope_2"); diff --git a/tests/cases/fourslash/extract-method39.ts b/tests/cases/fourslash/extract-method39.ts new file mode 100644 index 00000000000..85b51dcd9c0 --- /dev/null +++ b/tests/cases/fourslash/extract-method39.ts @@ -0,0 +1,14 @@ +/// + +////function bar(fn: () => void) {} +//// +////class Foo { +//// x: number; +//// foo() { +//// /*start*/bar(() => {});/*end*/ +//// } +////} + +goTo.select("start", "end"); +verify.refactorAvailable("Extract Symbol", "function_scope_1"); +verify.refactorAvailable("Extract Symbol", "function_scope_2"); From 1b7b3eb0f7833e9e14e8d519ead975d07b5f302b Mon Sep 17 00:00:00 2001 From: Wenqi <1264578441@qq.com> Date: Tue, 12 May 2020 03:47:49 +0800 Subject: [PATCH 06/43] report error for duplicate @type declaration (#38340) --- src/compiler/diagnosticMessages.json | 8 ++++++++ src/compiler/parser.ts | 8 ++++++++ .../typedefDuplicateTypeDeclaration.errors.txt | 13 +++++++++++++ .../typedefDuplicateTypeDeclaration.symbols | 7 +++++++ .../reference/typedefDuplicateTypeDeclaration.types | 7 +++++++ .../jsdoc/typedefDuplicateTypeDeclaration.ts | 9 +++++++++ 6 files changed, 52 insertions(+) create mode 100644 tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt create mode 100644 tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols create mode 100644 tests/baselines/reference/typedefDuplicateTypeDeclaration.types create mode 100644 tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 78c047a5e4a..41e0a051ab4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4911,6 +4911,14 @@ "category": "Error", "code": 8032 }, + "A JSDoc '@typedef' comment may not contain multiple '@type' tags.": { + "category": "Error", + "code": 8033 + }, + "The tag was first specified here.": { + "category": "Error", + "code": 8034 + }, "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": { "category": "Error", "code": 9002 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ae13b113897..fdc1e8246ac 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7483,6 +7483,14 @@ namespace ts { } if (child.kind === SyntaxKind.JSDocTypeTag) { if (childTypeTag) { + parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags); + const lastError = lastOrUndefined(parseDiagnostics); + if (lastError) { + addRelatedInfo( + lastError, + createDiagnosticForNode(sourceFile, Diagnostics.The_tag_was_first_specified_here) + ); + } break; } else { diff --git a/tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt b/tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt new file mode 100644 index 00000000000..70e0f941b97 --- /dev/null +++ b/tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js(4,16): error TS8033: A JSDoc '@typedef' comment may not contain multiple '@type' tags. + + +==== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js (1 errors) ==== + /** + * @typedef Name + * @type {string} + * @type {Oops} + + */ + +!!! error TS8033: A JSDoc '@typedef' comment may not contain multiple '@type' tags. +!!! related TS8034 tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js:1:1: The tag was first specified here. \ No newline at end of file diff --git a/tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols b/tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols new file mode 100644 index 00000000000..eeafce6655c --- /dev/null +++ b/tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js === +/** +No type information for this code. * @typedef Name +No type information for this code. * @type {string} +No type information for this code. * @type {Oops} +No type information for this code. */ +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/typedefDuplicateTypeDeclaration.types b/tests/baselines/reference/typedefDuplicateTypeDeclaration.types new file mode 100644 index 00000000000..eeafce6655c --- /dev/null +++ b/tests/baselines/reference/typedefDuplicateTypeDeclaration.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js === +/** +No type information for this code. * @typedef Name +No type information for this code. * @type {string} +No type information for this code. * @type {Oops} +No type information for this code. */ +No type information for this code. \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts b/tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts new file mode 100644 index 00000000000..75ec41f78e3 --- /dev/null +++ b/tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts @@ -0,0 +1,9 @@ +// @allowJS: true +// @checkJS: true +// @noEmit: true +// @Filename: typedefDuplicateTypeDeclaration.js +/** + * @typedef Name + * @type {string} + * @type {Oops} + */ \ No newline at end of file From fd71eb2c856ceb5aa2e36cdd161641cd8d2d3fc3 Mon Sep 17 00:00:00 2001 From: jeffy-g Date: Tue, 12 May 2020 05:02:20 +0900 Subject: [PATCH 07/43] fix broken regex on "src/services/completions.ts#getCompletionData" (#37546) * fix broken regex on src/services/completions.ts#840 * update forslash test breaking changes fourslash test Temporarily retain the before fix code for easy comparison * regex * fourslash test (Temporary code * regex: more restrictive in terms of jsdoc format fourslash test * regex: max indent restriction * achieved goal by partial match strategy (probably * cleanup * apply requested changes * Change to a version with minimal modifications --- src/services/completions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index a1e98a03d87..a3845bf3ece 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -875,7 +875,7 @@ namespace ts.Completions { // * |c| // */ const lineStart = getLineStartPositionForPosition(position, sourceFile); - if (!(sourceFile.text.substring(lineStart, position).match(/[^\*|\s|(/\*\*)]/))) { + if (!/[^\*|\s(/)]/.test(sourceFile.text.substring(lineStart, position))) { return { kind: CompletionDataKind.JsDocTag }; } } From 1a88430a7e16acb0717d9e6ac9b30f3a82fc64f5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 11 May 2020 13:40:54 -0700 Subject: [PATCH 08/43] Improve assert message in binder (#38270) * Improve assert message in binder Looking at the code, I don't think the assert can ever fire, but it clearly does, or did in the past. This will make it easier for people to create a repro. * fix lint * Use BindableStaticNameExpression not BindableStaticAccessExpression This type does allow identifiers, but those are ruled out earlier, so I added an assert for that case. --- src/compiler/binder.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 07a26a7b837..9b82eb7ffd7 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2977,15 +2977,13 @@ namespace ts { // util.property = function ... bindExportsPropertyAssignment(node as BindableStaticPropertyAssignmentExpression); } + else if (hasDynamicName(node)) { + bindAnonymousDeclaration(node, SymbolFlags.Property | SymbolFlags.Assignment, InternalSymbolName.Computed); + const sym = bindPotentiallyMissingNamespaces(parentSymbol, node.left.expression, isTopLevelNamespaceAssignment(node.left), /*isPrototype*/ false, /*containerIsClass*/ false); + addLateBoundAssignmentDeclarationToSymbol(node, sym); + } else { - if (hasDynamicName(node)) { - bindAnonymousDeclaration(node, SymbolFlags.Property | SymbolFlags.Assignment, InternalSymbolName.Computed); - const sym = bindPotentiallyMissingNamespaces(parentSymbol, node.left.expression, isTopLevelNamespaceAssignment(node.left), /*isPrototype*/ false, /*containerIsClass*/ false); - addLateBoundAssignmentDeclarationToSymbol(node, sym); - } - else { - bindStaticPropertyAssignment(cast(node.left, isBindableStaticAccessExpression)); - } + bindStaticPropertyAssignment(cast(node.left, isBindableStaticNameExpression)); } } @@ -2993,7 +2991,8 @@ namespace ts { * For nodes like `x.y = z`, declare a member 'y' on 'x' if x is a function (or IIFE) or class or {}, or not declared. * Also works for expression statements preceded by JSDoc, like / ** @type number * / x.y; */ - function bindStaticPropertyAssignment(node: BindableStaticAccessExpression) { + function bindStaticPropertyAssignment(node: BindableStaticNameExpression) { + Debug.assert(!isIdentifier(node)); node.expression.parent = node; bindPropertyAssignment(node.expression, node, /*isPrototypeProperty*/ false, /*containerIsClass*/ false); } From 1450908e5c5406fc467f9205c13410196211a286 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 May 2020 21:36:43 +0000 Subject: [PATCH 09/43] Added tests for union types with identical doc comments. --- ...rtiesWithIdenticalJSDocComments01.baseline | 76 +++++++++++++++++++ ...nPropertiesWithIdenticalJSDocComments01.ts | 29 +++++++ 2 files changed, 105 insertions(+) create mode 100644 tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline create mode 100644 tests/cases/fourslash/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.ts diff --git a/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline b/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline new file mode 100644 index 00000000000..1fd2e593d2d --- /dev/null +++ b/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline @@ -0,0 +1,76 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.ts", + "position": 746 + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "optional", + "textSpan": { + "start": 746, + "length": 8 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "language", + "kind": "propertyName" + }, + { + "text": "?", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "A language id, like `typescript`.", + "kind": "text" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "A language id, like `typescript`.", + "kind": "text" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "A language id, like `typescript`.", + "kind": "text" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.ts b/tests/cases/fourslash/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.ts new file mode 100644 index 00000000000..132130da22f --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.ts @@ -0,0 +1,29 @@ +/// + +////export type DocumentFilter = { +//// /** A language id, like `typescript`. */ +//// language: string; +//// /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */ +//// scheme?: string; +//// /** A glob pattern, like `*.{ts,js}`. */ +//// pattern?: string; +////} | { +//// /** A language id, like `typescript`. */ +//// language?: string; +//// /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */ +//// scheme: string; +//// /** A glob pattern, like `*.{ts,js}`. */ +//// pattern?: string; +////} | { +//// /** A language id, like `typescript`. */ +//// language?: string; +//// /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */ +//// scheme?: string; +//// /** A glob pattern, like `*.{ts,js}`. */ +//// pattern: string; +////}; +//// +////declare let x: DocumentFilter; +////x./**/language + +verify.baselineQuickInfo(); \ No newline at end of file From 74d6d04d703c742f505d7a72cb7c549c27e26ea4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 May 2020 21:39:47 +0000 Subject: [PATCH 10/43] Don't add duplicates of JSDoc comments. --- src/services/jsDoc.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 63297c7868d..2616aea3144 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -93,10 +93,13 @@ namespace ts.JsDoc { forEachUnique(declarations, declaration => { for (const { comment } of getCommentHavingNodes(declaration)) { if (comment === undefined) continue; - if (documentationComment.length) { - documentationComment.push(lineBreakPart()); + const commentTextPart = textPart(comment); + if (!contains(documentationComment, commentTextPart)) { + if (documentationComment.length) { + documentationComment.push(lineBreakPart()); + } + documentationComment.push(commentTextPart); } - documentationComment.push(textPart(comment)); } }); return documentationComment; From d07e866a28879f38d8cf7aea2a1b030de26613cc Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 11 May 2020 15:07:43 -0700 Subject: [PATCH 11/43] Fix for jsdoc modifiers on constructor params (#38403) * Fix for jsdoc modifiers on constructor params * Update Public API baseline and fix unique symbol grammar check for js --- src/compiler/binder.ts | 46 ++--- src/compiler/checker.ts | 163 +++++++++--------- src/compiler/debug.ts | 2 +- src/compiler/factory.ts | 2 +- src/compiler/program.ts | 2 +- src/compiler/transformers/declarations.ts | 30 ++-- .../transformers/declarations/diagnostics.ts | 20 +-- src/compiler/transformers/es2015.ts | 10 +- src/compiler/transformers/es2018.ts | 2 +- src/compiler/transformers/module/module.ts | 14 +- src/compiler/transformers/module/system.ts | 10 +- src/compiler/transformers/ts.ts | 28 +-- src/compiler/transformers/utilities.ts | 10 +- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 135 ++++++++++----- src/compiler/utilitiesPublic.ts | 110 ++++++++---- src/compiler/visitor.ts | 2 +- src/services/breakpoints.ts | 6 +- src/services/callHierarchy.ts | 2 +- src/services/codefixes/addMissingAsync.ts | 2 +- src/services/codefixes/addMissingAwait.ts | 2 +- .../codefixes/convertToMappedObjectType.ts | 2 +- ...sDoesntImplementInheritedAbstractMember.ts | 2 +- .../fixClassIncorrectlyImplementsInterface.ts | 2 +- .../codefixes/fixStrictClassInitialization.ts | 2 +- src/services/codefixes/helpers.ts | 2 +- src/services/completions.ts | 6 +- src/services/findAllReferences.ts | 14 +- src/services/importTracker.ts | 6 +- src/services/navigationBar.ts | 6 +- src/services/refactors/convertExport.ts | 2 +- src/services/refactors/extractSymbol.ts | 8 +- .../generateGetAccessorAndSetAccessor.ts | 6 +- src/services/refactors/moveToNewFile.ts | 6 +- src/services/services.ts | 2 +- src/services/symbolDisplay.ts | 2 +- src/services/utilities.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + .../jsdocAccessibilityTagsDeclarations.js | 15 +- ...jsdocAccessibilityTagsDeclarations.symbols | 10 ++ .../jsdocAccessibilityTagsDeclarations.types | 10 ++ .../reference/jsdocReadonlyDeclarations.js | 13 +- .../jsdocReadonlyDeclarations.symbols | 7 + .../reference/jsdocReadonlyDeclarations.types | 7 + .../uniqueSymbolsDeclarationsInJs.js | 76 ++++++++ .../uniqueSymbolsDeclarationsInJs.symbols | 43 +++++ .../uniqueSymbolsDeclarationsInJs.types | 48 ++++++ ...ueSymbolsDeclarationsInJsErrors.errors.txt | 24 +++ .../uniqueSymbolsDeclarationsInJsErrors.js | 38 ++++ ...niqueSymbolsDeclarationsInJsErrors.symbols | 23 +++ .../uniqueSymbolsDeclarationsInJsErrors.types | 23 +++ .../jsdocAccessibilityTagsDeclarations.ts | 6 + .../jsdoc/jsdocReadonlyDeclarations.ts | 5 + .../uniqueSymbolsDeclarationsInJs.ts | 32 ++++ .../uniqueSymbolsDeclarationsInJsErrors.ts | 23 +++ 56 files changed, 792 insertions(+), 282 deletions(-) create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJs.js create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJs.symbols create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJs.types create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.errors.txt create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.js create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.symbols create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.types create mode 100644 tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.ts create mode 100644 tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 9b82eb7ffd7..8a47755498b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -50,7 +50,7 @@ namespace ts { // 3. non-exported import declarations case SyntaxKind.ImportDeclaration: case SyntaxKind.ImportEqualsDeclaration: - if (!(hasModifier(node, ModifierFlags.Export))) { + if (!(hasSyntacticModifier(node, ModifierFlags.Export))) { return ModuleInstanceState.NonInstantiated; } break; @@ -413,7 +413,7 @@ namespace ts { function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean): Symbol { Debug.assert(!hasDynamicName(node)); - const isDefaultExport = hasModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; + const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; // The exported symbol for an export default function/class node is always named "default" const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node); @@ -508,7 +508,7 @@ namespace ts { } const relatedInformation: DiagnosticRelatedInformation[] = []; - if (isTypeAliasDeclaration(node) && nodeIsMissing(node.type) && hasModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) { + if (isTypeAliasDeclaration(node) && nodeIsMissing(node.type) && hasSyntacticModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) { // export type T; - may have meant export type { T }? relatedInformation.push(createDiagnosticForNode(node, Diagnostics.Did_you_mean_0, `export type { ${unescapeLeadingUnderscores(node.name.escapedText)} }`)); } @@ -572,7 +572,7 @@ namespace ts { // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed. if (isJSDocTypeAlias(node)) Debug.assert(isInJSFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file. if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypeAlias(node)) { - if (!container.locals || (hasModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) { + if (!container.locals || (hasSyntacticModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) { return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default! } const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0; @@ -637,7 +637,7 @@ namespace ts { const saveExceptionTarget = currentExceptionTarget; const saveActiveLabelList = activeLabelList; const saveHasExplicitReturn = hasExplicitReturn; - const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) && + const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasSyntacticModifier(node, ModifierFlags.Async) && !(node).asteriskToken && !!getImmediatelyInvokedFunctionExpression(node); // A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave // similarly to break statements that exit to a label just past the statement body. @@ -1906,7 +1906,7 @@ namespace ts { } function declareClassMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { - return hasModifier(node, ModifierFlags.Static) + return hasSyntacticModifier(node, ModifierFlags.Static) ? declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes) : declareSymbol(container.symbol.members!, container.symbol, node, symbolFlags, symbolExcludes); } @@ -1936,7 +1936,7 @@ namespace ts { function bindModuleDeclaration(node: ModuleDeclaration) { setExportContextFlag(node); if (isAmbientModule(node)) { - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible); } if (isModuleAugmentationExternal(node)) { @@ -2869,7 +2869,7 @@ namespace ts { // this.foo assignment in a JavaScript class // Bind this property to the containing class const containingClass = thisContainer.parent; - const symbolTable = hasModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!; + const symbolTable = hasSyntacticModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!; if (hasDynamicName(node)) { bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol); } @@ -3402,7 +3402,7 @@ namespace ts { case SyntaxKind.ModuleDeclaration: return getModuleInstanceState(s as ModuleDeclaration) !== ModuleInstanceState.Instantiated; case SyntaxKind.EnumDeclaration: - return hasModifier(s, ModifierFlags.Const); + return hasSyntacticModifier(s, ModifierFlags.Const); default: return false; } @@ -3636,7 +3636,7 @@ namespace ts { } // If a parameter has an accessibility modifier, then it is TypeScript syntax. - if (hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { + if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.ContainsTypeScriptClassSyntax; } @@ -3675,7 +3675,7 @@ namespace ts { function computeClassDeclaration(node: ClassDeclaration, subtreeFlags: TransformFlags) { let transformFlags: TransformFlags; - if (hasModifier(node, ModifierFlags.Ambient)) { + if (hasSyntacticModifier(node, ModifierFlags.Ambient)) { // An ambient declaration is TypeScript syntax. transformFlags = TransformFlags.AssertTypeScript; } @@ -3766,7 +3766,7 @@ namespace ts { let transformFlags = subtreeFlags; // TypeScript-specific modifiers and overloads are TypeScript syntax - if (hasModifier(node, ModifierFlags.TypeScriptModifier) + if (hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || !node.body) { transformFlags |= TransformFlags.AssertTypeScript; } @@ -3787,7 +3787,7 @@ namespace ts { // Decorators, TypeScript-specific modifiers, type parameters, type annotations, and // overloads are TypeScript syntax. if (node.decorators - || hasModifier(node, ModifierFlags.TypeScriptModifier) + || hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || node.typeParameters || node.type || !node.body @@ -3801,7 +3801,7 @@ namespace ts { } // An async method declaration is ES2017 syntax. - if (hasModifier(node, ModifierFlags.Async)) { + if (hasSyntacticModifier(node, ModifierFlags.Async)) { transformFlags |= node.asteriskToken ? TransformFlags.AssertES2018 : TransformFlags.AssertES2017; } @@ -3819,7 +3819,7 @@ namespace ts { // Decorators, TypeScript-specific modifiers, type annotations, and overloads are // TypeScript syntax. if (node.decorators - || hasModifier(node, ModifierFlags.TypeScriptModifier) + || hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || node.type || !node.body) { transformFlags |= TransformFlags.AssertTypeScript; @@ -3838,7 +3838,7 @@ namespace ts { let transformFlags = subtreeFlags | TransformFlags.ContainsClassFields; // Decorators, TypeScript-specific modifiers, and type annotations are TypeScript syntax. - if (some(node.decorators) || hasModifier(node, ModifierFlags.TypeScriptModifier) || node.type || node.questionToken || node.exclamationToken) { + if (some(node.decorators) || hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || node.type || node.questionToken || node.exclamationToken) { transformFlags |= TransformFlags.AssertTypeScript; } @@ -3853,7 +3853,7 @@ namespace ts { function computeFunctionDeclaration(node: FunctionDeclaration, subtreeFlags: TransformFlags) { let transformFlags: TransformFlags; - const modifierFlags = getModifierFlags(node); + const modifierFlags = getSyntacticModifierFlags(node); const body = node.body; if (!body || (modifierFlags & ModifierFlags.Ambient)) { @@ -3901,14 +3901,14 @@ namespace ts { // TypeScript-specific modifiers, type parameters, and type annotations are TypeScript // syntax. - if (hasModifier(node, ModifierFlags.TypeScriptModifier) + if (hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || node.typeParameters || node.type) { transformFlags |= TransformFlags.AssertTypeScript; } // An async function expression is ES2017 syntax. - if (hasModifier(node, ModifierFlags.Async)) { + if (hasSyntacticModifier(node, ModifierFlags.Async)) { transformFlags |= node.asteriskToken ? TransformFlags.AssertES2018 : TransformFlags.AssertES2017; } @@ -3934,14 +3934,14 @@ namespace ts { // TypeScript-specific modifiers, type parameters, and type annotations are TypeScript // syntax. - if (hasModifier(node, ModifierFlags.TypeScriptModifier) + if (hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || node.typeParameters || node.type) { transformFlags |= TransformFlags.AssertTypeScript; } // An async arrow function is ES2017 syntax. - if (hasModifier(node, ModifierFlags.Async)) { + if (hasSyntacticModifier(node, ModifierFlags.Async)) { transformFlags |= TransformFlags.AssertES2017; } @@ -4015,7 +4015,7 @@ namespace ts { const declarationListTransformFlags = node.declarationList.transformFlags; // An ambient declaration is TypeScript syntax. - if (hasModifier(node, ModifierFlags.Ambient)) { + if (hasSyntacticModifier(node, ModifierFlags.Ambient)) { transformFlags = TransformFlags.AssertTypeScript; } else { @@ -4063,7 +4063,7 @@ namespace ts { function computeModuleDeclaration(node: ModuleDeclaration, subtreeFlags: TransformFlags) { let transformFlags = TransformFlags.AssertTypeScript; - const modifierFlags = getModifierFlags(node); + const modifierFlags = getSyntacticModifierFlags(node); if ((modifierFlags & ModifierFlags.Ambient) === 0) { transformFlags |= subtreeFlags; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ac6cc094fe..590efccaa56 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1470,13 +1470,13 @@ namespace ts { (current.parent).initializer === current; if (initializerOfProperty) { - if (hasModifier(current.parent, ModifierFlags.Static)) { + if (hasSyntacticModifier(current.parent, ModifierFlags.Static)) { if (declaration.kind === SyntaxKind.MethodDeclaration) { return true; } } else { - const isDeclarationInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !hasModifier(declaration, ModifierFlags.Static); + const isDeclarationInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !hasSyntacticModifier(declaration, ModifierFlags.Static); if (!isDeclarationInstanceProperty || getContainingClass(usage) !== getContainingClass(declaration)) { return true; } @@ -1739,7 +1739,7 @@ namespace ts { // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. - if (!hasModifier(location, ModifierFlags.Static)) { + if (!hasSyntacticModifier(location, ModifierFlags.Static)) { const ctor = findConstructorDeclaration(location.parent as ClassLikeDeclaration); if (ctor && ctor.locals) { if (lookup(ctor.locals, name, meaning & SymbolFlags.Value)) { @@ -1761,7 +1761,7 @@ namespace ts { result = undefined; break; } - if (lastLocation && hasModifier(lastLocation, ModifierFlags.Static)) { + if (lastLocation && hasSyntacticModifier(lastLocation, ModifierFlags.Static)) { // TypeScript 1.0 spec (April 2014): 3.4.1 // The scope of a type parameter extends over the entire declaration with which the type // parameter list is associated, with the exception of static member declarations in classes. @@ -2046,14 +2046,14 @@ namespace ts { // initializers in instance property declaration of class like entities are executed in constructor and thus deferred return isTypeQueryNode(location) || (( isFunctionLikeDeclaration(location) || - (location.kind === SyntaxKind.PropertyDeclaration && !hasModifier(location, ModifierFlags.Static)) + (location.kind === SyntaxKind.PropertyDeclaration && !hasSyntacticModifier(location, ModifierFlags.Static)) ) && (!lastLocation || lastLocation !== (location as FunctionLike | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred } if (lastLocation && lastLocation === (location as FunctionExpression | ArrowFunction).name) { return false; } // generator functions and async functions are not inlined in control flow when immediately invoked - if ((location as FunctionExpression | ArrowFunction).asteriskToken || hasModifier(location, ModifierFlags.Async)) { + if ((location as FunctionExpression | ArrowFunction).asteriskToken || hasSyntacticModifier(location, ModifierFlags.Async)) { return true; } return !getImmediatelyInvokedFunctionExpression(location); @@ -2113,7 +2113,7 @@ namespace ts { // No static member is present. // Check if we're in an instance method and look for a relevant instance member. - if (location === container && !hasModifier(location, ModifierFlags.Static)) { + if (location === container && !hasSyntacticModifier(location, ModifierFlags.Static)) { const instanceType = (getDeclaredTypeOfSymbol(classSymbol)).thisType!; // TODO: GH#18217 if (getPropertyOfType(instanceType, name)) { error(errorLocation, Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0, diagnosticName(nameArg)); @@ -2404,7 +2404,7 @@ namespace ts { } function isSyntacticDefault(node: Node) { - return ((isExportAssignment(node) && !node.isExportEquals) || hasModifier(node, ModifierFlags.Default) || isExportSpecifier(node)); + return ((isExportAssignment(node) && !node.isExportEquals) || hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node)); } function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean) { @@ -4007,17 +4007,17 @@ namespace ts { const anyImportSyntax = getAnyImportSyntax(declaration); if (anyImportSyntax && - !hasModifier(anyImportSyntax, ModifierFlags.Export) && // import clause without export + !hasSyntacticModifier(anyImportSyntax, ModifierFlags.Export) && // import clause without export isDeclarationVisible(anyImportSyntax.parent)) { return addVisibleAlias(declaration, anyImportSyntax); } else if (isVariableDeclaration(declaration) && isVariableStatement(declaration.parent.parent) && - !hasModifier(declaration.parent.parent, ModifierFlags.Export) && // unexported variable statement + !hasSyntacticModifier(declaration.parent.parent, ModifierFlags.Export) && // unexported variable statement isDeclarationVisible(declaration.parent.parent.parent)) { return addVisibleAlias(declaration, declaration.parent.parent); } else if (isLateVisibilityPaintedStatement(declaration) // unexported top-level statement - && !hasModifier(declaration, ModifierFlags.Export) + && !hasSyntacticModifier(declaration, ModifierFlags.Export) && isDeclarationVisible(declaration.parent)) { return addVisibleAlias(declaration, declaration); } @@ -4466,7 +4466,7 @@ namespace ts { } function shouldWriteTypeOfFunctionSymbol() { const isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method) && // typeof static method - some(symbol.declarations, declaration => hasModifier(declaration, ModifierFlags.Static)); + some(symbol.declarations, declaration => hasSyntacticModifier(declaration, ModifierFlags.Static)); const isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) && (symbol.parent || // is exported function symbol forEach(symbol.declarations, declaration => @@ -5793,7 +5793,7 @@ namespace ts { ns.body && isModuleBlock(ns.body)) { // Pass 0: Correct situations where a module has both an `export = ns` and multiple top-level exports by stripping the export modifiers from // the top-level exports and exporting them in the targeted ns, as can occur when a js file has both typedefs and `module.export` assignments - const excessExports = filter(statements, s => !!(getModifierFlags(s) & ModifierFlags.Export)); + const excessExports = filter(statements, s => !!(getEffectiveModifierFlags(s) & ModifierFlags.Export)); if (length(excessExports)) { ns.body.statements = createNodeArray([...ns.body.statements, createExportDeclaration( /*decorators*/ undefined, @@ -5906,7 +5906,7 @@ namespace ts { } function addExportModifier(statement: Statement) { - const flags = (getModifierFlags(statement) | ModifierFlags.Export) & ~ModifierFlags.Ambient; + const flags = (getEffectiveModifierFlags(statement) | ModifierFlags.Export) & ~ModifierFlags.Ambient; statement.modifiers = createNodeArray(createModifiersFromModifierFlags(flags)); statement.modifierFlagsCache = 0; } @@ -6068,7 +6068,7 @@ namespace ts { newModifierFlags |= ModifierFlags.Default; } if (newModifierFlags) { - node.modifiers = createNodeArray(createModifiersFromModifierFlags(newModifierFlags | getModifierFlags(node))); + node.modifiers = createNodeArray(createModifiersFromModifierFlags(newModifierFlags | getEffectiveModifierFlags(node))); node.modifierFlagsCache = 0; // Reset computed flags cache } results.push(node); @@ -6752,7 +6752,7 @@ namespace ts { let privateProtected: ModifierFlags = 0; for (const s of signatures) { if (s.declaration) { - privateProtected |= getSelectedModifierFlags(s.declaration, ModifierFlags.Private | ModifierFlags.Protected); + privateProtected |= getSelectedEffectiveModifierFlags(s.declaration, ModifierFlags.Private | ModifierFlags.Protected); } } if (privateProtected) { @@ -7095,7 +7095,7 @@ namespace ts { case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasModifier(node, ModifierFlags.Private | ModifierFlags.Protected)) { + if (hasEffectiveModifier(node, ModifierFlags.Private | ModifierFlags.Protected)) { // Private/protected properties/methods are not visible return false; } @@ -7597,7 +7597,7 @@ namespace ts { // Use control flow analysis of this.xxx assignments the constructor to determine the type of the property. const constructor = findConstructorDeclaration(declaration.parent); const type = constructor ? getFlowTypeInConstructor(declaration.symbol, constructor) : - getModifierFlags(declaration) & ModifierFlags.Ambient ? getTypeOfPropertyInBaseClass(declaration.symbol) : + getEffectiveModifierFlags(declaration) & ModifierFlags.Ambient ? getTypeOfPropertyInBaseClass(declaration.symbol) : undefined; return type && addOptionality(type, isOptional); } @@ -7667,7 +7667,7 @@ namespace ts { } function getFlowTypeOfProperty(reference: Node, prop: Symbol | undefined) { - const initialType = prop && (!isAutoTypedProperty(prop) || getModifierFlags(prop.valueDeclaration) & ModifierFlags.Ambient) && getTypeOfPropertyInBaseClass(prop) || undefinedType; + const initialType = prop && (!isAutoTypedProperty(prop) || getEffectiveModifierFlags(prop.valueDeclaration) & ModifierFlags.Ambient) && getTypeOfPropertyInBaseClass(prop) || undefinedType; return getFlowTypeOfReference(reference, autoType, initialType); } @@ -9127,7 +9127,7 @@ namespace ts { } function isStaticPrivateIdentifierProperty(s: Symbol): boolean { - return !!s.valueDeclaration && isPrivateIdentifierPropertyDeclaration(s.valueDeclaration) && hasModifier(s.valueDeclaration, ModifierFlags.Static); + return !!s.valueDeclaration && isPrivateIdentifierPropertyDeclaration(s.valueDeclaration) && hasSyntacticModifier(s.valueDeclaration, ModifierFlags.Static); } function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers { @@ -11409,7 +11409,7 @@ namespace ts { const declaration = getIndexDeclarationOfSymbol(symbol, kind); if (declaration) { return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, - hasModifier(declaration, ModifierFlags.Readonly), declaration); + hasEffectiveModifier(declaration, ModifierFlags.Readonly), declaration); } return undefined; } @@ -13804,7 +13804,7 @@ namespace ts { const container = getThisContainer(node, /*includeArrowFunctions*/ false); const parent = container && container.parent; if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) { - if (!hasModifier(container, ModifierFlags.Static) && + if (!hasSyntacticModifier(container, ModifierFlags.Static) && (!isConstructorDeclaration(container) || isNodeDescendantOf(node, container.body))) { return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent as ClassLikeDeclaration | InterfaceDeclaration)).thisType!; } @@ -17246,8 +17246,8 @@ namespace ts { return true; } - const sourceAccessibility = getSelectedModifierFlags(sourceSignature.declaration, ModifierFlags.NonPublicAccessibilityModifier); - const targetAccessibility = getSelectedModifierFlags(targetSignature.declaration, ModifierFlags.NonPublicAccessibilityModifier); + const sourceAccessibility = getSelectedEffectiveModifierFlags(sourceSignature.declaration, ModifierFlags.NonPublicAccessibilityModifier); + const targetAccessibility = getSelectedEffectiveModifierFlags(targetSignature.declaration, ModifierFlags.NonPublicAccessibilityModifier); // A public, protected and private signature is assignable to a private signature. if (targetAccessibility === ModifierFlags.Private) { @@ -21309,7 +21309,7 @@ namespace ts { if (container.kind === SyntaxKind.ArrowFunction) { error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } - else if (hasModifier(container, ModifierFlags.Async)) { + else if (hasSyntacticModifier(container, ModifierFlags.Async)) { error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES3_and_ES5_Consider_using_a_standard_function_or_method); } } @@ -21351,7 +21351,7 @@ namespace ts { let container = getThisContainer(node, /*includeArrowFunctions*/ false); while (container.kind !== SyntaxKind.SourceFile) { if (container.parent === declaration) { - if (container.kind === SyntaxKind.PropertyDeclaration && hasModifier(container, ModifierFlags.Static)) { + if (container.kind === SyntaxKind.PropertyDeclaration && hasSyntacticModifier(container, ModifierFlags.Static)) { getNodeLinks(declaration).flags |= NodeCheckFlags.ClassWithConstructorReference; getNodeLinks(node).flags |= NodeCheckFlags.ConstructorReferenceInClass; } @@ -21671,7 +21671,7 @@ namespace ts { break; case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - if (hasModifier(container, ModifierFlags.Static) && !(compilerOptions.target === ScriptTarget.ESNext && compilerOptions.useDefineForClassFields)) { + if (hasSyntacticModifier(container, ModifierFlags.Static) && !(compilerOptions.target === ScriptTarget.ESNext && compilerOptions.useDefineForClassFields)) { error(node, Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks } @@ -21741,7 +21741,7 @@ namespace ts { if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); - const type = hasModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; + const type = hasSyntacticModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; return getFlowTypeOfReference(node, type); } @@ -21777,7 +21777,7 @@ namespace ts { } if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); - return hasModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; + return hasSyntacticModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; } } @@ -21897,7 +21897,7 @@ namespace ts { checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class); } - if (hasModifier(container, ModifierFlags.Static) || isCallExpression) { + if (hasSyntacticModifier(container, ModifierFlags.Static) || isCallExpression) { nodeCheckFlag = NodeCheckFlags.SuperStatic; } else { @@ -21965,7 +21965,7 @@ namespace ts { // as a call expression cannot be used as the target of a destructuring assignment while a property access can. // // For element access expressions (`super[x]`), we emit a generic helper that forwards the element access in both situations. - if (container.kind === SyntaxKind.MethodDeclaration && hasModifier(container, ModifierFlags.Async)) { + if (container.kind === SyntaxKind.MethodDeclaration && hasSyntacticModifier(container, ModifierFlags.Async)) { if (isSuperProperty(node.parent) && isAssignmentTarget(node.parent)) { getNodeLinks(container).flags |= NodeCheckFlags.AsyncMethodWithSuperBinding; } @@ -22033,7 +22033,7 @@ namespace ts { // topmost container must be something that is directly nested in the class declaration\object literal expression if (isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression) { - if (hasModifier(container, ModifierFlags.Static)) { + if (hasSyntacticModifier(container, ModifierFlags.Static)) { return container.kind === SyntaxKind.MethodDeclaration || container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || @@ -24499,7 +24499,7 @@ namespace ts { function typeHasStaticProperty(propName: __String, containingType: Type): boolean { const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName); - return prop !== undefined && prop.valueDeclaration && hasModifier(prop.valueDeclaration, ModifierFlags.Static); + return prop !== undefined && prop.valueDeclaration && hasSyntacticModifier(prop.valueDeclaration, ModifierFlags.Static); } function getSuggestedSymbolForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type): Symbol | undefined { @@ -24608,7 +24608,7 @@ namespace ts { if (!valueDeclaration) { return; } - const hasPrivateModifier = hasModifier(valueDeclaration, ModifierFlags.Private); + const hasPrivateModifier = hasEffectiveModifier(valueDeclaration, ModifierFlags.Private); const hasPrivateIdentifier = isNamedDeclaration(prop.valueDeclaration) && isPrivateIdentifier(prop.valueDeclaration.name); if (!hasPrivateModifier && !hasPrivateIdentifier) { return; @@ -26176,7 +26176,7 @@ namespace ts { // In the case of a merged class-module or class-interface declaration, // only the class declaration node will have the Abstract flag set. const valueDecl = expressionType.symbol && getClassLikeDeclarationOfSymbol(expressionType.symbol); - if (valueDecl && hasModifier(valueDecl, ModifierFlags.Abstract)) { + if (valueDecl && hasSyntacticModifier(valueDecl, ModifierFlags.Abstract)) { error(node, Diagnostics.Cannot_create_an_instance_of_an_abstract_class); return resolveErrorCall(node); } @@ -26244,7 +26244,7 @@ namespace ts { } const declaration = signature.declaration; - const modifiers = getSelectedModifierFlags(declaration, ModifierFlags.NonPublicAccessibilityModifier); + const modifiers = getSelectedEffectiveModifierFlags(declaration, ModifierFlags.NonPublicAccessibilityModifier); // (1) Public constructors and (2) constructor functions are always accessible. if (!modifiers || declaration.kind !== SyntaxKind.Constructor) { @@ -29427,7 +29427,7 @@ namespace ts { checkVariableLikeDeclaration(node); const func = getContainingFunction(node)!; - if (hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { + if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) { error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } @@ -29654,7 +29654,7 @@ namespace ts { } } else { - const isStatic = hasModifier(member, ModifierFlags.Static); + const isStatic = hasSyntacticModifier(member, ModifierFlags.Static); const name = member.name; if (!name) { return; @@ -29721,7 +29721,7 @@ namespace ts { function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { for (const member of node.members) { const memberNameNode = member.name; - const isStatic = hasModifier(member, ModifierFlags.Static); + const isStatic = hasSyntacticModifier(member, ModifierFlags.Static); if (isStatic && memberNameNode) { const memberName = getPropertyNameForPropertyNameNode(memberNameNode); switch (memberName) { @@ -29844,7 +29844,7 @@ namespace ts { // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. - if (hasModifier(node, ModifierFlags.Abstract) && node.kind === SyntaxKind.MethodDeclaration && node.body) { + if (hasSyntacticModifier(node, ModifierFlags.Abstract) && node.kind === SyntaxKind.MethodDeclaration && node.body) { error(node, Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, declarationNameToString(node.name)); } } @@ -29879,7 +29879,7 @@ namespace ts { return true; } return n.kind === SyntaxKind.PropertyDeclaration && - !hasModifier(n, ModifierFlags.Static) && + !hasSyntacticModifier(n, ModifierFlags.Static) && !!(n).initializer; } @@ -29904,7 +29904,7 @@ namespace ts { const superCallShouldBeFirst = (compilerOptions.target !== ScriptTarget.ESNext || !compilerOptions.useDefineForClassFields) && (some((node.parent).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) || - some(node.parameters, p => hasModifier(p, ModifierFlags.ParameterPropertyModifier))); + some(node.parameters, p => hasSyntacticModifier(p, ModifierFlags.ParameterPropertyModifier))); // Skip past any prologue directives to find the first statement // to ensure that it was a super call. @@ -29961,8 +29961,8 @@ namespace ts { const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor; const otherAccessor = getDeclarationOfKind(getSymbolOfNode(node), otherKind); if (otherAccessor) { - const nodeFlags = getModifierFlags(node); - const otherFlags = getModifierFlags(otherAccessor); + const nodeFlags = getEffectiveModifierFlags(node); + const otherFlags = getEffectiveModifierFlags(otherAccessor); if ((nodeFlags & ModifierFlags.AccessibilityModifier) !== (otherFlags & ModifierFlags.AccessibilityModifier)) { error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility); } @@ -30189,7 +30189,7 @@ namespace ts { } function isPrivateWithinAmbient(node: Node): boolean { - return (hasModifier(node, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(node)) && !!(node.flags & NodeFlags.Ambient); + return (hasEffectiveModifier(node, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(node)) && !!(node.flags & NodeFlags.Ambient); } function getEffectiveDeclarationFlags(n: Declaration, flagsToCheck: ModifierFlags): ModifierFlags { @@ -30308,13 +30308,13 @@ namespace ts { )) { const reportError = (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && - hasModifier(node, ModifierFlags.Static) !== hasModifier(subsequentNode, ModifierFlags.Static); + hasSyntacticModifier(node, ModifierFlags.Static) !== hasSyntacticModifier(subsequentNode, ModifierFlags.Static); // we can get here in two cases // 1. mixed static and instance class members // 2. something with the same name was defined before the set of overloads that prevents them from merging // here we'll report error only for the first case since for second we should already report error in binder if (reportError) { - const diagnostic = hasModifier(node, ModifierFlags.Static) ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static; + const diagnostic = hasSyntacticModifier(node, ModifierFlags.Static) ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static; error(errorNode, diagnostic); } return; @@ -30332,7 +30332,7 @@ namespace ts { else { // Report different errors regarding non-consecutive blocks of declarations depending on whether // the node in question is abstract. - if (hasModifier(node, ModifierFlags.Abstract)) { + if (hasSyntacticModifier(node, ModifierFlags.Abstract)) { error(errorNode, Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive); } else { @@ -30423,7 +30423,7 @@ namespace ts { // Abstract methods can't have an implementation -- in particular, they don't need one. if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && - !hasModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) { + !hasSyntacticModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -31367,14 +31367,14 @@ namespace ts { } const symbol = getSymbolOfNode(member); if (!symbol.isReferenced - && (hasModifier(member, ModifierFlags.Private) || isNamedDeclaration(member) && isPrivateIdentifier(member.name)) + && (hasEffectiveModifier(member, ModifierFlags.Private) || isNamedDeclaration(member) && isPrivateIdentifier(member.name)) && !(member.flags & NodeFlags.Ambient)) { addDiagnostic(member, UnusedKind.Local, createDiagnosticForNode(member.name!, Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case SyntaxKind.Constructor: for (const parameter of (member).parameters) { - if (!parameter.symbol.isReferenced && hasModifier(parameter, ModifierFlags.Private)) { + if (!parameter.symbol.isReferenced && hasSyntacticModifier(parameter, ModifierFlags.Private)) { addDiagnostic(parameter, UnusedKind.Local, createDiagnosticForNode(parameter.name, Diagnostics.Property_0_is_declared_but_its_value_is_never_read, symbolName(parameter.symbol))); } } @@ -31969,7 +31969,7 @@ namespace ts { ModifierFlags.Readonly | ModifierFlags.Static; - return getSelectedModifierFlags(left, interestingFlags) === getSelectedModifierFlags(right, interestingFlags); + return getSelectedEffectiveModifierFlags(left, interestingFlags) === getSelectedEffectiveModifierFlags(right, interestingFlags); } function checkVariableDeclaration(node: VariableDeclaration) { @@ -33158,7 +33158,7 @@ namespace ts { // Only process instance properties with computed names here. // Static properties cannot be in conflict with indexers, // and properties with literal names were already checked. - if (!hasModifier(member, ModifierFlags.Static) && hasNonBindableDynamicName(member)) { + if (!hasSyntacticModifier(member, ModifierFlags.Static) && hasNonBindableDynamicName(member)) { const symbol = getSymbolOfNode(member); const propType = getTypeOfSymbol(symbol); checkIndexConstraintForProperty(symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String); @@ -33394,7 +33394,7 @@ namespace ts { } function checkClassDeclaration(node: ClassDeclaration) { - if (!node.name && !hasModifier(node, ModifierFlags.Default)) { + if (!node.name && !hasSyntacticModifier(node, ModifierFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } checkClassLikeDeclaration(node); @@ -33549,7 +33549,7 @@ namespace ts { const signatures = getSignaturesOfType(type, SignatureKind.Construct); if (signatures.length) { const declaration = signatures[0].declaration; - if (declaration && hasModifier(declaration, ModifierFlags.Private)) { + if (declaration && hasEffectiveModifier(declaration, ModifierFlags.Private)) { const typeClassDeclaration = getClassLikeDeclarationOfSymbol(type.symbol)!; if (!isNodeWithinClass(node, typeClassDeclaration)) { error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, getFullyQualifiedName(type.symbol)); @@ -33611,7 +33611,7 @@ namespace ts { // It is an error to inherit an abstract member without implementing it or being declared abstract. // If there is no declaration for the derived class (as in the case of class expressions), // then the class cannot be declared abstract. - if (baseDeclarationFlags & ModifierFlags.Abstract && (!derivedClassDecl || !hasModifier(derivedClassDecl, ModifierFlags.Abstract))) { + if (baseDeclarationFlags & ModifierFlags.Abstract && (!derivedClassDecl || !hasSyntacticModifier(derivedClassDecl, ModifierFlags.Abstract))) { // Searches other base types for a declaration that would satisfy the inherited abstract member. // (The class may have more than one base type via declaration merging with an interface with the // same name.) @@ -33772,7 +33772,7 @@ namespace ts { } const constructor = findConstructorDeclaration(node); for (const member of node.members) { - if (getModifierFlags(member) & ModifierFlags.Ambient) { + if (getEffectiveModifierFlags(member) & ModifierFlags.Ambient) { continue; } if (isInstancePropertyWithoutInitializer(member)) { @@ -33791,7 +33791,7 @@ namespace ts { function isInstancePropertyWithoutInitializer(node: Node) { return node.kind === SyntaxKind.PropertyDeclaration && - !hasModifier(node, ModifierFlags.Static | ModifierFlags.Abstract) && + !hasSyntacticModifier(node, ModifierFlags.Static | ModifierFlags.Abstract) && !(node).exclamationToken && !(node).initializer; } @@ -34371,7 +34371,7 @@ namespace ts { // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. return; } - if (!checkGrammarDecoratorsAndModifiers(node) && hasModifiers(node)) { + if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -34404,7 +34404,7 @@ namespace ts { checkGrammarDecoratorsAndModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { markExportAsReferenced(node); } if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) { @@ -34437,7 +34437,7 @@ namespace ts { return; } - if (!checkGrammarDecoratorsAndModifiers(node) && hasModifiers(node)) { + if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); } @@ -34560,7 +34560,7 @@ namespace ts { return; } // Grammar checking - if (!checkGrammarDecoratorsAndModifiers(node) && hasModifiers(node)) { + if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } if (node.expression.kind === SyntaxKind.Identifier) { @@ -35177,7 +35177,7 @@ namespace ts { copySymbol(argumentsSymbol, meaning); } - isStatic = hasModifier(location, ModifierFlags.Static); + isStatic = hasSyntacticModifier(location, ModifierFlags.Static); location = location.parent; } @@ -35702,7 +35702,7 @@ namespace ts { */ function getParentTypeOfClassElement(node: ClassElement) { const classSymbol = getSymbolOfNode(node.parent)!; - return hasModifier(node, ModifierFlags.Static) + return hasSyntacticModifier(node, ModifierFlags.Static) ? getTypeOfSymbol(classSymbol) : getDeclaredTypeOfSymbol(classSymbol); } @@ -36005,7 +36005,7 @@ namespace ts { return true; } const target = getSymbolLinks(symbol!).target; // TODO: GH#18217 - if (target && getModifierFlags(node) & ModifierFlags.Export && + if (target && getEffectiveModifierFlags(node) & ModifierFlags.Export && target.flags & SymbolFlags.Value && (compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target))) { // An `export import ... =` of a value symbol is always considered referenced @@ -36046,14 +36046,14 @@ namespace ts { !isOptionalParameter(parameter) && !isJSDocParameterTag(parameter) && !!parameter.initializer && - !hasModifier(parameter, ModifierFlags.ParameterPropertyModifier); + !hasSyntacticModifier(parameter, ModifierFlags.ParameterPropertyModifier); } function isOptionalUninitializedParameterProperty(parameter: ParameterDeclaration) { return strictNullChecks && isOptionalParameter(parameter) && !parameter.initializer && - hasModifier(parameter, ModifierFlags.ParameterPropertyModifier); + hasSyntacticModifier(parameter, ModifierFlags.ParameterPropertyModifier); } function isExpandoFunctionDeclaration(node: Declaration): boolean { @@ -36889,7 +36889,7 @@ namespace ts { node.kind !== SyntaxKind.SetAccessor) { return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration); } - if (!(node.parent.kind === SyntaxKind.ClassDeclaration && hasModifier(node.parent, ModifierFlags.Abstract))) { + if (!(node.parent.kind === SyntaxKind.ClassDeclaration && hasSyntacticModifier(node.parent, ModifierFlags.Abstract))) { return grammarErrorOnNode(modifier, Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); } if (flags & ModifierFlags.Static) { @@ -37135,7 +37135,7 @@ namespace ts { if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - if (hasModifiers(parameter)) { + if (hasEffectiveModifiers(parameter)) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } if (parameter.questionToken) { @@ -37529,11 +37529,11 @@ namespace ts { if (languageVersion < ScriptTarget.ES5) { return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } - if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) { + if (accessor.body === undefined && !hasSyntacticModifier(accessor, ModifierFlags.Abstract)) { return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); } } - if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) { + if (accessor.body && hasSyntacticModifier(accessor, ModifierFlags.Abstract)) { return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation); } if (accessor.typeParameters) { @@ -37583,7 +37583,14 @@ namespace ts { return grammarErrorOnNode(node.type, Diagnostics._0_expected, tokenToString(SyntaxKind.SymbolKeyword)); } - const parent = walkUpParenthesizedTypes(node.parent); + let parent = walkUpParenthesizedTypes(node.parent); + if (isInJSFile(parent) && isJSDocTypeExpression(parent)) { + parent = parent.parent; + if (isJSDocTypeTag(parent)) { + // walk up past JSDoc comment node + parent = parent.parent.parent; + } + } switch (parent.kind) { case SyntaxKind.VariableDeclaration: const decl = parent as VariableDeclaration; @@ -37599,14 +37606,14 @@ namespace ts { break; case SyntaxKind.PropertyDeclaration: - if (!hasModifier(parent, ModifierFlags.Static) || - !hasModifier(parent, ModifierFlags.Readonly)) { + if (!hasSyntacticModifier(parent, ModifierFlags.Static) || + !hasEffectiveModifier(parent, ModifierFlags.Readonly)) { return grammarErrorOnNode((parent).name, Diagnostics.A_property_of_a_class_whose_type_is_a_unique_symbol_type_must_be_both_static_and_readonly); } break; case SyntaxKind.PropertySignature: - if (!hasModifier(parent, ModifierFlags.Readonly)) { + if (!hasSyntacticModifier(parent, ModifierFlags.Readonly)) { return grammarErrorOnNode((parent).name, Diagnostics.A_property_of_an_interface_or_type_literal_whose_type_is_a_unique_symbol_type_must_be_readonly); } break; @@ -37813,7 +37820,7 @@ namespace ts { const moduleKind = getEmitModuleKind(compilerOptions); if (moduleKind < ModuleKind.ES2015 && moduleKind !== ModuleKind.System && !compilerOptions.noEmit && - !(node.parent.parent.flags & NodeFlags.Ambient) && hasModifier(node.parent.parent, ModifierFlags.Export)) { + !(node.parent.parent.flags & NodeFlags.Ambient) && hasSyntacticModifier(node.parent.parent, ModifierFlags.Export)) { checkESModuleMarker(node.name); } @@ -38001,7 +38008,7 @@ namespace ts { } if (isPropertyDeclaration(node) && node.exclamationToken && (!isClassLike(node.parent) || !node.type || node.initializer || - node.flags & NodeFlags.Ambient || hasModifier(node, ModifierFlags.Static | ModifierFlags.Abstract))) { + node.flags & NodeFlags.Ambient || hasSyntacticModifier(node, ModifierFlags.Static | ModifierFlags.Abstract))) { return grammarErrorOnNode(node.exclamationToken, Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context); } } @@ -38026,7 +38033,7 @@ namespace ts { node.kind === SyntaxKind.ExportDeclaration || node.kind === SyntaxKind.ExportAssignment || node.kind === SyntaxKind.NamespaceExportDeclaration || - hasModifier(node, ModifierFlags.Ambient | ModifierFlags.Export | ModifierFlags.Default)) { + hasSyntacticModifier(node, ModifierFlags.Ambient | ModifierFlags.Export | ModifierFlags.Default)) { return false; } diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 53e23b02ace..37beb5225b5 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -376,7 +376,7 @@ namespace ts { Object.defineProperties(ctor.prototype, { __debugKind: { get(this: Node) { return formatSyntaxKind(this.kind); } }, __debugNodeFlags: { get(this: Node) { return formatNodeFlags(this.flags); } }, - __debugModifierFlags: { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } }, + __debugModifierFlags: { get(this: Node) { return formatModifierFlags(getEffectiveModifierFlagsNoCache(this)); } }, __debugTransformFlags: { get(this: Node) { return formatTransformFlags(this.transformFlags); } }, __debugIsParseTreeNode: { get(this: Node) { return isParseTreeNode(this); } }, __debugEmitFlags: { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } }, diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index ed854342245..833da8c8a6a 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -751,7 +751,7 @@ namespace ts { * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. */ export function getExternalModuleOrNamespaceExportName(ns: Identifier | undefined, node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier | PropertyAccessExpression { - if (ns && hasModifier(node, ModifierFlags.Export)) { + if (ns && hasSyntacticModifier(node, ModifierFlags.Export)) { return getNamespaceMemberName(ns, getName(node), allowComments, allowSourceMaps); } return getExportName(node, allowComments, allowSourceMaps); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 437ec09e8b8..c8847d04358 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2145,7 +2145,7 @@ namespace ts { } } else if (isModuleDeclaration(node)) { - if (isAmbientModule(node) && (inAmbientModule || hasModifier(node, ModifierFlags.Ambient) || file.isDeclarationFile)) { + if (isAmbientModule(node) && (inAmbientModule || hasSyntacticModifier(node, ModifierFlags.Ambient) || file.isDeclarationFile)) { const nameText = getTextOfIdentifierOrLiteral(node.name); // Ambient module declarations can be interpreted as augmentations for some existing external modules. // This will happen in two cases: diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 413ff8f8cd2..1e9aa130f68 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -487,7 +487,7 @@ namespace ts { | PropertySignature; function ensureType(node: HasInferredType, type: TypeNode | undefined, ignorePrivate?: boolean): TypeNode | undefined { - if (!ignorePrivate && hasModifier(node, ModifierFlags.Private)) { + if (!ignorePrivate && hasEffectiveModifier(node, ModifierFlags.Private)) { // Private nodes emit no types (except private parameter properties, whose parameter types are actually visible) return; } @@ -571,7 +571,7 @@ namespace ts { } function updateParamsList(node: Node, params: NodeArray, modifierMask?: ModifierFlags) { - if (hasModifier(node, ModifierFlags.Private)) { + if (hasEffectiveModifier(node, ModifierFlags.Private)) { return undefined!; // TODO: GH#18217 } const newParams = map(params, p => ensureParameter(p, modifierMask)); @@ -612,7 +612,7 @@ namespace ts { } function ensureTypeParams(node: Node, params: NodeArray | undefined) { - return hasModifier(node, ModifierFlags.Private) ? undefined : visitNodes(params, visitDeclarationSubtree); + return hasEffectiveModifier(node, ModifierFlags.Private) ? undefined : visitNodes(params, visitDeclarationSubtree); } function isEnclosingDeclaration(node: Node) { @@ -825,7 +825,7 @@ namespace ts { // Emit methods which are private as properties with no type information if (isMethodDeclaration(input) || isMethodSignature(input)) { - if (hasModifier(input, ModifierFlags.Private)) { + if (hasEffectiveModifier(input, ModifierFlags.Private)) { if (input.symbol && input.symbol.declarations && input.symbol.declarations[0] !== input) return; // Elide all but the first overload return cleanup(createProperty(/*decorators*/undefined, ensureModifiers(input), input.name, /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined)); } @@ -901,7 +901,7 @@ namespace ts { /*decorators*/ undefined, ensureModifiers(input), input.name, - updateAccessorParamsList(input, hasModifier(input, ModifierFlags.Private)), + updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)), ensureType(input, accessorType), /*body*/ undefined)); } @@ -914,7 +914,7 @@ namespace ts { /*decorators*/ undefined, ensureModifiers(input), input.name, - updateAccessorParamsList(input, hasModifier(input, ModifierFlags.Private)), + updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)), /*body*/ undefined)); } case SyntaxKind.PropertyDeclaration: @@ -1041,7 +1041,7 @@ namespace ts { } function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { - return node.parent.kind === SyntaxKind.MethodDeclaration && hasModifier(node.parent, ModifierFlags.Private); + return node.parent.kind === SyntaxKind.MethodDeclaration && hasEffectiveModifier(node.parent, ModifierFlags.Private); } function visitDeclarationStatements(input: Node): VisitResult { @@ -1096,13 +1096,13 @@ namespace ts { } function stripExportModifiers(statement: Statement): Statement { - if (isImportEqualsDeclaration(statement) || hasModifier(statement, ModifierFlags.Default)) { + if (isImportEqualsDeclaration(statement) || hasEffectiveModifier(statement, ModifierFlags.Default)) { // `export import` statements should remain as-is, as imports are _not_ implicitly exported in an ambient namespace // Likewise, `export default` classes and the like and just be `default`, so we preserve their `export` modifiers, too return statement; } const clone = getMutableClone(statement); - const modifiers = createModifiersFromModifierFlags(getModifierFlags(statement) & (ModifierFlags.All ^ ModifierFlags.Export)); + const modifiers = createModifiersFromModifierFlags(getEffectiveModifierFlags(statement) & (ModifierFlags.All ^ ModifierFlags.Export)); clone.modifiers = modifiers.length ? createNodeArray(modifiers) : undefined; return clone; } @@ -1188,11 +1188,11 @@ namespace ts { }); const namespaceDecl = createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name!, createModuleBlock(declarations), NodeFlags.Namespace); - if (!hasModifier(clean, ModifierFlags.Default)) { + if (!hasEffectiveModifier(clean, ModifierFlags.Default)) { return [clean, namespaceDecl]; } - const modifiers = createModifiersFromModifierFlags((getModifierFlags(clean) & ~ModifierFlags.ExportDefault) | ModifierFlags.Ambient); + const modifiers = createModifiersFromModifierFlags((getEffectiveModifierFlags(clean) & ~ModifierFlags.ExportDefault) | ModifierFlags.Ambient); const cleanDeclaration = updateFunctionDeclaration( clean, /*decorators*/ undefined, @@ -1295,7 +1295,7 @@ namespace ts { if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; parameterProperties = compact(flatMap(ctor.parameters, (param) => { - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; + if (!hasSyntacticModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1482,7 +1482,7 @@ namespace ts { } function ensureModifiers(node: Node): readonly Modifier[] | undefined { - const currentFlags = getModifierFlags(node); + const currentFlags = getEffectiveModifierFlags(node); const newFlags = ensureModifierFlags(node); if (currentFlags === newFlags) { return node.modifiers; @@ -1536,7 +1536,7 @@ namespace ts { } function maskModifierFlags(node: Node, modifierMask: ModifierFlags = ModifierFlags.All ^ ModifierFlags.Public, modifierAdditions: ModifierFlags = ModifierFlags.None): ModifierFlags { - let flags = (getModifierFlags(node) & modifierMask) | modifierAdditions; + let flags = (getEffectiveModifierFlags(node) & modifierMask) | modifierAdditions; if (flags & ModifierFlags.Default && !(flags & ModifierFlags.Export)) { // A non-exported default is a nonsequitor - we usually try to remove all export modifiers // from statements in ambient declarations; but a default export must retain its export modifier to be syntactically valid @@ -1563,7 +1563,7 @@ namespace ts { switch (node.kind) { case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - return !hasModifier(node, ModifierFlags.Private); + return !hasEffectiveModifier(node, ModifierFlags.Private); case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: return true; diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index ac44f7efd15..1294739ef96 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -71,7 +71,7 @@ namespace ts { } function getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { - if (hasModifier(node, ModifierFlags.Static)) { + if (hasSyntacticModifier(node, ModifierFlags.Static)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -102,7 +102,7 @@ namespace ts { } function getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { - if (hasModifier(node, ModifierFlags.Static)) { + if (hasSyntacticModifier(node, ModifierFlags.Static)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -135,7 +135,7 @@ namespace ts { return getReturnTypeVisibilityError; } else if (isParameter(node)) { - if (isParameterPropertyDeclaration(node, node.parent) && hasModifier(node.parent, ModifierFlags.Private)) { + if (isParameterPropertyDeclaration(node, node.parent) && hasSyntacticModifier(node.parent, ModifierFlags.Private)) { return getVariableDeclarationTypeVisibilityError; } return getParameterDeclarationTypeVisibilityError; @@ -167,9 +167,9 @@ namespace ts { // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit // The only exception here is if the constructor was marked as private. we are not emitting the constructor parameters at all. else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.PropertySignature || - (node.kind === SyntaxKind.Parameter && hasModifier(node.parent, ModifierFlags.Private))) { + (node.kind === SyntaxKind.Parameter && hasSyntacticModifier(node.parent, ModifierFlags.Private))) { // TODO(jfreeman): Deal with computed properties in error reporting. - if (hasModifier(node, ModifierFlags.Static)) { + if (hasSyntacticModifier(node, ModifierFlags.Static)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -206,7 +206,7 @@ namespace ts { if (node.kind === SyntaxKind.SetAccessor) { // Getters can infer the return type from the returned expression, but setters cannot, so the // "_from_external_module_1_but_cannot_be_named" case cannot occur. - if (hasModifier(node, ModifierFlags.Static)) { + if (hasSyntacticModifier(node, ModifierFlags.Static)) { diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_private_name_1; @@ -218,7 +218,7 @@ namespace ts { } } else { - if (hasModifier(node, ModifierFlags.Static)) { + if (hasSyntacticModifier(node, ModifierFlags.Static)) { diagnosticMessage = symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -266,7 +266,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasModifier(node, ModifierFlags.Static)) { + if (hasSyntacticModifier(node, ModifierFlags.Static)) { diagnosticMessage = symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -345,7 +345,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasModifier(node.parent, ModifierFlags.Static)) { + if (hasSyntacticModifier(node.parent, ModifierFlags.Static)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -413,7 +413,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasModifier(node.parent, ModifierFlags.Static)) { + if (hasSyntacticModifier(node.parent, ModifierFlags.Static)) { diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 3e2e88d15c2..d4a42cfb186 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -681,8 +681,8 @@ namespace ts { statements.push(statement); // Add an `export default` statement for default exports (for `--target es5 --module es6`) - if (hasModifier(node, ModifierFlags.Export)) { - const exportStatement = hasModifier(node, ModifierFlags.Default) + if (hasSyntacticModifier(node, ModifierFlags.Export)) { + const exportStatement = hasSyntacticModifier(node, ModifierFlags.Default) ? createExportDefault(getLocalName(node)) : createExternalModuleExport(getLocalName(node)); @@ -1804,7 +1804,7 @@ namespace ts { function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: TextRange | undefined, name: Identifier | undefined, container: Node | undefined): FunctionExpression { const savedConvertedLoopState = convertedLoopState; convertedLoopState = undefined; - const ancestorFacts = container && isClassLike(container) && !hasModifier(node, ModifierFlags.Static) + const ancestorFacts = container && isClassLike(container) && !hasSyntacticModifier(node, ModifierFlags.Static) ? enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes | HierarchyFacts.NonStaticClassElement) : enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes); const parameters = visitParameterList(node.parameters, visitor, context); @@ -2011,7 +2011,7 @@ namespace ts { } function visitVariableStatement(node: VariableStatement): Statement | undefined { - const ancestorFacts = enterSubtree(HierarchyFacts.None, hasModifier(node, ModifierFlags.Export) ? HierarchyFacts.ExportedVariableStatement : HierarchyFacts.None); + const ancestorFacts = enterSubtree(HierarchyFacts.None, hasSyntacticModifier(node, ModifierFlags.Export) ? HierarchyFacts.ExportedVariableStatement : HierarchyFacts.None); let updated: Statement | undefined; if (convertedLoopState && (node.declarationList.flags & NodeFlags.BlockScoped) === 0 && !isVariableStatementOfTypeScriptClassWrapper(node)) { // we are inside a converted loop - hoist variable declarations @@ -4257,7 +4257,7 @@ namespace ts { } function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { - return hasModifier(member, ModifierFlags.Static) + return hasSyntacticModifier(member, ModifierFlags.Static) ? getInternalName(node) : createPropertyAccess(getInternalName(node), "prototype"); } diff --git a/src/compiler/transformers/es2018.ts b/src/compiler/transformers/es2018.ts index 16d67fcef38..585ec59241e 100644 --- a/src/compiler/transformers/es2018.ts +++ b/src/compiler/transformers/es2018.ts @@ -486,7 +486,7 @@ namespace ts { } function visitVariableStatement(node: VariableStatement): VisitResult { - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { const savedExportedVariableStatement = exportedVariableStatement; exportedVariableStatement = true; const visited = visitEachChild(node, visitor, context); diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 2bb81ff255c..85b18b4f7b5 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -895,7 +895,7 @@ namespace ts { let statements: Statement[] | undefined; if (moduleKind !== ModuleKind.AMD) { - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { statements = append(statements, setOriginalNode( setTextRange( @@ -934,7 +934,7 @@ namespace ts { } } else { - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { statements = append(statements, setOriginalNode( setTextRange( @@ -1095,7 +1095,7 @@ namespace ts { */ function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { let statements: Statement[] | undefined; - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { statements = append(statements, setOriginalNode( setTextRange( @@ -1138,7 +1138,7 @@ namespace ts { */ function visitClassDeclaration(node: ClassDeclaration): VisitResult { let statements: Statement[] | undefined; - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { statements = append(statements, setOriginalNode( setTextRange( @@ -1182,7 +1182,7 @@ namespace ts { let variables: VariableDeclaration[] | undefined; let expressions: Expression[] | undefined; - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { let modifiers: NodeArray | undefined; // If we're exporting these variables, then these just become assignments to 'exports.x'. @@ -1442,8 +1442,8 @@ namespace ts { return statements; } - if (hasModifier(decl, ModifierFlags.Export)) { - const exportName = hasModifier(decl, ModifierFlags.Default) ? createIdentifier("default") : getDeclarationName(decl); + if (hasSyntacticModifier(decl, ModifierFlags.Export)) { + const exportName = hasSyntacticModifier(decl, ModifierFlags.Default) ? createIdentifier("default") : getDeclarationName(decl); statements = appendExportStatement(statements, exportName, getLocalName(decl), /*location*/ decl); } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index a198164078c..6d0a7ee6b52 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -693,7 +693,7 @@ namespace ts { * @param node The node to visit. */ function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { hoistedStatements = append(hoistedStatements, updateFunctionDeclaration( node, @@ -780,7 +780,7 @@ namespace ts { } let expressions: Expression[] | undefined; - const isExportedDeclaration = hasModifier(node, ModifierFlags.Export); + const isExportedDeclaration = hasSyntacticModifier(node, ModifierFlags.Export); const isMarkedDeclaration = hasAssociatedEndOfDeclarationMarker(node); for (const variable of node.declarationList.declarations) { if (variable.initializer) { @@ -911,7 +911,7 @@ namespace ts { // statement until we visit this declaration's `EndOfDeclarationMarker`. if (hasAssociatedEndOfDeclarationMarker(node) && node.original!.kind === SyntaxKind.VariableStatement) { const id = getOriginalNodeId(node); - const isExportedDeclaration = hasModifier(node.original!, ModifierFlags.Export); + const isExportedDeclaration = hasSyntacticModifier(node.original!, ModifierFlags.Export); deferredExports[id] = appendExportsOfVariableStatement(deferredExports[id], node.original, isExportedDeclaration); } @@ -1087,8 +1087,8 @@ namespace ts { } let excludeName: string | undefined; - if (hasModifier(decl, ModifierFlags.Export)) { - const exportName = hasModifier(decl, ModifierFlags.Default) ? createLiteral("default") : decl.name!; + if (hasSyntacticModifier(decl, ModifierFlags.Export)) { + const exportName = hasSyntacticModifier(decl, ModifierFlags.Default) ? createLiteral("default") : decl.name!; statements = appendExportStatement(statements, exportName, getLocalName(decl)); excludeName = getTextOfIdentifierOrLiteral(exportName); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0ef7db06272..7f848685aec 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -166,7 +166,7 @@ namespace ts { case SyntaxKind.ClassDeclaration: case SyntaxKind.FunctionDeclaration: - if (hasModifier(node, ModifierFlags.Ambient)) { + if (hasSyntacticModifier(node, ModifierFlags.Ambient)) { break; } @@ -178,7 +178,7 @@ namespace ts { // These nodes should always have names unless they are default-exports; // however, class declaration parsing allows for undefined names, so syntactically invalid // programs may also have an undefined name. - Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default)); + Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasSyntacticModifier(node, ModifierFlags.Default)); } if (isClassDeclaration(node)) { // XXX: should probably also cover interfaces and type aliases that can have type variables? @@ -287,7 +287,7 @@ namespace ts { // do not emit ES6 imports and exports since they are illegal inside a namespace return undefined; } - else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasModifier(node, ModifierFlags.Export)) { + else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasSyntacticModifier(node, ModifierFlags.Export)) { return visitTypeScript(node); } @@ -349,7 +349,7 @@ namespace ts { * @param node The node to visit. */ function visitTypeScript(node: Node): VisitResult { - if (isStatement(node) && hasModifier(node, ModifierFlags.Ambient)) { + if (isStatement(node) && hasSyntacticModifier(node, ModifierFlags.Ambient)) { // TypeScript ambient declarations are elided, but some comments may be preserved. // See the implementation of `getLeadingComments` in comments.ts for more details. return createNotEmittedStatement(node); @@ -610,7 +610,7 @@ namespace ts { } function visitClassDeclaration(node: ClassDeclaration): VisitResult { - if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasModifier(node, ModifierFlags.Export))) { + if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasSyntacticModifier(node, ModifierFlags.Export))) { return visitEachChild(node, visitor, context); } @@ -966,7 +966,7 @@ namespace ts { */ function isDecoratedClassElement(member: ClassElement, isStatic: boolean, parent: ClassLikeDeclaration) { return nodeOrChildIsDecorated(member, parent) - && isStatic === hasModifier(member, ModifierFlags.Static); + && isStatic === hasSyntacticModifier(member, ModifierFlags.Static); } /** @@ -2045,7 +2045,7 @@ namespace ts { * @param node The declaration node. */ function shouldEmitAccessorDeclaration(node: AccessorDeclaration) { - return !(nodeIsMissing(node.body) && hasModifier(node, ModifierFlags.Abstract)); + return !(nodeIsMissing(node.body) && hasSyntacticModifier(node, ModifierFlags.Abstract)); } function visitGetAccessor(node: GetAccessorDeclaration) { @@ -2352,7 +2352,7 @@ namespace ts { const containerName = getNamespaceContainerName(node); // `exportName` is the expression used within this node's container for any exported references. - const exportName = hasModifier(node, ModifierFlags.Export) + const exportName = hasSyntacticModifier(node, ModifierFlags.Export) ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); @@ -2653,7 +2653,7 @@ namespace ts { const containerName = getNamespaceContainerName(node); // `exportName` is the expression used within this node's container for any exported references. - const exportName = hasModifier(node, ModifierFlags.Export) + const exportName = hasSyntacticModifier(node, ModifierFlags.Export) ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); @@ -3039,7 +3039,7 @@ namespace ts { * @param node The node to test. */ function isExportOfNamespace(node: Node) { - return currentNamespace !== undefined && hasModifier(node, ModifierFlags.Export); + return currentNamespace !== undefined && hasSyntacticModifier(node, ModifierFlags.Export); } /** @@ -3048,7 +3048,7 @@ namespace ts { * @param node The node to test. */ function isExternalModuleExport(node: Node) { - return currentNamespace === undefined && hasModifier(node, ModifierFlags.Export); + return currentNamespace === undefined && hasSyntacticModifier(node, ModifierFlags.Export); } /** @@ -3058,7 +3058,7 @@ namespace ts { */ function isNamedExternalModuleExport(node: Node) { return isExternalModuleExport(node) - && !hasModifier(node, ModifierFlags.Default); + && !hasSyntacticModifier(node, ModifierFlags.Default); } /** @@ -3068,7 +3068,7 @@ namespace ts { */ function isDefaultExternalModuleExport(node: Node) { return isExternalModuleExport(node) - && hasModifier(node, ModifierFlags.Default); + && hasSyntacticModifier(node, ModifierFlags.Default); } /** @@ -3147,7 +3147,7 @@ namespace ts { } function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { - return hasModifier(member, ModifierFlags.Static) + return hasSyntacticModifier(member, ModifierFlags.Static) ? getDeclarationName(node) : getClassPrototype(node); } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index a602d6c0486..4a4dc05de76 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -143,7 +143,7 @@ namespace ts { break; case SyntaxKind.VariableStatement: - if (hasModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { for (const decl of (node).declarationList.declarations) { exportedNames = collectExportedVariableInfo(decl, uniqueExports, exportedNames); } @@ -151,8 +151,8 @@ namespace ts { break; case SyntaxKind.FunctionDeclaration: - if (hasModifier(node, ModifierFlags.Export)) { - if (hasModifier(node, ModifierFlags.Default)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Default)) { // export default function() { } if (!hasExportDefault) { multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); @@ -172,8 +172,8 @@ namespace ts { break; case SyntaxKind.ClassDeclaration: - if (hasModifier(node, ModifierFlags.Export)) { - if (hasModifier(node, ModifierFlags.Default)) { + if (hasSyntacticModifier(node, ModifierFlags.Export)) { + if (hasSyntacticModifier(node, ModifierFlags.Default)) { // export default class { } if (!hasExportDefault) { multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 72c6dcfd79f..54d889b2ff4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -609,6 +609,7 @@ namespace ts { Async = 1 << 8, // Property/Method/Function Default = 1 << 9, // Function/Class (export default declaration) Const = 1 << 11, // Const enum + HasComputedJSDocModifiers = 1 << 12, // Indicates the computed modifier flags include modifiers from JSDoc. HasComputedFlags = 1 << 29, // Modifier flags have been computed AccessibilityModifier = Public | Private | Protected, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 07613e301fa..17ce0562122 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1370,8 +1370,8 @@ namespace ts { export function isValidESSymbolDeclaration(node: Node): node is VariableDeclaration | PropertyDeclaration | SignatureDeclaration { return isVariableDeclaration(node) ? isVarConst(node) && isIdentifier(node.name) && isVariableDeclarationInVariableStatement(node) : - isPropertyDeclaration(node) ? hasReadonlyModifier(node) && hasStaticModifier(node) : - isPropertySignature(node) && hasReadonlyModifier(node); + isPropertyDeclaration(node) ? hasEffectiveReadonlyModifier(node) && hasStaticModifier(node) : + isPropertySignature(node) && hasEffectiveReadonlyModifier(node); } export function introducesArgumentsExoticObject(node: Node) { @@ -2471,7 +2471,7 @@ namespace ts { : undefined; } - export function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[] { + export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[] { let result: (JSDoc | JSDocTag)[] | undefined; // Pull parameter comments from declaring function as well if (isVariableLike(hostNode) && hasInitializer(hostNode) && hasJSDocNodes(hostNode.initializer!)) { @@ -2485,11 +2485,11 @@ namespace ts { } if (node.kind === SyntaxKind.Parameter) { - result = addRange(result, getJSDocParameterTags(node as ParameterDeclaration)); + result = addRange(result, (noCache ? getJSDocParameterTagsNoCache : getJSDocParameterTags)(node as ParameterDeclaration)); break; } if (node.kind === SyntaxKind.TypeParameter) { - result = addRange(result, getJSDocTypeParameterTags(node as TypeParameterDeclaration)); + result = addRange(result, (noCache ? getJSDocTypeParameterTagsNoCache : getJSDocTypeParameterTags)(node as TypeParameterDeclaration)); break; } node = getNextJSDocCommentLocation(node); @@ -3007,7 +3007,7 @@ namespace ts { // falls through case SyntaxKind.ArrowFunction: - if (hasModifier(node, ModifierFlags.Async)) { + if (hasSyntacticModifier(node, ModifierFlags.Async)) { flags |= FunctionFlags.Async; } break; @@ -3028,7 +3028,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: return (node).body !== undefined && (node).asteriskToken === undefined - && hasModifier(node, ModifierFlags.Async); + && hasSyntacticModifier(node, ModifierFlags.Async); } return false; } @@ -4017,7 +4017,7 @@ namespace ts { else { forEach(declarations, member => { if (isAccessor(member) - && hasModifier(member, ModifierFlags.Static) === hasModifier(accessor, ModifierFlags.Static)) { + && hasSyntacticModifier(member, ModifierFlags.Static) === hasSyntacticModifier(accessor, ModifierFlags.Static)) { const memberName = getPropertyNameForPropertyNameNode(member.name); const accessorName = getPropertyNameForPropertyNameNode(accessor.name); if (memberName === accessorName) { @@ -4312,61 +4312,112 @@ namespace ts { return currentLineIndent; } - export function hasModifiers(node: Node) { - return getModifierFlags(node) !== ModifierFlags.None; + export function hasEffectiveModifiers(node: Node) { + return getEffectiveModifierFlags(node) !== ModifierFlags.None; } - export function hasModifier(node: Node, flags: ModifierFlags): boolean { - return !!getSelectedModifierFlags(node, flags); + export function hasSyntacticModifiers(node: Node) { + return getSyntacticModifierFlags(node) !== ModifierFlags.None; + } + + export function hasEffectiveModifier(node: Node, flags: ModifierFlags): boolean { + return !!getSelectedEffectiveModifierFlags(node, flags); + } + + export function hasSyntacticModifier(node: Node, flags: ModifierFlags): boolean { + return !!getSelectedSyntacticModifierFlags(node, flags); } export function hasStaticModifier(node: Node): boolean { - return hasModifier(node, ModifierFlags.Static); + return hasSyntacticModifier(node, ModifierFlags.Static); } - export function hasReadonlyModifier(node: Node): boolean { - return hasModifier(node, ModifierFlags.Readonly); + export function hasEffectiveReadonlyModifier(node: Node): boolean { + return hasEffectiveModifier(node, ModifierFlags.Readonly); } - export function getSelectedModifierFlags(node: Node, flags: ModifierFlags): ModifierFlags { - return getModifierFlags(node) & flags; + export function getSelectedEffectiveModifierFlags(node: Node, flags: ModifierFlags): ModifierFlags { + return getEffectiveModifierFlags(node) & flags; } - export function getModifierFlags(node: Node): ModifierFlags { + export function getSelectedSyntacticModifierFlags(node: Node, flags: ModifierFlags): ModifierFlags { + return getSyntacticModifierFlags(node) & flags; + } + + function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags { if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) { return ModifierFlags.None; } - if (node.modifierFlagsCache & ModifierFlags.HasComputedFlags) { - return node.modifierFlagsCache & ~ModifierFlags.HasComputedFlags; + + if (!(node.modifierFlagsCache & ModifierFlags.HasComputedFlags)) { + node.modifierFlagsCache = getSyntacticModifierFlagsNoCache(node) | ModifierFlags.HasComputedFlags; } - const flags = getModifierFlagsNoCache(node); - node.modifierFlagsCache = flags | ModifierFlags.HasComputedFlags; + if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && isInJSFile(node) && node.parent) { + node.modifierFlagsCache |= getJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers; + } + + return node.modifierFlagsCache & ~(ModifierFlags.HasComputedFlags | ModifierFlags.HasComputedJSDocModifiers); + } + + /** + * Gets the effective ModifierFlags for the provided node, including JSDoc modifiers. The modifiers will be cached on the node to improve performance. + * + * NOTE: This function may use `parent` pointers. + */ + export function getEffectiveModifierFlags(node: Node): ModifierFlags { + return getModifierFlagsWorker(node, /*includeJSDoc*/ true); + } + + /** + * Gets the ModifierFlags for syntactic modifiers on the provided node. The modifiers will be cached on the node to improve performance. + * + * NOTE: This function does not use `parent` pointers and will not include modifiers from JSDoc. + */ + export function getSyntacticModifierFlags(node: Node): ModifierFlags { + return getModifierFlagsWorker(node, /*includeJSDoc*/ false); + } + + function getJSDocModifierFlagsNoCache(node: Node): ModifierFlags { + let flags = ModifierFlags.None; + if (isInJSFile(node) && !!node.parent && !isParameter(node)) { + if (getJSDocPublicTagNoCache(node)) flags |= ModifierFlags.Public; + if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.Private; + if (getJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.Protected; + if (getJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.Readonly; + } return flags; } - export function getModifierFlagsNoCache(node: Node): ModifierFlags { - let flags = ModifierFlags.None; - if (node.modifiers) { - for (const modifier of node.modifiers) { - flags |= modifierToFlag(modifier.kind); - } - } - - if (isInJSFile(node) && !!node.parent) { - // getModifierFlagsNoCache should only be called when parent pointers are set, - // or when !(node.flags & NodeFlags.Synthesized) && node.kind !== SyntaxKind.SourceFile) - const tags = (getJSDocPublicTag(node) ? ModifierFlags.Public : ModifierFlags.None) - | (getJSDocPrivateTag(node) ? ModifierFlags.Private : ModifierFlags.None) - | (getJSDocProtectedTag(node) ? ModifierFlags.Protected : ModifierFlags.None) - | (getJSDocReadonlyTag(node) ? ModifierFlags.Readonly : ModifierFlags.None); - flags |= tags; - } + /** + * Gets the effective ModifierFlags for the provided node, including JSDoc modifiers. The modifier flags cache on the node is ignored. + * + * NOTE: This function may use `parent` pointers. + */ + export function getEffectiveModifierFlagsNoCache(node: Node): ModifierFlags { + return getSyntacticModifierFlagsNoCache(node) | getJSDocModifierFlagsNoCache(node); + } + /** + * Gets the ModifierFlags for syntactic modifiers on the provided node. The modifier flags cache on the node is ignored. + * + * NOTE: This function does not use `parent` pointers and will not include modifiers from JSDoc. + */ + export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags { + let flags = modifiersToFlags(node.modifiers); if (node.flags & NodeFlags.NestedNamespace || (node.kind === SyntaxKind.Identifier && (node).isInJSDocNamespace)) { flags |= ModifierFlags.Export; } + return flags; + } + export function modifiersToFlags(modifiers: NodeArray | undefined) { + let flags = ModifierFlags.None; + if (modifiers) { + for (const modifier of modifiers) { + flags |= modifierToFlag(modifier.kind); + } + } return flags; } @@ -4507,7 +4558,7 @@ namespace ts { } function isExportDefaultSymbol(symbol: Symbol): boolean { - return symbol && length(symbol.declarations) > 0 && hasModifier(symbol.declarations[0], ModifierFlags.Default); + return symbol && length(symbol.declarations) > 0 && hasSyntacticModifier(symbol.declarations[0], ModifierFlags.Default); } /** Return ".ts", ".d.ts", or ".tsx", if that is the extension. */ @@ -5055,7 +5106,7 @@ namespace ts { export function isAbstractConstructorSymbol(symbol: Symbol): boolean { if (symbol.flags & SymbolFlags.Class) { const declaration = getClassLikeDeclarationOfSymbol(symbol); - return !!declaration && hasModifier(declaration, ModifierFlags.Abstract); + return !!declaration && hasSyntacticModifier(declaration, ModifierFlags.Abstract); } return false; } @@ -6365,7 +6416,7 @@ namespace ts { if (node.kind !== SyntaxKind.ComputedPropertyName) { return false; } - if (hasModifier(node.parent, ModifierFlags.Abstract)) { + if (hasSyntacticModifier(node.parent, ModifierFlags.Abstract)) { return true; } const containerKind = node.parent.parent.kind; diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index d38187b406a..0da9f34ecec 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -255,7 +255,7 @@ namespace ts { export type ParameterPropertyDeclaration = ParameterDeclaration & { parent: ConstructorDeclaration, name: Identifier }; export function isParameterPropertyDeclaration(node: Node, parent: Node): node is ParameterPropertyDeclaration { - return hasModifier(node, ModifierFlags.ParameterPropertyModifier) && parent.kind === SyntaxKind.Constructor; + return hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier) && parent.kind === SyntaxKind.Constructor; } export function isEmptyBindingPattern(node: BindingName): node is BindingPattern { @@ -299,7 +299,7 @@ namespace ts { } export function getCombinedModifierFlags(node: Declaration): ModifierFlags { - return getCombinedFlags(node, getModifierFlags); + return getCombinedFlags(node, getEffectiveModifierFlags); } // Returns the node flags for this node and all relevant parent nodes. This is done so that @@ -609,6 +609,25 @@ namespace ts { } } + function getJSDocParameterTagsWorker(param: ParameterDeclaration, noCache?: boolean): readonly JSDocParameterTag[] { + if (param.name) { + if (isIdentifier(param.name)) { + const name = param.name.escapedText; + return getJSDocTagsWorker(param.parent, noCache).filter((tag): tag is JSDocParameterTag => isJSDocParameterTag(tag) && isIdentifier(tag.name) && tag.name.escapedText === name); + } + else { + const i = param.parent.parameters.indexOf(param); + Debug.assert(i > -1, "Parameters should always be in their parents' parameter list"); + const paramTags = getJSDocTagsWorker(param.parent, noCache).filter(isJSDocParameterTag); + if (i < paramTags.length) { + return [paramTags[i]]; + } + } + } + // return empty array for: out-of-order binding patterns and JSDoc function syntax, which has un-named parameters + return emptyArray; + } + /** * Gets the JSDoc parameter tags for the node if present. * @@ -622,22 +641,18 @@ namespace ts { * For binding patterns, parameter tags are matched by position. */ export function getJSDocParameterTags(param: ParameterDeclaration): readonly JSDocParameterTag[] { - if (param.name) { - if (isIdentifier(param.name)) { - const name = param.name.escapedText; - return getJSDocTags(param.parent).filter((tag): tag is JSDocParameterTag => isJSDocParameterTag(tag) && isIdentifier(tag.name) && tag.name.escapedText === name); - } - else { - const i = param.parent.parameters.indexOf(param); - Debug.assert(i > -1, "Parameters should always be in their parents' parameter list"); - const paramTags = getJSDocTags(param.parent).filter(isJSDocParameterTag); - if (i < paramTags.length) { - return [paramTags[i]]; - } - } - } - // return empty array for: out-of-order binding patterns and JSDoc function syntax, which has un-named parameters - return emptyArray; + return getJSDocParameterTagsWorker(param, /*noCache*/ false); + } + + /* @internal */ + export function getJSDocParameterTagsNoCache(param: ParameterDeclaration): readonly JSDocParameterTag[] { + return getJSDocParameterTagsWorker(param, /*noCache*/ true); + } + + function getJSDocTypeParameterTagsWorker(param: TypeParameterDeclaration, noCache?: boolean): readonly JSDocTemplateTag[] { + const name = param.name.escapedText; + return getJSDocTagsWorker(param.parent, noCache).filter((tag): tag is JSDocTemplateTag => + isJSDocTemplateTag(tag) && tag.typeParameters.some(tp => tp.name.escapedText === name)); } /** @@ -651,9 +666,12 @@ namespace ts { * tag on the containing function expression would be first. */ export function getJSDocTypeParameterTags(param: TypeParameterDeclaration): readonly JSDocTemplateTag[] { - const name = param.name.escapedText; - return getJSDocTags(param.parent).filter((tag): tag is JSDocTemplateTag => - isJSDocTemplateTag(tag) && tag.typeParameters.some(tp => tp.name.escapedText === name)); + return getJSDocTypeParameterTagsWorker(param, /*noCache*/ false); + } + + /* @internal */ + export function getJSDocTypeParameterTagsNoCache(param: TypeParameterDeclaration): readonly JSDocTemplateTag[] { + return getJSDocTypeParameterTagsWorker(param, /*noCache*/ true); } /** @@ -686,21 +704,41 @@ namespace ts { return getFirstJSDocTag(node, isJSDocPublicTag); } + /*@internal*/ + export function getJSDocPublicTagNoCache(node: Node): JSDocPublicTag | undefined { + return getFirstJSDocTag(node, isJSDocPublicTag, /*noCache*/ true); + } + /** Gets the JSDoc private tag for the node if present */ export function getJSDocPrivateTag(node: Node): JSDocPrivateTag | undefined { return getFirstJSDocTag(node, isJSDocPrivateTag); } + /*@internal*/ + export function getJSDocPrivateTagNoCache(node: Node): JSDocPrivateTag | undefined { + return getFirstJSDocTag(node, isJSDocPrivateTag, /*noCache*/ true); + } + /** Gets the JSDoc protected tag for the node if present */ export function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined { return getFirstJSDocTag(node, isJSDocProtectedTag); } + /*@internal*/ + export function getJSDocProtectedTagNoCache(node: Node): JSDocProtectedTag | undefined { + return getFirstJSDocTag(node, isJSDocProtectedTag, /*noCache*/ true); + } + /** Gets the JSDoc protected tag for the node if present */ export function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined { return getFirstJSDocTag(node, isJSDocReadonlyTag); } + /*@internal*/ + export function getJSDocReadonlyTagNoCache(node: Node): JSDocReadonlyTag | undefined { + return getFirstJSDocTag(node, isJSDocReadonlyTag, /*noCache*/ true); + } + /** Gets the JSDoc enum tag for the node if present */ export function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined { return getFirstJSDocTag(node, isJSDocEnumTag); @@ -775,21 +813,33 @@ namespace ts { } } - /** Get all JSDoc tags related to a node, including those on parent nodes. */ - export function getJSDocTags(node: Node): readonly JSDocTag[] { + function getJSDocTagsWorker(node: Node, noCache?: boolean): readonly JSDocTag[] { let tags = (node as JSDocContainer).jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. - if (tags === undefined) { - const comments = getJSDocCommentsAndTags(node); + if (tags === undefined || noCache) { + const comments = getJSDocCommentsAndTags(node, noCache); Debug.assert(comments.length < 2 || comments[0] !== comments[1]); - (node as JSDocContainer).jsDocCache = tags = flatMap(comments, j => isJSDoc(j) ? j.tags : j); + tags = flatMap(comments, j => isJSDoc(j) ? j.tags : j); + if (!noCache) { + (node as JSDocContainer).jsDocCache = tags; + } } return tags; } + /** Get all JSDoc tags related to a node, including those on parent nodes. */ + export function getJSDocTags(node: Node): readonly JSDocTag[] { + return getJSDocTagsWorker(node, /*noCache*/ false); + } + + /* @internal */ + export function getJSDocTagsNoCache(node: Node): readonly JSDocTag[] { + return getJSDocTagsWorker(node, /*noCache*/ true); + } + /** Get the first JSDoc tag of a specified kind, or undefined if not present. */ - function getFirstJSDocTag(node: Node, predicate: (tag: JSDocTag) => tag is T): T | undefined { - return find(getJSDocTags(node), predicate); + function getFirstJSDocTag(node: Node, predicate: (tag: JSDocTag) => tag is T, noCache?: boolean): T | undefined { + return find(getJSDocTagsWorker(node, noCache), predicate); } /** Gets all JSDoc tags that match a specified predicate */ @@ -2235,13 +2285,13 @@ namespace ts { /* @internal */ export function needsScopeMarker(result: Statement) { - return !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasModifier(result, ModifierFlags.Export) && !isAmbientModule(result); + return !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasSyntacticModifier(result, ModifierFlags.Export) && !isAmbientModule(result); } /* @internal */ export function isExternalModuleIndicator(result: Statement) { // Exported top-level member indicates moduleness - return isAnyImportOrReExport(result) || isExportAssignment(result) || hasModifier(result, ModifierFlags.Export); + return isAnyImportOrReExport(result) || isExportAssignment(result) || hasSyntacticModifier(result, ModifierFlags.Export); } /* @internal */ diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index c119eff97de..f1144b3eb35 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -684,7 +684,7 @@ namespace ts { function aggregateTransformFlagsForSubtree(node: Node): TransformFlags { // We do not transform ambient declarations or types, so there is no need to // recursively aggregate transform flags. - if (hasModifier(node, ModifierFlags.Ambient) || (isTypeNode(node) && node.kind !== SyntaxKind.ExpressionWithTypeArguments)) { + if (hasSyntacticModifier(node, ModifierFlags.Ambient) || (isTypeNode(node) && node.kind !== SyntaxKind.ExpressionWithTypeArguments)) { return TransformFlags.None; } diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 81e76a939d7..eee180ffe14 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -392,7 +392,7 @@ namespace ts.BreakpointResolver { // Breakpoint is possible in variableDeclaration only if there is initialization // or its declaration from 'for of' if (variableDeclaration.initializer || - hasModifier(variableDeclaration, ModifierFlags.Export) || + hasSyntacticModifier(variableDeclaration, ModifierFlags.Export) || parent.parent.kind === SyntaxKind.ForOfStatement) { return textSpanFromVariableDeclaration(variableDeclaration); } @@ -410,7 +410,7 @@ namespace ts.BreakpointResolver { function canHaveSpanInParameterDeclaration(parameter: ParameterDeclaration): boolean { // Breakpoint is possible on parameter only if it has initializer, is a rest parameter, or has public or private modifier return !!parameter.initializer || parameter.dotDotDotToken !== undefined || - hasModifier(parameter, ModifierFlags.Public | ModifierFlags.Private); + hasSyntacticModifier(parameter, ModifierFlags.Public | ModifierFlags.Private); } function spanInParameterDeclaration(parameter: ParameterDeclaration): TextSpan | undefined { @@ -437,7 +437,7 @@ namespace ts.BreakpointResolver { } function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionLikeDeclaration) { - return hasModifier(functionDeclaration, ModifierFlags.Export) || + return hasSyntacticModifier(functionDeclaration, ModifierFlags.Export) || (functionDeclaration.parent.kind === SyntaxKind.ClassDeclaration && functionDeclaration.kind !== SyntaxKind.Constructor); } diff --git a/src/services/callHierarchy.ts b/src/services/callHierarchy.ts index 3a114af16ef..bbf28ac8f11 100644 --- a/src/services/callHierarchy.ts +++ b/src/services/callHierarchy.ts @@ -410,7 +410,7 @@ namespace ts.CallHierarchy { } function collectCallSitesOfModuleDeclaration(node: ModuleDeclaration, collect: (node: Node | undefined) => void) { - if (!hasModifier(node, ModifierFlags.Ambient) && node.body && isModuleBlock(node.body)) { + if (!hasSyntacticModifier(node, ModifierFlags.Ambient) && node.body && isModuleBlock(node.body)) { forEach(node.body.statements, collect); } } diff --git a/src/services/codefixes/addMissingAsync.ts b/src/services/codefixes/addMissingAsync.ts index 59b0f2f279d..2f2ceba3570 100644 --- a/src/services/codefixes/addMissingAsync.ts +++ b/src/services/codefixes/addMissingAsync.ts @@ -53,7 +53,7 @@ namespace ts.codefix { } fixedDeclarations?.set(getNodeId(insertionSite).toString(), true); const cloneWithModifier = getSynthesizedDeepClone(insertionSite, /*includeTrivia*/ true); - cloneWithModifier.modifiers = createNodeArray(createModifiersFromModifierFlags(getModifierFlags(insertionSite) | ModifierFlags.Async)); + cloneWithModifier.modifiers = createNodeArray(createModifiersFromModifierFlags(getSyntacticModifierFlags(insertionSite) | ModifierFlags.Async)); cloneWithModifier.modifierFlagsCache = 0; changeTracker.replaceNode( sourceFile, diff --git a/src/services/codefixes/addMissingAwait.ts b/src/services/codefixes/addMissingAwait.ts index fa562d77e8d..89c6e6d267f 100644 --- a/src/services/codefixes/addMissingAwait.ts +++ b/src/services/codefixes/addMissingAwait.ts @@ -148,7 +148,7 @@ namespace ts.codefix { declaration.type || !declaration.initializer || variableStatement.getSourceFile() !== sourceFile || - hasModifier(variableStatement, ModifierFlags.Export) || + hasSyntacticModifier(variableStatement, ModifierFlags.Export) || !variableName || !isInsideAwaitableBody(declaration.initializer)) { isCompleteFix = false; diff --git a/src/services/codefixes/convertToMappedObjectType.ts b/src/services/codefixes/convertToMappedObjectType.ts index 0d79d6363c0..04de31faabf 100644 --- a/src/services/codefixes/convertToMappedObjectType.ts +++ b/src/services/codefixes/convertToMappedObjectType.ts @@ -42,7 +42,7 @@ namespace ts.codefix { const parameter = first(indexSignature.parameters); const mappedTypeParameter = createTypeParameterDeclaration(cast(parameter.name, isIdentifier), parameter.type); const mappedIntersectionType = createMappedTypeNode( - hasReadonlyModifier(indexSignature) ? createModifier(SyntaxKind.ReadonlyKeyword) : undefined, + hasEffectiveReadonlyModifier(indexSignature) ? createModifier(SyntaxKind.ReadonlyKeyword) : undefined, mappedTypeParameter, indexSignature.questionToken, indexSignature.type); diff --git a/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts b/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts index a27ded9d403..eac02f0d713 100644 --- a/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts +++ b/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts @@ -49,7 +49,7 @@ namespace ts.codefix { function symbolPointsToNonPrivateAndAbstractMember(symbol: Symbol): boolean { // See `codeFixClassExtendAbstractProtectedProperty.ts` in https://github.com/Microsoft/TypeScript/pull/11547/files // (now named `codeFixClassExtendAbstractPrivateProperty.ts`) - const flags = getModifierFlags(first(symbol.getDeclarations()!)); + const flags = getSyntacticModifierFlags(first(symbol.getDeclarations()!)); return !(flags & ModifierFlags.Private) && !!(flags & ModifierFlags.Abstract); } } diff --git a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts index 4059ee03ca7..954a64ef53d 100644 --- a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts +++ b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts @@ -34,7 +34,7 @@ namespace ts.codefix { } function symbolPointsToNonPrivateMember(symbol: Symbol) { - return !symbol.valueDeclaration || !(getModifierFlags(symbol.valueDeclaration) & ModifierFlags.Private); + return !symbol.valueDeclaration || !(getEffectiveModifierFlags(symbol.valueDeclaration) & ModifierFlags.Private); } function addMissingDeclarations( diff --git a/src/services/codefixes/fixStrictClassInitialization.ts b/src/services/codefixes/fixStrictClassInitialization.ts index f3286246e16..a4b0134853a 100644 --- a/src/services/codefixes/fixStrictClassInitialization.ts +++ b/src/services/codefixes/fixStrictClassInitialization.ts @@ -120,7 +120,7 @@ namespace ts.codefix { } else if (type.isClass()) { const classDeclaration = getClassLikeDeclarationOfSymbol(type.symbol); - if (!classDeclaration || hasModifier(classDeclaration, ModifierFlags.Abstract)) return undefined; + if (!classDeclaration || hasSyntacticModifier(classDeclaration, ModifierFlags.Abstract)) return undefined; const constructorDeclaration = getFirstConstructorWithBody(classDeclaration); if (constructorDeclaration && constructorDeclaration.parameters.length) return undefined; diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 4e9c3a9c5a7..7e879b96ba6 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -40,7 +40,7 @@ namespace ts.codefix { const scriptTarget = getEmitScriptTarget(context.program.getCompilerOptions()); const declaration = declarations[0]; const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName; - const visibilityModifier = createVisibilityModifier(getModifierFlags(declaration)); + const visibilityModifier = createVisibilityModifier(getEffectiveModifierFlags(declaration)); const modifiers = visibilityModifier ? createNodeArray([visibilityModifier]) : undefined; const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration)); const optional = !!(symbol.flags & SymbolFlags.Optional); diff --git a/src/services/completions.ts b/src/services/completions.ts index a3845bf3ece..8b9228d3441 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1990,7 +1990,7 @@ namespace ts.Completions { if (!isClassLike(decl)) return GlobalsSearch.Success; const classElement = contextToken.kind === SyntaxKind.SemicolonToken ? contextToken.parent.parent : contextToken.parent; - let classElementModifierFlags = isClassElement(classElement) ? getModifierFlags(classElement) : ModifierFlags.None; + let classElementModifierFlags = isClassElement(classElement) ? getEffectiveModifierFlags(classElement) : ModifierFlags.None; // If this is context token is not something we are editing now, consider if this would lead to be modifier if (contextToken.kind === SyntaxKind.Identifier && !isCurrentlyEditingNode(contextToken)) { switch (contextToken.getText()) { @@ -2409,12 +2409,12 @@ namespace ts.Completions { } // Dont filter member even if the name matches if it is declared private in the list - if (hasModifier(m, ModifierFlags.Private)) { + if (hasEffectiveModifier(m, ModifierFlags.Private)) { continue; } // do not filter it out if the static presence doesnt match - if (hasModifier(m, ModifierFlags.Static) !== !!(currentClassElementModifierFlags & ModifierFlags.Static)) { + if (hasEffectiveModifier(m, ModifierFlags.Static) !== !!(currentClassElementModifierFlags & ModifierFlags.Static)) { continue; } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index f79abf73437..74dffc3b00b 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -102,7 +102,7 @@ namespace ts.FindAllReferences { ((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent)) && node.parent.propertyName === node) || // Is default export - (node.kind === SyntaxKind.DefaultKeyword && hasModifier(node.parent, ModifierFlags.ExportDefault))) { + (node.kind === SyntaxKind.DefaultKeyword && hasSyntacticModifier(node.parent, ModifierFlags.ExportDefault))) { return getContextNode(node.parent); } @@ -1146,7 +1146,7 @@ namespace ts.FindAllReferences { // If this is private property or method, the scope is the containing class if (flags & (SymbolFlags.Property | SymbolFlags.Method)) { - const privateDeclaration = find(declarations, d => hasModifier(d, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(d)); + const privateDeclaration = find(declarations, d => hasEffectiveModifier(d, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(d)); if (privateDeclaration) { return getAncestor(privateDeclaration, SyntaxKind.ClassDeclaration); } @@ -1561,7 +1561,7 @@ namespace ts.FindAllReferences { Debug.assert(classLike.name === referenceLocation); const addRef = state.referenceAdder(search.symbol); for (const member of classLike.members) { - if (!(isMethodOrAccessor(member) && hasModifier(member, ModifierFlags.Static))) { + if (!(isMethodOrAccessor(member) && hasSyntacticModifier(member, ModifierFlags.Static))) { continue; } if (member.body) { @@ -1776,7 +1776,7 @@ namespace ts.FindAllReferences { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - staticFlag &= getModifierFlags(searchSpaceNode); + staticFlag &= getSyntacticModifierFlags(searchSpaceNode); searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; default: @@ -1794,7 +1794,7 @@ namespace ts.FindAllReferences { // If we have a 'super' container, we must have an enclosing class. // Now make sure the owning class is the same as the search-space // and has the same static qualifier as the original 'super's owner. - return container && (ModifierFlags.Static & getModifierFlags(container)) === staticFlag && container.parent.symbol === searchSpaceNode.symbol ? nodeEntry(node) : undefined; + return container && (ModifierFlags.Static & getSyntacticModifierFlags(container)) === staticFlag && container.parent.symbol === searchSpaceNode.symbol ? nodeEntry(node) : undefined; }); return [{ definition: { type: DefinitionKind.Symbol, symbol: searchSpaceNode.symbol }, references }]; @@ -1822,7 +1822,7 @@ namespace ts.FindAllReferences { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - staticFlag &= getModifierFlags(searchSpaceNode); + staticFlag &= getSyntacticModifierFlags(searchSpaceNode); searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; case SyntaxKind.SourceFile: @@ -1857,7 +1857,7 @@ namespace ts.FindAllReferences { case SyntaxKind.ClassDeclaration: // Make sure the container belongs to the same class // and has the appropriate static modifier from the original container. - return container.parent && searchSpaceNode.symbol === container.parent.symbol && (getModifierFlags(container) & ModifierFlags.Static) === staticFlag; + return container.parent && searchSpaceNode.symbol === container.parent.symbol && (getSyntacticModifierFlags(container) & ModifierFlags.Static) === staticFlag; case SyntaxKind.SourceFile: return container.kind === SyntaxKind.SourceFile && !isExternalModule(container) && !isParameterName(node); } diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index 91b53ea418a..6b3da6edc89 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -103,7 +103,7 @@ namespace ts.FindAllReferences { break; // TODO: GH#23879 case SyntaxKind.ImportEqualsDeclaration: - handleNamespaceImport(direct, direct.name, hasModifier(direct, ModifierFlags.Export), /*alreadyAddedDirect*/ false); + handleNamespaceImport(direct, direct.name, hasSyntacticModifier(direct, ModifierFlags.Export), /*alreadyAddedDirect*/ false); break; case SyntaxKind.ImportDeclaration: @@ -463,7 +463,7 @@ namespace ts.FindAllReferences { } else { const exportNode = getExportNode(parent, node); - if (exportNode && hasModifier(exportNode, ModifierFlags.Export)) { + if (exportNode && hasSyntacticModifier(exportNode, ModifierFlags.Export)) { if (isImportEqualsDeclaration(exportNode) && exportNode.moduleReference === node) { // We're at `Y` in `export import X = Y`. This is not the exported symbol, the left-hand-side is. So treat this as an import statement. if (comingFromExport) { @@ -553,7 +553,7 @@ namespace ts.FindAllReferences { // Not meant for use with export specifiers or export assignment. function getExportKindForDeclaration(node: Node): ExportKind { - return hasModifier(node, ModifierFlags.Default) ? ExportKind.Default : ExportKind.Named; + return hasSyntacticModifier(node, ModifierFlags.Default) ? ExportKind.Default : ExportKind.Named; } } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 38faf25da7f..b74da7fd8da 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -590,7 +590,7 @@ namespace ts.NavigationBar { case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return hasModifier(a, ModifierFlags.Static) === hasModifier(b, ModifierFlags.Static); + return hasSyntacticModifier(a, ModifierFlags.Static) === hasSyntacticModifier(b, ModifierFlags.Static); case SyntaxKind.ModuleDeclaration: return areSameModule(a, b); default: @@ -690,7 +690,7 @@ namespace ts.NavigationBar { case SyntaxKind.FunctionExpression: case SyntaxKind.ClassDeclaration: case SyntaxKind.ClassExpression: - if (getModifierFlags(node) & ModifierFlags.Default) { + if (getSyntacticModifierFlags(node) & ModifierFlags.Default) { return "default"; } // We may get a string with newlines or other whitespace in the case of an object dereference @@ -883,7 +883,7 @@ namespace ts.NavigationBar { return nodeText(parent.name); } // Default exports are named "default" - else if (getModifierFlags(node) & ModifierFlags.Default) { + else if (getSyntacticModifierFlags(node) & ModifierFlags.Default) { return "default"; } else if (isClassLike(node)) { diff --git a/src/services/refactors/convertExport.ts b/src/services/refactors/convertExport.ts index c08ae05bce8..18de048ac6c 100644 --- a/src/services/refactors/convertExport.ts +++ b/src/services/refactors/convertExport.ts @@ -38,7 +38,7 @@ namespace ts.refactor { const exportingModuleSymbol = isSourceFile(exportNode.parent) ? exportNode.parent.symbol : exportNode.parent.parent.symbol; - const flags = getModifierFlags(exportNode); + const flags = getSyntacticModifierFlags(exportNode); const wasDefault = !!(flags & ModifierFlags.Default); // If source file already has a default export, don't offer refactor. if (!(flags & ModifierFlags.Export) || !wasDefault && exportingModuleSymbol.exports!.has(InternalSymbolName.Default)) { diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 0e5034ff843..7858012a0bb 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -309,7 +309,7 @@ namespace ts.refactor.extractSymbol { let current: Node = nodeToCheck; while (current !== containingClass) { if (current.kind === SyntaxKind.PropertyDeclaration) { - if (hasModifier(current, ModifierFlags.Static)) { + if (hasSyntacticModifier(current, ModifierFlags.Static)) { rangeFacts |= RangeFacts.InStaticRegion; } break; @@ -322,7 +322,7 @@ namespace ts.refactor.extractSymbol { break; } else if (current.kind === SyntaxKind.MethodDeclaration) { - if (hasModifier(current, ModifierFlags.Static)) { + if (hasSyntacticModifier(current, ModifierFlags.Static)) { rangeFacts |= RangeFacts.InStaticRegion; } } @@ -375,7 +375,7 @@ namespace ts.refactor.extractSymbol { if (isDeclaration(node)) { const declaringNode = (node.kind === SyntaxKind.VariableDeclaration) ? node.parent.parent : node; - if (hasModifier(declaringNode, ModifierFlags.Export)) { + if (hasSyntacticModifier(declaringNode, ModifierFlags.Export)) { // TODO: GH#18217 Silly to use `errors ||` since it's definitely not defined (see top of `visit`) // Also, if we're only pushing one error, just use `let error: Diagnostic | undefined`! // Also TODO: GH#19956 @@ -1584,7 +1584,7 @@ namespace ts.refactor.extractSymbol { hasWrite = true; if (value.symbol.flags & SymbolFlags.ClassMember && value.symbol.valueDeclaration && - hasModifier(value.symbol.valueDeclaration, ModifierFlags.Readonly)) { + hasEffectiveModifier(value.symbol.valueDeclaration, ModifierFlags.Readonly)) { readonlyClassPropertyWrite = value.symbol.valueDeclaration; } } diff --git a/src/services/refactors/generateGetAccessorAndSetAccessor.ts b/src/services/refactors/generateGetAccessorAndSetAccessor.ts index 038cd04cdeb..df1799e336a 100644 --- a/src/services/refactors/generateGetAccessorAndSetAccessor.ts +++ b/src/services/refactors/generateGetAccessorAndSetAccessor.ts @@ -52,7 +52,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { const isInClassLike = isClassLike(container); // avoid Readonly modifier because it will convert to get accessor - const modifierFlags = getModifierFlags(declaration) & ~ModifierFlags.Readonly; + const modifierFlags = getEffectiveModifierFlags(declaration) & ~ModifierFlags.Readonly; const accessorModifiers = isInClassLike ? !modifierFlags || modifierFlags & ModifierFlags.Private ? getModifiers(isJS, isStatic, SyntaxKind.PublicKeyword) @@ -121,7 +121,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { // make sure declaration have AccessibilityModifier or Static Modifier or Readonly Modifier const meaning = ModifierFlags.AccessibilityModifier | ModifierFlags.Static | ModifierFlags.Readonly; if (!declaration || !nodeOverlapsWithStartEnd(declaration.name, file, startPosition, endPosition!) // TODO: GH#18217 - || !isConvertibleName(declaration.name) || (getModifierFlags(declaration) | meaning) !== meaning) return undefined; + || !isConvertibleName(declaration.name) || (getEffectiveModifierFlags(declaration) | meaning) !== meaning) return undefined; const name = declaration.name.text; const startWithUnderscore = startsWithUnderscore(name); @@ -129,7 +129,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { const accessorName = createPropertyName(startWithUnderscore ? getUniqueName(name.substring(1), file) : name, declaration.name); return { isStatic: hasStaticModifier(declaration), - isReadonly: hasReadonlyModifier(declaration), + isReadonly: hasEffectiveReadonlyModifier(declaration), type: getTypeAnnotationNode(declaration), container: declaration.kind === SyntaxKind.Parameter ? declaration.parent.parent : declaration.parent, originalName: (declaration.name).text, diff --git a/src/services/refactors/moveToNewFile.ts b/src/services/refactors/moveToNewFile.ts index e714315f313..7737a5cc8df 100644 --- a/src/services/refactors/moveToNewFile.ts +++ b/src/services/refactors/moveToNewFile.ts @@ -84,7 +84,7 @@ namespace ts.refactor { case SyntaxKind.ImportDeclaration: return true; case SyntaxKind.ImportEqualsDeclaration: - return !hasModifier(node, ModifierFlags.Export); + return !hasSyntacticModifier(node, ModifierFlags.Export); case SyntaxKind.VariableStatement: return (node as VariableStatement).declarationList.declarations.every(d => !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true)); default: @@ -420,7 +420,7 @@ namespace ts.refactor { if (markSeenTop(top)) { addExportToChanges(oldFile, top, changes, useEs6ModuleSyntax); } - if (hasModifier(decl, ModifierFlags.Default)) { + if (hasSyntacticModifier(decl, ModifierFlags.Default)) { oldFileDefault = name; } else { @@ -737,7 +737,7 @@ namespace ts.refactor { function isExported(sourceFile: SourceFile, decl: TopLevelDeclarationStatement, useEs6Exports: boolean): boolean { if (useEs6Exports) { - return !isExpressionStatement(decl) && hasModifier(decl, ModifierFlags.Export); + return !isExpressionStatement(decl) && hasSyntacticModifier(decl, ModifierFlags.Export); } else { return getNamesToExportInCommonJS(decl).some(name => sourceFile.symbol.exports!.has(escapeLeadingUnderscores(name))); diff --git a/src/services/services.ts b/src/services/services.ts index 0ad6ea996e7..f50d99e55d1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -763,7 +763,7 @@ namespace ts { case SyntaxKind.Parameter: // Only consider parameter properties - if (!hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { + if (!hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { break; } // falls through diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index c9af01faef8..138ed53c50d 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -389,7 +389,7 @@ namespace ts.SymbolDisplay { if (declarationName) { const isExternalModuleDeclaration = isModuleWithStringLiteralName(resolvedNode) && - hasModifier(resolvedNode, ModifierFlags.Ambient); + hasSyntacticModifier(resolvedNode, ModifierFlags.Ambient); const shouldUseAliasName = symbol.name !== "default" && !isExternalModuleDeclaration; const resolvedInfo = getSymbolDisplayPartsDocumentationAndSymbolKind( typeChecker, diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 58f53198f79..617855c584a 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -407,7 +407,7 @@ namespace ts { case SyntaxKind.Constructor: return ScriptElementKind.constructorImplementationElement; case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement; case SyntaxKind.EnumMember: return ScriptElementKind.enumMemberElement; - case SyntaxKind.Parameter: return hasModifier(node, ModifierFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case SyntaxKind.Parameter: return hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index cd164686ae2..2c7742fb88b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -482,6 +482,7 @@ declare namespace ts { Async = 256, Default = 512, Const = 2048, + HasComputedJSDocModifiers = 4096, HasComputedFlags = 536870912, AccessibilityModifier = 28, ParameterPropertyModifier = 92, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f1a808da728..c901f86e384 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -482,6 +482,7 @@ declare namespace ts { Async = 256, Default = 512, Const = 2048, + HasComputedJSDocModifiers = 4096, HasComputedFlags = 536870912, AccessibilityModifier = 28, ParameterPropertyModifier = 92, diff --git a/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.js b/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.js index 18031abf9ca..b7e4cd93941 100644 --- a/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.js +++ b/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.js @@ -30,7 +30,12 @@ class Private { /** @private */ set p(value) { this.c = value } } - + +// https://github.com/microsoft/TypeScript/issues/38401 +class C { + constructor(/** @public */ x, /** @protected */ y, /** @private */ z) { + } +} //// [foo.js] class Protected { @@ -63,6 +68,11 @@ class Private { /** @private */ set p(value) { this.c = value; } } +// https://github.com/microsoft/TypeScript/issues/38401 +class C { + constructor(/** @public */ x, /** @protected */ y, /** @private */ z) { + } +} //// [foo.d.ts] @@ -90,3 +100,6 @@ declare class Private { /** @private */ private get p(); } +declare class C { + constructor(x: any, y: any, z: any); +} diff --git a/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.symbols b/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.symbols index 0316e157d31..d9961837e7a 100644 --- a/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.symbols +++ b/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.symbols @@ -79,3 +79,13 @@ class Private { >value : Symbol(value, Decl(jsdocAccessibilityTagDeclarations.js, 29, 10)) } +// https://github.com/microsoft/TypeScript/issues/38401 +class C { +>C : Symbol(C, Decl(jsdocAccessibilityTagDeclarations.js, 30, 1)) + + constructor(/** @public */ x, /** @protected */ y, /** @private */ z) { +>x : Symbol(x, Decl(jsdocAccessibilityTagDeclarations.js, 34, 16)) +>y : Symbol(y, Decl(jsdocAccessibilityTagDeclarations.js, 34, 33)) +>z : Symbol(z, Decl(jsdocAccessibilityTagDeclarations.js, 34, 54)) + } +} diff --git a/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.types b/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.types index 88c6acd855d..3db28ea64d9 100644 --- a/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.types +++ b/tests/baselines/reference/jsdocAccessibilityTagsDeclarations.types @@ -83,3 +83,13 @@ class Private { >value : any } +// https://github.com/microsoft/TypeScript/issues/38401 +class C { +>C : C + + constructor(/** @public */ x, /** @protected */ y, /** @private */ z) { +>x : any +>y : any +>z : any + } +} diff --git a/tests/baselines/reference/jsdocReadonlyDeclarations.js b/tests/baselines/reference/jsdocReadonlyDeclarations.js index 09568ef6b19..e4ed7a7df4e 100644 --- a/tests/baselines/reference/jsdocReadonlyDeclarations.js +++ b/tests/baselines/reference/jsdocReadonlyDeclarations.js @@ -18,7 +18,11 @@ function F() { /** @readonly */ this.z = 1 } - + +// https://github.com/microsoft/TypeScript/issues/38401 +class D { + constructor(/** @readonly */ x) {} +} //// [foo.js] class C { @@ -39,6 +43,10 @@ function F() { /** @readonly */ this.z = 1; } +// https://github.com/microsoft/TypeScript/issues/38401 +class D { + constructor(/** @readonly */ x) { } +} //// [foo.d.ts] @@ -58,3 +66,6 @@ declare class C { */ readonly y: number; } +declare class D { + constructor(x: any); +} diff --git a/tests/baselines/reference/jsdocReadonlyDeclarations.symbols b/tests/baselines/reference/jsdocReadonlyDeclarations.symbols index 29ac14063dc..97c9d3d3ef3 100644 --- a/tests/baselines/reference/jsdocReadonlyDeclarations.symbols +++ b/tests/baselines/reference/jsdocReadonlyDeclarations.symbols @@ -40,3 +40,10 @@ function F() { >z : Symbol(F.z, Decl(jsdocReadonlyDeclarations.js, 15, 14)) } +// https://github.com/microsoft/TypeScript/issues/38401 +class D { +>D : Symbol(D, Decl(jsdocReadonlyDeclarations.js, 18, 1)) + + constructor(/** @readonly */ x) {} +>x : Symbol(x, Decl(jsdocReadonlyDeclarations.js, 22, 16)) +} diff --git a/tests/baselines/reference/jsdocReadonlyDeclarations.types b/tests/baselines/reference/jsdocReadonlyDeclarations.types index ebb5fd00ff1..10e0a99c05e 100644 --- a/tests/baselines/reference/jsdocReadonlyDeclarations.types +++ b/tests/baselines/reference/jsdocReadonlyDeclarations.types @@ -48,3 +48,10 @@ function F() { >1 : 1 } +// https://github.com/microsoft/TypeScript/issues/38401 +class D { +>D : D + + constructor(/** @readonly */ x) {} +>x : any +} diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.js b/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.js new file mode 100644 index 00000000000..2ff4da1f22a --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.js @@ -0,0 +1,76 @@ +//// [uniqueSymbolsDeclarationsInJs.js] +// classes +class C { + /** + * @readonly + */ + static readonlyStaticCall = Symbol(); + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticType; + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticTypeAndCall = Symbol(); + static readwriteStaticCall = Symbol(); + + /** + * @readonly + */ + readonlyCall = Symbol(); + readwriteCall = Symbol(); +} + + +//// [uniqueSymbolsDeclarationsInJs-out.js] +// classes +let C = /** @class */ (() => { + class C { + constructor() { + /** + * @readonly + */ + this.readonlyCall = Symbol(); + this.readwriteCall = Symbol(); + } + } + /** + * @readonly + */ + C.readonlyStaticCall = Symbol(); + /** + * @type {unique symbol} + * @readonly + */ + C.readonlyStaticTypeAndCall = Symbol(); + C.readwriteStaticCall = Symbol(); + return C; +})(); + + +//// [uniqueSymbolsDeclarationsInJs-out.d.ts] +declare class C { + /** + * @readonly + */ + static readonly readonlyStaticCall: unique symbol; + /** + * @type {unique symbol} + * @readonly + */ + static readonly readonlyStaticType: unique symbol; + /** + * @type {unique symbol} + * @readonly + */ + static readonly readonlyStaticTypeAndCall: unique symbol; + static readwriteStaticCall: symbol; + /** + * @readonly + */ + readonly readonlyCall: symbol; + readwriteCall: symbol; +} diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.symbols b/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.symbols new file mode 100644 index 00000000000..b48c5cc6c58 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.symbols @@ -0,0 +1,43 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.js === +// classes +class C { +>C : Symbol(C, Decl(uniqueSymbolsDeclarationsInJs.js, 0, 0)) + + /** + * @readonly + */ + static readonlyStaticCall = Symbol(); +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarationsInJs.js, 1, 9)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticType; +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarationsInJs.js, 5, 41)) + + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticTypeAndCall = Symbol(); +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarationsInJs.js, 10, 30)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + + static readwriteStaticCall = Symbol(); +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarationsInJs.js, 15, 48)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + + /** + * @readonly + */ + readonlyCall = Symbol(); +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarationsInJs.js, 16, 42)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + + readwriteCall = Symbol(); +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarationsInJs.js, 21, 28)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) +} + diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.types b/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.types new file mode 100644 index 00000000000..a51ba3c324d --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJs.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.js === +// classes +class C { +>C : C + + /** + * @readonly + */ + static readonlyStaticCall = Symbol(); +>readonlyStaticCall : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticType; +>readonlyStaticType : symbol + + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticTypeAndCall = Symbol(); +>readonlyStaticTypeAndCall : symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + + static readwriteStaticCall = Symbol(); +>readwriteStaticCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor + + /** + * @readonly + */ + readonlyCall = Symbol(); +>readonlyCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor + + readwriteCall = Symbol(); +>readwriteCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor +} + diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.errors.txt b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.errors.txt new file mode 100644 index 00000000000..16120be782b --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.js(5,12): error TS1331: A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.js(14,12): error TS1331: A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'. + + +==== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.js (2 errors) ==== + class C { + /** + * @type {unique symbol} + */ + static readwriteStaticType; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1331: A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'. + /** + * @type {unique symbol} + * @readonly + */ + static readonlyType; + /** + * @type {unique symbol} + */ + static readwriteType; + ~~~~~~~~~~~~~ +!!! error TS1331: A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'. + } \ No newline at end of file diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.js b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.js new file mode 100644 index 00000000000..65019a88efd --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.js @@ -0,0 +1,38 @@ +//// [uniqueSymbolsDeclarationsInJsErrors.js] +class C { + /** + * @type {unique symbol} + */ + static readwriteStaticType; + /** + * @type {unique symbol} + * @readonly + */ + static readonlyType; + /** + * @type {unique symbol} + */ + static readwriteType; +} + +//// [uniqueSymbolsDeclarationsInJsErrors-out.js] +class C { +} + + +//// [uniqueSymbolsDeclarationsInJsErrors-out.d.ts] +declare class C { + /** + * @type {unique symbol} + */ + static readwriteStaticType: unique symbol; + /** + * @type {unique symbol} + * @readonly + */ + static readonly readonlyType: unique symbol; + /** + * @type {unique symbol} + */ + static readwriteType: unique symbol; +} diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.symbols b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.symbols new file mode 100644 index 00000000000..6ac6e495d77 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.js === +class C { +>C : Symbol(C, Decl(uniqueSymbolsDeclarationsInJsErrors.js, 0, 0)) + + /** + * @type {unique symbol} + */ + static readwriteStaticType; +>readwriteStaticType : Symbol(C.readwriteStaticType, Decl(uniqueSymbolsDeclarationsInJsErrors.js, 0, 9)) + + /** + * @type {unique symbol} + * @readonly + */ + static readonlyType; +>readonlyType : Symbol(C.readonlyType, Decl(uniqueSymbolsDeclarationsInJsErrors.js, 4, 31)) + + /** + * @type {unique symbol} + */ + static readwriteType; +>readwriteType : Symbol(C.readwriteType, Decl(uniqueSymbolsDeclarationsInJsErrors.js, 9, 24)) +} diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.types b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.types new file mode 100644 index 00000000000..4571b2c3825 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsInJsErrors.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.js === +class C { +>C : C + + /** + * @type {unique symbol} + */ + static readwriteStaticType; +>readwriteStaticType : symbol + + /** + * @type {unique symbol} + * @readonly + */ + static readonlyType; +>readonlyType : symbol + + /** + * @type {unique symbol} + */ + static readwriteType; +>readwriteType : symbol +} diff --git a/tests/cases/conformance/jsdoc/jsdocAccessibilityTagsDeclarations.ts b/tests/cases/conformance/jsdoc/jsdocAccessibilityTagsDeclarations.ts index cfc488a972e..8890dbf9247 100644 --- a/tests/cases/conformance/jsdoc/jsdocAccessibilityTagsDeclarations.ts +++ b/tests/cases/conformance/jsdoc/jsdocAccessibilityTagsDeclarations.ts @@ -35,3 +35,9 @@ class Private { /** @private */ set p(value) { this.c = value } } + +// https://github.com/microsoft/TypeScript/issues/38401 +class C { + constructor(/** @public */ x, /** @protected */ y, /** @private */ z) { + } +} \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/jsdocReadonlyDeclarations.ts b/tests/cases/conformance/jsdoc/jsdocReadonlyDeclarations.ts index a9a3f0d16e0..854a67989c3 100644 --- a/tests/cases/conformance/jsdoc/jsdocReadonlyDeclarations.ts +++ b/tests/cases/conformance/jsdoc/jsdocReadonlyDeclarations.ts @@ -23,3 +23,8 @@ function F() { /** @readonly */ this.z = 1 } + +// https://github.com/microsoft/TypeScript/issues/38401 +class D { + constructor(/** @readonly */ x) {} +} \ No newline at end of file diff --git a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.ts b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.ts new file mode 100644 index 00000000000..ff32ca4393d --- /dev/null +++ b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.ts @@ -0,0 +1,32 @@ +// @target: esnext +// @lib: esnext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @filename: uniqueSymbolsDeclarationsInJs.js +// @out: uniqueSymbolsDeclarationsInJs-out.js + +// classes +class C { + /** + * @readonly + */ + static readonlyStaticCall = Symbol(); + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticType; + /** + * @type {unique symbol} + * @readonly + */ + static readonlyStaticTypeAndCall = Symbol(); + static readwriteStaticCall = Symbol(); + + /** + * @readonly + */ + readonlyCall = Symbol(); + readwriteCall = Symbol(); +} diff --git a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.ts b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.ts new file mode 100644 index 00000000000..52d9afd5d63 --- /dev/null +++ b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJsErrors.ts @@ -0,0 +1,23 @@ +// @target: esnext +// @lib: esnext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @filename: uniqueSymbolsDeclarationsInJsErrors.js +// @out: uniqueSymbolsDeclarationsInJsErrors-out.js + +class C { + /** + * @type {unique symbol} + */ + static readwriteStaticType; + /** + * @type {unique symbol} + * @readonly + */ + static readonlyType; + /** + * @type {unique symbol} + */ + static readwriteType; +} \ No newline at end of file From 27b9daf0a389c1423c01ce55540fa7c823c4d10d Mon Sep 17 00:00:00 2001 From: csigs Date: Mon, 11 May 2020 22:10:44 +0000 Subject: [PATCH 12/43] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index aa1a21e275f..14887d133d9 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -3710,6 +3710,15 @@ + + + + + + + + + From e9867a73532d7235cfc57210f0f59bdcd4967f5e Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 May 2020 22:14:45 +0000 Subject: [PATCH 13/43] Add and use the 'intersperse' helper function. --- src/compiler/core.ts | 16 ++++++++++++++++ src/services/jsDoc.ts | 12 +++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 2841b80aedf..63e293f2e8f 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -129,6 +129,22 @@ namespace ts { return map; } + /** + * Creates a new array with `element` interspersed in between each element of `input` + * if there is more than 1 value in `input`. Otherwise, returns the existing array. + */ + export function intersperse(input: T[], element: T): T[] { + if (input.length <= 1) { + return input; + } + const result: T[] = []; + for (let i = 0, n = input.length; i < n; i++) { + if (i) result.push(element); + result.push(input[i]); + } + return result; + } + /** * Iterates through `array` by index and performs the callback on each element of array until the callback * returns a falsey value, then returns false. diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 2616aea3144..3115109572a 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -89,20 +89,14 @@ namespace ts.JsDoc { // Eg. const a: Array | Array; a.length // The property length will have two declarations of property length coming // from Array - Array and Array - const documentationComment: SymbolDisplayPart[] = []; + const documentationComment: string[] = []; forEachUnique(declarations, declaration => { for (const { comment } of getCommentHavingNodes(declaration)) { if (comment === undefined) continue; - const commentTextPart = textPart(comment); - if (!contains(documentationComment, commentTextPart)) { - if (documentationComment.length) { - documentationComment.push(lineBreakPart()); - } - documentationComment.push(commentTextPart); - } + pushIfUnique(documentationComment, comment); } }); - return documentationComment; + return intersperse(map(documentationComment, textPart), lineBreakPart()); } function getCommentHavingNodes(declaration: Declaration): readonly (JSDoc | JSDocTag)[] { From 355c28ea70233a27c43a95a7fe1d1384b736c434 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 May 2020 22:15:05 +0000 Subject: [PATCH 14/43] Update baselines. --- ...opertiesWithIdenticalJSDocComments01.baseline | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline b/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline index 1fd2e593d2d..b03ca277801 100644 --- a/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline +++ b/tests/baselines/reference/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.baseline @@ -50,22 +50,6 @@ } ], "documentation": [ - { - "text": "A language id, like `typescript`.", - "kind": "text" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "A language id, like `typescript`.", - "kind": "text" - }, - { - "text": "\n", - "kind": "lineBreak" - }, { "text": "A language id, like `typescript`.", "kind": "text" From 0e37296396b283cb437f0f98cbb951df7c27bb2b Mon Sep 17 00:00:00 2001 From: csigs Date: Tue, 12 May 2020 04:10:41 +0000 Subject: [PATCH 15/43] LEGO: check in for master to temporary branch. --- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 1965a850988..3909794c3f6 100644 --- a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -3710,6 +3710,9 @@ + + + From ee3f2ce36258bf8c32e304d3a676068c674872d8 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 12 May 2020 12:30:46 +0300 Subject: [PATCH 16/43] regression(38485): allow using rawText property in processing a tagged template --- src/compiler/transformers/taggedTemplate.ts | 19 ++++++++++-------- src/testRunner/unittests/transform.ts | 20 +++++++++++++++++++ ...orrectly.transformTaggedTemplateLiteral.js | 5 +++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/transformApi/transformsCorrectly.transformTaggedTemplateLiteral.js diff --git a/src/compiler/transformers/taggedTemplate.ts b/src/compiler/transformers/taggedTemplate.ts index 8dc0fe1a964..33710eff54f 100644 --- a/src/compiler/transformers/taggedTemplate.ts +++ b/src/compiler/transformers/taggedTemplate.ts @@ -71,18 +71,21 @@ namespace ts { * * @param node The ES6 template literal. */ - function getRawLiteral(node: LiteralLikeNode, currentSourceFile: SourceFile) { + function getRawLiteral(node: TemplateLiteralLikeNode, currentSourceFile: SourceFile) { // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + let text = node.rawText; + if (text === undefined) { + text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - const isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + const isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index cce8c92ad41..54d511233fa 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -50,6 +50,15 @@ namespace ts { return (node: SourceFile) => visitNode(node, visitor); } + function createTaggedTemplateLiteral(): Transformer { + return sourceFile => updateSourceFileNode(sourceFile, [ + createStatement( + createTaggedTemplate( + createIdentifier("$tpl"), + createNoSubstitutionTemplateLiteral("foo", "foo"))) + ]); + } + function transformSourceFile(sourceText: string, transformers: TransformerFactory[]) { const transformed = transform(createSourceFile("source.ts", sourceText, ScriptTarget.ES2015), transformers); const printer = createPrinter({ newLine: NewLineKind.CarriageReturnLineFeed }, { @@ -120,6 +129,17 @@ namespace ts { }).outputText; }); + testBaseline("transformTaggedTemplateLiteral", () => { + return transpileModule("", { + transformers: { + before: [createTaggedTemplateLiteral], + }, + compilerOptions: { + target: ScriptTarget.ES5 + } + }).outputText; + }); + testBaseline("issue27854", () => { return transpileModule(`oldName<{ a: string; }>\` ... \`;`, { transformers: { diff --git a/tests/baselines/reference/transformApi/transformsCorrectly.transformTaggedTemplateLiteral.js b/tests/baselines/reference/transformApi/transformsCorrectly.transformTaggedTemplateLiteral.js new file mode 100644 index 00000000000..e693443d134 --- /dev/null +++ b/tests/baselines/reference/transformApi/transformsCorrectly.transformTaggedTemplateLiteral.js @@ -0,0 +1,5 @@ +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +$tpl(__makeTemplateObject(["foo"], ["foo"])); From 7ec21e93fe69268388d53eb322ee75f87e5533b6 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 12 May 2020 13:27:01 +0200 Subject: [PATCH 17/43] fix: add missing semi-colon to `__exportStar` unnamed function Fixes #38501 --- src/compiler/transformers/module/module.ts | 2 +- tests/baselines/reference/ambientShorthand_reExport.js | 2 +- .../baselines/reference/declarationEmitAliasExportStar.js | 2 +- ...tExportAssignedNamespaceNoTripleSlashTypesReference.js | 2 +- .../declarationEmitReexportedSymlinkReference.js | 2 +- .../declarationEmitReexportedSymlinkReference2.js | 2 +- .../declarationEmitReexportedSymlinkReference3.js | 2 +- .../reference/doubleUnderscoreExportStarConflict.js | 2 +- tests/baselines/reference/es6ExportAllInEs5.js | 2 +- tests/baselines/reference/es6ExportEqualsInterop.js | 2 +- .../esModuleInteropWithExportStar(target=es3).js | 2 +- .../esModuleInteropWithExportStar(target=es5).js | 2 +- tests/baselines/reference/exportNamespace1.js | 2 +- tests/baselines/reference/exportStar-amd.js | 2 +- tests/baselines/reference/exportStar.js | 2 +- tests/baselines/reference/exportStarForValues.js | 2 +- tests/baselines/reference/exportStarForValues2.js | 4 ++-- tests/baselines/reference/exportStarForValues3.js | 8 ++++---- tests/baselines/reference/exportStarForValues4.js | 4 ++-- tests/baselines/reference/exportStarForValues5.js | 2 +- tests/baselines/reference/exportStarForValues7.js | 4 ++-- tests/baselines/reference/exportStarForValues8.js | 8 ++++---- tests/baselines/reference/exportStarForValues9.js | 4 ++-- tests/baselines/reference/exportStarFromEmptyModule.js | 2 +- tests/baselines/reference/exportStarNotElided.js | 2 +- tests/baselines/reference/inlineJsxFactoryDeclarations.js | 2 +- tests/baselines/reference/jsDeclarationsExportForms.js | 4 ++-- tests/baselines/reference/jsDeclarationsExportFormsErr.js | 2 +- .../moduleAugmentationDoesInterfaceMergeOfReexport.js | 2 +- .../moduleAugmentationDoesNamespaceEnumMergeOfReexport.js | 2 +- .../moduleAugmentationDoesNamespaceMergeOfReexport.js | 2 +- .../moduleAugmentationEnumClassMergeOfReexportIsError.js | 2 +- ...oduleDeclarationExportStarShadowingGlobalIsNameable.js | 2 +- .../moduleSameValueDuplicateExportedBindings1.js | 4 ++-- .../moduleSameValueDuplicateExportedBindings2.js | 2 +- .../reference/symbolLinkDeclarationEmitModuleNames.js | 2 +- .../transformsCorrectly.transformAddCommentToImport.js | 2 +- .../watchMode/reexport/Reports-errors-correctly.js | 2 +- ...g-package-through-indirect-symlink-moduleCaseChange.js | 2 +- ...references-sibling-package-through-indirect-symlink.js | 2 +- .../when-there-are-circular-import-and-exports.js | 6 +++--- .../when-there-are-no-circular-import-and-exports.js | 6 +++--- .../when-there-are-circular-import-and-exports.js | 6 +++--- .../when-there-are-no-circular-import-and-exports.js | 6 +++--- .../when-there-are-circular-import-and-exports.js | 6 +++--- .../when-there-are-no-circular-import-and-exports.js | 6 +++--- .../when-there-are-circular-import-and-exports.js | 6 +++--- .../when-there-are-no-circular-import-and-exports.js | 6 +++--- .../when-there-are-circular-import-and-exports.js | 6 +++--- .../when-there-are-no-circular-import-and-exports.js | 6 +++--- .../when-there-are-circular-import-and-exports.js | 6 +++--- .../when-there-are-no-circular-import-and-exports.js | 6 +++--- ...changes-in-files-are-reflected-in-project-structure.js | 4 ++-- .../deleted-files-affect-project-structure-2.js | 4 ++-- .../deleted-files-affect-project-structure.js | 4 ++-- 55 files changed, 94 insertions(+), 94 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 85b18b4f7b5..5f0381c7fa5 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1887,7 +1887,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( text: ` var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); - }` + };` }; function createExportStarHelper(context: TransformationContext, module: Expression) { diff --git a/tests/baselines/reference/ambientShorthand_reExport.js b/tests/baselines/reference/ambientShorthand_reExport.js index 56a8cbaa427..5d8b1ff9dfd 100644 --- a/tests/baselines/reference/ambientShorthand_reExport.js +++ b/tests/baselines/reference/ambientShorthand_reExport.js @@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("jquery"), exports); //// [reExportUser.js] diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.js b/tests/baselines/reference/declarationEmitAliasExportStar.js index e4dc99a7074..8cd03b75e7c 100644 --- a/tests/baselines/reference/declarationEmitAliasExportStar.js +++ b/tests/baselines/reference/declarationEmitAliasExportStar.js @@ -23,7 +23,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./thingB"), exports); //// [index.js] diff --git a/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js b/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js index 8f147063de0..1e6e0c58f64 100644 --- a/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js +++ b/tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js @@ -66,7 +66,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("@emotion/core"), exports); diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js index 930ab97bfec..99ad86960e2 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js @@ -60,7 +60,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./keys"), exports); diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js index ccda718f60c..50c0ddb6f96 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js @@ -63,7 +63,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./keys"), exports); diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js index 3f27689c985..f83c0e0daf3 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js @@ -60,7 +60,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./keys"), exports); diff --git a/tests/baselines/reference/doubleUnderscoreExportStarConflict.js b/tests/baselines/reference/doubleUnderscoreExportStarConflict.js index a5d60f02159..3497051eb15 100644 --- a/tests/baselines/reference/doubleUnderscoreExportStarConflict.js +++ b/tests/baselines/reference/doubleUnderscoreExportStarConflict.js @@ -34,7 +34,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./b"), exports); __exportStar(require("./c"), exports); diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js index 72ec47714d8..aaf14965eca 100644 --- a/tests/baselines/reference/es6ExportAllInEs5.js +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -41,7 +41,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./server"), exports); diff --git a/tests/baselines/reference/es6ExportEqualsInterop.js b/tests/baselines/reference/es6ExportEqualsInterop.js index 6f24e91d8fd..9e0caded280 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.js +++ b/tests/baselines/reference/es6ExportEqualsInterop.js @@ -218,7 +218,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; var z2 = require("variable"); var z3 = require("interface-variable"); diff --git a/tests/baselines/reference/esModuleInteropWithExportStar(target=es3).js b/tests/baselines/reference/esModuleInteropWithExportStar(target=es3).js index 3db289c7f1a..de77e148cdf 100644 --- a/tests/baselines/reference/esModuleInteropWithExportStar(target=es3).js +++ b/tests/baselines/reference/esModuleInteropWithExportStar(target=es3).js @@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; var fs = __importStar(require("./fs")); fs; diff --git a/tests/baselines/reference/esModuleInteropWithExportStar(target=es5).js b/tests/baselines/reference/esModuleInteropWithExportStar(target=es5).js index 1ebde18e428..133a175e1ad 100644 --- a/tests/baselines/reference/esModuleInteropWithExportStar(target=es5).js +++ b/tests/baselines/reference/esModuleInteropWithExportStar(target=es5).js @@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); var fs = __importStar(require("./fs")); fs; diff --git a/tests/baselines/reference/exportNamespace1.js b/tests/baselines/reference/exportNamespace1.js index ff02a98707e..5631e6d8194 100644 --- a/tests/baselines/reference/exportNamespace1.js +++ b/tests/baselines/reference/exportNamespace1.js @@ -38,7 +38,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./b"), exports); //// [d.js] diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index a2a062a7501..3292a18294d 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -67,7 +67,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "./t1", "./t2", "./t3"], function (require, exports, t1_1, t2_1, t3_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index bf65527a104..7d2cb9e1fe8 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -62,7 +62,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./t1"), exports); __exportStar(require("./t2"), exports); diff --git a/tests/baselines/reference/exportStarForValues.js b/tests/baselines/reference/exportStarForValues.js index 277b953d353..fad8c19a1c7 100644 --- a/tests/baselines/reference/exportStarForValues.js +++ b/tests/baselines/reference/exportStarForValues.js @@ -22,7 +22,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues2.js b/tests/baselines/reference/exportStarForValues2.js index 01ded620485..19c55f2ff84 100644 --- a/tests/baselines/reference/exportStarForValues2.js +++ b/tests/baselines/reference/exportStarForValues2.js @@ -26,7 +26,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; @@ -43,7 +43,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file2"], function (require, exports, file2_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues3.js b/tests/baselines/reference/exportStarForValues3.js index e31102f3f7f..a0ea7d524ee 100644 --- a/tests/baselines/reference/exportStarForValues3.js +++ b/tests/baselines/reference/exportStarForValues3.js @@ -38,7 +38,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; @@ -55,7 +55,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; @@ -72,7 +72,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file2", "file3"], function (require, exports, file2_1, file3_1) { "use strict"; exports.__esModule = true; @@ -90,7 +90,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file4"], function (require, exports, file4_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues4.js b/tests/baselines/reference/exportStarForValues4.js index 527df22d292..13a6dfae6cc 100644 --- a/tests/baselines/reference/exportStarForValues4.js +++ b/tests/baselines/reference/exportStarForValues4.js @@ -30,7 +30,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file2"], function (require, exports, file2_1) { "use strict"; exports.__esModule = true; @@ -47,7 +47,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1", "file3"], function (require, exports, file1_1, file3_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues5.js b/tests/baselines/reference/exportStarForValues5.js index 6a5c2e6755f..d3ecb850f86 100644 --- a/tests/baselines/reference/exportStarForValues5.js +++ b/tests/baselines/reference/exportStarForValues5.js @@ -22,7 +22,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues7.js b/tests/baselines/reference/exportStarForValues7.js index 3fe3020756c..5d9e534333e 100644 --- a/tests/baselines/reference/exportStarForValues7.js +++ b/tests/baselines/reference/exportStarForValues7.js @@ -26,7 +26,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; @@ -44,7 +44,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file2"], function (require, exports, file2_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues8.js b/tests/baselines/reference/exportStarForValues8.js index 3458e5f6a38..66111015e70 100644 --- a/tests/baselines/reference/exportStarForValues8.js +++ b/tests/baselines/reference/exportStarForValues8.js @@ -38,7 +38,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; @@ -56,7 +56,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1"], function (require, exports, file1_1) { "use strict"; exports.__esModule = true; @@ -74,7 +74,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file2", "file3"], function (require, exports, file2_1, file3_1) { "use strict"; exports.__esModule = true; @@ -93,7 +93,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file4"], function (require, exports, file4_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarForValues9.js b/tests/baselines/reference/exportStarForValues9.js index 70ab46eafeb..c328f25910b 100644 --- a/tests/baselines/reference/exportStarForValues9.js +++ b/tests/baselines/reference/exportStarForValues9.js @@ -30,7 +30,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file2"], function (require, exports, file2_1) { "use strict"; exports.__esModule = true; @@ -48,7 +48,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; define(["require", "exports", "file1", "file3"], function (require, exports, file1_1, file3_1) { "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportStarFromEmptyModule.js b/tests/baselines/reference/exportStarFromEmptyModule.js index 450bbafe424..9864a341f7e 100644 --- a/tests/baselines/reference/exportStarFromEmptyModule.js +++ b/tests/baselines/reference/exportStarFromEmptyModule.js @@ -45,7 +45,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.A = void 0; __exportStar(require("./exportStarFromEmptyModule_module2"), exports); diff --git a/tests/baselines/reference/exportStarNotElided.js b/tests/baselines/reference/exportStarNotElided.js index 41d2b55483b..27a8616b32f 100644 --- a/tests/baselines/reference/exportStarNotElided.js +++ b/tests/baselines/reference/exportStarNotElided.js @@ -33,7 +33,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./register"), exports); __exportStar(require("./data1"), exports); diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarations.js b/tests/baselines/reference/inlineJsxFactoryDeclarations.js index c4909439e54..e799b950b6a 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarations.js +++ b/tests/baselines/reference/inlineJsxFactoryDeclarations.js @@ -74,7 +74,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; /** @jsx dom */ var renderer_1 = require("./renderer"); diff --git a/tests/baselines/reference/jsDeclarationsExportForms.js b/tests/baselines/reference/jsDeclarationsExportForms.js index 2ff100c4eda..8134e557a11 100644 --- a/tests/baselines/reference/jsDeclarationsExportForms.js +++ b/tests/baselines/reference/jsDeclarationsExportForms.js @@ -85,7 +85,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./cls"), exports); //// [bar2.js] @@ -99,7 +99,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./func"), exports); __exportStar(require("./cls"), exports); diff --git a/tests/baselines/reference/jsDeclarationsExportFormsErr.js b/tests/baselines/reference/jsDeclarationsExportFormsErr.js index f30b0a90ab0..6f777832804 100644 --- a/tests/baselines/reference/jsDeclarationsExportFormsErr.js +++ b/tests/baselines/reference/jsDeclarationsExportFormsErr.js @@ -51,7 +51,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./cls"), exports); //// [includeAll.js] diff --git a/tests/baselines/reference/moduleAugmentationDoesInterfaceMergeOfReexport.js b/tests/baselines/reference/moduleAugmentationDoesInterfaceMergeOfReexport.js index 1366f9cb258..2d3b3b7a1b4 100644 --- a/tests/baselines/reference/moduleAugmentationDoesInterfaceMergeOfReexport.js +++ b/tests/baselines/reference/moduleAugmentationDoesInterfaceMergeOfReexport.js @@ -36,7 +36,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./file"), exports); //// [augment.js] diff --git a/tests/baselines/reference/moduleAugmentationDoesNamespaceEnumMergeOfReexport.js b/tests/baselines/reference/moduleAugmentationDoesNamespaceEnumMergeOfReexport.js index 0cf02bb0c60..38bfb39d776 100644 --- a/tests/baselines/reference/moduleAugmentationDoesNamespaceEnumMergeOfReexport.js +++ b/tests/baselines/reference/moduleAugmentationDoesNamespaceEnumMergeOfReexport.js @@ -41,7 +41,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./file"), exports); //// [augment.js] diff --git a/tests/baselines/reference/moduleAugmentationDoesNamespaceMergeOfReexport.js b/tests/baselines/reference/moduleAugmentationDoesNamespaceMergeOfReexport.js index 9ddd49666a8..8a606153bd1 100644 --- a/tests/baselines/reference/moduleAugmentationDoesNamespaceMergeOfReexport.js +++ b/tests/baselines/reference/moduleAugmentationDoesNamespaceMergeOfReexport.js @@ -40,7 +40,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./file"), exports); //// [augment.js] diff --git a/tests/baselines/reference/moduleAugmentationEnumClassMergeOfReexportIsError.js b/tests/baselines/reference/moduleAugmentationEnumClassMergeOfReexportIsError.js index 1bd7540e23f..0cb50179bfd 100644 --- a/tests/baselines/reference/moduleAugmentationEnumClassMergeOfReexportIsError.js +++ b/tests/baselines/reference/moduleAugmentationEnumClassMergeOfReexportIsError.js @@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./file"), exports); //// [augment.js] diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js index 9e49c965bfa..f243093f5be 100644 --- a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js @@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./account"), exports); //// [index.js] diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js index ab43c82628d..4051b88b059 100644 --- a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings1.js @@ -26,7 +26,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./c"), exports); //// [a.js] @@ -40,7 +40,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./b"), exports); __exportStar(require("./c"), exports); diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js index 456cc75fe8b..1a0b21438e2 100644 --- a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings2.js @@ -46,7 +46,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./b"), exports); __exportStar(require("./c"), exports); diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js index a4f5f4e177c..7474849c1a8 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js @@ -51,7 +51,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./src/value-promise"), exports); __exportStar(require("./src/bindingkey"), exports); diff --git a/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js b/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js index 2cadc1e1ec5..7f04a9b7201 100644 --- a/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js +++ b/tests/baselines/reference/transformApi/transformsCorrectly.transformAddCommentToImport.js @@ -8,7 +8,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Value = void 0; /*comment*/ diff --git a/tests/baselines/reference/tsbuild/watchMode/reexport/Reports-errors-correctly.js b/tests/baselines/reference/tsbuild/watchMode/reexport/Reports-errors-correctly.js index deeefd1ad04..6001eeaf1f7 100644 --- a/tests/baselines/reference/tsbuild/watchMode/reexport/Reports-errors-correctly.js +++ b/tests/baselines/reference/tsbuild/watchMode/reexport/Reports-errors-correctly.js @@ -85,7 +85,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./session"), exports); diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js index 649de585df5..29eefb2d8e1 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js @@ -73,7 +73,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./keys"), exports); diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js index 4a223fe9c6d..40045b6d167 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js @@ -73,7 +73,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./keys"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js index 9c1f665cca0..03e43850ee9 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js @@ -70,7 +70,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -86,7 +86,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -132,7 +132,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js index 20027ce38f1..d9199bcceef 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js @@ -64,7 +64,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -80,7 +80,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -114,7 +114,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js index e51fe281ec1..8fd7efd3250 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js @@ -76,7 +76,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -96,7 +96,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -162,7 +162,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js index 6c1de9a4deb..76c72db2a76 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js @@ -70,7 +70,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -90,7 +90,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -135,7 +135,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js index f72345ccc56..e927c312aca 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js @@ -70,7 +70,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -86,7 +86,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -132,7 +132,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js index 8de8338f4bb..96f39107d7d 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js @@ -64,7 +64,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -80,7 +80,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -114,7 +114,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js index 071013c5e81..18c3f4e5ea1 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js @@ -76,7 +76,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -96,7 +96,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -162,7 +162,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js index 547418b8fce..9f9528102ad 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/defaultAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js @@ -70,7 +70,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -90,7 +90,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -135,7 +135,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js index b1eead4925a..1c96e77804b 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js @@ -70,7 +70,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -86,7 +86,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -132,7 +132,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js index bda31bf5c1f..950359dda9e 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModules/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js @@ -64,7 +64,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -80,7 +80,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -114,7 +114,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js index cfe43df46a1..e793fd4f72b 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-circular-import-and-exports.js @@ -76,7 +76,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -96,7 +96,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -162,7 +162,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js index c0a64ac97a5..8eed0ceda00 100644 --- a/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js +++ b/tests/baselines/reference/tscWatch/emitAndErrorUpdates/isolatedModulesAndD/updates-errors-when-file-transitively-exported-file-changes/when-there-are-no-circular-import-and-exports.js @@ -70,7 +70,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools.interface"), exports); @@ -90,7 +90,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./tools/public"), exports); @@ -135,7 +135,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./data"), exports); diff --git a/tests/baselines/reference/tscWatch/programUpdates/changes-in-files-are-reflected-in-project-structure.js b/tests/baselines/reference/tscWatch/programUpdates/changes-in-files-are-reflected-in-project-structure.js index 2345c69fd19..b5479b07279 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/changes-in-files-are-reflected-in-project-structure.js +++ b/tests/baselines/reference/tscWatch/programUpdates/changes-in-files-are-reflected-in-project-structure.js @@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./f2"), exports); @@ -96,7 +96,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("../c/f3"), exports); diff --git a/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure-2.js b/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure-2.js index 6db5d9bcb60..0d56470f85e 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure-2.js +++ b/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure-2.js @@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("../c/f3"), exports); @@ -55,7 +55,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./f2"), exports); diff --git a/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure.js b/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure.js index 75dd1b1443f..6973c5ff627 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure.js +++ b/tests/baselines/reference/tscWatch/programUpdates/deleted-files-affect-project-structure.js @@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("../c/f3"), exports); @@ -55,7 +55,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} +}; exports.__esModule = true; __exportStar(require("./f2"), exports); From 5895493815ceebfa4e83d5ccdaaa5306cdd0b216 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 12 May 2020 17:26:31 +0300 Subject: [PATCH 18/43] fix(37877): include in NavigationBar default exported child items (#38255) --- src/services/navigationBar.ts | 13 +++++++- .../navigationItemsExportDefaultExpression.ts | 32 +++++++++++++++++++ .../navigationItemsExportEqualsExpression.ts | 32 +++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index b74da7fd8da..91bf61270de 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -307,7 +307,18 @@ namespace ts.NavigationBar { addNodeWithRecursiveChild(node, getInteriorModule(node).body); break; - case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportAssignment: { + const expression = (node).expression; + if (isObjectLiteralExpression(expression)) { + startNode(node); + addChildrenRecursively(expression); + endNode(); + } + else { + addLeafNode(node); + } + break; + } case SyntaxKind.ExportSpecifier: case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.IndexSignature: diff --git a/tests/cases/fourslash/navigationItemsExportDefaultExpression.ts b/tests/cases/fourslash/navigationItemsExportDefaultExpression.ts index 6425fd4bf7a..c3059d50c03 100644 --- a/tests/cases/fourslash/navigationItemsExportDefaultExpression.ts +++ b/tests/cases/fourslash/navigationItemsExportDefaultExpression.ts @@ -5,6 +5,13 @@ //// export default () => "" //// export default abc; //// export default class AB {} +//// export default { +//// a: 1, +//// b: 1, +//// c: { +//// d: 1 +//// } +//// } verify.navigationTree({ "text": '"navigationItemsExportDefaultExpression"', @@ -20,6 +27,31 @@ verify.navigationTree({ "kind": "function", "kindModifiers": "export" }, + { + "text": "default", + "kind": "const", + "kindModifiers": "export", + "childItems": [ + { + "text": "a", + "kind": "property" + }, + { + "text": "b", + "kind": "property" + }, + { + "text": "c", + "kind": "property", + "childItems": [ + { + "text": "d", + "kind": "property" + } + ] + } + ] + }, { "text": "AB", "kind": "class", diff --git a/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts b/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts index 053a1fa0023..f63db161b09 100644 --- a/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts +++ b/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts @@ -6,6 +6,13 @@ //// export = function () {} //// export = () => "" //// export = class AB {} +//// export = { +//// a: 1, +//// b: 1, +//// c: { +//// d: 1 +//// } +//// } verify.navigationTree({ "text": '"navigationItemsExportEqualsExpression"', @@ -26,6 +33,31 @@ verify.navigationTree({ "kind": "class", "kindModifiers": "export" }, + { + "text": "export=", + "kind": "const", + "kindModifiers": "export", + "childItems": [ + { + "text": "a", + "kind": "property" + }, + { + "text": "b", + "kind": "property" + }, + { + "text": "c", + "kind": "property", + "childItems": [ + { + "text": "d", + "kind": "property" + } + ] + } + ] + }, { "text": "abc", "kind": "const" From 5d6a5d04eac5dbc557eadf1d88f980d633232ae5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 12 May 2020 10:16:59 -0700 Subject: [PATCH 19/43] Fix detecting default project when file is part for more than one project but not part of default configured project (eg because its output of that projet) (#38429) Fixes #38366 --- src/server/editorServices.ts | 4 +- src/testRunner/unittests/tsbuild/watchMode.ts | 7 +++ .../unittests/tsserver/configuredProjects.ts | 58 +++++++++++++++++++ .../tsserver/projectReferenceCompileOnSave.ts | 4 +- .../unittests/tsserver/projectReferences.ts | 6 +- 5 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 47d0dc71f2f..f98f0dce2db 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1743,7 +1743,9 @@ namespace ts.server { return project?.isSolution() ? project.getDefaultChildProjectFromSolution(info) : - project; + project && projectContainsInfoDirectly(project, info) ? + project : + undefined; } /** diff --git a/src/testRunner/unittests/tsbuild/watchMode.ts b/src/testRunner/unittests/tsbuild/watchMode.ts index 308c229776d..69faba35c31 100644 --- a/src/testRunner/unittests/tsbuild/watchMode.ts +++ b/src/testRunner/unittests/tsbuild/watchMode.ts @@ -15,6 +15,13 @@ namespace ts.tscWatch { return ts.createSolutionBuilder(host, rootNames, defaultOptions || {}); } + export function ensureErrorFreeBuild(host: WatchedSystem, rootNames: readonly string[]) { + // ts build should succeed + const solutionBuilder = createSolutionBuilder(host, rootNames, {}); + solutionBuilder.build(); + assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " ")); + } + type OutputFileStamp = [string, Date | undefined, boolean]; function transformOutputToOutputFileStamp(f: string, host: TsBuildWatchSystem): OutputFileStamp { return [f, host.getModifiedTime(f), host.writtenFiles.has(host.toFullPath(f))] as OutputFileStamp; diff --git a/src/testRunner/unittests/tsserver/configuredProjects.ts b/src/testRunner/unittests/tsserver/configuredProjects.ts index 4c61106a1d6..b8ec47946a3 100644 --- a/src/testRunner/unittests/tsserver/configuredProjects.ts +++ b/src/testRunner/unittests/tsserver/configuredProjects.ts @@ -1050,6 +1050,64 @@ declare var console: { }); }); }); + + it("when default configured project does not contain the file", () => { + const barConfig: File = { + path: `${tscWatch.projectRoot}/bar/tsconfig.json`, + content: "{}" + }; + const barIndex: File = { + path: `${tscWatch.projectRoot}/bar/index.ts`, + content: `import {foo} from "../foo/lib"; +foo();` + }; + const fooBarConfig: File = { + path: `${tscWatch.projectRoot}/foobar/tsconfig.json`, + content: barConfig.path + }; + const fooBarIndex: File = { + path: `${tscWatch.projectRoot}/foobar/index.ts`, + content: barIndex.content + }; + const fooConfig: File = { + path: `${tscWatch.projectRoot}/foo/tsconfig.json`, + content: JSON.stringify({ + include: ["index.ts"], + compilerOptions: { + declaration: true, + outDir: "lib" + } + }) + }; + const fooIndex: File = { + path: `${tscWatch.projectRoot}/foo/index.ts`, + content: `export function foo() {}` + }; + const host = createServerHost([barConfig, barIndex, fooBarConfig, fooBarIndex, fooConfig, fooIndex, libFile]); + tscWatch.ensureErrorFreeBuild(host, [fooConfig.path]); + const fooDts = `${tscWatch.projectRoot}/foo/lib/index.d.ts`; + assert.isTrue(host.fileExists(fooDts)); + const session = createSession(host); + const service = session.getProjectService(); + service.openClientFile(barIndex.path); + checkProjectActualFiles(service.configuredProjects.get(barConfig.path)!, [barIndex.path, fooDts, libFile.path, barConfig.path]); + service.openClientFile(fooBarIndex.path); + checkProjectActualFiles(service.configuredProjects.get(fooBarConfig.path)!, [fooBarIndex.path, fooDts, libFile.path, fooBarConfig.path]); + service.openClientFile(fooIndex.path); + checkProjectActualFiles(service.configuredProjects.get(fooConfig.path)!, [fooIndex.path, libFile.path, fooConfig.path]); + service.openClientFile(fooDts); + session.executeCommandSeq({ + command: protocol.CommandTypes.GetApplicableRefactors, + arguments: { + file: fooDts, + startLine: 1, + startOffset: 1, + endLine: 1, + endOffset: 1 + } + }); + assert.equal(service.tryGetDefaultProjectForFile(server.toNormalizedPath(fooDts)), service.configuredProjects.get(barConfig.path)); + }); }); describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories listed in config file input array", () => { diff --git a/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts b/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts index e8442e07e69..e4301b3c271 100644 --- a/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts +++ b/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts @@ -469,9 +469,7 @@ ${appendDts}` const host = createServerHost([libFile, tsbaseJson, buttonConfig, buttonSource, siblingConfig, siblingSource], { useCaseSensitiveFileNames: true }); // ts build should succeed - const solutionBuilder = tscWatch.createSolutionBuilder(host, [siblingConfig.path], {}); - solutionBuilder.build(); - assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " ")); + tscWatch.ensureErrorFreeBuild(host, [siblingConfig.path]); const sourceJs = changeExtension(siblingSource.path, ".js"); const expectedSiblingJs = host.readFile(sourceJs); diff --git a/src/testRunner/unittests/tsserver/projectReferences.ts b/src/testRunner/unittests/tsserver/projectReferences.ts index 2eb7d7710ce..8da081d82c1 100644 --- a/src/testRunner/unittests/tsserver/projectReferences.ts +++ b/src/testRunner/unittests/tsserver/projectReferences.ts @@ -2,12 +2,8 @@ namespace ts.projectSystem { describe("unittests:: tsserver:: with project references and tsbuild", () => { function createHost(files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], rootNames: readonly string[]) { const host = createServerHost(files); - // ts build should succeed - const solutionBuilder = tscWatch.createSolutionBuilder(host, rootNames, {}); - solutionBuilder.build(); - assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " ")); - + tscWatch.ensureErrorFreeBuild(host, rootNames); return host; } From c44759a55381564241a6b9b06395cd097eeb917f Mon Sep 17 00:00:00 2001 From: typescript-bot Date: Tue, 12 May 2020 20:21:01 +0000 Subject: [PATCH 20/43] Update user baselines --- .../reference/docker/office-ui-fabric.log | 58 +++++++++---------- tests/baselines/reference/docker/vue-next.log | 8 +-- .../reference/user/eventemitter3.log | 7 --- 3 files changed, 33 insertions(+), 40 deletions(-) delete mode 100644 tests/baselines/reference/user/eventemitter3.log diff --git a/tests/baselines/reference/docker/office-ui-fabric.log b/tests/baselines/reference/docker/office-ui-fabric.log index 69f3f4e63a1..3a8ae0d4b9b 100644 --- a/tests/baselines/reference/docker/office-ui-fabric.log +++ b/tests/baselines/reference/docker/office-ui-fabric.log @@ -19,36 +19,36 @@ Standard output: Standard error: info cli using local version of lerna -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency @uifabric/tslint-rules: (Use `node --trace-warnings ...` to show where the warning was created) -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'find' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'head' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'set' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'test' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'to' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency -@uifabric/tslint-rules: (node:29) Warning: Accessing non-existent property 'which' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'find' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'head' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'set' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'test' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'to' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency +@uifabric/tslint-rules: (node:28) Warning: Accessing non-existent property 'which' of module exports inside circular dependency @uifabric/tslint-rules: [XX:XX:XX XM] ▲ One of these [node-sass, postcss, autoprefixer] is not installed, so this task has no effect @fluentui/ability-attributes: npm WARN lifecycle The node binary used for scripts is but npm is using /usr/local/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with. @fluentui/ability-attributes: internal/modules/cjs/loader.js:491 diff --git a/tests/baselines/reference/docker/vue-next.log b/tests/baselines/reference/docker/vue-next.log index ddb045b9940..9187c7c5d17 100644 --- a/tests/baselines/reference/docker/vue-next.log +++ b/tests/baselines/reference/docker/vue-next.log @@ -1,7 +1,7 @@ Exit Code: 0 Standard output: -> @X.X.X-beta.10 build /vue-next +> @X.X.X-beta.12 build /vue-next > node scripts/build.js "--types" Rolling up type definitions for compiler-core... Writing: /vue-next/temp/compiler-core.api.json @@ -115,7 +115,7 @@ Error: /vue-next/packages/runtime-core/src/apiInject.ts(40,9): semantic error TS at forEach (/vue-next/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:9342:14) at _.each (/vue-next/node_modules/rollup-plugin-typescript2/src/print-diagnostics.ts:9:2) at Object.transform (/vue-next/node_modules/rollup-plugin-typescript2/src/index.ts:242:5) -(node:17) UnhandledPromiseRejectionWarning: Error: Command failed with exit code 1 (EPERM): rollup -c --environment COMMIT:9d111f5,NODE_ENV:production,TARGET:runtime-core,TYPES:true +(node:18) UnhandledPromiseRejectionWarning: Error: Command failed with exit code 1 (EPERM): rollup -c --environment COMMIT:74ed7d1,NODE_ENV:production,TARGET:runtime-core,TYPES:true at makeError (/vue-next/node_modules/execa/lib/error.js:59:11) at handlePromise (/vue-next/node_modules/execa/index.js:112:26) at processTicksAndRejections (internal/process/task_queues.js:97:5) @@ -123,5 +123,5 @@ Error: /vue-next/packages/runtime-core/src/apiInject.ts(40,9): semantic error TS at async buildAll (/vue-next/scripts/build.js:50:5) at async run (/vue-next/scripts/build.js:40:5) (Use `node --trace-warnings ...` to show where the warning was created) -(node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) -(node:17) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. +(node:18) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) +(node:18) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. diff --git a/tests/baselines/reference/user/eventemitter3.log b/tests/baselines/reference/user/eventemitter3.log deleted file mode 100644 index 6d255ed9eec..00000000000 --- a/tests/baselines/reference/user/eventemitter3.log +++ /dev/null @@ -1,7 +0,0 @@ -Exit Code: 1 -Standard output: -node_modules/eventemitter3/index.d.ts(117,17): error TS2536: Type 'K' cannot be used to index type 'ArgumentMap'. - - - -Standard error: From 9725d623cea96f5e30dde3f330abed31cc445782 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Wed, 13 May 2020 19:44:49 +0800 Subject: [PATCH 21/43] Fix build type error (#38525) --- src/harness/vfsUtil.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/harness/vfsUtil.ts b/src/harness/vfsUtil.ts index 76475b00360..88fc73ebca9 100644 --- a/src/harness/vfsUtil.ts +++ b/src/harness/vfsUtil.ts @@ -649,14 +649,14 @@ namespace vfs { * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ - public readFileSync(path: string, encoding: string): string; + public readFileSync(path: string, encoding: BufferEncoding): string; /** * Read from a file. * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ - public readFileSync(path: string, encoding?: string | null): string | Buffer; - public readFileSync(path: string, encoding: string | null = null) { // eslint-disable-line no-null/no-null + public readFileSync(path: string, encoding?: BufferEncoding | null): string | Buffer; + public readFileSync(path: string, encoding: BufferEncoding | null = null) { // eslint-disable-line no-null/no-null const { node } = this._walk(this._resolve(path)); if (!node) throw createIOError("ENOENT"); if (isDirectory(node)) throw createIOError("EISDIR"); From 71711257eafedd26992dc1c640b6bbe029f898e7 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Wed, 13 May 2020 23:28:32 +0300 Subject: [PATCH 22/43] fix(33836): allow readonly modifier for a field with only get accessor (#36543) --- .../generateGetAccessorAndSetAccessor.ts | 50 +++++++++++++------ ...efactorConvertToGetAccessAndSetAccess14.ts | 3 +- ...efactorConvertToGetAccessAndSetAccess33.ts | 2 +- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/services/refactors/generateGetAccessorAndSetAccessor.ts b/src/services/refactors/generateGetAccessorAndSetAccessor.ts index df1799e336a..024a27f5a92 100644 --- a/src/services/refactors/generateGetAccessorAndSetAccessor.ts +++ b/src/services/refactors/generateGetAccessorAndSetAccessor.ts @@ -41,7 +41,6 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { const fieldInfo = getConvertibleFieldAtPosition(context); if (!fieldInfo) return undefined; - const isJS = isSourceFileJS(file); const changeTracker = textChanges.ChangeTracker.fromContext(context); const { isStatic, isReadonly, fieldName, accessorName, originalName, type, container, declaration, renameAccessor } = fieldInfo; @@ -50,15 +49,20 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { suppressLeadingAndTrailingTrivia(declaration); suppressLeadingAndTrailingTrivia(container); - const isInClassLike = isClassLike(container); - // avoid Readonly modifier because it will convert to get accessor - const modifierFlags = getEffectiveModifierFlags(declaration) & ~ModifierFlags.Readonly; - const accessorModifiers = isInClassLike - ? !modifierFlags || modifierFlags & ModifierFlags.Private - ? getModifiers(isJS, isStatic, SyntaxKind.PublicKeyword) - : createNodeArray(createModifiersFromModifierFlags(modifierFlags)) - : undefined; - const fieldModifiers = isInClassLike ? getModifiers(isJS, isStatic, SyntaxKind.PrivateKeyword) : undefined; + let accessorModifiers: ModifiersArray | undefined; + let fieldModifiers: ModifiersArray | undefined; + if (isClassLike(container)) { + const modifierFlags = getEffectiveModifierFlags(declaration); + if (isSourceFileJS(file)) { + const modifiers = createModifiers(modifierFlags); + accessorModifiers = modifiers; + fieldModifiers = modifiers; + } + else { + accessorModifiers = createModifiers(prepareModifierFlagsForAccessor(modifierFlags)); + fieldModifiers = createModifiers(prepareModifierFlagsForField(modifierFlags)); + } + } updateFieldDeclaration(changeTracker, file, declaration, fieldName, fieldModifiers); @@ -105,12 +109,26 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { return isIdentifier(fieldName) ? createPropertyAccess(leftHead, fieldName) : createElementAccess(leftHead, createLiteral(fieldName)); } - function getModifiers(isJS: boolean, isStatic: boolean, accessModifier: SyntaxKind.PublicKeyword | SyntaxKind.PrivateKeyword): NodeArray | undefined { - const modifiers = append( - !isJS ? [createToken(accessModifier) as Token | Token] : undefined, - isStatic ? createToken(SyntaxKind.StaticKeyword) : undefined - ); - return modifiers && createNodeArray(modifiers); + function createModifiers(modifierFlags: ModifierFlags): ModifiersArray | undefined { + return modifierFlags ? createNodeArray(createModifiersFromModifierFlags(modifierFlags)) : undefined; + } + + function prepareModifierFlagsForAccessor(modifierFlags: ModifierFlags): ModifierFlags { + modifierFlags &= ~ModifierFlags.Readonly; // avoid Readonly modifier because it will convert to get accessor + modifierFlags &= ~ModifierFlags.Private; + + if (!(modifierFlags & ModifierFlags.Protected)) { + modifierFlags |= ModifierFlags.Public; + } + + return modifierFlags; + } + + function prepareModifierFlagsForField(modifierFlags: ModifierFlags): ModifierFlags { + modifierFlags &= ~ModifierFlags.Public; + modifierFlags &= ~ModifierFlags.Protected; + modifierFlags |= ModifierFlags.Private; + return modifierFlags; } function getConvertibleFieldAtPosition(context: RefactorContext): Info | undefined { diff --git a/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess14.ts b/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess14.ts index 095cc4fdd79..c3c6c824fbe 100644 --- a/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess14.ts +++ b/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess14.ts @@ -4,14 +4,13 @@ //// /*a*/public readonly a: string = "foo";/*b*/ //// } -goTo.select("a", "b"); goTo.select("a", "b"); edit.applyRefactor({ refactorName: "Generate 'get' and 'set' accessors", actionName: "Generate 'get' and 'set' accessors", actionDescription: "Generate 'get' and 'set' accessors", newContent: `class A { - private /*RENAME*/_a: string = "foo"; + private readonly /*RENAME*/_a: string = "foo"; public get a(): string { return this._a; } diff --git a/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess33.ts b/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess33.ts index aa224b8b31b..f490c27f714 100644 --- a/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess33.ts +++ b/tests/cases/fourslash/refactorConvertToGetAccessAndSetAccess33.ts @@ -22,7 +22,7 @@ edit.applyRefactor({ actionName: "Generate 'get' and 'set' accessors", actionDescription: "Generate 'get' and 'set' accessors", newContent: `class A { - private /*RENAME*/_a: number; + private readonly /*RENAME*/_a: number; public get a(): number { return this._a; } From c1f676dd3f1337286bd99d3d189bc59c930b703d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 13 May 2020 20:57:17 -0700 Subject: [PATCH 23/43] Perform intersection reduction before and after getApparentType (#38565) * Perform intersection reduction before and after getApparentType * Add regression tests --- src/compiler/checker.ts | 20 +++-- .../intersectionReduction.errors.txt | 32 +++++++ .../reference/intersectionReduction.js | 41 +++++++++ .../reference/intersectionReduction.symbols | 84 +++++++++++++++++++ .../reference/intersectionReduction.types | 62 ++++++++++++++ .../intersection/intersectionReduction.ts | 32 +++++++ 6 files changed, 265 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 590efccaa56..48367ce63e0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10202,7 +10202,7 @@ namespace ts { } function getPropertiesOfType(type: Type): Symbol[] { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & TypeFlags.UnionOrIntersection ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -10558,6 +10558,14 @@ namespace ts { t; } + function getReducedApparentType(type: Type): Type { + // Since getApparentType may return a non-reduced union or intersection type, we need to perform + // type reduction both before and after obtaining the apparent type. For example, given a type parameter + // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and + // that type may need futher reduction to remove empty intersections. + return getReducedType(getApparentType(getReducedType(type))); + } + function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined { let singleProp: Symbol | undefined; let propSet: Map | undefined; @@ -10779,7 +10787,7 @@ namespace ts { * @param name a name of property to look up in a given type */ function getPropertyOfType(type: Type, name: __String): Symbol | undefined { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); const symbol = resolved.members.get(name); @@ -10817,7 +10825,7 @@ namespace ts { * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[] { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo | undefined { @@ -10835,13 +10843,13 @@ namespace ts { // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined { @@ -13215,7 +13223,7 @@ namespace ts { // In the following we resolve T[K] to the type of the property in T selected by K. // We treat boolean as different from other unions to improve errors; // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. - const apparentObjectType = getApparentType(getReducedType(objectType)); + const apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Boolean)) { const propTypes: Type[] = []; let wasMissingProp = false; diff --git a/tests/baselines/reference/intersectionReduction.errors.txt b/tests/baselines/reference/intersectionReduction.errors.txt index 7026fcda0a9..82911aca009 100644 --- a/tests/baselines/reference/intersectionReduction.errors.txt +++ b/tests/baselines/reference/intersectionReduction.errors.txt @@ -120,4 +120,36 @@ tests/cases/conformance/types/intersection/intersectionReduction.ts(81,1): error const f2 = (t: Container<"a"> | (Container<"b"> & Container<"c">)): Container<"a"> => t; const f3 = (t: Container<"a"> | (Container<"b"> & { dataB: boolean } & Container<"a">)): Container<"a"> => t; const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): number => t; + + // Repro from #38549 + + interface A2 { + kind: "A"; + a: number; + } + + interface B2 { + kind: "B"; + b: number; + } + + declare const shouldBeB: (A2 | B2) & B2; + const b: B2 = shouldBeB; // works + + function inGeneric(alsoShouldBeB: T & B2) { + const b: B2 = alsoShouldBeB; + } + + // Repro from #38542 + + interface ABI { + kind: 'a' | 'b'; + } + + declare class CA { kind: 'a'; a: string; x: number }; + declare class CB { kind: 'b'; b: string; y: number }; + + function bar(x: T & CA) { + let ab: ABI = x; + } \ No newline at end of file diff --git a/tests/baselines/reference/intersectionReduction.js b/tests/baselines/reference/intersectionReduction.js index c04ce9973bc..64b1757b09d 100644 --- a/tests/baselines/reference/intersectionReduction.js +++ b/tests/baselines/reference/intersectionReduction.js @@ -107,6 +107,38 @@ type Container = { const f2 = (t: Container<"a"> | (Container<"b"> & Container<"c">)): Container<"a"> => t; const f3 = (t: Container<"a"> | (Container<"b"> & { dataB: boolean } & Container<"a">)): Container<"a"> => t; const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): number => t; + +// Repro from #38549 + +interface A2 { + kind: "A"; + a: number; +} + +interface B2 { + kind: "B"; + b: number; +} + +declare const shouldBeB: (A2 | B2) & B2; +const b: B2 = shouldBeB; // works + +function inGeneric(alsoShouldBeB: T & B2) { + const b: B2 = alsoShouldBeB; +} + +// Repro from #38542 + +interface ABI { + kind: 'a' | 'b'; +} + +declare class CA { kind: 'a'; a: string; x: number }; +declare class CB { kind: 'b'; b: string; y: number }; + +function bar(x: T & CA) { + let ab: ABI = x; +} //// [intersectionReduction.js] @@ -128,3 +160,12 @@ var f1 = function (t) { return t; }; var f2 = function (t) { return t; }; var f3 = function (t) { return t; }; var f4 = function (t) { return t; }; +var b = shouldBeB; // works +function inGeneric(alsoShouldBeB) { + var b = alsoShouldBeB; +} +; +; +function bar(x) { + var ab = x; +} diff --git a/tests/baselines/reference/intersectionReduction.symbols b/tests/baselines/reference/intersectionReduction.symbols index 2949e87b2c7..02cc8c9ff2f 100644 --- a/tests/baselines/reference/intersectionReduction.symbols +++ b/tests/baselines/reference/intersectionReduction.symbols @@ -373,3 +373,87 @@ const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): >Container : Symbol(Container, Decl(intersectionReduction.ts, 99, 44)) >t : Symbol(t, Decl(intersectionReduction.ts, 107, 12)) +// Repro from #38549 + +interface A2 { +>A2 : Symbol(A2, Decl(intersectionReduction.ts, 107, 93)) + + kind: "A"; +>kind : Symbol(A2.kind, Decl(intersectionReduction.ts, 111, 14)) + + a: number; +>a : Symbol(A2.a, Decl(intersectionReduction.ts, 112, 14)) +} + +interface B2 { +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) + + kind: "B"; +>kind : Symbol(B2.kind, Decl(intersectionReduction.ts, 116, 14)) + + b: number; +>b : Symbol(B2.b, Decl(intersectionReduction.ts, 117, 14)) +} + +declare const shouldBeB: (A2 | B2) & B2; +>shouldBeB : Symbol(shouldBeB, Decl(intersectionReduction.ts, 121, 13)) +>A2 : Symbol(A2, Decl(intersectionReduction.ts, 107, 93)) +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) + +const b: B2 = shouldBeB; // works +>b : Symbol(b, Decl(intersectionReduction.ts, 122, 5)) +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) +>shouldBeB : Symbol(shouldBeB, Decl(intersectionReduction.ts, 121, 13)) + +function inGeneric(alsoShouldBeB: T & B2) { +>inGeneric : Symbol(inGeneric, Decl(intersectionReduction.ts, 122, 24)) +>T : Symbol(T, Decl(intersectionReduction.ts, 124, 19)) +>A2 : Symbol(A2, Decl(intersectionReduction.ts, 107, 93)) +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) +>alsoShouldBeB : Symbol(alsoShouldBeB, Decl(intersectionReduction.ts, 124, 38)) +>T : Symbol(T, Decl(intersectionReduction.ts, 124, 19)) +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) + + const b: B2 = alsoShouldBeB; +>b : Symbol(b, Decl(intersectionReduction.ts, 125, 9)) +>B2 : Symbol(B2, Decl(intersectionReduction.ts, 114, 1)) +>alsoShouldBeB : Symbol(alsoShouldBeB, Decl(intersectionReduction.ts, 124, 38)) +} + +// Repro from #38542 + +interface ABI { +>ABI : Symbol(ABI, Decl(intersectionReduction.ts, 126, 1)) + + kind: 'a' | 'b'; +>kind : Symbol(ABI.kind, Decl(intersectionReduction.ts, 130, 15)) +} + +declare class CA { kind: 'a'; a: string; x: number }; +>CA : Symbol(CA, Decl(intersectionReduction.ts, 132, 1)) +>kind : Symbol(CA.kind, Decl(intersectionReduction.ts, 134, 18)) +>a : Symbol(CA.a, Decl(intersectionReduction.ts, 134, 29)) +>x : Symbol(CA.x, Decl(intersectionReduction.ts, 134, 40)) + +declare class CB { kind: 'b'; b: string; y: number }; +>CB : Symbol(CB, Decl(intersectionReduction.ts, 134, 53)) +>kind : Symbol(CB.kind, Decl(intersectionReduction.ts, 135, 18)) +>b : Symbol(CB.b, Decl(intersectionReduction.ts, 135, 29)) +>y : Symbol(CB.y, Decl(intersectionReduction.ts, 135, 40)) + +function bar(x: T & CA) { +>bar : Symbol(bar, Decl(intersectionReduction.ts, 135, 53)) +>T : Symbol(T, Decl(intersectionReduction.ts, 137, 13)) +>CA : Symbol(CA, Decl(intersectionReduction.ts, 132, 1)) +>CB : Symbol(CB, Decl(intersectionReduction.ts, 134, 53)) +>x : Symbol(x, Decl(intersectionReduction.ts, 137, 32)) +>T : Symbol(T, Decl(intersectionReduction.ts, 137, 13)) +>CA : Symbol(CA, Decl(intersectionReduction.ts, 132, 1)) + + let ab: ABI = x; +>ab : Symbol(ab, Decl(intersectionReduction.ts, 138, 7)) +>ABI : Symbol(ABI, Decl(intersectionReduction.ts, 126, 1)) +>x : Symbol(x, Decl(intersectionReduction.ts, 137, 32)) +} + diff --git a/tests/baselines/reference/intersectionReduction.types b/tests/baselines/reference/intersectionReduction.types index 8c4ee05051b..c1ae0685836 100644 --- a/tests/baselines/reference/intersectionReduction.types +++ b/tests/baselines/reference/intersectionReduction.types @@ -315,3 +315,65 @@ const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): >dataB : boolean >t : number +// Repro from #38549 + +interface A2 { + kind: "A"; +>kind : "A" + + a: number; +>a : number +} + +interface B2 { + kind: "B"; +>kind : "B" + + b: number; +>b : number +} + +declare const shouldBeB: (A2 | B2) & B2; +>shouldBeB : B2 + +const b: B2 = shouldBeB; // works +>b : B2 +>shouldBeB : B2 + +function inGeneric(alsoShouldBeB: T & B2) { +>inGeneric : (alsoShouldBeB: T & B2) => void +>alsoShouldBeB : T & B2 + + const b: B2 = alsoShouldBeB; +>b : B2 +>alsoShouldBeB : T & B2 +} + +// Repro from #38542 + +interface ABI { + kind: 'a' | 'b'; +>kind : "a" | "b" +} + +declare class CA { kind: 'a'; a: string; x: number }; +>CA : CA +>kind : "a" +>a : string +>x : number + +declare class CB { kind: 'b'; b: string; y: number }; +>CB : CB +>kind : "b" +>b : string +>y : number + +function bar(x: T & CA) { +>bar : (x: T & CA) => void +>x : T & CA + + let ab: ABI = x; +>ab : ABI +>x : T & CA +} + diff --git a/tests/cases/conformance/types/intersection/intersectionReduction.ts b/tests/cases/conformance/types/intersection/intersectionReduction.ts index 8aeb110fd5f..0901524e141 100644 --- a/tests/cases/conformance/types/intersection/intersectionReduction.ts +++ b/tests/cases/conformance/types/intersection/intersectionReduction.ts @@ -108,3 +108,35 @@ type Container = { const f2 = (t: Container<"a"> | (Container<"b"> & Container<"c">)): Container<"a"> => t; const f3 = (t: Container<"a"> | (Container<"b"> & { dataB: boolean } & Container<"a">)): Container<"a"> => t; const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): number => t; + +// Repro from #38549 + +interface A2 { + kind: "A"; + a: number; +} + +interface B2 { + kind: "B"; + b: number; +} + +declare const shouldBeB: (A2 | B2) & B2; +const b: B2 = shouldBeB; // works + +function inGeneric(alsoShouldBeB: T & B2) { + const b: B2 = alsoShouldBeB; +} + +// Repro from #38542 + +interface ABI { + kind: 'a' | 'b'; +} + +declare class CA { kind: 'a'; a: string; x: number }; +declare class CB { kind: 'b'; b: string; y: number }; + +function bar(x: T & CA) { + let ab: ABI = x; +} From cfc4573c827b8ed482e36546fa33be4152950a84 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Thu, 14 May 2020 19:40:41 +0200 Subject: [PATCH 24/43] Fix (cosmetic) typos in checker.ts comments Just some small things I noticed while looking at some recent PRs. --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 48367ce63e0..c4f07e72f1b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7594,7 +7594,7 @@ namespace ts { if (isPropertyDeclaration(declaration) && (noImplicitAny || isInJSFile(declaration))) { // We have a property declaration with no type annotation or initializer, in noImplicitAny mode or a .js file. - // Use control flow analysis of this.xxx assignments the constructor to determine the type of the property. + // Use control flow analysis of this.xxx assignments in the constructor to determine the type of the property. const constructor = findConstructorDeclaration(declaration.parent); const type = constructor ? getFlowTypeInConstructor(declaration.symbol, constructor) : getEffectiveModifierFlags(declaration) & ModifierFlags.Ambient ? getTypeOfPropertyInBaseClass(declaration.symbol) : @@ -7619,7 +7619,7 @@ namespace ts { } function isConstructorDeclaredProperty(symbol: Symbol) { - // A propery is considered a constructor declared property when all declaration sites are this.xxx assignments, + // A property is considered a constructor declared property when all declaration sites are this.xxx assignments, // when no declaration sites have JSDoc type annotations, and when at least one declaration site is in the body of // a class constructor. if (symbol.valueDeclaration && isBinaryExpression(symbol.valueDeclaration)) { @@ -10562,7 +10562,7 @@ namespace ts { // Since getApparentType may return a non-reduced union or intersection type, we need to perform // type reduction both before and after obtaining the apparent type. For example, given a type parameter // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and - // that type may need futher reduction to remove empty intersections. + // that type may need further reduction to remove empty intersections. return getReducedType(getApparentType(getReducedType(type))); } From 7fc456f2d70348725bbef92732b98a33c07f85ad Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 14 May 2020 14:36:38 -0700 Subject: [PATCH 25/43] Include unknown in spread prop override check (#38577) --- src/compiler/checker.ts | 2 +- tests/baselines/reference/jsxPartialSpread.js | 26 +++++++++++++++ .../reference/jsxPartialSpread.symbols | 28 ++++++++++++++++ .../reference/jsxPartialSpread.types | 33 +++++++++++++++++++ tests/cases/compiler/jsxPartialSpread.tsx | 12 +++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsxPartialSpread.js create mode 100644 tests/baselines/reference/jsxPartialSpread.symbols create mode 100644 tests/baselines/reference/jsxPartialSpread.types create mode 100644 tests/cases/compiler/jsxPartialSpread.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c4f07e72f1b..3828e6587be 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23592,7 +23592,7 @@ namespace ts { for (const right of getPropertiesOfType(type)) { const left = props.get(right.escapedName); const rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.Any) && right.flags & SymbolFlags.Optional)) { + if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.AnyOrUnknown) && right.flags & SymbolFlags.Optional)) { const diagnostic = error(left.valueDeclaration, Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, unescapeLeadingUnderscores(left.escapedName)); addRelatedInfo(diagnostic, createDiagnosticForNode(spread, Diagnostics.This_spread_always_overwrites_this_property)); } diff --git a/tests/baselines/reference/jsxPartialSpread.js b/tests/baselines/reference/jsxPartialSpread.js new file mode 100644 index 00000000000..e37b12f7d7a --- /dev/null +++ b/tests/baselines/reference/jsxPartialSpread.js @@ -0,0 +1,26 @@ +//// [jsxPartialSpread.tsx] +/// +const Select = (p: {value?: unknown}) =>

; +import React from 'react'; + +export function Repro({ SelectProps = {} }: { SelectProps?: Partial[0]> }) { + return ( + ); +} +exports.Repro = Repro; diff --git a/tests/baselines/reference/jsxPartialSpread.symbols b/tests/baselines/reference/jsxPartialSpread.symbols new file mode 100644 index 00000000000..7b0a1710649 --- /dev/null +++ b/tests/baselines/reference/jsxPartialSpread.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/jsxPartialSpread.tsx === +/// +const Select = (p: {value?: unknown}) =>

; +>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5)) +>p : Symbol(p, Decl(jsxPartialSpread.tsx, 1, 16)) +>value : Symbol(value, Decl(jsxPartialSpread.tsx, 1, 20)) +>p : Symbol(JSX.IntrinsicElements.p, Decl(react16.d.ts, 2467, 102)) +>p : Symbol(JSX.IntrinsicElements.p, Decl(react16.d.ts, 2467, 102)) + +import React from 'react'; +>React : Symbol(React, Decl(jsxPartialSpread.tsx, 2, 6)) + +export function Repro({ SelectProps = {} }: { SelectProps?: Partial[0]> }) { +>Repro : Symbol(Repro, Decl(jsxPartialSpread.tsx, 2, 26)) +>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 23)) +>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 45)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --)) +>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5)) + + return ( + ) : JSX.Element + + : JSX.Element +>Select : (p: { value?: unknown; }) => JSX.Element +>value : string +>'test' : "test" +>SelectProps : Partial<{ value?: unknown; }> + + ); +} diff --git a/tests/cases/compiler/jsxPartialSpread.tsx b/tests/cases/compiler/jsxPartialSpread.tsx new file mode 100644 index 00000000000..b71ee00e5d9 --- /dev/null +++ b/tests/cases/compiler/jsxPartialSpread.tsx @@ -0,0 +1,12 @@ +// @jsx: preserve +// @esModuleInterop: true +// @strict: true +/// +const Select = (p: {value?: unknown}) =>

; +import React from 'react'; + +export function Repro({ SelectProps = {} }: { SelectProps?: Partial[0]> }) { + return ( +