diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9502f761c8a..a448fe0d3c7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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 = 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 = createNode(SyntaxKind.OperatorExpression, fullStart); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1e88ed02905..0806430c1a8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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) { diff --git a/tests/baselines/reference/parser.operatorExpressions.esnext.1.symbols b/tests/baselines/reference/parser.operatorExpressions.esnext.1.symbols new file mode 100644 index 00000000000..2774a4c79fa --- /dev/null +++ b/tests/baselines/reference/parser.operatorExpressions.esnext.1.symbols @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/parser.operatorExpressions.esnext.1.types b/tests/baselines/reference/parser.operatorExpressions.esnext.1.types new file mode 100644 index 00000000000..059b4e182c7 --- /dev/null +++ b/tests/baselines/reference/parser.operatorExpressions.esnext.1.types @@ -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 +(<); +>(<) : (a: T, b: T) => boolean + +(<=); +>(<=) : (a: T, b: T) => boolean + +(>); +>(>) : (a: T, b: T) => boolean + +(>=); +>(>=) : (a: T, b: T) => boolean + +(instanceof); +>(instanceof) : (a: any, b: Function) => boolean + +(in); +>(in) : (a: string | number | symbol, b: any) => boolean + +// equality +(==); +>(==) : (a: T, b: T) => boolean + +(===); +>(===) : (a: T, b: T) => boolean + +(!=); +>(!=) : (a: T, b: T) => boolean + +(!==); +>(!==) : (a: T, b: T) => boolean + +// bitwise +(&); +>(&) : (a: number, b: number) => number + +(|); +>(|) : (a: number, b: number) => number + +(^); +>(^) : (a: number, b: number) => number + +// logical +(&&); +>(&&) : (a: T, b: U) => 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 + diff --git a/tests/cases/conformance/parser/esnext/parser.operatorExpressions.esnext.1.ts b/tests/cases/conformance/parser/esnext/parser.operatorExpressions.esnext.1.ts new file mode 100644 index 00000000000..463e23a835e --- /dev/null +++ b/tests/cases/conformance/parser/esnext/parser.operatorExpressions.esnext.1.ts @@ -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);