Skip to content

Commit a2ecaf6

Browse files
committed
Merge branch 'master' into tsconfig
2 parents 9c802e7 + 1e8e65c commit a2ecaf6

111 files changed

Lines changed: 3398 additions & 143 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.

src/compiler/checker.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,6 +3339,8 @@ module ts {
33393339
case SyntaxKind.MethodDeclaration:
33403340
case SyntaxKind.MethodSignature:
33413341
return isContextSensitiveFunctionLikeDeclaration(<MethodDeclaration>node);
3342+
case SyntaxKind.ParenthesizedExpression:
3343+
return isContextSensitive((<ParenthesizedExpression>node).expression);
33423344
}
33433345

33443346
return false;
@@ -4722,7 +4724,7 @@ module ts {
47224724
return targetType;
47234725
}
47244726
// If current type is a union type, remove all constituents that aren't subtypes of target type
4725-
if (type.flags && TypeFlags.Union) {
4727+
if (type.flags & TypeFlags.Union) {
47264728
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
47274729
}
47284730
return type;
@@ -5231,6 +5233,8 @@ module ts {
52315233
case SyntaxKind.TemplateSpan:
52325234
Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression);
52335235
return getContextualTypeForSubstitutionExpression(<TemplateExpression>parent.parent, node);
5236+
case SyntaxKind.ParenthesizedExpression:
5237+
return getContextualType(<ParenthesizedExpression>parent);
52345238
}
52355239
return undefined;
52365240
}
@@ -6132,34 +6136,47 @@ module ts {
61326136
var result = candidates;
61336137
var lastParent: Node;
61346138
var lastSymbol: Symbol;
6135-
var cutoffPos: number = 0;
6136-
var pos: number;
6139+
var cutoffIndex: number = 0;
6140+
var index: number;
6141+
var specializedIndex: number = -1;
6142+
var spliceIndex: number;
61376143
Debug.assert(!result.length);
61386144
for (var i = 0; i < signatures.length; i++) {
61396145
var signature = signatures[i];
61406146
var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
61416147
var parent = signature.declaration && signature.declaration.parent;
61426148
if (!lastSymbol || symbol === lastSymbol) {
61436149
if (lastParent && parent === lastParent) {
6144-
pos++;
6150+
index++;
61456151
}
61466152
else {
61476153
lastParent = parent;
6148-
pos = cutoffPos;
6154+
index = cutoffIndex;
61496155
}
61506156
}
61516157
else {
61526158
// current declaration belongs to a different symbol
6153-
// set cutoffPos so re-orderings in the future won't change result set from 0 to cutoffPos
6154-
pos = cutoffPos = result.length;
6159+
// set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex
6160+
index = cutoffIndex = result.length;
61556161
lastParent = parent;
61566162
}
61576163
lastSymbol = symbol;
61586164

6159-
for (var j = result.length; j > pos; j--) {
6160-
result[j] = result[j - 1];
6165+
// specialized signatures always need to be placed before non-specialized signatures regardless
6166+
// of the cutoff position; see GH#1133
6167+
if (signature.hasStringLiterals) {
6168+
specializedIndex++;
6169+
spliceIndex = specializedIndex;
6170+
// The cutoff index always needs to be greater than or equal to the specialized signature index
6171+
// in order to prevent non-specialized signatures from being added before a specialized
6172+
// signature.
6173+
cutoffIndex++;
61616174
}
6162-
result[pos] = signature;
6175+
else {
6176+
spliceIndex = index;
6177+
}
6178+
6179+
result.splice(spliceIndex, 0, signature);
61636180
}
61646181
}
61656182
}
@@ -7191,12 +7208,15 @@ module ts {
71917208

71927209
checkVariableLikeDeclaration(node);
71937210
var func = getContainingFunction(node);
7194-
if (node.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) {
7211+
if (node.flags & NodeFlags.AccessibilityModifier) {
71957212
func = getContainingFunction(node);
71967213
if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
71977214
error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
71987215
}
71997216
}
7217+
if (node.questionToken && isBindingPattern(node.name) && func.body) {
7218+
error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
7219+
}
72007220
if (node.dotDotDotToken) {
72017221
if (!isArrayType(getTypeOfSymbol(node.symbol))) {
72027222
error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
@@ -7210,17 +7230,20 @@ module ts {
72107230
checkGrammarIndexSignature(<SignatureDeclaration>node);
72117231
}
72127232
// TODO (yuisu): Remove this check in else-if when SyntaxKind.Construct is moved and ambient context is handled
7213-
else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType ||
7233+
else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType ||
72147234
node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.Constructor ||
72157235
node.kind === SyntaxKind.ConstructSignature){
72167236
checkGrammarFunctionLikeDeclaration(<FunctionLikeDeclaration>node);
72177237
}
72187238

72197239
checkTypeParameters(node.typeParameters);
7240+
72207241
forEach(node.parameters, checkParameter);
7242+
72217243
if (node.type) {
72227244
checkSourceElement(node.type);
72237245
}
7246+
72247247
if (produceDiagnostics) {
72257248
checkCollisionWithArgumentsInGeneratedCode(node);
72267249
if (compilerOptions.noImplicitAny && !node.type) {
@@ -10171,6 +10194,9 @@ module ts {
1017110194
else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) {
1017210195
return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
1017310196
}
10197+
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.AccessibilityModifier) && isBindingPattern((<ParameterDeclaration>node).name)) {
10198+
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
10199+
}
1017410200
}
1017510201

1017610202
function checkGrammarForDisallowedTrailingComma(list: NodeArray<Node>): boolean {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ module ts {
146146
Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
147147
Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
148148
A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." },
149+
A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." },
149150
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
150151
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
151152
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -297,6 +298,7 @@ module ts {
297298
Type_0_has_no_property_1: { code: 2460, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
298299
Type_0_is_not_an_array_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
299300
A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" },
301+
A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." },
300302
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
301303
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
302304
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },

src/compiler/diagnosticMessages.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
"A 'declare' modifier cannot be used with an import declaration.": {
225225
"category": "Error",
226226
"code": 1079,
227-
"isEarly": true
227+
"isEarly": true
228228
},
229229
"Invalid 'reference' directive syntax.": {
230230
"category": "Error",
@@ -659,7 +659,7 @@
659659
"An implementation cannot be declared in ambient contexts.": {
660660
"category": "Error",
661661
"code": 1184,
662-
"isEarly": true
662+
"isEarly": true
663663
},
664664
"Modifiers cannot appear here.": {
665665
"category": "Error",
@@ -673,6 +673,10 @@
673673
"category": "Error",
674674
"code": 1186
675675
},
676+
"A parameter property may not be a binding pattern.": {
677+
"category": "Error",
678+
"code": 1187
679+
},
676680

677681
"Duplicate identifier '{0}'.": {
678682
"category": "Error",
@@ -1282,6 +1286,10 @@
12821286
"category": "Error",
12831287
"code": 2462
12841288
},
1289+
"A binding pattern parameter cannot be optional in an implementation signature.": {
1290+
"category": "Error",
1291+
"code": 2463
1292+
},
12851293

12861294
"Import declaration '{0}' is using private name '{1}'.": {
12871295
"category": "Error",

src/compiler/parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,10 @@ module ts {
13951395
}
13961396

13971397
function canFollowModifier(): boolean {
1398-
return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName();
1398+
return token === SyntaxKind.OpenBracketToken
1399+
|| token === SyntaxKind.OpenBraceToken
1400+
|| token === SyntaxKind.AsteriskToken
1401+
|| isLiteralPropertyName();
13991402
}
14001403

14011404
// True if positioned at the start of a list element

src/compiler/scanner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ module ts {
10391039
value = 0;
10401040
}
10411041
tokenValue = "" + value;
1042-
return SyntaxKind.NumericLiteral;
1042+
return token = SyntaxKind.NumericLiteral;
10431043
}
10441044
else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) {
10451045
pos += 2;
@@ -1049,7 +1049,7 @@ module ts {
10491049
value = 0;
10501050
}
10511051
tokenValue = "" + value;
1052-
return SyntaxKind.NumericLiteral;
1052+
return token = SyntaxKind.NumericLiteral;
10531053
}
10541054
// Try to parse as an octal
10551055
if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) {

src/harness/harness.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,18 @@ module Harness {
810810
export function createCompilerHost(inputFiles: { unitName: string; content: string; }[],
811811
writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void,
812812
scriptTarget: ts.ScriptTarget,
813-
useCaseSensitiveFileNames: boolean): ts.CompilerHost {
813+
useCaseSensitiveFileNames: boolean,
814+
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
815+
currentDirectory?: string): ts.CompilerHost {
814816

815817
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
816818
function getCanonicalFileName(fileName: string): string {
817819
return useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
818820
}
819821

820822
var filemap: { [filename: string]: ts.SourceFile; } = {};
823+
var getCurrentDirectory = currentDirectory === undefined ? ts.sys.getCurrentDirectory : () => currentDirectory;
824+
821825
// Register input files
822826
function register(file: { unitName: string; content: string; }) {
823827
if (file.content !== undefined) {
@@ -828,11 +832,15 @@ module Harness {
828832
inputFiles.forEach(register);
829833

830834
return {
831-
getCurrentDirectory: ts.sys.getCurrentDirectory,
835+
getCurrentDirectory,
832836
getSourceFile: (fn, languageVersion) => {
833837
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
834838
return filemap[getCanonicalFileName(fn)];
835839
}
840+
else if (currentDirectory) {
841+
var canonicalAbsolutePath = getCanonicalFileName(ts.getNormalizedAbsolutePath(fn, currentDirectory));
842+
return Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(canonicalAbsolutePath)) ? filemap[canonicalAbsolutePath] : undefined;
843+
}
836844
else if (fn === fourslashFilename) {
837845
var tsFn = 'tests/cases/fourslash/' + fourslashFilename;
838846
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), scriptTarget);
@@ -909,7 +917,9 @@ module Harness {
909917
otherFiles: { unitName: string; content: string }[],
910918
onComplete: (result: CompilerResult, program: ts.Program) => void,
911919
settingsCallback?: (settings: ts.CompilerOptions) => void,
912-
options?: ts.CompilerOptions) {
920+
options?: ts.CompilerOptions,
921+
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
922+
currentDirectory?: string) {
913923

914924
options = options || { noResolve: false };
915925
options.target = options.target || ts.ScriptTarget.ES3;
@@ -1063,8 +1073,7 @@ module Harness {
10631073
var programFiles = inputFiles.map(file => file.unitName);
10641074
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(otherFiles),
10651075
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
1066-
options.target,
1067-
useCaseSensitiveFileNames));
1076+
options.target, useCaseSensitiveFileNames, currentDirectory));
10681077

10691078
var checker = program.getTypeChecker(/*produceDiagnostics*/ true);
10701079

@@ -1095,7 +1104,9 @@ module Harness {
10951104
otherFiles: { unitName: string; content: string; }[],
10961105
result: CompilerResult,
10971106
settingsCallback?: (settings: ts.CompilerOptions) => void,
1098-
options?: ts.CompilerOptions) {
1107+
options?: ts.CompilerOptions,
1108+
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
1109+
currentDirectory?: string) {
10991110
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) {
11001111
throw new Error('There were no errors and declFiles generated did not match number of js files generated');
11011112
}
@@ -1108,9 +1119,8 @@ module Harness {
11081119

11091120
ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
11101121
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
1111-
this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) {
1112-
declResult = compileResult;
1113-
}, settingsCallback, options);
1122+
this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) { declResult = compileResult; },
1123+
settingsCallback, options, currentDirectory);
11141124

11151125
return { declInputFiles, declOtherFiles, declResult };
11161126
}

src/harness/instrumenter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var fs: any = require('fs');
33
var path: any = require('path');
44

55
function instrumentForRecording(fn: string, tscPath: string) {
6-
instrument(tscPath, 'sys = Playback.wrapSystem(sys); sys.startRecord("' + fn + '");', 'sys.endRecord();');
6+
instrument(tscPath, 'ts.sys = Playback.wrapSystem(ts.sys); ts.sys.startRecord("' + fn + '");', 'ts.sys.endRecord();');
77
}
88

99
function instrumentForReplay(logFilename: string, tscPath: string) {
10-
instrument(tscPath, 'sys = Playback.wrapSystem(sys); sys.startReplay("' + logFilename + '");');
10+
instrument(tscPath, 'ts.sys = Playback.wrapSystem(ts.sys); ts.sys.startReplay("' + logFilename + '");');
1111
}
1212

1313
function instrument(tscPath: string, prepareCode: string, cleanupCode: string = '') {
@@ -27,8 +27,12 @@ function instrument(tscPath: string, prepareCode: string, cleanupCode: string =
2727
fs.readFile(path.resolve(path.dirname(tscPath) + '/loggedIO.js'), 'utf-8', (err: any, loggerContent: string) => {
2828
if (err) throw err;
2929

30-
var invocationLine = 'ts.executeCommandLine(sys.args);';
30+
var invocationLine = 'ts.executeCommandLine(ts.sys.args);';
3131
var index1 = tscContent.indexOf(invocationLine);
32+
if (index1 < 0) {
33+
throw new Error("Could not find " + invocationLine);
34+
}
35+
3236
var index2 = index1 + invocationLine.length;
3337
var newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + '\r\n';
3438
fs.writeFile(tscPath, newContent);

0 commit comments

Comments
 (0)