Skip to content

Commit c52c6e8

Browse files
committed
Merge branch 'master' into tscJsFiles
2 parents 1ae1464 + d703e09 commit c52c6e8

File tree

259 files changed

+14458
-666
lines changed

Some content is hidden

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

259 files changed

+14458
-666
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22

33
node_js:
4+
- '4'
45
- '0.10'
56

6-
sudo: false
7+
sudo: false

lib/lib.core.es6.d.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,34 +3965,7 @@ interface ObjectConstructor {
39653965
* Copy the values of all of the enumerable own properties from one or more source objects to a
39663966
* target object. Returns the target object.
39673967
* @param target The target object to copy to.
3968-
* @param source The source object from which to copy properties.
3969-
*/
3970-
assign<T, U>(target: T, source: U): T & U;
3971-
3972-
/**
3973-
* Copy the values of all of the enumerable own properties from one or more source objects to a
3974-
* target object. Returns the target object.
3975-
* @param target The target object to copy to.
3976-
* @param source1 The first source object from which to copy properties.
3977-
* @param source2 The second source object from which to copy properties.
3978-
*/
3979-
assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
3980-
3981-
/**
3982-
* Copy the values of all of the enumerable own properties from one or more source objects to a
3983-
* target object. Returns the target object.
3984-
* @param target The target object to copy to.
3985-
* @param source1 The first source object from which to copy properties.
3986-
* @param source2 The second source object from which to copy properties.
3987-
* @param source3 The third source object from which to copy properties.
3988-
*/
3989-
assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
3990-
3991-
/**
3992-
* Copy the values of all of the enumerable own properties from one or more source objects to a
3993-
* target object. Returns the target object.
3994-
* @param target The target object to copy to.
3995-
* @param sources One or more source objects from which to copy properties
3968+
* @param sources One or more source objects to copy properties from.
39963969
*/
39973970
assign(target: any, ...sources: any[]): any;
39983971

src/compiler/checker.ts

Lines changed: 73 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,72 @@ namespace ts {
383383
// return undefined if we can't find a symbol.
384384
}
385385

386-
/** Returns true if node1 is defined before node 2**/
387-
function isDefinedBefore(node1: Node, node2: Node): boolean {
388-
let file1 = getSourceFileOfNode(node1);
389-
let file2 = getSourceFileOfNode(node2);
390-
if (file1 === file2) {
391-
return node1.pos <= node2.pos;
386+
function isBlockScopedNameDeclaredBeforeUse(declaration: Declaration, usage: Node): boolean {
387+
const declarationFile = getSourceFileOfNode(declaration);
388+
const useFile = getSourceFileOfNode(usage);
389+
if (declarationFile !== useFile) {
390+
if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) {
391+
// nodes are in different files and order cannot be determines
392+
return true;
393+
}
394+
395+
const sourceFiles = host.getSourceFiles();
396+
return indexOf(sourceFiles, declarationFile) <= indexOf(sourceFiles, useFile);
392397
}
393398

394-
if (!compilerOptions.outFile && !compilerOptions.out) {
395-
return true;
399+
if (declaration.pos <= usage.pos) {
400+
// declaration is before usage
401+
// still might be illegal if usage is in the initializer of the variable declaration
402+
return declaration.kind !== SyntaxKind.VariableDeclaration ||
403+
!isImmediatelyUsedInInitializerOfBlockScopedVariable(<VariableDeclaration>declaration, usage);
404+
}
405+
406+
// declaration is after usage
407+
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
408+
return isUsedInFunctionOrNonStaticProperty(declaration, usage);
409+
410+
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
411+
const container = getEnclosingBlockScopeContainer(declaration);
412+
413+
if (declaration.parent.parent.kind === SyntaxKind.VariableStatement ||
414+
declaration.parent.parent.kind === SyntaxKind.ForStatement) {
415+
// variable statement/for statement case,
416+
// use site should not be inside variable declaration (initializer of declaration or binding element)
417+
return isSameScopeDescendentOf(usage, declaration, container);
418+
}
419+
else if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement ||
420+
declaration.parent.parent.kind === SyntaxKind.ForInStatement) {
421+
// ForIn/ForOf case - use site should not be used in expression part
422+
let expression = (<ForInStatement | ForOfStatement>declaration.parent.parent).expression;
423+
return isSameScopeDescendentOf(usage, expression, container);
424+
}
396425
}
397426

398-
let sourceFiles = host.getSourceFiles();
399-
return indexOf(sourceFiles, file1) <= indexOf(sourceFiles, file2);
427+
function isUsedInFunctionOrNonStaticProperty(declaration: Declaration, usage: Node): boolean {
428+
const container = getEnclosingBlockScopeContainer(declaration);
429+
let current = usage;
430+
while (current) {
431+
if (current === container) {
432+
return false;
433+
}
434+
435+
if (isFunctionLike(current)) {
436+
return true;
437+
}
438+
439+
const initializerOfNonStaticProperty = current.parent &&
440+
current.parent.kind === SyntaxKind.PropertyDeclaration &&
441+
(current.parent.flags & NodeFlags.Static) === 0 &&
442+
(<PropertyDeclaration>current.parent).initializer === current;
443+
444+
if (initializerOfNonStaticProperty) {
445+
return true;
446+
}
447+
448+
current = current.parent;
449+
}
450+
return false;
451+
}
400452
}
401453

402454
// Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
@@ -627,34 +679,7 @@ namespace ts {
627679

628680
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
629681

630-
// first check if usage is lexically located after the declaration
631-
let isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
632-
if (!isUsedBeforeDeclaration) {
633-
// lexical check succeeded however code still can be illegal.
634-
// - block scoped variables cannot be used in its initializers
635-
// let x = x; // illegal but usage is lexically after definition
636-
// - in ForIn/ForOf statements variable cannot be contained in expression part
637-
// for (let x in x)
638-
// for (let x of x)
639-
640-
// climb up to the variable declaration skipping binding patterns
641-
let variableDeclaration = <VariableDeclaration>getAncestor(declaration, SyntaxKind.VariableDeclaration);
642-
let container = getEnclosingBlockScopeContainer(variableDeclaration);
643-
644-
if (variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement ||
645-
variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement) {
646-
// variable statement/for statement case,
647-
// use site should not be inside variable declaration (initializer of declaration or binding element)
648-
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
649-
}
650-
else if (variableDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement ||
651-
variableDeclaration.parent.parent.kind === SyntaxKind.ForInStatement) {
652-
// ForIn/ForOf case - use site should not be used in expression part
653-
let expression = (<ForInStatement | ForOfStatement>variableDeclaration.parent.parent).expression;
654-
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container);
655-
}
656-
}
657-
if (isUsedBeforeDeclaration) {
682+
if (!isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
658683
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
659684
}
660685
}
@@ -7984,6 +8009,11 @@ namespace ts {
79848009
return true;
79858010
}
79868011
// An instance property must be accessed through an instance of the enclosing class
8012+
if (type.flags & TypeFlags.ThisType) {
8013+
// get the original type -- represented as the type constraint of the 'this' type
8014+
type = getConstraintOfTypeParameter(<TypeParameter>type);
8015+
}
8016+
79878017
// TODO: why is the first part of this check here?
79888018
if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(<InterfaceType>type, enclosingClass))) {
79898019
error(node, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
@@ -10069,7 +10099,9 @@ namespace ts {
1006910099
let rightType = checkExpression(right, contextualMapper);
1007010100
switch (operator) {
1007110101
case SyntaxKind.AsteriskToken:
10102+
case SyntaxKind.AsteriskAsteriskToken:
1007210103
case SyntaxKind.AsteriskEqualsToken:
10104+
case SyntaxKind.AsteriskAsteriskEqualsToken:
1007310105
case SyntaxKind.SlashToken:
1007410106
case SyntaxKind.SlashEqualsToken:
1007510107
case SyntaxKind.PercentToken:
@@ -10088,7 +10120,7 @@ namespace ts {
1008810120
case SyntaxKind.CaretEqualsToken:
1008910121
case SyntaxKind.AmpersandToken:
1009010122
case SyntaxKind.AmpersandEqualsToken:
10091-
// TypeScript 1.0 spec (April 2014): 4.15.1
10123+
// TypeScript 1.0 spec (April 2014): 4.19.1
1009210124
// These operators require their operands to be of type Any, the Number primitive type,
1009310125
// or an enum type. Operands of an enum type are treated
1009410126
// as having the primitive type Number. If one operand is the null or undefined value,
@@ -10117,7 +10149,7 @@ namespace ts {
1011710149
return numberType;
1011810150
case SyntaxKind.PlusToken:
1011910151
case SyntaxKind.PlusEqualsToken:
10120-
// TypeScript 1.0 spec (April 2014): 4.15.2
10152+
// TypeScript 1.0 spec (April 2014): 4.19.2
1012110153
// The binary + operator requires both operands to be of the Number primitive type or an enum type,
1012210154
// or at least one of the operands to be of type Any or the String primitive type.
1012310155

@@ -11760,10 +11792,6 @@ namespace ts {
1176011792
checkSignatureDeclaration(node);
1176111793
let isAsync = isAsyncFunctionLike(node);
1176211794
if (isAsync) {
11763-
if (!compilerOptions.experimentalAsyncFunctions) {
11764-
error(node, Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning);
11765-
}
11766-
1176711795
emitAwaiter = true;
1176811796
}
1176911797

@@ -13358,7 +13386,7 @@ namespace ts {
1335813386
}
1335913387

1336013388
// illegal case: forward reference
13361-
if (!isDefinedBefore(propertyDecl, member)) {
13389+
if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) {
1336213390
reportError = false;
1336313391
error(e, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
1336413392
return undefined;

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ namespace ts {
222222
type: "boolean",
223223
description: Diagnostics.Watch_input_files,
224224
},
225-
{
226-
name: "experimentalAsyncFunctions",
227-
type: "boolean",
228-
description: Diagnostics.Enables_experimental_support_for_ES7_async_functions
229-
},
230225
{
231226
name: "experimentalDecorators",
232227
type: "boolean",
@@ -450,15 +445,15 @@ namespace ts {
450445
catch (e) {
451446
return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
452447
}
453-
return parseConfigFileText(fileName, text);
448+
return parseConfigFileTextToJson(fileName, text);
454449
}
455450

456451
/**
457452
* Parse the text of the tsconfig.json file
458453
* @param fileName The path to the config file
459454
* @param jsonText The text of the config file
460455
*/
461-
export function parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } {
456+
export function parseConfigFileTextToJson(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } {
462457
try {
463458
return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
464459
}
@@ -506,7 +501,7 @@ namespace ts {
506501
* file to. e.g. outDir
507502
* @param existingOptions optional existing options to extend into
508503
*/
509-
export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}): ParsedCommandLine {
504+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}): ParsedCommandLine {
510505
let errors: Diagnostic[] = [];
511506

512507
let options = getCompilerOptions(existingOptions);

src/compiler/core.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,12 @@ namespace ts {
437437
}
438438

439439
export function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain {
440-
Debug.assert(!headChain.next);
441-
headChain.next = tailChain;
440+
let lastChain = headChain;
441+
while (lastChain.next) {
442+
lastChain = lastChain.next;
443+
}
444+
445+
lastChain.next = tailChain;
442446
return headChain;
443447
}
444448

@@ -700,6 +704,9 @@ namespace ts {
700704
}
701705

702706
export function getBaseFileName(path: string) {
707+
if (!path) {
708+
return undefined;
709+
}
703710
let i = path.lastIndexOf(directorySeparator);
704711
return i < 0 ? path : path.substring(i + 1);
705712
}
@@ -723,6 +730,24 @@ namespace ts {
723730
*/
724731
export const supportedTypeScriptExtensions = ["ts", "tsx", "d.ts"];
725732

733+
/**
734+
* List of extensions that will be used to look for external modules.
735+
* This list is kept separate from supportedExtensions to for cases when we'll allow to include .js files in compilation,
736+
* but still would like to load only TypeScript files as modules
737+
*/
738+
export const moduleFileExtensions = supportedTypeScriptExtensions;
739+
740+
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) {
741+
if (!fileName) { return false; }
742+
743+
for (let extension of getSupportedExtensions(compilerOptions)) {
744+
if (fileExtensionIs(fileName, extension)) {
745+
return true;
746+
}
747+
}
748+
return false;
749+
}
750+
726751
export function removeFileExtension(path: string, supportedExtensions: string[]): string {
727752
// Sort the extensions in descending order of their length
728753
let extensionsToRemove = supportedExtensions.slice(0, supportedExtensions.length) // Get duplicate array
@@ -819,4 +844,14 @@ namespace ts {
819844
Debug.assert(false, message);
820845
}
821846
}
822-
}
847+
848+
export function copyListRemovingItem<T>(item: T, list: T[]) {
849+
let copiedList: T[] = [];
850+
for (var i = 0, len = list.length; i < len; i++) {
851+
if (list[i] !== item) {
852+
copiedList.push(list[i]);
853+
}
854+
}
855+
return copiedList;
856+
}
857+
}

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,6 @@
783783
"category": "Error",
784784
"code": 1245
785785
},
786-
"Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning.": {
787-
"category": "Error",
788-
"code": 1246
789-
},
790786

791787
"'with' statements are not allowed in an async function block.": {
792788
"category": "Error",
@@ -2298,10 +2294,6 @@
22982294
"category": "Message",
22992295
"code": 6066
23002296
},
2301-
"Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower.": {
2302-
"category": "Message",
2303-
"code": 6067
2304-
},
23052297
"Enables experimental support for ES7 async functions.": {
23062298
"category": "Message",
23072299
"code": 6068
@@ -2497,5 +2489,13 @@
24972489
"A constructor cannot contain a 'super' call when its class extends 'null'": {
24982490
"category": "Error",
24992491
"code": 17005
2492+
},
2493+
"An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2494+
"category": "Error",
2495+
"code": 17006
2496+
},
2497+
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2498+
"category": "Error",
2499+
"code": 17007
25002500
}
25012501
}

0 commit comments

Comments
 (0)