Merge pull request #1364 from Microsoft/coverage

Add grammar walker test coverage cases.
This commit is contained in:
CyrusNajmabadi 2014-12-04 13:01:42 -08:00
commit 4d0f9920e9
34 changed files with 173 additions and 47 deletions

View file

@ -1033,10 +1033,6 @@ module ts {
writer.writePunctuation(tokenToString(kind));
}
function writeOperator(writer: SymbolWriter, kind: SyntaxKind) {
writer.writeOperator(tokenToString(kind));
}
function writeSpace(writer: SymbolWriter) {
writer.writeSpace(" ");
}
@ -7820,7 +7816,9 @@ module ts {
}
function checkThrowStatement(node: ThrowStatement) {
checkExpression(node.expression);
if (node.expression) {
checkExpression(node.expression);
}
}
function checkTryStatement(node: TryStatement) {
@ -8740,20 +8738,6 @@ module ts {
// Language service support
function getNodeAtPosition(sourceFile: SourceFile, position: number): Node {
function findChildAtPosition(parent: Node): Node {
var child = forEachChild(parent, node => {
if (position >= node.pos && position <= node.end && position >= getTokenPosOfNode(node)) {
return findChildAtPosition(node);
}
});
return child || parent;
}
if (position < sourceFile.pos) position = sourceFile.pos;
if (position > sourceFile.end) position = sourceFile.end;
return findChildAtPosition(sourceFile);
}
function isInsideWithStatementBody(node: Node): boolean {
if (node) {
while (node.parent) {

View file

@ -5379,19 +5379,6 @@ module ts {
return new RegExp(regExpString, "gim");
}
function getContainingComment(comments: CommentRange[], position: number): CommentRange {
if (comments) {
for (var i = 0, n = comments.length; i < n; i++) {
var comment = comments[i];
if (comment.pos <= position && position < comment.end) {
return comment;
}
}
}
return undefined;
}
function isLetterOrDigit(char: number): boolean {
return (char >= CharacterCodes.a && char <= CharacterCodes.z) ||
(char >= CharacterCodes.A && char <= CharacterCodes.Z) ||

View file

@ -104,21 +104,6 @@ module ts {
return syntaxList;
}
/**
* Includes the start position of each child, but excludes the end.
*/
export function findListItemIndexContainingPosition(list: Node, position: number): number {
Debug.assert(list.kind === SyntaxKind.SyntaxList);
var children = list.getChildren();
for (var i = 0; i < children.length; i++) {
if (children[i].pos <= position && children[i].end > position) {
return i;
}
}
return -1;
}
/* Gets the token whose text has range [start, end) and
* position >= start and (position < end or (position === end && token is keyword or identifier))
*/

View file

@ -0,0 +1,7 @@
tests/cases/compiler/accessorWithoutBody1.ts(1,19): error TS1005: '{' expected.
==== tests/cases/compiler/accessorWithoutBody1.ts (1 errors) ====
var v = { get foo() }
~
!!! error TS1005: '{' expected.

View file

@ -0,0 +1,7 @@
tests/cases/compiler/accessorWithoutBody2.ts(1,20): error TS1005: '{' expected.
==== tests/cases/compiler/accessorWithoutBody2.ts (1 errors) ====
var v = { set foo(a) }
~
!!! error TS1005: '{' expected.

View file

@ -0,0 +1,10 @@
tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts(1,7): error TS1110: Type expected.
tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts(1,1): error TS2304: Cannot find name 'Foo'.
==== tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts (2 errors) ====
Foo<a,,b>();
!!! error TS1110: Type expected.
~~~
!!! error TS2304: Cannot find name 'Foo'.

View file

@ -0,0 +1,10 @@
tests/cases/compiler/declareModifierOnImport1.ts(1,1): error TS1079: A 'declare' modifier cannot be used with an import declaration.
tests/cases/compiler/declareModifierOnImport1.ts(1,1): error TS2304: Cannot find name 'b'.
==== tests/cases/compiler/declareModifierOnImport1.ts (2 errors) ====
declare import a = b;
~~~~~~~
!!! error TS1079: A 'declare' modifier cannot be used with an import declaration.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'b'.

View file

@ -0,0 +1,12 @@
tests/cases/compiler/indexSignatureWithInitializer1.ts(2,4): error TS1020: An index signature parameter cannot have an initializer.
tests/cases/compiler/indexSignatureWithInitializer1.ts(2,4): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
==== tests/cases/compiler/indexSignatureWithInitializer1.ts (2 errors) ====
class C {
[a: number = 1]: number;
~
!!! error TS1020: An index signature parameter cannot have an initializer.
~~~~~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
}

View file

@ -0,0 +1,4 @@
//// [indexSignatureWithoutTypeAnnotation1..ts]
//// [indexSignatureWithoutTypeAnnotation1..js]

View file

@ -0,0 +1,3 @@
=== tests/cases/compiler/indexSignatureWithoutTypeAnnotation1..ts ===
No type information for this code.

View file

@ -0,0 +1,9 @@
tests/cases/compiler/indexSignatureWithoutTypeAnnotation1.ts(2,3): error TS1021: An index signature must have a type annotation.
==== tests/cases/compiler/indexSignatureWithoutTypeAnnotation1.ts (1 errors) ====
class C {
[a: number];
~~~~~~~~~~~~
!!! error TS1021: An index signature must have a type annotation.
}

View file

@ -0,0 +1,9 @@
tests/cases/compiler/modifierOnParameter1.ts(2,16): error TS1090: 'declare' modifier cannot appear on a parameter.
==== tests/cases/compiler/modifierOnParameter1.ts (1 errors) ====
class C {
constructor(declare p) { }
~~~~~~~
!!! error TS1090: 'declare' modifier cannot appear on a parameter.
}

View file

@ -0,0 +1,7 @@
tests/cases/compiler/throwWithoutNewLine1.ts(1,6): error TS1109: Expression expected.
==== tests/cases/compiler/throwWithoutNewLine1.ts (1 errors) ====
throw
!!! error TS1109: Expression expected.

View file

@ -0,0 +1,11 @@
tests/cases/compiler/throwWithoutNewLine2.ts(1,6): error TS1142: Line break not permitted here.
tests/cases/compiler/throwWithoutNewLine2.ts(2,1): error TS2304: Cannot find name 'a'.
==== tests/cases/compiler/throwWithoutNewLine2.ts (2 errors) ====
throw
!!! error TS1142: Line break not permitted here.
a;
~
!!! error TS2304: Cannot find name 'a'.

View file

@ -0,0 +1,8 @@
tests/cases/compiler/typeParameterInConstraint1.ts(1,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
==== tests/cases/compiler/typeParameterInConstraint1.ts (1 errors) ====
class C<T, U extends T> {
~~~~~~~~~~~
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
}

View file

@ -0,0 +1,10 @@
//// [typeParameterInConstraint1.ts]
class C<T, U extends T> {
}
//// [typeParameterInConstraint1.js]
var C = (function () {
function C() {
}
return C;
})();

View file

@ -0,0 +1,10 @@
//// [typeParameterListWithTrailingComma1.ts]
class C<T,> {
}
//// [typeParameterListWithTrailingComma1.js]
var C = (function () {
function C() {
}
return C;
})();

View file

@ -0,0 +1,5 @@
=== tests/cases/compiler/typeParameterListWithTrailingComma1.ts ===
class C<T,> {
>C : C<T>
>T : T
}

View file

@ -0,0 +1,12 @@
tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS1100: Invalid use of 'eval' in strict mode.
lib.d.ts(29,18): error TS2300: Duplicate identifier 'eval'.
tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS2300: Duplicate identifier 'eval'.
==== tests/cases/compiler/variableDeclarationInStrictMode1.ts (2 errors) ====
"use strict";
var eval;
~~~~
!!! error TS1100: Invalid use of 'eval' in strict mode.
~~~~
!!! error TS2300: Duplicate identifier 'eval'.

View file

@ -0,0 +1,9 @@
tests/cases/compiler/yieldExpression1.ts(1,9): error TS9001: 'generators' are not currently supported.
==== tests/cases/compiler/yieldExpression1.ts (1 errors) ====
function* foo() {
~
!!! error TS9001: 'generators' are not currently supported.
yield
}

View file

@ -0,0 +1,2 @@
// @target: ES5
var v = { get foo() }

View file

@ -0,0 +1,2 @@
// @target: ES5
var v = { set foo(a) }

View file

@ -0,0 +1 @@
Foo<a,,b>();

View file

@ -0,0 +1 @@
declare import a = b;

View file

@ -0,0 +1,3 @@
class C {
[a: number = 1]: number;
}

View file

@ -0,0 +1,3 @@
class C {
[a: number];
}

View file

@ -0,0 +1,3 @@
class C {
constructor(declare p) { }
}

View file

@ -0,0 +1 @@
throw

View file

@ -0,0 +1,2 @@
throw
a;

View file

@ -0,0 +1,2 @@
class C<T, U extends T> {
}

View file

@ -0,0 +1,2 @@
class C<T,> {
}

View file

@ -0,0 +1,2 @@
"use strict";
var eval;

View file

@ -0,0 +1,3 @@
function* foo() {
yield
}