Skip to content

Commit 5ec5815

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: Update user baselines 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) (microsoft#38429) fix(37877): include in NavigationBar default exported child items (microsoft#38255) fix: add missing semi-colon to `__exportStar` unnamed function Update baselines. Add and use the 'intersperse' helper function. Don't add duplicates of JSDoc comments. Added tests for union types with identical doc comments. feat(38225): change diagnostic message for remove braces from arrow function body Add outlining spans for object destructuring elements
2 parents 2e7319b + 5ef2228 commit 5ec5815

File tree

87 files changed

+458
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+458
-187
lines changed

src/compiler/core.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ namespace ts {
129129
return map;
130130
}
131131

132+
/**
133+
* Creates a new array with `element` interspersed in between each element of `input`
134+
* if there is more than 1 value in `input`. Otherwise, returns the existing array.
135+
*/
136+
export function intersperse<T>(input: T[], element: T): T[] {
137+
if (input.length <= 1) {
138+
return input;
139+
}
140+
const result: T[] = [];
141+
for (let i = 0, n = input.length; i < n; i++) {
142+
if (i) result.push(element);
143+
result.push(input[i]);
144+
}
145+
return result;
146+
}
147+
132148
/**
133149
* Iterates through `array` by index and performs the callback on each element of array until the callback
134150
* returns a falsey value, then returns false.

src/compiler/diagnosticMessages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,7 +5657,7 @@
56575657
"category": "Message",
56585658
"code": 95111
56595659
},
5660-
"Remove block body braces": {
5660+
"Remove braces from arrow function body": {
56615661
"category": "Message",
56625662
"code": 95112
56635663
},
@@ -5669,15 +5669,15 @@
56695669
"category": "Message",
56705670
"code": 95114
56715671
},
5672-
"Remove all incorrect body block braces": {
5672+
"Remove braces from all arrow function bodies with relevant issues": {
56735673
"category": "Message",
56745674
"code": 95115
56755675
},
56765676
"Wrap all object literal with parentheses": {
56775677
"category": "Message",
56785678
"code": 95116
56795679
},
5680-
5680+
56815681
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
56825682
"category": "Error",
56835683
"code": 18004

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18871887
text: `
18881888
var __exportStar = (this && this.__exportStar) || function(m, exports) {
18891889
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
1890-
}`
1890+
};`
18911891
};
18921892

18931893
function createExportStarHelper(context: TransformationContext, module: Expression) {

src/server/editorServices.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,9 @@ namespace ts.server {
17431743

17441744
return project?.isSolution() ?
17451745
project.getDefaultChildProjectFromSolution(info) :
1746-
project;
1746+
project && projectContainsInfoDirectly(project, info) ?
1747+
project :
1748+
undefined;
17471749
}
17481750

17491751
/**

src/services/codefixes/returnValueCorrect.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace ts.codefix {
33
const fixId = "returnValueCorrect";
44
const fixIdAddReturnStatement = "fixAddReturnStatement";
5-
const fixIdRemoveBlockBodyBrace = "fixRemoveBlockBodyBrace";
5+
const fixRemoveBracesFromArrowFunctionBody = "fixRemoveBracesFromArrowFunctionBody";
66
const fixIdWrapTheBlockWithParen = "fixWrapTheBlockWithParen";
77
const errorCodes = [
88
Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code,
@@ -35,7 +35,7 @@ namespace ts.codefix {
3535

3636
registerCodeFix({
3737
errorCodes,
38-
fixIds: [fixIdAddReturnStatement, fixIdRemoveBlockBodyBrace, fixIdWrapTheBlockWithParen],
38+
fixIds: [fixIdAddReturnStatement, fixRemoveBracesFromArrowFunctionBody, fixIdWrapTheBlockWithParen],
3939
getCodeActions: context => {
4040
const { program, sourceFile, span: { start }, errorCode } = context;
4141
const info = getInfo(program.getTypeChecker(), sourceFile, start, errorCode);
@@ -44,7 +44,7 @@ namespace ts.codefix {
4444
if (info.kind === ProblemKind.MissingReturnStatement) {
4545
return append(
4646
[getActionForfixAddReturnStatement(context, info.expression, info.statement)],
47-
isArrowFunction(info.declaration) ? getActionForfixRemoveBlockBodyBrace(context, info.declaration, info.expression, info.commentSource): undefined);
47+
isArrowFunction(info.declaration) ? getActionForFixRemoveBracesFromArrowFunctionBody(context, info.declaration, info.expression, info.commentSource): undefined);
4848
}
4949
else {
5050
return [getActionForfixWrapTheBlockWithParen(context, info.declaration, info.expression)];
@@ -58,7 +58,7 @@ namespace ts.codefix {
5858
case fixIdAddReturnStatement:
5959
addReturnStatement(changes, diag.file, info.expression, info.statement);
6060
break;
61-
case fixIdRemoveBlockBodyBrace:
61+
case fixRemoveBracesFromArrowFunctionBody:
6262
if (!isArrowFunction(info.declaration)) return undefined;
6363
removeBlockBodyBrace(changes, diag.file, info.declaration, info.expression, info.commentSource, /* withParen */ false);
6464
break;
@@ -196,9 +196,9 @@ namespace ts.codefix {
196196
return createCodeFixAction(fixId, changes, Diagnostics.Add_a_return_statement, fixIdAddReturnStatement, Diagnostics.Add_all_missing_return_statement);
197197
}
198198

