Skip to content

Commit 1a3db28

Browse files
author
Yui T
committed
2 parents 21e1951 + 1a7862c commit 1a3db28

File tree

63 files changed

+2210
-469
lines changed

Some content is hidden

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

63 files changed

+2210
-469
lines changed
Binary file not shown.
Binary file not shown.
-2.5 KB
Binary file not shown.
19.3 KB
Binary file not shown.

doc/spec.md

Lines changed: 291 additions & 127 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 47 additions & 19 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");
@@ -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.

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

src/compiler/parser.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ module ts {
10731073
case ParsingContext.TypeParameters:
10741074
return isIdentifier();
10751075
case ParsingContext.ArgumentExpressions:
1076-
return isExpression();
1076+
return token === SyntaxKind.CommaToken || isExpression();
10771077
case ParsingContext.ArrayLiteralMembers:
10781078
return token === SyntaxKind.CommaToken || isExpression();
10791079
case ParsingContext.Parameters:
@@ -1226,18 +1226,6 @@ module ts {
12261226
error(Diagnostics._0_expected, ",");
12271227
}
12281228
else if (isListTerminator(kind)) {
1229-
// Check if the last token was a comma.
1230-
if (commaStart >= 0) {
1231-
if (!allowTrailingComma) {
1232-
if (file.syntacticErrors.length === errorCountBeforeParsingList) {
1233-
// Report a grammar error so we don't affect lookahead
1234-
grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed);
1235-
}
1236-
}
1237-
// Always preserve a trailing comma by marking it on the NodeArray
1238-
result.hasTrailingComma = true;
1239-
}
1240-
12411229
break;
12421230
}
12431231
else {
@@ -1248,6 +1236,23 @@ module ts {
12481236
nextToken();
12491237
}
12501238
}
1239+
1240+
// Recording the trailing comma is deliberately done after the previous
1241+
// loop, and not just if we see a list terminator. This is because the list
1242+
// may have ended incorrectly, but it is still important to know if there
1243+
// was a trailing comma.
1244+
// Check if the last token was a comma.
1245+
if (commaStart >= 0) {
1246+
if (!allowTrailingComma) {
1247+
if (file.syntacticErrors.length === errorCountBeforeParsingList) {
1248+
// Report a grammar error so we don't affect lookahead
1249+
grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed);
1250+
}
1251+
}
1252+
// Always preserve a trailing comma by marking it on the NodeArray
1253+
result.hasTrailingComma = true;
1254+
}
1255+
12511256
result.end = getNodeEnd();
12521257
parsingContext = saveParsingContext;
12531258
return result;
@@ -3826,15 +3831,17 @@ module ts {
38263831
}
38273832
else {
38283833
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
3834+
var start = range.pos;
3835+
var end = range.end;
3836+
var length = end - start;
3837+
38293838
if (!matchResult) {
3830-
var start = range.pos;
3831-
var length = range.end - start;
38323839
errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax);
38333840
}
38343841
else {
38353842
referencedFiles.push({
3836-
pos: range.pos,
3837-
end: range.end,
3843+
pos: start,
3844+
end: end,
38383845
filename: matchResult[3]
38393846
});
38403847
}
@@ -3951,6 +3958,9 @@ module ts {
39513958
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
39523959
diagnostic = Diagnostics.File_0_not_found;
39533960
}
3961+
else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) {
3962+
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
3963+
}
39543964
}
39553965
else {
39563966
if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) {

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ module ts {
655655
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
656656
// computed value.
657657
getEnumMemberValue(node: EnumMember): number;
658+
659+
isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
660+
getAliasedSymbol(symbol: Symbol): Symbol;
658661
}
659662

660663
export interface TextWriter {

0 commit comments

Comments
 (0)