Skip to content

Commit e8c7224

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map4
2 parents f73d906 + 9f73ae5 commit e8c7224

29 files changed

Lines changed: 1201 additions & 95 deletions

src/compiler/binder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,9 +2223,9 @@ namespace ts {
22232223
if (currentFlow) {
22242224
node.flowNode = currentFlow;
22252225
}
2226-
checkStrictModeFunctionName(<FunctionExpression>node);
2227-
const bindingName = (<FunctionExpression>node).name ? (<FunctionExpression>node).name.text : "__function";
2228-
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, bindingName);
2226+
checkStrictModeFunctionName(node);
2227+
const bindingName = node.name ? node.name.text : "__function";
2228+
return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName);
22292229
}
22302230

22312231
function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ namespace ts {
972972
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {
973973

974974
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json"
975-
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true }
975+
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true, skipLibCheck: true }
976976
: {};
977977
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
978978
return options;

src/compiler/diagnosticMessages.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3073,13 +3073,40 @@
30733073
"category": "Error",
30743074
"code": 17010
30753075
},
3076-
30773076
"Circularity detected while resolving configuration: {0}": {
30783077
"category": "Error",
30793078
"code": 18000
30803079
},
30813080
"The path in an 'extends' options must be relative or rooted.": {
30823081
"category": "Error",
30833082
"code": 18001
3083+
},
3084+
"Add missing 'super()' call.": {
3085+
"category": "Message",
3086+
"code": 90001
3087+
},
3088+
"Make 'super()' call the first statement in the constructor.": {
3089+
"category": "Message",
3090+
"code": 90002
3091+
},
3092+
"Change 'extends' to 'implements'": {
3093+
"category": "Message",
3094+
"code": 90003
3095+
},
3096+
"Remove unused identifiers": {
3097+
"category": "Message",
3098+
"code": 90004
3099+
},
3100+
"Implement interface on reference": {
3101+
"category": "Message",
3102+
"code": 90005
3103+
},
3104+
"Implement interface on class": {
3105+
"category": "Message",
3106+
"code": 90006
3107+
},
3108+
"Implement inherited abstract class": {
3109+
"category": "Message",
3110+
"code": 90007
30843111
}
30853112
}

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5352,7 +5352,7 @@ namespace ts {
53525352
parseExpected(SyntaxKind.EqualsToken);
53535353
node.type = parseType();
53545354
parseSemicolon();
5355-
return finishNode(node);
5355+
return addJSDocComment(finishNode(node));
53565356
}
53575357

53585358
// In an ambient declaration, the grammar only allows integer literals as initializers.

src/compiler/program.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ namespace ts {
358358
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
359359
const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, host);
360360

