Skip to content

Commit 5c56684

Browse files
committed
Merge branch 'master' into exportDefault
Conflicts: tests/baselines/reference/exportAssignDottedName.errors.txt
2 parents 981ef7f + af41be8 commit 5c56684

File tree

84 files changed

+494
-402
lines changed

Some content is hidden

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

84 files changed

+494
-402
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr
99
## Legal
1010
You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright.
1111

12-
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <[email protected]>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
12+
Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <[email protected]>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
1313

1414
## Housekeeping
1515
Your pull request should:

scripts/VSDevMode.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.SYNOPSIS
33
Run this PowerShell script to enable dev mode and/or a custom script for the TypeScript language service, e.g.
44
5-
PS C:\> .\scripts\VSDevMode.ps1 -enableDevMode -tsScript C:\src\TypeScript\built\local\typescriptServices.js
5+
PS C:\> .\scripts\VSDevMode.ps1 -enableDevMode -tsScript C:\src\TypeScript\built\local\
66
77
Note: If you get security errors, try running powershell as an Administrator and with the "-executionPolicy remoteSigned" switch
88
@@ -13,7 +13,7 @@ Set to "12" for Dev12 (VS2013) or "14" (the default) for Dev14 (VS2015)
1313
Pass this switch to enable attaching a debugger to the language service
1414
1515
.PARAMETER tsScript
16-
The path to a custom language service script to use, e.g. "C:\src\TypeScript\built\local\typescriptServices.js"
16+
The path to a directory containing a custom language service script to use (typescriptServices.js), e.g. "C:\src\TypeScript\built\local\"
1717
#>
1818
Param(
1919
[int]$vsVersion = 14,

src/compiler/checker.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8560,7 +8560,7 @@ module ts {
85608560
// since LHS will be block scoped name instead of function scoped
85618561
if (!namesShareScope) {
85628562
var name = symbolToString(localDeclarationSymbol);
8563-
error(getErrorSpanForNode(node), Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name);
8563+
error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name);
85648564
}
85658565
}
85668566
}
@@ -9113,6 +9113,15 @@ module ts {
91139113
grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
91149114
}
91159115
else {
9116+
var identifierName = (<Identifier>catchClause.variableDeclaration.name).text;
9117+
var locals = catchClause.block.locals;
9118+
if (locals && hasProperty(locals, identifierName)) {
9119+
var localSymbol = locals[identifierName]
9120+
if (localSymbol && (localSymbol.flags & SymbolFlags.BlockScopedVariable) !== 0) {
9121+
grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
9122+
}
9123+
}
9124+
91169125
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
91179126
// Catch production is eval or arguments
91189127
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>catchClause.variableDeclaration.name);
@@ -11828,19 +11837,11 @@ module ts {
1182811837
return sourceFile.parseDiagnostics.length > 0;
1182911838
}
1183011839

