Tests for operator expressions

This commit is contained in:
Ron Buckton 2016-11-26 05:26:09 -05:00
parent dba5c2bf87
commit 33e22ba456
5 changed files with 201 additions and 11 deletions

View file

@ -4231,6 +4231,8 @@ namespace ts {
const fullStart = scanner.getStartPos();
parseExpected(SyntaxKind.OpenParenToken);
reScanTildeToken();
reScanGreaterToken();
let operator = token();
switch (operator) {
case SyntaxKind.AsteriskAsteriskToken:
@ -4245,7 +4247,7 @@ namespace ts {
case SyntaxKind.LessThanToken:
case SyntaxKind.LessThanEqualsToken:
case SyntaxKind.GreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.InstanceOfKeyword:
case SyntaxKind.InKeyword:
case SyntaxKind.EqualsEqualsToken:
@ -4260,17 +4262,10 @@ namespace ts {
case SyntaxKind.ExclamationToken:
case SyntaxKind.VoidKeyword:
case SyntaxKind.TypeOfKeyword:
nextToken();
if (token() === SyntaxKind.CloseParenToken) {
nextToken();
const node = <OperatorExpression>createNode(SyntaxKind.OperatorExpression, fullStart);
node.operator = operator;
return finishNode(node);
}
return undefined;
case SyntaxKind.TildeToken:
operator = reScanTildeToken();
nextToken()
case SyntaxKind.TildePlusToken:
case SyntaxKind.TildeMinusToken:
nextToken();
if (token() === SyntaxKind.CloseParenToken) {
nextToken();
const node = <OperatorExpression>createNode(SyntaxKind.OperatorExpression, fullStart);

View file

@ -1193,6 +1193,9 @@ namespace ts {
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.YieldExpression:
case SyntaxKind.AwaitExpression:
case SyntaxKind.BindExpression:
case SyntaxKind.BindToExpression:
case SyntaxKind.OperatorExpression:
return true;
case SyntaxKind.QualifiedName:
while (node.parent.kind === SyntaxKind.QualifiedName) {

View file

@ -0,0 +1,45 @@
=== tests/cases/conformance/parser/esnext/parser.operatorExpressions.esnext.1.ts ===
// exponentiation
No type information for this code.(**);
No type information for this code.// multiplicative
No type information for this code.(*);
No type information for this code.(/);
No type information for this code.(%);
No type information for this code.// additive
No type information for this code.(+);
No type information for this code.(-);
No type information for this code.// shift
No type information for this code.(<<);
No type information for this code.(>>);
No type information for this code.(>>>);
No type information for this code.// relational
No type information for this code.(<);
No type information for this code.(<=);
No type information for this code.(>);
No type information for this code.(>=);
No type information for this code.(instanceof);
No type information for this code.(in);
No type information for this code.// equality
No type information for this code.(==);
No type information for this code.(===);
No type information for this code.(!=);
No type information for this code.(!==);
No type information for this code.// bitwise
No type information for this code.(&);
No type information for this code.(|);
No type information for this code.(^);
No type information for this code.// logical
No type information for this code.(&&);
No type information for this code.(||);
No type information for this code.// unary additive
No type information for this code.(~+);
No type information for this code.(~-);
No type information for this code.// unary bitwise
No type information for this code.(~);
No type information for this code.// unary logical
No type information for this code.(!);
No type information for this code.// unary other
No type information for this code.(void);
No type information for this code.(typeof);
No type information for this code.
No type information for this code.

View file

@ -0,0 +1,103 @@
=== tests/cases/conformance/parser/esnext/parser.operatorExpressions.esnext.1.ts ===
// exponentiation
(**);
>(**) : (a: number, b: number) => number
// multiplicative
(*);
>(*) : (a: number, b: number) => number
(/);
>(/) : (a: number, b: number) => number
(%);
>(%) : (a: number, b: number) => number
// additive
(+);
>(+) : { (a: string, b: string): string; (a: string, b: number): string; (a: number, b: string): string; (a: number, b: number): number; }
(-);
>(-) : (a: number, b: number) => number
// shift
(<<);
>(<<) : (a: number, b: number) => number
(>>);
>(>>) : (a: number, b: number) => number
(>>>);
>(>>>) : (a: number, b: number) => number
// relational
(<);
>(<) : <T>(a: T, b: T) => boolean
(<=);
>(<=) : <T>(a: T, b: T) => boolean
(>);
>(>) : <T>(a: T, b: T) => boolean
(>=);
>(>=) : <T>(a: T, b: T) => boolean
(instanceof);
>(instanceof) : (a: any, b: Function) => boolean
(in);
>(in) : (a: string | number | symbol, b: any) => boolean
// equality
(==);
>(==) : <T>(a: T, b: T) => boolean
(===);
>(===) : <T>(a: T, b: T) => boolean
(!=);
>(!=) : <T>(a: T, b: T) => boolean
(!==);
>(!==) : <T>(a: T, b: T) => boolean
// bitwise
(&);
>(&) : (a: number, b: number) => number
(|);
>(|) : (a: number, b: number) => number
(^);
>(^) : (a: number, b: number) => number
// logical
(&&);
>(&&) : <T, U>(a: T, b: U) => U
(||);
>(||) : <T, U>(a: T, b: U) => T | U
// unary additive
(~+);
>(~+) : (a: any) => number
(~-);
>(~-) : (a: any) => number
// unary bitwise
(~);
>(~) : (a: any) => number
// unary logical
(!);
>(!) : (a: any) => boolean
// unary other
(void);
>(void) : (a: any) => void
(typeof);
>(typeof) : (a: any) => string

View file

@ -0,0 +1,44 @@
// @target: esnext
// @noEmit: true
// exponentiation
(**);
// multiplicative
(*);
(/);
(%);
// additive
(+);
(-);
// shift
(<<);
(>>);
(>>>);
// relational
(<);
(<=);
(>);
(>=);
(instanceof);
(in);
// equality
(==);
(===);
(!=);
(!==);
// bitwise
(&);
(|);
(^);
// logical
(&&);
(||);
// unary additive
(~+);
(~-);
// unary bitwise
(~);
// unary logical
(!);
// unary other
(void);
(typeof);