Skip to content

Commit 5f91b3c

Browse files
authored
[Transforms] merging "master" on 06/15/2016 (#9218)
* Add upper limit for the program size, fix readDirectory for the symlink files * Add comments * CR feedback / Change upper limit / Add disableSizeLimit compiler option * online and offline CR feedback * Don't count current opened client file if it's TS file * Speed up file searching * Make language service optional for a project * Fix failed tests * Fix project updateing issue after editing config file * Fix merging issues and multiple project scenario * Refactoring * add test and spit commandLineParser changes to another PR * Fix #8523 * check the declaration and use order if both are not in module file * Fix #9098: report missing function impelementation errors for merged classes and namespaces * Added tests. * Accepted baselines. * Check tuple types when getting the type node's type. * Accepted baselines. * Fix #9173: clear out lib and types before creating a program in transpileModule * Added tests. * Accepted baselines. * Always check type assertion types. * Accepted baselines. * Use helper functions to simplify range tests * Remove String, Number, and Boolean from TypeFlags.Falsy * Add regression test * Accept new baselines * Allow property declarations in .js files * Remove old test * Refactor code to make if statements cheaper * Fix test failure from mergining with master
1 parent a766005 commit 5f91b3c

File tree

119 files changed

+1387
-786
lines changed

Some content is hidden

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

119 files changed

+1387
-786
lines changed

Diff for: src/compiler/checker.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ namespace ts {
560560
const declarationFile = getSourceFileOfNode(declaration);
561561
const useFile = getSourceFileOfNode(usage);
562562
if (declarationFile !== useFile) {
563-
if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) {
563+
if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
564+
(!compilerOptions.outFile && !compilerOptions.out)) {
564565
// nodes are in different files and order cannot be determines
565566
return true;
566567
}
@@ -11529,7 +11530,10 @@ namespace ts {
1152911530

1153011531
function checkAssertion(node: AssertionExpression) {
1153111532
const exprType = getRegularTypeOfObjectLiteral(checkExpression(node.expression));
11533+
11534+
checkSourceElement(node.type);
1153211535
const targetType = getTypeFromTypeNode(node.type);
11536+
1153311537
if (produceDiagnostics && targetType !== unknownType) {
1153411538
const widenedType = getWidenedType(exprType);
1153511539
if (!isTypeComparableTo(targetType, widenedType)) {
@@ -13564,9 +13568,6 @@ namespace ts {
1356413568
}
1356513569
}
1356613570

13567-
// when checking exported function declarations across modules check only duplicate implementations
13568-
// names and consistency of modifiers are verified when we check local symbol
13569-
const isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
1357013571
let duplicateFunctionDeclaration = false;
1357113572
let multipleConstructorImplementation = false;
1357213573
for (const current of declarations) {
@@ -13599,7 +13600,7 @@ namespace ts {
1359913600
duplicateFunctionDeclaration = true;
1360013601
}
1360113602
}
13602-
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
13603+
else if (previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
1360313604
reportImplementationExpectedError(previousDeclaration);
1360413605
}
1360513606

@@ -13633,8 +13634,8 @@ namespace ts {
1363313634
}
1363413635

1363513636
// Abstract methods can't have an implementation -- in particular, they don't need one.
13636-
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
13637-
!hasModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) {
13637+
if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
13638+
!(getModifierFlags(lastSeenNonAmbientDeclaration) & ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) {
1363813639
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
1363913640
}
1364013641

Diff for: src/compiler/commandLineParser.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ namespace ts {
417417
},
418418
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon
419419
},
420+
{
421+
name: "disableProjectSizeLimit",
422+
type: "boolean"
423+
},
420424
{
421425
name: "strictNullChecks",
422426
type: "boolean",
@@ -771,8 +775,10 @@ namespace ts {
771775
}
772776
}
773777

774-
filesSeen[fileName] = true;
775-
fileNames.push(fileName);
778+
if (!filesSeen[fileName]) {
779+
filesSeen[fileName] = true;
780+
fileNames.push(fileName);
781+
}
776782
}
777783
}
778784
}

Diff for: src/compiler/diagnosticMessages.json

-4
Original file line numberDiff line numberDiff line change
@@ -2925,10 +2925,6 @@
29252925
"category": "Error",
29262926
"code": 8012
29272927
},
2928-
"'property declarations' can only be used in a .ts file.": {
2929-
"category": "Error",
2930-
"code": 8014
2931-
},
29322928
"'enum declarations' can only be used in a .ts file.": {
29332929
"category": "Error",
29342930
"code": 8015

Diff for: src/compiler/program.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,19 @@ namespace ts {
15981598
}
15991599
break;
16001600
case SyntaxKind.PropertyDeclaration:
1601-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.property_declarations_can_only_be_used_in_a_ts_file));
1602-
return true;
1601+
const propertyDeclaration = <PropertyDeclaration>node;
1602+
if (propertyDeclaration.modifiers) {
1603+
for (const modifier of propertyDeclaration.modifiers) {
1604+
if (modifier.kind !== SyntaxKind.StaticKeyword) {
1605+
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
1606+
return true;
1607+
}
1608+
}
1609+
}
1610+
if (checkTypeAnnotation((<PropertyDeclaration>node).type)) {
1611+
return true;
1612+
}
1613+
break;
16031614
case SyntaxKind.EnumDeclaration:
16041615
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
16051616
return true;