11831-
function scanToken(scanner: Scanner, pos: number) {
11832-
scanner.setTextPos(pos);
11833-
scanner.scan();
11834-
var start = scanner.getTokenPos();
11835-
return start;
11836-
}
11837-
1183811840
function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
1183911841
var sourceFile = getSourceFileOfNode(node);
1184011842
if (!hasParseDiagnostics(sourceFile)) {
11841-
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
11842-
var start = scanToken(scanner, node.pos);
11843-
diagnostics.add(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
11843+
var span = getSpanOfTokenAtPosition(sourceFile, node.pos);
11844+
diagnostics.add(createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2));
1184411845
return true;
1184511846
}
1184611847
}
@@ -11855,9 +11856,7 @@ module ts {
1185511856
function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
1185611857
var sourceFile = getSourceFileOfNode(node);
1185711858
if (!hasParseDiagnostics(sourceFile)) {
11858-
var span = getErrorSpanForNode(node);
11859-
var start = span.end > span.pos ? skipTrivia(sourceFile.text, span.pos) : span.pos;
11860-
diagnostics.add(createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
11859+
diagnostics.add(createDiagnosticForNode(node, message, arg0, arg1, arg2));
1186111860
return true;
1186211861
}
1186311862
}
@@ -11994,9 +11993,8 @@ module ts {
1199411993
function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
1199511994
var sourceFile = getSourceFileOfNode(node);
1199611995
if (!hasParseDiagnostics(sourceFile)) {
11997-
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
11998-
scanToken(scanner, node.pos);
11999-
diagnostics.add(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
11996+
var span = getSpanOfTokenAtPosition(sourceFile, node.pos);
11997+
diagnostics.add(createFileDiagnostic(sourceFile, textSpanEnd(span), /*length*/ 0, message, arg0, arg1, arg2));
1200011998
return true;
1200111999
}
1200212000
}

src/compiler/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,11 @@ module ts {
430430
normalized.pop();
431431
}
432432
else {
433-
normalized.push(part);
433+
// A part may be an empty string (which is 'falsy') if the path had consecutive slashes,
434+
// e.g. "path//file.ts". Drop these before re-joining the parts.
435+
if(part) {
436+
normalized.push(part);
437+
}
434438
}
435439
}
436440
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ module ts {
337337
The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: DiagnosticCategory.Error, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." },
338338
The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: DiagnosticCategory.Error, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." },
339339
The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." },
340+
Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },
340341
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
341342
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}'." },
342343
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,10 @@
13391339
"category": "Error",
13401340
"code": 2491
13411341
},
1342+
"Cannot redeclare identifier '{0}' in catch clause": {
1343+
"category": "Error",
1344+
"code": 2492
1345+
},
13421346

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

src/compiler/program.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,21 +423,19 @@ module ts {
423423
return;
424424
}
425425

