Merge pull request #1364 from Microsoft/coverage
Add grammar walker test coverage cases.
This commit is contained in:
commit
4d0f9920e9
34 changed files with 173 additions and 47 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) ||
|
||||
|
|
|
@ -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))
|
||||
*/
|
||||
|
|
|
@ -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.
|
|
@ -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.
|
|
@ -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'.
|
|
@ -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'.
|
|
@ -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.
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
//// [indexSignatureWithoutTypeAnnotation1..ts]
|
||||
|
||||
|
||||
//// [indexSignatureWithoutTypeAnnotation1..js]
|
|
@ -0,0 +1,3 @@
|
|||
=== tests/cases/compiler/indexSignatureWithoutTypeAnnotation1..ts ===
|
||||
|
||||
No type information for this code.
|
|
@ -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.
|
||||
}
|
|
@ -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.
|
||||
}
|
|
@ -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.
|
11
tests/baselines/reference/throwWithoutNewLine2.errors.txt
Normal file
11
tests/baselines/reference/throwWithoutNewLine2.errors.txt
Normal 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'.
|
|
@ -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.
|
||||
}
|
10
tests/baselines/reference/typeParameterInConstraint1.js
Normal file
10
tests/baselines/reference/typeParameterInConstraint1.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
//// [typeParameterInConstraint1.ts]
|
||||
class C<T, U extends T> {
|
||||
}
|
||||
|
||||
//// [typeParameterInConstraint1.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
|
@ -0,0 +1,10 @@
|
|||
//// [typeParameterListWithTrailingComma1.ts]
|
||||
class C<T,> {
|
||||
}
|
||||
|
||||
//// [typeParameterListWithTrailingComma1.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
|
@ -0,0 +1,5 @@
|
|||
=== tests/cases/compiler/typeParameterListWithTrailingComma1.ts ===
|
||||
class C<T,> {
|
||||
>C : C<T>
|
||||
>T : T
|
||||
}
|
|
@ -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'.
|
9
tests/baselines/reference/yieldExpression1.errors.txt
Normal file
9
tests/baselines/reference/yieldExpression1.errors.txt
Normal 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
|
||||
}
|
2
tests/cases/compiler/accessorWithoutBody1.ts
Normal file
2
tests/cases/compiler/accessorWithoutBody1.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
// @target: ES5
|
||||
var v = { get foo() }
|
2
tests/cases/compiler/accessorWithoutBody2.ts
Normal file
2
tests/cases/compiler/accessorWithoutBody2.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
// @target: ES5
|
||||
var v = { set foo(a) }
|
|
@ -0,0 +1 @@
|
|||
Foo<a,,b>();
|
1
tests/cases/compiler/declareModifierOnImport1.ts
Normal file
1
tests/cases/compiler/declareModifierOnImport1.ts
Normal file
|
@ -0,0 +1 @@
|
|||
declare import a = b;
|
3
tests/cases/compiler/indexSignatureWithInitializer1.ts
Normal file
3
tests/cases/compiler/indexSignatureWithInitializer1.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
class C {
|
||||
[a: number = 1]: number;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class C {
|
||||
[a: number];
|
||||
}
|
3
tests/cases/compiler/modifierOnParameter1.ts
Normal file
3
tests/cases/compiler/modifierOnParameter1.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
class C {
|
||||
constructor(declare p) { }
|
||||
}
|
1
tests/cases/compiler/throwWithoutNewLine1.ts
Normal file
1
tests/cases/compiler/throwWithoutNewLine1.ts
Normal file
|
@ -0,0 +1 @@
|
|||
throw
|
2
tests/cases/compiler/throwWithoutNewLine2.ts
Normal file
2
tests/cases/compiler/throwWithoutNewLine2.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
throw
|
||||
a;
|
2
tests/cases/compiler/typeParameterInConstraint1.ts
Normal file
2
tests/cases/compiler/typeParameterInConstraint1.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
class C<T, U extends T> {
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
class C<T,> {
|
||||
}
|
2
tests/cases/compiler/variableDeclarationInStrictMode1.ts
Normal file
2
tests/cases/compiler/variableDeclarationInStrictMode1.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
var eval;
|
3
tests/cases/compiler/yieldExpression1.ts
Normal file
3
tests/cases/compiler/yieldExpression1.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
function* foo() {
|
||||
yield
|
||||
}
|
Loading…
Reference in a new issue