361-
if (typeReferences) {
361+
if (typeReferences.length) {
362362
// This containingFilename needs to match with the one used in managed-side
363363
const containingFilename = combinePaths(host.getCurrentDirectory(), "__inferred type names__.ts");
364364
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
@@ -1307,7 +1307,6 @@ namespace ts {
13071307
for (let i = 0; i < moduleNames.length; i++) {
13081308
const resolution = resolutions[i];
13091309
setResolvedModule(file, moduleNames[i], resolution);
1310-
const resolvedPath = resolution ? toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName) : undefined;
13111310

13121311
// add file to program only if:
13131312
// - resolution was successful
@@ -1329,7 +1328,7 @@ namespace ts {
13291328
}
13301329
else if (shouldAddFile) {
13311330
findSourceFile(resolution.resolvedFileName,
1332-
resolvedPath,
1331+
toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName),
13331332
/*isDefaultLib*/ false, /*isReference*/ false,
13341333
file,
13351334
skipTrivia(file.text, file.imports[i].pos),

src/harness/fourslash.ts

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -427,7 +427,7 @@ namespace FourSlash {
427427

428428
if (exists !== negative) {
429429
this.printErrorLog(negative, this.getAllDiagnostics());
430-
throw new Error("Failure between markers: " + startMarkerName + ", " + endMarkerName);
430+
throw new Error(`Failure between markers: '${startMarkerName}', '${endMarkerName}'`);
431431
}
432432
}
433433

@@ -740,7 +740,6 @@ namespace FourSlash {
740740
}
741741
}
742742

743-
744743
public verifyCompletionListAllowsNewIdentifier(negative: boolean) {
745744
const completions = this.getCompletionListAtCaret();
746745

@@ -1610,7 +1609,7 @@ namespace FourSlash {
16101609
if (isFormattingEdit) {
16111610
const newContent = this.getFileContent(fileName);
16121611

1613-
if (newContent.replace(/\s/g, "") !== oldContent.replace(/\s/g, "")) {
1612+
if (this.removeWhitespace(newContent) !== this.removeWhitespace(oldContent)) {
16141613
this.raiseError("Formatting operation destroyed non-whitespace content");
16151614
}
16161615
}
@@ -1676,6 +1675,10 @@ namespace FourSlash {
16761675
}
16771676
}
16781677

1678+
private removeWhitespace(text: string): string {
1679+
return text.replace(/\s/g, "");
1680+
}
1681+
16791682
public goToBOF() {
16801683
this.goToPosition(0);
16811684
}
@@ -2041,6 +2044,47 @@ namespace FourSlash {
20412044
}
20422045
}
20432046

2047+
private getCodeFixes(errorCode?: number) {
2048+
const fileName = this.activeFile.fileName;
2049+
const diagnostics = this.getDiagnostics(fileName);
2050+
2051+
if (diagnostics.length === 0) {
2052+
this.raiseError("Errors expected.");
2053+
}
2054+
2055+
if (diagnostics.length > 1 && errorCode !== undefined) {
2056+
this.raiseError("When there's more than one error, you must specify the errror to fix.");
2057+
}
2058+
2059+
const diagnostic = !errorCode ? diagnostics[0] : ts.find(diagnostics, d => d.code == errorCode);
2060+
2061+
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]);
2062+
}
2063+
2064+
public verifyCodeFixAtPosition(expectedText: string, errorCode?: number) {
2065+
const ranges = this.getRanges();
2066+
if (ranges.length == 0) {
2067+
this.raiseError("At least one range should be specified in the testfile.");
2068+
}
2069+
2070+
const actual = this.getCodeFixes(errorCode);
2071+
2072+
if (!actual || actual.length == 0) {
2073+
this.raiseError("No codefixes returned.");
2074+
}
2075+
2076+
if (actual.length > 1) {
2077+
this.raiseError("More than 1 codefix returned.");
2078+
}
2079+
2080+
this.applyEdits(actual[0].changes[0].fileName, actual[0].changes[0].textChanges, /*isFormattingEdit*/ false);
2081+
const actualText = this.rangeText(ranges[0]);
2082+
2083+
if (this.removeWhitespace(actualText) !== this.removeWhitespace(expectedText)) {
2084+
this.raiseError(`Actual text doesn't match expected text. Actual: '${actualText}' Expected: '${expectedText}'`);
2085+
}
2086+
}
2087+
20442088
public verifyDocCommentTemplate(expected?: ts.TextInsertion) {
20452089
const name = "verifyDocCommentTemplate";
20462090
const actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition);
@@ -2312,6 +2356,18 @@ namespace FourSlash {
23122356
}
23132357
}
23142358

2359+
public verifyCodeFixAvailable(negative: boolean, errorCode?: number) {
2360+
const fixes = this.getCodeFixes(errorCode);
2361+
2362+
if (negative && fixes && fixes.length > 0) {
2363+
this.raiseError(`verifyCodeFixAvailable failed - expected no fixes, actual: ${fixes.length}`);
2364+
}
2365+
2366+
if (!negative && (fixes === undefined || fixes.length === 0)) {
2367+
this.raiseError(`verifyCodeFixAvailable failed - expected code fixes, actual: 0`);
2368+
}
2369+
}
2370+
23152371
// Get the text of the entire line the caret is currently at
23162372
private getCurrentLineContent() {
23172373
const text = this.getFileContent(this.activeFile.fileName);
@@ -3099,6 +3155,10 @@ namespace FourSlashInterface {
30993155
public isValidBraceCompletionAtPosition(openingBrace: string) {
31003156
this.state.verifyBraceCompletionAtPosition(this.negative, openingBrace);
31013157
}
3158+
3159+
public codeFixAvailable(errorCode?: number) {
3160+
this.state.verifyCodeFixAvailable(this.negative, errorCode);
3161+
}
31023162
}
31033163

31043164
export class Verify extends VerifyNegatable {
@@ -3278,6 +3338,10 @@ namespace FourSlashInterface {
32783338
this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true);
32793339
}
32803340

3341+
public codeFixAtPosition(expectedText: string, errorCode?: number): void {
3342+
this.state.verifyCodeFixAtPosition(expectedText, errorCode);
3343+
}
3344+
32813345
public navigationBar(json: any) {
32823346
this.state.verifyNavigationBar(json);
32833347
}

src/harness/harnessLanguageService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ namespace Harness.LanguageService {
486486
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
487487
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));
488488
}
489+
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[]): ts.CodeAction[] {
490+
throw new Error("Not supported on the shim.");
491+
}
489492
getEmitOutput(fileName: string): ts.EmitOutput {
490493
return unwrapJSONCallResult(this.shim.getEmitOutput(fileName));
491494
}

src/harness/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ namespace ts {
405405
allowJs: true,
406406
maxNodeModuleJsDepth: 2,
407407
allowSyntheticDefaultImports: true,
408+
skipLibCheck: true,
408409
module: ModuleKind.CommonJS,
409410
target: ScriptTarget.ES5,
410411
noImplicitAny: false,
@@ -433,6 +434,7 @@ namespace ts {
433434
allowJs: false,
434435
maxNodeModuleJsDepth: 2,
435436
allowSyntheticDefaultImports: true,
437+
skipLibCheck: true,
436438
module: ModuleKind.CommonJS,
437439
target: ScriptTarget.ES5,
438440
noImplicitAny: false,
@@ -456,7 +458,8 @@ namespace ts {
456458
{
457459
allowJs: true,
458460
maxNodeModuleJsDepth: 2,
459-
allowSyntheticDefaultImports: true
461+
allowSyntheticDefaultImports: true,
462+
skipLibCheck: true
460463
},
461464
errors: [{
462465
file: undefined,
@@ -477,7 +480,8 @@ namespace ts {
477480
{
478481
allowJs: true,
479482
maxNodeModuleJsDepth: 2,
480-
allowSyntheticDefaultImports: true
483+
allowSyntheticDefaultImports: true,
484+
skipLibCheck: true
481485
},
482486
errors: <Diagnostic[]>[]
483487
}

0 commit comments

Comments
 (0)