Skip to content

Commit 27dabe4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix4376_2
# Conflicts: # src/compiler/emitter.ts
2 parents 16e7297 + ea1512e commit 27dabe4

File tree

807 files changed

+18270
-13648
lines changed

Some content is hidden

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

807 files changed

+18270
-13648
lines changed

Jakefile.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ var harnessSources = harnessCoreSources.concat([
141141
"session.ts",
142142
"versionCache.ts",
143143
"convertToBase64.ts",
144-
"transpile.ts"
144+
"transpile.ts",
145+
"reuseProgramStructure.ts",
146+
"cachingInServerLSHost.ts"
145147
].map(function (f) {
146148
return path.join(unittestsDirectory, f);
147149
})).concat([
@@ -155,10 +157,10 @@ var harnessSources = harnessCoreSources.concat([
155157

156158
var librarySourceMap = [
157159
{ target: "lib.core.d.ts", sources: ["core.d.ts"] },
158-
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
159-
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
160+
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
161+
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
160162
{ target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], },
161-
{ target: "lib.d.ts", sources: ["core.d.ts", "extensions.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
163+
{ target: "lib.d.ts", sources: ["core.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
162164
{ target: "lib.core.es6.d.ts", sources: ["core.d.ts", "es6.d.ts"]},
163165
{ target: "lib.es6.d.ts", sources: ["core.d.ts", "es6.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] },
164166
];

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
88

9-
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang).
9+
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [Twitter account](https://twitter.com/typescriptlang).
1010

1111
## Installing
1212

lib/typescript.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,6 @@ declare module "typescript" {
10191019
emitSkipped: boolean;
10201020
diagnostics: Diagnostic[];
10211021
}
1022-
interface TypeCheckerHost {
1023-
getCompilerOptions(): CompilerOptions;
1024-
getSourceFiles(): SourceFile[];
1025-
getSourceFile(fileName: string): SourceFile;
1026-
}
10271022
interface TypeChecker {
10281023
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
10291024
getDeclaredTypeOfSymbol(symbol: Symbol): Type;

lib/typescriptServices.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,6 @@ declare namespace ts {
10191019
emitSkipped: boolean;
10201020
diagnostics: Diagnostic[];
10211021
}
1022-
interface TypeCheckerHost {
1023-
getCompilerOptions(): CompilerOptions;
1024-
getSourceFiles(): SourceFile[];
1025-
getSourceFile(fileName: string): SourceFile;
1026-
}
10271022
interface TypeChecker {
10281023
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
10291024
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
@@ -1450,6 +1445,7 @@ declare namespace ts {
14501445
function getTrailingCommentRanges(text: string, pos: number): CommentRange[];
14511446
function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean;
14521447
function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean;
1448+
function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant: ts.LanguageVariant, text?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner;
14531449
}
14541450
declare namespace ts {
14551451
function getDefaultLibFileName(options: CompilerOptions): string;

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@
4343
"build:compiler": "jake local",
4444
"build:tests": "jake tests",
4545
"clean": "jake clean"
46+
},
47+
"browser": {
48+
"buffer": false,
49+
"fs": false,
50+
"os": false,
51+
"path": false
4652
}
4753
}

src/compiler/checker.ts

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ namespace ts {
388388
return node1.pos <= node2.pos;
389389
}
390390

391-
if (!compilerOptions.out) {
391+
if (!compilerOptions.outFile && !compilerOptions.out) {
392392
return true;
393393
}
394394

@@ -965,28 +965,19 @@ namespace ts {
965965
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
966966
let moduleName = escapeIdentifier(moduleReferenceLiteral.text);
967967

968-
if (!moduleName) return;
968+
if (!moduleName) {
969+
return;
970+
}
969971
let isRelative = isExternalModuleNameRelative(moduleName);
970972
if (!isRelative) {
971973
let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule);
972974
if (symbol) {
973975
return symbol;
974976
}
975977
}
976-
let fileName: string;
977-
let sourceFile: SourceFile;
978-
while (true) {
979-
fileName = normalizePath(combinePaths(searchPath, moduleName));
980-
sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension));
981-
if (sourceFile || isRelative) {
982-
break;
983-
}
984-
let parentPath = getDirectoryPath(searchPath);
985-
if (parentPath === searchPath) {
986-
break;
987-
}
988-
searchPath = parentPath;
989-
}
978+
979+
let fileName = getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text);
980+
let sourceFile = fileName && host.getSourceFile(fileName);
990981
if (sourceFile) {
991982
if (sourceFile.symbol) {
992983
return sourceFile.symbol;
@@ -2175,10 +2166,13 @@ namespace ts {
21752166
function collectLinkedAliases(node: Identifier): Node[] {
21762167
let exportSymbol: Symbol;
21772168
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
2178-
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
2169+
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
21792170
}
21802171
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
2181-
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent);
2172+
let exportSpecifier = <ExportSpecifier>node.parent;
2173+
exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
2174+
getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
2175+
resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
21822176
}
21832177
let result: Node[] = [];
21842178
if (exportSymbol) {
@@ -3131,52 +3125,66 @@ namespace ts {
31313125
setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
31323126
}
31333127

3134-
function findMatchingSignature(signature: Signature, signatureList: Signature[]): Signature {
3135-
for (let s of signatureList) {
3136-
// Only signatures with no type parameters may differ in return types
3137-
if (compareSignatures(signature, s, /*compareReturnTypes*/ !!signature.typeParameters, compareTypes)) {
3128+
function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature {
3129+
for (let s of signatureList) {
3130+
if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
31383131
return s;
31393132
}
31403133
}
31413134
}
31423135

3143-
function findMatchingSignatures(signature: Signature, signatureLists: Signature[][]): Signature[] {
3136+
function findMatchingSignatures(signatureLists: Signature[][], signature: Signature, listIndex: number): Signature[] {
3137+
if (signature.typeParameters) {
3138+
// We require an exact match for generic signatures, so we only return signatures from the first
3139+
// signature list and only if they have exact matches in the other signature lists.
3140+
if (listIndex > 0) {
3141+
return undefined;
3142+
}
3143+
for (let i = 1; i < signatureLists.length; i++) {
3144+
if (!findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ false)) {
3145+
return undefined;
3146+
}
3147+
}
3148+
return [signature];
3149+
}
31443150
let result: Signature[] = undefined;
3145-
for (let i = 1; i < signatureLists.length; i++) {
3146-
let match = findMatchingSignature(signature, signatureLists[i]);
3151+
for (let i = 0; i < signatureLists.length; i++) {
3152+
// Allow matching non-generic signatures to have excess parameters and different return types
3153+
let match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true);
31473154
if (!match) {
31483155
return undefined;
31493156
}
3150-
if (!result) {
3151-
result = [signature];
3152-
}
3153-
if (match !== signature) {
3154-
result.push(match);
3157+
if (!contains(result, match)) {
3158+
(result || (result = [])).push(match);
31553159
}
31563160
}
31573161
return result;
31583162
}
31593163

3160-
// The signatures of a union type are those signatures that are present and identical in each of the
3161-
// constituent types, except that non-generic signatures may differ in return types. When signatures
3162-
// differ in return types, the resulting return type is the union of the constituent return types.
3164+
// The signatures of a union type are those signatures that are present in each of the constituent types.
3165+
// Generic signatures must match exactly, but non-generic signatures are allowed to have extra optional
3166+
// parameters and may differ in return types. When signatures differ in return types, the resulting return
3167+
// type is the union of the constituent return types.
31633168
function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] {
31643169
let signatureLists = map(types, t => getSignaturesOfType(t, kind));
31653170
let result: Signature[] = undefined;
3166-
for (let source of signatureLists[0]) {
3167-
let unionSignatures = findMatchingSignatures(source, signatureLists);
3168-
if (unionSignatures) {
3169-
let signature: Signature = undefined;
3170-
if (unionSignatures.length === 1 || source.typeParameters) {
3171-
signature = source;
3172-
}
3173-
else {
3174-
signature = cloneSignature(source);
3175-
// Clear resolved return type we possibly got from cloneSignature
3176-
signature.resolvedReturnType = undefined;
3177-
signature.unionSignatures = unionSignatures;
3171+
for (let i = 0; i < signatureLists.length; i++) {
3172+
for (let signature of signatureLists[i]) {
3173+
// Only process signatures with parameter lists that aren't already in the result list
3174+
if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true)) {
3175+
let unionSignatures = findMatchingSignatures(signatureLists, signature, i);
3176+
if (unionSignatures) {
3177+
let s = signature;
3178+
// Union the result types when more than one signature matches
3179+
if (unionSignatures.length > 1) {
3180+
s = cloneSignature(signature);
3181+
// Clear resolved return type we possibly got from cloneSignature
3182+
s.resolvedReturnType = undefined;
3183+
s.unionSignatures = unionSignatures;
3184+
}
3185+
(result || (result = [])).push(s);
3186+
}
31783187
}
3179-
(result || (result = [])).push(signature);
31803188
}
31813189
}
31823190
return result || emptyArray;
@@ -5272,7 +5280,7 @@ namespace ts {
52725280
}
52735281
let result = Ternary.True;
52745282
for (let i = 0, len = sourceSignatures.length; i < len; ++i) {
5275-
let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo);
5283+
let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
52765284
if (!related) {
52775285
return Ternary.False;
52785286
}
@@ -5402,14 +5410,18 @@ namespace ts {
54025410
return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
54035411
}
54045412

5405-
function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
5413+
function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
54065414
if (source === target) {
54075415
return Ternary.True;
54085416
}
54095417
if (source.parameters.length !== target.parameters.length ||
54105418
source.minArgumentCount !== target.minArgumentCount ||
54115419
source.hasRestParameter !== target.hasRestParameter) {
5412-
return Ternary.False;
5420+
if (!partialMatch ||
5421+
source.parameters.length < target.parameters.length && !source.hasRestParameter ||
5422+
source.minArgumentCount > target.minArgumentCount) {
5423+
return Ternary.False;
5424+
}
54135425
}
54145426
let result = Ternary.True;
54155427
if (source.typeParameters && target.typeParameters) {
@@ -5431,16 +5443,18 @@ namespace ts {
54315443
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
54325444
source = getErasedSignature(source);
54335445
target = getErasedSignature(target);
5434-
for (let i = 0, len = source.parameters.length; i < len; i++) {
5435-
let s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
5436-
let t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
5446+
let sourceLen = source.parameters.length;
5447+
let targetLen = target.parameters.length;
5448+
for (let i = 0; i < targetLen; i++) {
5449+
let s = source.hasRestParameter && i === sourceLen - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
5450+
let t = target.hasRestParameter && i === targetLen - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
54375451
let related = compareTypes(s, t);
54385452
if (!related) {
54395453
return Ternary.False;
54405454
}
54415455
result &= related;
54425456
}
5443-
if (compareReturnTypes) {
5457+
if (!ignoreReturnTypes) {
54445458
result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
54455459
}
54465460
return result;
@@ -6954,20 +6968,13 @@ namespace ts {
69546968
let signatureList: Signature[];
69556969
let types = (<UnionType>type).types;
69566970
for (let current of types) {
6957-
// The signature set of all constituent type with call signatures should match
6958-
// So number of signatures allowed is either 0 or 1
6959-
if (signatureList &&
6960-
getSignaturesOfStructuredType(current, SignatureKind.Call).length > 1) {
6961-
return undefined;
6962-
}
6963-
69646971
let signature = getNonGenericSignature(current);
69656972
if (signature) {
69666973
if (!signatureList) {
69676974
// This signature will contribute to contextual union signature
69686975
signatureList = [signature];
69696976
}
6970-
else if (!compareSignatures(signatureList[0], signature, /*compareReturnTypes*/ false, compareTypes)) {
6977+
else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) {
69716978
// Signatures aren't identical, do not use
69726979
return undefined;
69736980
}
@@ -13315,7 +13322,7 @@ namespace ts {
1331513322
}
1331613323
}
1331713324
else {
13318-
if (languageVersion >= ScriptTarget.ES6) {
13325+
if (languageVersion >= ScriptTarget.ES6 && !isInAmbientContext(node)) {
1331913326
// Import equals declaration is deprecated in es6 or above
1332013327
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead);
1332113328
}
@@ -13838,7 +13845,11 @@ namespace ts {
1383813845
}
1383913846
break;
1384013847
}
13841-
13848+
13849+
if (introducesArgumentsExoticObject(location)) {
13850+
copySymbol(argumentsSymbol, meaning);
13851+
}
13852+
1384213853
memberFlags = location.flags;
1384313854
location = location.parent;
1384413855
}

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ namespace ts {
120120
{
121121
name: "out",
122122
type: "string",
123+
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
124+
// for correct behaviour, please use outFile
125+
paramType: Diagnostics.FILE,
126+
},
127+
{
128+
name: "outFile",
129+
type: "string",
123130
isFilePath: true,
124131
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
125132
paramType: Diagnostics.FILE,

0 commit comments

Comments
 (0)