199-
function getActionForfixRemoveBlockBodyBrace(context: CodeFixContext, declaration: ArrowFunction, expression: Expression, commentSource: Node) {
199+
function getActionForFixRemoveBracesFromArrowFunctionBody(context: CodeFixContext, declaration: ArrowFunction, expression: Expression, commentSource: Node) {
200200
const changes = textChanges.ChangeTracker.with(context, t => removeBlockBodyBrace(t, context.sourceFile, declaration, expression, commentSource, /* withParen */ false));
201-
return createCodeFixAction(fixId, changes, Diagnostics.Remove_block_body_braces, fixIdRemoveBlockBodyBrace, Diagnostics.Remove_all_incorrect_body_block_braces);
201+
return createCodeFixAction(fixId, changes, Diagnostics.Remove_braces_from_arrow_function_body, fixRemoveBracesFromArrowFunctionBody, Diagnostics.Remove_braces_from_all_arrow_function_bodies_with_relevant_issues);
202202
}
203203

204204
function getActionForfixWrapTheBlockWithParen(context: CodeFixContext, declaration: ArrowFunction, expression: Expression) {

src/services/jsDoc.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,14 @@ namespace ts.JsDoc {
8989
// Eg. const a: Array<string> | Array<number>; a.length
9090
// The property length will have two declarations of property length coming
9191
// from Array<T> - Array<string> and Array<number>
92-
const documentationComment: SymbolDisplayPart[] = [];
92+
const documentationComment: string[] = [];
9393
forEachUnique(declarations, declaration => {
9494
for (const { comment } of getCommentHavingNodes(declaration)) {
9595
if (comment === undefined) continue;
96-
if (documentationComment.length) {
97-
documentationComment.push(lineBreakPart());
98-
}
99-
documentationComment.push(textPart(comment));
96+
pushIfUnique(documentationComment, comment);
10097
}
10198
});
102-
return documentationComment;
99+
return intersperse(map(documentationComment, textPart), lineBreakPart());
103100
}
104101

105102
function getCommentHavingNodes(declaration: Declaration): readonly (JSDoc | JSDocTag)[] {

src/services/navigationBar.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,18 @@ namespace ts.NavigationBar {
307307
addNodeWithRecursiveChild(node, getInteriorModule(<ModuleDeclaration>node).body);
308308
break;
309309

310-
case SyntaxKind.ExportAssignment:
310+
case SyntaxKind.ExportAssignment: {
311+
const expression = (<ExportAssignment>node).expression;
312+
if (isObjectLiteralExpression(expression)) {
313+
startNode(node);
314+
addChildrenRecursively(expression);
315+
endNode();
316+
}
317+
else {
318+
addLeafNode(node);
319+
}
320+
break;
321+
}
311322
case SyntaxKind.ExportSpecifier:
312323
case SyntaxKind.ImportEqualsDeclaration:
313324
case SyntaxKind.IndexSignature:

src/services/outliningElementsCollector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ namespace ts.OutliningElementsCollector {
200200
case SyntaxKind.EnumDeclaration:
201201
case SyntaxKind.CaseBlock:
202202
case SyntaxKind.TypeLiteral:
203+
case SyntaxKind.ObjectBindingPattern:
203204
return spanForNode(n);
204205
case SyntaxKind.TupleType:
205206
return spanForNode(n, /*autoCollapse*/ false, /*useFullStart*/ !isTupleTypeNode(n.parent), SyntaxKind.OpenBracketToken);

src/testRunner/unittests/tsbuild/watchMode.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace ts.tscWatch {
1515
return ts.createSolutionBuilder(host, rootNames, defaultOptions || {});
1616
}
1717

18+
export function ensureErrorFreeBuild(host: WatchedSystem, rootNames: readonly string[]) {
19+
// ts build should succeed
20+
const solutionBuilder = createSolutionBuilder(host, rootNames, {});
21+
solutionBuilder.build();
22+
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
23+
}
24+
1825
type OutputFileStamp = [string, Date | undefined, boolean];
1926
function transformOutputToOutputFileStamp(f: string, host: TsBuildWatchSystem): OutputFileStamp {
2027
return [f, host.getModifiedTime(f), host.writtenFiles.has(host.toFullPath(f))] as OutputFileStamp;

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,64 @@ declare var console: {
10501050
});
10511051
});
10521052
});
1053+
1054+
it("when default configured project does not contain the file", () => {
1055+
const barConfig: File = {
1056+
path: `${tscWatch.projectRoot}/bar/tsconfig.json`,
1057+
content: "{}"
1058+
};
1059+
const barIndex: File = {
1060+
path: `${tscWatch.projectRoot}/bar/index.ts`,
1061+
content: `import {foo} from "../foo/lib";
1062+
foo();`
1063+
};
1064+
const fooBarConfig: File = {
1065+
path: `${tscWatch.projectRoot}/foobar/tsconfig.json`,
1066+
content: barConfig.path
1067+
};
1068+
const fooBarIndex: File = {
1069+
path: `${tscWatch.projectRoot}/foobar/index.ts`,
1070+
content: barIndex.content
1071+
};
1072+
const fooConfig: File = {
1073+
path: `${tscWatch.projectRoot}/foo/tsconfig.json`,
1074+
content: JSON.stringify({
1075+
include: ["index.ts"],
1076+
compilerOptions: {
1077+
declaration: true,
1078+
outDir: "lib"
1079+
}
1080+
})
1081+
};
1082+
const fooIndex: File = {
1083+
path: `${tscWatch.projectRoot}/foo/index.ts`,
1084+
content: `export function foo() {}`
1085+
};
1086+
const host = createServerHost([barConfig, barIndex, fooBarConfig, fooBarIndex, fooConfig, fooIndex, libFile]);
1087+
tscWatch.ensureErrorFreeBuild(host, [fooConfig.path]);
1088+
const fooDts = `${tscWatch.projectRoot}/foo/lib/index.d.ts`;
1089+
assert.isTrue(host.fileExists(fooDts));
1090+
const session = createSession(host);
1091+
const service = session.getProjectService();
1092+
service.openClientFile(barIndex.path);
1093+
checkProjectActualFiles(service.configuredProjects.get(barConfig.path)!, [barIndex.path, fooDts, libFile.path, barConfig.path]);
1094+
service.openClientFile(fooBarIndex.path);
1095+
checkProjectActualFiles(service.configuredProjects.get(fooBarConfig.path)!, [fooBarIndex.path, fooDts, libFile.path, fooBarConfig.path]);
1096+
service.openClientFile(fooIndex.path);
1097+
checkProjectActualFiles(service.configuredProjects.get(fooConfig.path)!, [fooIndex.path, libFile.path, fooConfig.path]);
1098+
service.openClientFile(fooDts);
1099+
session.executeCommandSeq<protocol.GetApplicableRefactorsRequest>({
1100+
command: protocol.CommandTypes.GetApplicableRefactors,
1101+
arguments: {
1102+
file: fooDts,
1103+
startLine: 1,
1104+
startOffset: 1,
1105+
endLine: 1,
1106+
endOffset: 1
1107+
}
1108+
});
1109+
assert.equal(service.tryGetDefaultProjectForFile(server.toNormalizedPath(fooDts)), service.configuredProjects.get(barConfig.path));
1110+
});
10531111
});
10541112

10551113
describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories listed in config file input array", () => {

0 commit comments

Comments
 (0)