Diff for: src/compiler/sys.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace ts {
1515
useCaseSensitiveFileNames: boolean;
1616
write(s: string): void;
1717
readFile(path: string, encoding?: string): string;
18+
getFileSize?(path: string): number;
1819
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
1920
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
2021
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
@@ -82,7 +83,7 @@ namespace ts {
8283
getEnvironmentVariable?(name: string): string;
8384
};
8485

85-
export var sys: System = (function () {
86+
export var sys: System = (function() {
8687

8788
function getWScriptSystem(): System {
8889

@@ -509,7 +510,7 @@ namespace ts {
509510
}
510511
);
511512
},
512-
resolvePath: function (path: string): string {
513+
resolvePath: function(path: string): string {
513514
return _path.resolve(path);
514515
},
515516
fileExists,
@@ -549,6 +550,16 @@ namespace ts {
549550
}
550551
return process.memoryUsage().heapUsed;
551552
},
553+
getFileSize(path) {
554+
try {
555+
const stat = _fs.statSync(path);
556+
if (stat.isFile()) {
557+
return stat.size;
558+
}
559+
}
560+
catch (e) { }
561+
return 0;
562+
},
552563
exit(exitCode?: number): void {
553564
process.exit(exitCode);
554565
},

Diff for: src/compiler/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,8 @@ namespace ts {
22932293

22942294
/* @internal */
22952295
Nullable = Undefined | Null,
2296-
Falsy = String | Number | Boolean | Void | Undefined | Null,
2296+
/* @internal */
2297+
Falsy = Void | Undefined | Null, // TODO: Add false, 0, and ""
22972298
/* @internal */
22982299
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null | Never,
22992300
/* @internal */
@@ -2632,6 +2633,7 @@ namespace ts {
26322633
/* @internal */ suppressOutputPathCheck?: boolean;
26332634
target?: ScriptTarget;
26342635
traceResolution?: boolean;
2636+
disableSizeLimit?: boolean;
26352637
types?: string[];
26362638
/** Paths used to used to compute primary types search locations */
26372639
typeRoots?: string[];

Diff for: src/compiler/utilities.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,10 @@ namespace ts {
30943094
return forEach(supportedJavascriptExtensions, extension => fileExtensionIs(fileName, extension));
30953095
}
30963096

3097+
export function hasTypeScriptFileExtension(fileName: string) {
3098+
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
3099+
}
3100+
30973101
/**
30983102
* Replace each instance of non-ascii characters by one, two, three, or four escape sequences
30993103
* representing the UTF-8 encoding of the character, and return the expanded char code list.

Diff for: src/harness/fourslash.ts

+82-31
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,78 @@ namespace FourSlash {
730730
}
731731
}
732732

733-
public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) {
733+
public verifyReferencesCountIs(count: number, localFilesOnly = true) {
734734
const references = this.getReferencesAtCaret();
735+
let referencesCount = 0;
736+
737+
if (localFilesOnly) {
738+
const localFiles = this.testData.files.map<string>(file => file.fileName);
739+
// Count only the references in local files. Filter the ones in lib and other files.
740+
ts.forEach(references, entry => {
741+
if (localFiles.some((fileName) => fileName === entry.fileName)) {
742+
referencesCount++;
743+
}
744+
});
745+
}
746+
else {
747+
referencesCount = references && references.length || 0;
748+
}
749+
750+
if (referencesCount !== count) {
751+
const condition = localFilesOnly ? "excluding libs" : "including libs";
752+
this.raiseError("Expected references count (" + condition + ") to be " + count + ", but is actually " + referencesCount);
753+
}
754+
}
755+
756+
public verifyReferencesAre(expectedReferences: Range[]) {
757+
const actualReferences = this.getReferencesAtCaret() || [];
758+
759+
if (actualReferences.length > expectedReferences.length) {
760+
// Find the unaccounted-for reference.
761+
for (const actual of actualReferences) {
762+
if (!ts.forEach(expectedReferences, r => r.start === actual.textSpan.start)) {
763+
this.raiseError(`A reference ${actual} is unaccounted for.`);
764+
}
765+
}
766+
// Probably will never reach here.
767+
this.raiseError(`There are ${actualReferences.length} references but only ${expectedReferences.length} were expected.`);
768+
}
769+
770+
for (const reference of expectedReferences) {
771+
const {fileName, start, end} = reference;
772+
if (reference.marker) {
773+
const {isWriteAccess, isDefinition} = reference.marker.data;
774+
this.verifyReferencesWorker(actualReferences, fileName, start, end, isWriteAccess, isDefinition);
775+
}
776+
else {
777+
this.verifyReferencesWorker(actualReferences, fileName, start, end);
778+
}
779+
}
780+
}
781+
782+
public verifyReferencesOf({fileName, start}: Range, references: Range[]) {
783+
this.openFile(fileName);
784+
this.goToPosition(start);
785+
this.verifyReferencesAre(references);
786+
}
735787

788+
public verifyRangesReferenceEachOther(ranges?: Range[]) {
789+
ranges = ranges || this.getRanges();
790+
assert(ranges.length);
791+
for (const range of ranges) {
792+
this.verifyReferencesOf(range, ranges);
793+
}
794+
}
795+
796+
public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) {
797+
const references = this.getReferencesAtCaret();
736798
if (!references || references.length === 0) {
737799
this.raiseError("verifyReferencesAtPositionListContains failed - found 0 references, expected at least one.");
738800
}
801+
this.verifyReferencesWorker(references, fileName, start, end, isWriteAccess, isDefinition);
802+
}
739803

804+
private verifyReferencesWorker(references: ts.ReferenceEntry[], fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) {
740805
for (let i = 0; i < references.length; i++) {
741806
const reference = references[i];
742807
if (reference && reference.fileName === fileName && reference.textSpan.start === start && ts.textSpanEnd(reference.textSpan) === end) {
@@ -752,29 +817,7 @@ namespace FourSlash {
752817

753818
const missingItem = { fileName, start, end, isWriteAccess, isDefinition };
754819
this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(references)})`);
755-
}
756-
757-
public verifyReferencesCountIs(count: number, localFilesOnly = true) {
758-
const references = this.getReferencesAtCaret();
759-
let referencesCount = 0;
760-
761-
if (localFilesOnly) {
762-
const localFiles = this.testData.files.map<string>(file => file.fileName);
763-
// Count only the references in local files. Filter the ones in lib and other files.
764-
ts.forEach(references, entry => {
765-
if (localFiles.some((fileName) => fileName === entry.fileName)) {
766-
referencesCount++;
767-
}
768-
});
769-
}
770-
else {
771-
referencesCount = references && references.length || 0;
772-
}
773820

774-
if (referencesCount !== count) {
775-
const condition = localFilesOnly ? "excluding libs" : "including libs";
776-
this.raiseError("Expected references count (" + condition + ") to be " + count + ", but is actually " + referencesCount);
777-
}
778821
}
779822

780823
private getMemberListAtCaret() {
@@ -2836,14 +2879,6 @@ namespace FourSlashInterface {
28362879
this.state.verifyMemberListIsEmpty(this.negative);
28372880
}
28382881

2839-
public referencesCountIs(count: number) {
2840-
this.state.verifyReferencesCountIs(count, /*localFilesOnly*/ false);
2841-
}
2842-
2843-
public referencesAtPositionContains(range: FourSlash.Range, isWriteAccess?: boolean, isDefinition?: boolean) {
2844-
this.state.verifyReferencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess, isDefinition);
2845-
}
2846-
28472882
public signatureHelpPresent() {
28482883
this.state.verifySignatureHelpPresent(!this.negative);
28492884
}
@@ -2935,6 +2970,22 @@ namespace FourSlashInterface {
29352970
this.state.verifyGetEmitOutputContentsForCurrentFile(expected);
29362971
}
29372972

2973+
public referencesCountIs(count: number) {
2974+
this.state.verifyReferencesCountIs(count, /*localFilesOnly*/ false);
2975+
}
2976+
2977+
public referencesAre(ranges: FourSlash.Range[]) {
2978+
this.state.verifyReferencesAre(ranges);
2979+
}
2980+
2981+
public referencesOf(start: FourSlash.Range, references: FourSlash.Range[]) {
2982+
this.state.verifyReferencesOf(start, references);
2983+
}
2984+
2985+
public rangesReferenceEachOther(ranges?: FourSlash.Range[]) {
2986+
this.state.verifyRangesReferenceEachOther(ranges);
2987+
}
2988+
29382989
public currentParameterHelpArgumentNameIs(name: string) {
29392990
this.state.verifyCurrentParameterHelpName(name);
29402991
}

0 commit comments

Comments
 (0)