426-
var firstExternalModule = forEach(files, f => isExternalModule(f) ? f : undefined);
427-
if (firstExternalModule && !options.module) {
428-
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
429-
var externalModuleErrorSpan = getErrorSpanForNode(firstExternalModule.externalModuleIndicator);
430-
var errorStart = skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos);
431-
var errorLength = externalModuleErrorSpan.end - errorStart;
432-
diagnostics.add(createFileDiagnostic(firstExternalModule, errorStart, errorLength, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
426+
var firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
427+
if (firstExternalModuleSourceFile && !options.module) {
428+
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
429+
var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
430+
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
433431
}
434432

435433
// there has to be common source directory if user specified --outdir || --sourcRoot
436434
// if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted
437435
if (options.outDir || // there is --outDir specified
438436
options.sourceRoot || // there is --sourceRoot specified
439437
(options.mapRoot && // there is --mapRoot Specified and there would be multiple js files generated
440-
(!options.out || firstExternalModule !== undefined))) {
438+
(!options.out || firstExternalModuleSourceFile !== undefined))) {
441439

442440
var commonPathComponents: string[];
443441
forEach(files, sourceFile => {

src/compiler/tsc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ module ts {
250250

251251
var compileResult = compile(rootFileNames, compilerOptions, compilerHost);
252252

253-
if (!commandLine.options.watch) {
253+
if (!compilerOptions.watch) {
254254
return sys.exit(compileResult.exitStatus);
255255
}
256256

@@ -269,7 +269,7 @@ module ts {
269269
}
270270
// Use default host function
271271
var sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
272-
if (sourceFile && commandLine.options.watch) {
272+
if (sourceFile && compilerOptions.watch) {
273273
// Attach a file watcher
274274
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile));
275275
}

src/compiler/utilities.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,32 +218,35 @@ module ts {
218218
}
219219

220220
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic {
221-
node = getErrorSpanForNode(node);
222-
var file = getSourceFileOfNode(node);
223-
224-
var start = getTokenPosOfNode(node, file);
225-
var length = node.end - start;
226-
227-
return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
221+
var sourceFile = getSourceFileOfNode(node);
222+
var span = getErrorSpanForNode(sourceFile, node);
223+
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
228224
}
229225

230226
export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic {
231-
node = getErrorSpanForNode(node);
232-
var file = getSourceFileOfNode(node);
233-
var start = skipTrivia(file.text, node.pos);
234-
var length = node.end - start;
227+
var sourceFile = getSourceFileOfNode(node);
228+
var span = getErrorSpanForNode(sourceFile, node);
235229
return {
236-
file,
237-
start,
238-
length,
230+
file: sourceFile,
231+
start: span.start,
232+
length: span.length,
239233
code: messageChain.code,
240234
category: messageChain.category,
241235
messageText: messageChain.next ? messageChain : messageChain.messageText
242236
};
243237
}
244238

245-
export function getErrorSpanForNode(node: Node): Node {
246-
var errorSpan: Node;
239+
/* @internal */
240+
export function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan {
241+
var scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text);
242+
scanner.setTextPos(pos);
243+
scanner.scan();
244+
var start = scanner.getTokenPos();
245+
return createTextSpanFromBounds(start, scanner.getTextPos());
246+
}
247+
248+
export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
249+
var errorNode = node;
247250
switch (node.kind) {
248251
// This list is a work in progress. Add missing node kinds to improve their error
249252
// spans.
@@ -254,16 +257,23 @@ module ts {
254257
case SyntaxKind.ModuleDeclaration:
255258
case SyntaxKind.EnumDeclaration:
256259
case SyntaxKind.EnumMember:
257-
errorSpan = (<Declaration>node).name;
260+
case SyntaxKind.FunctionDeclaration:
261+
case SyntaxKind.FunctionExpression:
262+
errorNode = (<Declaration>node).name;
258263
break;
259264
}
265+
266+
if (errorNode === undefined) {
267+
// If we don't have a better node, then just set the error on the first token of
268+
// construct.
269+
return getSpanOfTokenAtPosition(sourceFile, node.pos);
270+
}
271+
272+
var pos = nodeIsMissing(errorNode)
273+
? errorNode.pos
274+
: skipTrivia(sourceFile.text, errorNode.pos);
260275

261-
// We now have the ideal error span, but it may be a node that is optional and absent
262-
// (e.g. the name of a function expression), in which case errorSpan will be undefined.
263-
// Alternatively, it might be required and missing (e.g. the name of a module), in which
264-
// case its pos will equal its end (length 0). In either of these cases, we should fall
265-
// back to the original node that the error was issued on.
266-
return errorSpan && errorSpan.pos < errorSpan.end ? errorSpan : node;
276+
return createTextSpanFromBounds(pos, errorNode.end);
267277
}
268278

269279
export function isExternalModule(file: SourceFile): boolean {

src/services/signatureHelp.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,16 @@ module ts.SignatureHelp {
264264
// the comma. That amounts to taking the ceiling of half the index.
265265
var argumentIndex = (listItemInfo.listItemIndex + 1) >> 1;
266266

267+
var argumentCount = getCommaBasedArgCount(list);
268+
269+
Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, `argumentCount < argumentIndex, ${argumentCount} < ${argumentIndex}`);
270+
267271
return {
268272
kind: isTypeArgList ? ArgumentListKind.TypeArguments : ArgumentListKind.CallArguments,
269273
invocation: callExpression,
270274
argumentsSpan: getApplicableSpanForArguments(list),
271275
argumentIndex: argumentIndex,
272-
argumentCount: getCommaBasedArgCount(list)
276+
argumentCount: argumentCount
273277
};
274278
}
275279
}
@@ -347,6 +351,8 @@ module ts.SignatureHelp {
347351
? 1
348352
: (<TemplateExpression>tagExpression.template).templateSpans.length + 1;
349353

354+
Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, `argumentCount < argumentIndex, ${argumentCount} < ${argumentIndex}`);
355+
350356
return {
351357
kind: ArgumentListKind.TaggedTemplateArguments,
352358
invocation: tagExpression,
@@ -512,6 +518,8 @@ module ts.SignatureHelp {
512518
selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount);
513519
}
514520

521+
Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, `argumentCount < argumentIndex, ${argumentCount} < ${argumentIndex}`);
522+
515523
return {
516524
items,
517525
applicableSpan,

0 commit comments

Comments
 (0)