Skip to content

Commit 959a4b1

Browse files
Copilotjakebailey
andauthored
fix: add parentheses to enforce [no LineTerminator here] for using declarations
Fix operator precedence bug in nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine where hasPrecedingLineBreak() check was only applied to OpenBraceToken due to Go's && binding tighter than ||, instead of applying to both isBindingIdentifier() and OpenBraceToken as in the TypeScript reference implementation. Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/b40162ed-f661-46b3-bea6-cba2dc0dcb36 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent d019baa commit 959a4b1

6 files changed

Lines changed: 44 additions & 1 deletion

File tree

internal/parser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6330,7 +6330,7 @@ func (p *Parser) nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine(di
63306330
if disallowOf && p.token == ast.KindOfKeyword {
63316331
return p.lookAhead((*Parser).nextTokenIsEqualsOrSemicolonOrColonToken)
63326332
}
6333-
return p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken && !p.hasPrecedingLineBreak()
6333+
return (p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken) && !p.hasPrecedingLineBreak()
63346334
}
63356335

63366336
func (p *Parser) nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLineDisallowOf() bool {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
usingDeclarationWithNewline.ts(1,1): error TS2304: Cannot find name 'using'.
2+
usingDeclarationWithNewline.ts(2,1): error TS2304: Cannot find name 'identifier'.
3+
4+
5+
==== usingDeclarationWithNewline.ts (2 errors) ====
6+
using
7+
~~~~~
8+
!!! error TS2304: Cannot find name 'using'.
9+
identifier;
10+
~~~~~~~~~~
11+
!!! error TS2304: Cannot find name 'identifier'.
12+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/usingDeclarationWithNewline.ts] ////
2+
3+
//// [usingDeclarationWithNewline.ts]
4+
using
5+
identifier;
6+
7+
8+
//// [usingDeclarationWithNewline.js]
9+
"use strict";
10+
using;
11+
identifier;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/usingDeclarationWithNewline.ts] ////
2+
3+
=== usingDeclarationWithNewline.ts ===
4+
5+
using
6+
identifier;
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [tests/cases/compiler/usingDeclarationWithNewline.ts] ////
2+
3+
=== usingDeclarationWithNewline.ts ===
4+
using
5+
>using : any
6+
7+
identifier;
8+
>identifier : any
9+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target: esnext
2+
3+
using
4+
identifier;

0 commit comments

Comments
 (0)