Skip to content

Commit 7c235db

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/TypeScript into bug/32341
2 parents 06d36d6 + 9725d62 commit 7c235db

File tree

88 files changed

+461
-190
lines changed

Some content is hidden

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

88 files changed

+461
-190
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/harness/vfsUtil.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,14 @@ namespace vfs {
649649
*
650650
* NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module.
651651
*/
652-
public readFileSync(path: string, encoding: string): string;
652+
public readFileSync(path: string, encoding: BufferEncoding): string;
653653
/**
654654
* Read from a file.
655655
*
656656
* NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module.
657657
*/
658-
public readFileSync(path: string, encoding?: string | null): string | Buffer;
659-
public readFileSync(path: string, encoding: string | null = null) { // eslint-disable-line no-null/no-null
658+
public readFileSync(path: string, encoding?: BufferEncoding | null): string | Buffer;
659+
public readFileSync(path: string, encoding: BufferEncoding | null = null) { // eslint-disable-line no-null/no-null
660660
const { node } = this._walk(this._resolve(path));
661661
if (!node) throw createIOError("ENOENT");
662662
if (isDirectory(node)) throw createIOError("EISDIR");

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", () => {

src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,7 @@ ${appendDts}`
469469
const host = createServerHost([libFile, tsbaseJson, buttonConfig, buttonSource, siblingConfig, siblingSource], { useCaseSensitiveFileNames: true });
470470

471471
// ts build should succeed
472-
const solutionBuilder = tscWatch.createSolutionBuilder(host, [siblingConfig.path], {});
473-
solutionBuilder.build();
474-
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
472+
tscWatch.ensureErrorFreeBuild(host, [siblingConfig.path]);
475473
const sourceJs = changeExtension(siblingSource.path, ".js");
476474
const expectedSiblingJs = host.readFile(sourceJs);
477475

src/testRunner/unittests/tsserver/projectReferences.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ namespace ts.projectSystem {
22
describe("unittests:: tsserver:: with project references and tsbuild", () => {
33
function createHost(files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], rootNames: readonly string[]) {
44
const host = createServerHost(files);
5-
65
// ts build should succeed
7-
const solutionBuilder = tscWatch.createSolutionBuilder(host, rootNames, {});
8-
solutionBuilder.build();
9-
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
10-
6+
tscWatch.ensureErrorFreeBuild(host, rootNames);
117
return host;
128
}
139

tests/baselines/reference/ambientShorthand_reExport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
3939
}));
4040
var __exportStar = (this && this.__exportStar) || function(m, exports) {
4141
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
42-
}
42+
};
4343
exports.__esModule = true;
4444
__exportStar(require("jquery"), exports);
4545
//// [reExportUser.js]

tests/baselines/reference/declarationEmitAliasExportStar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
2323
}));
2424
var __exportStar = (this && this.__exportStar) || function(m, exports) {
2525
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
26-
}
26+
};
2727
exports.__esModule = true;
2828
__exportStar(require("./thingB"), exports);
2929
//// [index.js]

tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6666
}));
6767
var __exportStar = (this && this.__exportStar) || function(m, exports) {
6868
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
69-
}
69+
};
7070
exports.__esModule = true;
7171
__exportStar(require("@emotion/core"), exports);
7272

tests/baselines/reference/declarationEmitReexportedSymlinkReference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6060
}));
6161
var __exportStar = (this && this.__exportStar) || function(m, exports) {
6262
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
63-
}
63+
};
6464
Object.defineProperty(exports, "__esModule", { value: true });
6565
__exportStar(require("./keys"), exports);
6666

tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6363
}));
6464
var __exportStar = (this && this.__exportStar) || function(m, exports) {
6565
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
66-
}
66+
};
6767
Object.defineProperty(exports, "__esModule", { value: true });
6868
__exportStar(require("./keys"), exports);
6969

tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6060
}));
6161
var __exportStar = (this && this.__exportStar) || function(m, exports) {
6262
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
63-
}
63+
};
6464
Object.defineProperty(exports, "__esModule", { value: true });
6565
__exportStar(require("./keys"), exports);
6666

0 commit comments

Comments
 (0)