Skip to content

Commit 696b688

Browse files
committed
Merge branch 'master' into exportDefaultType
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json
2 parents 44a5343 + 85cf761 commit 696b688

22 files changed

+835
-258
lines changed

src/compiler/checker.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ module ts {
448448
let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined);
449449

450450
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
451-
451+
452452
// first check if usage is lexically located after the declaration
453453
let isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
454454
if (!isUsedBeforeDeclaration) {
@@ -465,7 +465,7 @@ module ts {
465465

466466
if (variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement ||
467467
variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement) {
468-
// variable statement/for statement case,
468+
// variable statement/for statement case,
469469
// use site should not be inside variable declaration (initializer of declaration or binding element)
470470
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
471471
}
@@ -4421,7 +4421,7 @@ module ts {
44214421
}
44224422

44234423
/**
4424-
* Check if a Type was written as a tuple type literal.
4424+
* Check if a Type was written as a tuple type literal.
44254425
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
44264426
*/
44274427
function isTupleType(type: Type) : boolean {
@@ -9101,7 +9101,7 @@ module ts {
91019101
*/
91029102
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type {
91039103
Debug.assert(languageVersion < ScriptTarget.ES6);
9104-
9104+
91059105
// After we remove all types that are StringLike, we will know if there was a string constituent
91069106
// based on whether the remaining type is the same as the initial type.
91079107
let arrayType = removeTypesFromUnionType(arrayOrStringType, TypeFlags.StringLike, /*isTypeOfKind*/ true, /*allowEmptyUnionResult*/ true);
@@ -11103,26 +11103,11 @@ module ts {
1110311103
function getBlockScopedVariableId(n: Identifier): number {
1110411104
Debug.assert(!nodeIsSynthesized(n));
1110511105

11106-
// ignore name parts of property access expressions
11107-
if (n.parent.kind === SyntaxKind.PropertyAccessExpression &&
11108-
(<PropertyAccessExpression>n.parent).name === n) {
11109-
return undefined;
11110-
}
11111-
11112-
// ignore property names in object binding patterns
11113-
if (n.parent.kind === SyntaxKind.BindingElement &&
11114-
(<BindingElement>n.parent).propertyName === n) {
11115-
return undefined;
11116-
}
11117-
11118-
// for names in variable declarations and binding elements try to short circuit and fetch symbol from the node
11119-
let declarationSymbol: Symbol =
11120-
(n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n) ||
11121-
n.parent.kind === SyntaxKind.BindingElement
11122-
? getSymbolOfNode(n.parent)
11123-
: undefined;
11106+
let isVariableDeclarationOrBindingElement =
11107+
n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n);
1112411108

11125-
let symbol = declarationSymbol ||
11109+
let symbol =
11110+
(isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) ||
1112611111
getNodeLinks(n).resolvedSymbol ||
1112711112
resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
1112811113

@@ -11354,16 +11339,15 @@ module ts {
1135411339
}
1135511340
}
1135611341

11357-
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>): boolean {
11342+
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>, file: SourceFile): boolean {
1135811343
if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
1135911344
return true;
1136011345
}
1136111346

1136211347
if (typeParameters && typeParameters.length === 0) {
1136311348
let start = typeParameters.pos - "<".length;
11364-
let sourceFile = getSourceFileOfNode(node);
11365-
let end = skipTrivia(sourceFile.text, typeParameters.end) + ">".length;
11366-
return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty);
11349+
let end = skipTrivia(file.text, typeParameters.end) + ">".length;
11350+
return grammarErrorAtPos(file, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty);
1136711351
}
1136811352
}
1136911353

@@ -11407,7 +11391,21 @@ module ts {
1140711391

1140811392
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
1140911393
// Prevent cascading error by short-circuit
11410-
return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters);
11394+
let file = getSourceFileOfNode(node);
11395+
return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
11396+
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
11397+
}
11398+
11399+
function checkGrammarArrowFunction(node: FunctionLikeDeclaration, file: SourceFile): boolean {
11400+
if (node.kind === SyntaxKind.ArrowFunction) {
11401+
let arrowFunction = <ArrowFunction>node;
11402+
let startLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
11403+
let endLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
11404+
if (startLine !== endLine) {
11405+
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
11406+
}
11407+
}
11408+
return false;
1141111409
}
1141211410

1141311411
function checkGrammarIndexSignatureParameters(node: SignatureDeclaration): boolean {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ module ts {
157157
Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
158158
An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." },
159159
Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
160-
A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1200, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." },
160+
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
161+
A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." },
161162
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
162163
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." },
163164
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,14 @@
619619
"category": "Error",
620620
"code": 1199
621621
},
622-
"A type annotation on an export statement is only allowed in an ambient external module declaration.": {
622+
"Line terminator not permitted before arrow.": {
623623
"category": "Error",
624624
"code": 1200
625625
},
626+
"A type annotation on an export statement is only allowed in an ambient external module declaration.": {
627+
"category": "Error",
628+
"code": 1201
629+
},
626630

627631
"Duplicate identifier '{0}'.": {
628632
"category": "Error",

src/compiler/emitter.ts

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,19 +2074,19 @@ module ts {
20742074
sourceMapDir = getDirectoryPath(normalizePath(jsFilePath));
20752075
}
20762076

2077-
function emitNodeWithSourceMap(node: Node) {
2077+
function emitNodeWithSourceMap(node: Node, allowGeneratedIdentifiers?: boolean) {
20782078
if (node) {
20792079
if (nodeIsSynthesized(node)) {
2080-
return emitNodeWithoutSourceMap(node);
2080+
return emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false);
20812081
}
20822082
if (node.kind != SyntaxKind.SourceFile) {
20832083
recordEmitNodeStartSpan(node);
2084-
emitNodeWithoutSourceMap(node);
2084+
emitNodeWithoutSourceMap(node, allowGeneratedIdentifiers);
20852085
recordEmitNodeEndSpan(node);
20862086
}
20872087
else {
20882088
recordNewSourceFileStart(<SourceFile>node);
2089-
emitNodeWithoutSourceMap(node);
2089+
emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false);
20902090
}
20912091
}
20922092
}
@@ -2623,17 +2623,24 @@ module ts {
26232623
}
26242624
}
26252625

2626-
function getBlockScopedVariableId(node: Identifier): number {
2627-
// return undefined for synthesized nodes
2628-
return !nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node);
2626+
function getGeneratedNameForIdentifier(node: Identifier): string {
2627+
if (nodeIsSynthesized(node) || !generatedBlockScopeNames) {
2628+
return undefined;
2629+
}
2630+
2631+
var variableId = resolver.getBlockScopedVariableId(node)
2632+
if (variableId === undefined) {
2633+
return undefined;
2634+
}
2635+
2636+
return generatedBlockScopeNames[variableId];
26292637
}
26302638

2631-
function emitIdentifier(node: Identifier) {
2632-
let variableId = getBlockScopedVariableId(node);
2633-
if (variableId !== undefined && generatedBlockScopeNames) {
2634-
let text = generatedBlockScopeNames[variableId];
2635-
if (text) {
2636-
write(text);
2639+
function emitIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean) {
2640+
if (allowGeneratedIdentifiers) {
2641+
let generatedName = getGeneratedNameForIdentifier(node);
2642+
if (generatedName) {
2643+
write(generatedName);
26372644
return;
26382645
}
26392646
}
@@ -2686,7 +2693,7 @@ module ts {
26862693

26872694
function emitBindingElement(node: BindingElement) {
26882695
if (node.propertyName) {
2689-
emit(node.propertyName);
2696+
emit(node.propertyName, /*allowGeneratedIdentifiers*/ false);
26902697
write(": ");
26912698
}
26922699
if (node.dotDotDotToken) {
@@ -3030,21 +3037,21 @@ module ts {
30303037
}
30313038

30323039
function emitMethod(node: MethodDeclaration) {
3033-
emit(node.name);
3040+
emit(node.name, /*allowGeneratedIdentifiers*/ false);
30343041
if (languageVersion < ScriptTarget.ES6) {
30353042
write(": function ");
30363043
}
30373044
emitSignatureAndBody(node);
30383045
}
30393046

30403047
function emitPropertyAssignment(node: PropertyDeclaration) {
3041-
emit(node.name);
3048+
emit(node.name, /*allowGeneratedIdentifiers*/ false);
30423049
write(": ");
30433050
emit(node.initializer);
30443051
}
30453052

30463053
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
3047-
emit(node.name);
3054+
emit(node.name, /*allowGeneratedIdentifiers*/ false);
30483055
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
30493056
// module m {
30503057
// export let y;
@@ -3053,7 +3060,20 @@ module ts {
30533060
// export let obj = { y };
30543061
// }
30553062
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
3056-
if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNameSubstitution(node.name)) {
3063+
if (languageVersion < ScriptTarget.ES6) {
3064+
// Emit identifier as an identifier
3065+
write(": ");
3066+
var generatedName = getGeneratedNameForIdentifier(node.name);
3067+
if (generatedName) {
3068+
write(generatedName);
3069+
}
3070+
else {
3071+
// Even though this is stored as identifier treat it as an expression
3072+
// Short-hand, { x }, is equivalent of normal form { x: x }
3073+
emitExpressionIdentifier(node.name);
3074+
}
3075+
}
3076+
else if (resolver.getExpressionNameSubstitution(node.name)) {
30573077
// Emit identifier as an identifier
30583078
write(": ");
30593079
// Even though this is stored as identifier treat it as an expression
@@ -3106,7 +3126,7 @@ module ts {
31063126
let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
31073127
write(".");
31083128
let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
3109-
emit(node.name);
3129+
emit(node.name, /*allowGeneratedIdentifiers*/ false);
31103130
decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
31113131
}
31123132

@@ -4294,7 +4314,7 @@ module ts {
42944314

42954315
function emitAccessor(node: AccessorDeclaration) {
42964316
write(node.kind === SyntaxKind.GetAccessor ? "get " : "set ");
4297-
emit(node.name);
4317+
emit(node.name, /*allowGeneratedIdentifiers*/ false);
42984318
emitSignatureAndBody(node);
42994319
}
43004320

@@ -5340,7 +5360,7 @@ module ts {
53405360
emitLeadingComments(node.endOfFileToken);
53415361
}
53425362

5343-
function emitNodeWithoutSourceMapWithComments(node: Node): void {
5363+
function emitNodeWithoutSourceMapWithComments(node: Node, allowGeneratedIdentifiers?: boolean): void {
53445364
if (!node) {
53455365
return;
53465366
}
@@ -5354,14 +5374,14 @@ module ts {
53545374
emitLeadingComments(node);
53555375
}
53565376

5357-
emitJavaScriptWorker(node);
5377+
emitJavaScriptWorker(node, allowGeneratedIdentifiers);
53585378

53595379
if (emitComments) {
53605380
emitTrailingComments(node);
53615381
}
53625382
}
53635383

5364-
function emitNodeWithoutSourceMapWithoutComments(node: Node): void {
5384+
function emitNodeWithoutSourceMapWithoutComments(node: Node, allowGeneratedIdentifiers?: boolean): void {
53655385
if (!node) {
53665386
return;
53675387
}
@@ -5370,7 +5390,7 @@ module ts {
53705390
return emitPinnedOrTripleSlashComments(node);
53715391
}
53725392

5373-
emitJavaScriptWorker(node);
5393+
emitJavaScriptWorker(node, allowGeneratedIdentifiers);
53745394
}
53755395

53765396
function shouldEmitLeadingAndTrailingComments(node: Node) {
@@ -5400,11 +5420,11 @@ module ts {
54005420
return true;
54015421
}
54025422

5403-
function emitJavaScriptWorker(node: Node) {
5423+
function emitJavaScriptWorker(node: Node, allowGeneratedIdentifiers: boolean = true) {
54045424
// Check if the node can be emitted regardless of the ScriptTarget
54055425
switch (node.kind) {
54065426
case SyntaxKind.Identifier:
5407-
return emitIdentifier(<Identifier>node);
5427+
return emitIdentifier(<Identifier>node, allowGeneratedIdentifiers);
54085428
case SyntaxKind.Parameter:
54095429
return emitParameter(<ParameterDeclaration>node);
54105430
case SyntaxKind.MethodDeclaration:

0 commit comments

Comments
 (0)