Skip to content

Commit c1d15c7

Browse files
Merge branch 'master' into navbar
Also fixed getSourceText and renamed it to getTextOfNode
2 parents 208e36d + 6b76a6d commit c1d15c7

File tree

225 files changed

+3743
-852
lines changed

Some content is hidden

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

225 files changed

+3743
-852
lines changed
3.81 KB
Binary file not shown.
-69.4 KB
Binary file not shown.

doc/spec.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ For this switch statement, the compiler will generate the following code.
581581

582582
```TypeScript
583583
switch (op) {
584-
case 0 /* Operator.ADD */ :
584+
case 0 /* Operator.ADD */:
585585
// execute add
586586
break;
587-
case 1 /* Operator.DIV */ :
587+
case 1 /* Operator.DIV */:
588588
// execute div
589589
break;
590590
// ...
@@ -738,7 +738,7 @@ var M;
738738
return s;
739739
}
740740
M.f = f;
741-
})(M||(M={}));
741+
})(M || (M = {}));
742742
```
743743

744744
In this case, the compiler assumes that the module object resides in global variable ‘M’, which may or may not have been initialized to the desired module object.
@@ -1068,7 +1068,7 @@ Type references (section [3.6.2](#3.6.2)) to class and interface types are class
10681068

10691069
### <a name="3.3.2"/>3.3.2 Array Types
10701070

1071-
***Array types*** represent JavaScript arrays with a common element type. Array types are named type references created from the generic interface type ‘Array’ in the global module with the array element type as a type argument. Array type literals (section [Error! Reference source not found.](#Error! Reference source not found.)) provide a shorthand notation for creating such references.
1071+
***Array types*** represent JavaScript arrays with a common element type. Array types are named type references created from the generic interface type ‘Array’ in the global module with the array element type as a type argument. Array type literals (section [3.6.4](#3.6.4)) provide a shorthand notation for creating such references.
10721072

10731073
The declaration of the ‘Array’ interface includes a property ‘length’ and a numeric index signature for the element type, along with other members:
10741074

src/compiler/binder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ module ts {
8484
if (node.name) {
8585
node.name.parent = node;
8686
}
87-
file.semanticErrors.push(createDiagnosticForNode(node.name ? node.name : node,
88-
Diagnostics.Duplicate_identifier_0, getDisplayName(node)));
87+
// Report errors every position with duplicate declaration
88+
// Report errors on previous encountered declarations
89+
forEach(symbol.declarations, (declaration) => {
90+
file.semanticErrors.push(createDiagnosticForNode(declaration.name, Diagnostics.Duplicate_identifier_0, getDisplayName(declaration)));
91+
});
92+
file.semanticErrors.push(createDiagnosticForNode(node.name, Diagnostics.Duplicate_identifier_0, getDisplayName(node)));
93+
8994
symbol = createSymbol(0, name);
9095
}
9196
}

src/compiler/checker.ts

Lines changed: 65 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ module ts {
9292
getContextualType: getContextualType,
9393
getFullyQualifiedName: getFullyQualifiedName,
9494
getResolvedSignature: getResolvedSignature,
95-
getEnumMemberValue: getEnumMemberValue
95+
getEnumMemberValue: getEnumMemberValue,
96+
isValidPropertyAccess: isValidPropertyAccess,
97+
getAliasedSymbol: resolveImport
9698
};
9799

98100
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -2573,7 +2575,7 @@ module ts {
25732575
function getStringLiteralType(node: StringLiteralTypeNode): StringLiteralType {
25742576
if (hasProperty(stringLiteralTypes, node.text)) return stringLiteralTypes[node.text];
25752577
var type = stringLiteralTypes[node.text] = <StringLiteralType>createType(TypeFlags.StringLiteral);
2576-
type.text = getSourceTextOfNode(node);
2578+
type.text = getTextOfNode(node);
25772579
return type;
25782580
}
25792581

@@ -4239,6 +4241,25 @@ module ts {
42394241
return anyType;
42404242
}
42414243

4244+
function isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean {
4245+
var type = checkExpression(node.left);
4246+
if (type !== unknownType && type !== anyType) {
4247+
var apparentType = getApparentType(getWidenedType(type));
4248+
var prop = getPropertyOfApparentType(apparentType, propertyName);
4249+
if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) {
4250+
if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
4251+
return false;
4252+
}
4253+
else {
4254+
var diagnosticsCount = diagnostics.length;
4255+
checkClassPropertyAccess(node, type, prop);
4256+
return diagnostics.length === diagnosticsCount
4257+
}
4258+
}
4259+
}
4260+
return true;
4261+
}
4262+
42424263
function checkIndexedAccess(node: IndexedAccess): Type {
42434264
var objectType = checkExpression(node.object);
42444265
var indexType = checkExpression(node.index);
@@ -4311,25 +4332,32 @@ module ts {
43114332
}
43124333

43134334
function signatureHasCorrectArity(node: CallExpression, signature: Signature): boolean {
4314-
var args = node.arguments || emptyArray;
4315-
var isCorrect = args.length >= signature.minArgumentCount &&
4316-
(signature.hasRestParameter || args.length <= signature.parameters.length) &&
4317-
(!node.typeArguments || signature.typeParameters && node.typeArguments.length === signature.typeParameters.length);
4318-
4319-
// For error recovery, since we have parsed OmittedExpressions for any extra commas
4320-
// in the argument list, if we see any OmittedExpressions, just return true.
4321-
// The reason this is ok is because omitted expressions here are syntactically
4322-
// illegal, and will cause a parse error.
4323-
// Note: It may be worth keeping the upper bound check on arity, but removing
4324-
// the lower bound check if there are omitted expressions.
4325-
if (!isCorrect) {
4326-
// Technically this type assertion is not safe because args could be initialized to emptyArray
4327-
// above.
4328-
if ((<NodeArray<Node>>args).hasTrailingComma || forEach(args, arg => arg.kind === SyntaxKind.OmittedExpression)) {
4329-
return true;
4330-
}
4335+
if (!node.arguments) {
4336+
// This only happens when we have something of the form:
4337+
// new C
4338+
//
4339+
return signature.minArgumentCount === 0;
4340+
}
4341+
4342+
// For IDE scenarios, since we may have an incomplete call, we make two modifications
4343+
// to arity checking.
4344+
// 1. A trailing comma is tantamount to adding another argument
4345+
// 2. If the call is incomplete (no closing paren) allow fewer arguments than expected
4346+
var args = node.arguments;
4347+
var numberOfArgs = args.hasTrailingComma ? args.length + 1 : args.length;
4348+
var hasTooManyArguments = !signature.hasRestParameter && numberOfArgs > signature.parameters.length;
4349+
var hasRightNumberOfTypeArguments = !node.typeArguments ||
4350+
(signature.typeParameters && node.typeArguments.length === signature.typeParameters.length);
4351+
4352+
if (hasTooManyArguments || !hasRightNumberOfTypeArguments) {
4353+
return false;
43314354
}
4332-
return isCorrect;
4355+
4356+
// If we are missing the close paren, the call is incomplete, and we should skip
4357+
// the lower bound check.
4358+
var callIsIncomplete = args.end === node.end;
4359+
var hasEnoughArguments = numberOfArgs >= signature.minArgumentCount;
4360+
return callIsIncomplete || hasEnoughArguments;
43334361
}
43344362

43354363
// If type has a single call signature and no other members, return that signature. Otherwise, return undefined.
@@ -5672,6 +5700,8 @@ module ts {
56725700
// when checking exported function declarations across modules check only duplicate implementations
56735701
// names and consistency of modifiers are verified when we check local symbol
56745702
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
5703+
var duplicateFunctionDeclaration = false;
5704+
var multipleConstructorImplementation = false;
56755705
for (var i = 0; i < declarations.length; i++) {
56765706
var node = <FunctionDeclaration>declarations[i];
56775707
var inAmbientContext = isInAmbientContext(node);
@@ -5694,10 +5724,10 @@ module ts {
56945724

56955725
if (node.body && bodyDeclaration) {
56965726
if (isConstructor) {
5697-
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
5727+
multipleConstructorImplementation = true;
56985728
}
56995729
else {
5700-
error(node, Diagnostics.Duplicate_function_implementation);
5730+
duplicateFunctionDeclaration = true;
57015731
}
57025732
}
57035733
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
@@ -5721,6 +5751,18 @@ module ts {
57215751
}
57225752
}
57235753

5754+
if (multipleConstructorImplementation) {
5755+
forEach(declarations, declaration => {
5756+
error(declaration, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
5757+
});
5758+
}
5759+
5760+
if (duplicateFunctionDeclaration) {
5761+
forEach( declarations, declaration => {
5762+
error(declaration.name, Diagnostics.Duplicate_function_implementation);
5763+
});
5764+
}
5765+
57245766
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
57255767
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
57265768
}
@@ -7061,23 +7103,6 @@ module ts {
70617103
return mapToArray(symbols);
70627104
}
70637105

7064-
// True if the given identifier is the name of a type declaration node (class, interface, enum, type parameter, etc)
7065-
function isTypeDeclarationName(name: Node): boolean {
7066-
return name.kind == SyntaxKind.Identifier &&
7067-
isTypeDeclaration(name.parent) &&
7068-
(<Declaration>name.parent).name === name;
7069-
}
7070-
7071-
function isTypeDeclaration(node: Node): boolean {
7072-
switch (node.kind) {
7073-
case SyntaxKind.TypeParameter:
7074-
case SyntaxKind.ClassDeclaration:
7075-
case SyntaxKind.InterfaceDeclaration:
7076-
case SyntaxKind.EnumDeclaration:
7077-
return true;
7078-
}
7079-
}
7080-
70817106
// True if the given identifier is part of a type reference
70827107
function isTypeReferenceIdentifier(entityName: EntityName): boolean {
70837108
var node: Node = entityName;
@@ -7156,75 +7181,6 @@ module ts {
71567181
return false;
71577182
}
71587183

7159-
function isTypeNode(node: Node): boolean {
7160-
if (node.kind >= SyntaxKind.FirstTypeNode && node.kind <= SyntaxKind.LastTypeNode) {
7161-
return true;
7162-
}
7163-
7164-
switch (node.kind) {
7165-
case SyntaxKind.AnyKeyword:
7166-
case SyntaxKind.NumberKeyword:
7167-
case SyntaxKind.StringKeyword:
7168-
case SyntaxKind.BooleanKeyword:
7169-
return true;
7170-
case SyntaxKind.VoidKeyword:
7171-
return node.parent.kind !== SyntaxKind.PrefixOperator;
7172-
case SyntaxKind.StringLiteral:
7173-
// Specialized signatures can have string literals as their parameters' type names
7174-
return node.parent.kind === SyntaxKind.Parameter;
7175-
// Identifiers and qualified names may be type nodes, depending on their context. Climb
7176-
// above them to find the lowest container
7177-
case SyntaxKind.Identifier:
7178-
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
7179-
if (node.parent.kind === SyntaxKind.QualifiedName) {
7180-
node = node.parent;
7181-
}
7182-
// Fall through
7183-
case SyntaxKind.QualifiedName:
7184-
// At this point, node is either a qualified name or an identifier
7185-
var parent = node.parent;
7186-
if (parent.kind === SyntaxKind.TypeQuery) {
7187-
return false;
7188-
}
7189-
// Do not recursively call isTypeNode on the parent. In the example:
7190-
//
7191-
// var a: A.B.C;
7192-
//
7193-
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
7194-
// A.B.C is a type node.
7195-
if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) {
7196-
return true;
7197-
}
7198-
switch (parent.kind) {
7199-
case SyntaxKind.TypeParameter:
7200-
return node === (<TypeParameterDeclaration>parent).constraint;
7201-
case SyntaxKind.Property:
7202-
case SyntaxKind.Parameter:
7203-
case SyntaxKind.VariableDeclaration:
7204-
return node === (<VariableDeclaration>parent).type;
7205-
case SyntaxKind.FunctionDeclaration:
7206-
case SyntaxKind.FunctionExpression:
7207-
case SyntaxKind.ArrowFunction:
7208-
case SyntaxKind.Constructor:
7209-
case SyntaxKind.Method:
7210-
case SyntaxKind.GetAccessor:
7211-
case SyntaxKind.SetAccessor:
7212-
return node === (<FunctionDeclaration>parent).type;
7213-
case SyntaxKind.CallSignature:
7214-
case SyntaxKind.ConstructSignature:
7215-
case SyntaxKind.IndexSignature:
7216-
return node === (<SignatureDeclaration>parent).type;
7217-
case SyntaxKind.TypeAssertion:
7218-
return node === (<TypeAssertion>parent).type;
7219-
case SyntaxKind.CallExpression:
7220-
case SyntaxKind.NewExpression:
7221-
return (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
7222-
}
7223-
}
7224-
7225-
return false;
7226-
}
7227-
72287184
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
72297185
while (node.parent.kind === SyntaxKind.QualifiedName) {
72307186
node = node.parent;
@@ -7478,7 +7434,7 @@ module ts {
74787434
while (!isUniqueLocalName(escapeIdentifier(prefix + name), container)) {
74797435
prefix += "_";
74807436
}
7481-
links.localModuleName = prefix + getSourceTextOfNode(container.name);
7437+
links.localModuleName = prefix + getTextOfNode(container.name);
74827438
}
74837439
return links.localModuleName;
74847440
}

src/compiler/core.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,9 @@ module ts {
209209
export var localizedDiagnosticMessages: Map<string> = undefined;
210210

211211
export function getLocaleSpecificMessage(message: string) {
212-
if (ts.localizedDiagnosticMessages) {
213-
message = localizedDiagnosticMessages[message];
214-
}
215-
216-
return message;
212+
return localizedDiagnosticMessages && localizedDiagnosticMessages[message]
213+
? localizedDiagnosticMessages[message]
214+
: message;
217215
}
218216

219217
export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic;

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module ts {
55
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
66
Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." },
77
_0_expected: { code: 1005, category: DiagnosticCategory.Error, key: "'{0}' expected." },
8+
A_file_cannot_have_a_reference_to_itself: { code: 1006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
89
Trailing_comma_not_allowed: { code: 1009, category: DiagnosticCategory.Error, key: "Trailing comma not allowed." },
910
Asterisk_Slash_expected: { code: 1010, category: DiagnosticCategory.Error, key: "'*/' expected." },
1011
Unexpected_token: { code: 1012, category: DiagnosticCategory.Error, key: "Unexpected token." },

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"'{0}' expected.": {
1111
"category": "Error",
1212
"code": 1005
13+
},
14+
"A file cannot have a reference to itself.": {
15+
"category": "Error",
16+
"code": 1006
1317
},
1418
"Trailing comma not allowed.": {
1519
"category": "Error",
@@ -1355,6 +1359,7 @@
13551359
"category": "Error",
13561360
"code": 5001
13571361
},
1362+
13581363
"Cannot find the common subdirectory path for the input files.": {
13591364
"category": "Error",
13601365
"code": 5009

0 commit comments

Comments
 (0)