Skip to content

Commit 0130c23

Browse files
committed
Merge remote-tracking branch 'origin/master' into pathMappingModuleResolution
2 parents 9a9b51f + 3a4ac33 commit 0130c23

175 files changed

Lines changed: 1850 additions & 284 deletions

File tree

Some content is hidden

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

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ Your pull request should:
3636

3737
The library sources are in: [src/lib](https://github.com/Microsoft/TypeScript/tree/master/src/lib)
3838

39-
To build the library files, run
39+
Library files in `built/local/` are updated by running
4040
```Shell
41-
jake lib
41+
jake
4242
```
4343

44+
The files in `lib/` are used to bootstrap compilation and usually do not need to be updated.
45+
4446
#### `src/lib/dom.generated.d.ts` and `src/lib/webworker.generated.d.ts`
4547

4648
These two files represent the DOM typings and are auto-generated. To make any modifications to them, please submit a PR to https://github.com/Microsoft/TSJS-lib-generator
-662 Bytes
Binary file not shown.
936 Bytes
Binary file not shown.

doc/spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ x = "hello"; // Ok
13231323
x = 42; // Ok
13241324
x = test; // Error, boolean not assignable
13251325
x = test ? 5 : "five"; // Ok
1326-
x = test ? 0 : false; // Error, number | boolean not asssignable
1326+
x = test ? 0 : false; // Error, number | boolean not assignable
13271327
```
13281328

13291329
it is possible to assign 'x' a value of type `string`, `number`, or the union type `string | number`, but not any other type. To access a value in 'x', a type guard can be used to first narrow the type of 'x' to either `string` or `number`:

lib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Read this!
22

33
These files are not meant to be edited by hand.
4-
If you need to make modifications, the respective files should be changed within the repository's top-level `src` directory.
4+
If you need to make modifications, the respective files should be changed within the repository's top-level `src` directory. Running `jake LKG` will then appropriately update the files in this directory.

src/compiler/checker.ts

Lines changed: 63 additions & 51 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,10 @@
17321732
"category": "Error",
17331733
"code": 2657
17341734
},
1735+
"Type '{0}' provides no match for the signature '{1}'": {
1736+
"category": "Error",
1737+
"code": 2658
1738+
},
17351739
"Import declaration '{0}' is using private name '{1}'.": {
17361740
"category": "Error",
17371741
"code": 4000

src/compiler/emitter.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3628,12 +3628,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
36283628
// only allow export default at a source file level
36293629
if (modulekind === ModuleKind.CommonJS || modulekind === ModuleKind.AMD || modulekind === ModuleKind.UMD) {
36303630
if (!isEs6Module) {
3631-
if (languageVersion === ScriptTarget.ES5) {
3631+
if (languageVersion !== ScriptTarget.ES3) {
36323632
// default value of configurable, enumerable, writable are `false`.
36333633
write("Object.defineProperty(exports, \"__esModule\", { value: true });");
36343634
writeLine();
36353635
}
3636-
else if (languageVersion === ScriptTarget.ES3) {
3636+
else {
36373637
write("exports.__esModule = true;");
36383638
writeLine();
36393639
}
@@ -5171,36 +5171,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
51715171
if (!(node.flags & NodeFlags.Export)) {
51725172
return;
51735173
}
5174-
// If this is an exported class, but not on the top level (i.e. on an internal
5175-
// module), export it
5176-
if (node.flags & NodeFlags.Default) {
5177-
// if this is a top level default export of decorated class, write the export after the declaration.
5178-
writeLine();
5179-
if (thisNodeIsDecorated && modulekind === ModuleKind.ES6) {
5180-
write("export default ");
5181-
emitDeclarationName(node);
5182-
write(";");
5183-
}
5184-
else if (modulekind === ModuleKind.System) {
5185-
write(`${exportFunctionForFile}("default", `);
5186-
emitDeclarationName(node);
5187-
write(");");
5174+
if (modulekind !== ModuleKind.ES6) {
5175+
emitExportMemberAssignment(node as ClassDeclaration);
5176+
}
5177+
else {
5178+
// If this is an exported class, but not on the top level (i.e. on an internal
5179+
// module), export it
5180+
if (node.flags & NodeFlags.Default) {
5181+
// if this is a top level default export of decorated class, write the export after the declaration.
5182+
if (thisNodeIsDecorated) {
5183+
writeLine();
5184+
write("export default ");
5185+
emitDeclarationName(node);
5186+
write(";");
5187+
}
51885188
}
5189-
else if (modulekind !== ModuleKind.ES6) {
5190-
write(`exports.default = `);
5189+
else if (node.parent.kind !== SyntaxKind.SourceFile) {
5190+
writeLine();
5191+
emitStart(node);
5192+
emitModuleMemberName(node);
5193+
write(" = ");
51915194
emitDeclarationName(node);
5195+
emitEnd(node);
51925196
write(";");
51935197
}
51945198
}
5195-
else if (node.parent.kind !== SyntaxKind.SourceFile || (modulekind !== ModuleKind.ES6 && !(node.flags & NodeFlags.Default))) {
5196-
writeLine();
5197-
emitStart(node);
5198-
emitModuleMemberName(node);
5199-
write(" = ");
5200-
emitDeclarationName(node);
5201-
emitEnd(node);
5202-
write(";");
5203-
}
52045199
}
52055200

52065201
function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {

src/compiler/program.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,19 +1030,17 @@ namespace ts {
10301030
}
10311031

10321032
function getSemanticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
1033-
// For JavaScript files, we don't want to report the normal typescript semantic errors.
1034-
// Instead, we just report errors for using TypeScript-only constructs from within a
1035-
// JavaScript file.
1036-
if (isSourceFileJavaScript(sourceFile)) {
1037-
return getJavaScriptSemanticDiagnosticsForFile(sourceFile, cancellationToken);
1038-
}
1039-
10401033
return runWithCancellationToken(() => {
10411034
const typeChecker = getDiagnosticsProducingTypeChecker();
10421035

10431036
Debug.assert(!!sourceFile.bindDiagnostics);
10441037
const bindDiagnostics = sourceFile.bindDiagnostics;
1045-
const checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken);
1038+
// For JavaScript files, we don't want to report the normal typescript semantic errors.
1039+
// Instead, we just report errors for using TypeScript-only constructs from within a
1040+
// JavaScript file.
1041+
const checkDiagnostics = isSourceFileJavaScript(sourceFile) ?
1042+
getJavaScriptSemanticDiagnosticsForFile(sourceFile, cancellationToken) :
1043+
typeChecker.getDiagnostics(sourceFile, cancellationToken);
10461044
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
10471045
const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);
10481046

@@ -1448,6 +1446,8 @@ namespace ts {
14481446
const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end);
14491447

14501448
if (importedFile && resolution.isExternalLibraryImport) {
1449+
// Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files,
1450+
// this check is ok. Otherwise this would be never true for javascript file
14511451
if (!isExternalModule(importedFile)) {
14521452
const start = getTokenPosOfNode(file.imports[i], file);
14531453
fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName));

src/compiler/sys.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ namespace ts {
4747
constructor(o: any);
4848
}
4949

50+
declare var ChakraHost: {
51+
args: string[];
52+
currentDirectory: string;
53+
executingFile: string;
54+
echo(s: string): void;
55+
quit(exitCode?: number): void;
56+
fileExists(path: string): boolean;
57+
directoryExists(path: string): boolean;
58+
createDirectory(path: string): void;
59+
resolvePath(path: string): string;
60+
readFile(path: string): string;
61+
writeFile(path: string, contents: string): void;
62+
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
63+
};
64+
5065
export var sys: System = (function () {
5166

5267
function getWScriptSystem(): System {
@@ -194,6 +209,7 @@ namespace ts {
194209
}
195210
};
196211
}
212+
197213
function getNodeSystem(): System {
198214
const _fs = require("fs");
199215
const _path = require("path");
@@ -281,7 +297,7 @@ namespace ts {
281297
// REVIEW: for now this implementation uses polling.
282298
// The advantage of polling is that it works reliably
283299
// on all os and with network mounted files.
284-
// For 90 referenced files, the average time to detect
300+
// For 90 referenced files, the average time to detect
285301
// changes is 2*msInterval (by default 5 seconds).
286302
// The overhead of this is .04 percent (1/2500) with
287303
// average pause of < 1 millisecond (and max
@@ -406,7 +422,7 @@ namespace ts {
406422
};
407423
},
408424
watchDirectory: (path, callback, recursive) => {
409-
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
425+
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
410426
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
411427
return _fs.watch(
412428
path,
@@ -454,6 +470,37 @@ namespace ts {
454470
}
455471
};
456472
}
473+
474+
function getChakraSystem(): System {
475+
476+
return {
477+
newLine: "\r\n",
478+
args: ChakraHost.args,
479+
useCaseSensitiveFileNames: false,
480+
write: ChakraHost.echo,
481+
readFile(path: string, encoding?: string) {
482+
// encoding is automatically handled by the implementation in ChakraHost
483+
return ChakraHost.readFile(path);
484+
},
485+
writeFile(path: string, data: string, writeByteOrderMark?: boolean) {
486+
// If a BOM is required, emit one
487+
if (writeByteOrderMark) {
488+
data = "\uFEFF" + data;
489+
}
490+
491+
ChakraHost.writeFile(path, data);
492+
},
493+
resolvePath: ChakraHost.resolvePath,
494+
fileExists: ChakraHost.fileExists,
495+
directoryExists: ChakraHost.directoryExists,
496+
createDirectory: ChakraHost.createDirectory,
497+
getExecutingFilePath: () => ChakraHost.executingFile,
498+
getCurrentDirectory: () => ChakraHost.currentDirectory,
499+
readDirectory: ChakraHost.readDirectory,
500+
exit: ChakraHost.quit,
501+
};
502+
}
503+
457504
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
458505
return getWScriptSystem();
459506
}
@@ -462,8 +509,13 @@ namespace ts {
462509
// process.browser check excludes webpack and browserify
463510
return getNodeSystem();
464511
}
512+
else if (typeof ChakraHost !== "undefined") {
513+
return getChakraSystem();
514+
}
465515
else {
466516
return undefined; // Unsupported host
467517
}
468518
})();
469519
}
520+
521+

0 commit comments

Comments
 (0)