Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: x < y >>>= z is incorrectly interpreted as a type argument list #7403

Closed
evanw opened this issue May 16, 2023 · 1 comment · Fixed by #7407
Closed

TypeScript: x < y >>>= z is incorrectly interpreted as a type argument list #7403

evanw opened this issue May 16, 2023 · 1 comment · Fixed by #7407
Assignees
Labels
Milestone

Comments

@evanw
Copy link

evanw commented May 16, 2023

Describe the bug

SWC's interpretation of type arguments in TypeScript code is different than the TypeScript compiler, which can cause SWC to generate incorrect JavaScript.

This is a follow-up to #7387, which was not fixed correctly.

Input code

declare let fn: any, x: any, y: any
declare function z<A, B>(_: any): any
fn(z < Number, Object > (y))
fn(z < Number, Object > = y)
fn(x < y, x > y)
fn(x < y, x >= y)
fn(x < y, x >> y)
fn(x < y, x >>= y)
fn(x < y, x >>>= y)
fn(x < y, x < y, x >>= y)
fn(x < y, x < y, x >>> y)
fn(x < y, x < y, x >>>= y)

Config

(I only ran SWC via the playground)

Playground link

https://play.swc.rs/?version=1.3.58&code=H4sIAAAAAAAAA0tJTc5JLEpVyEktUUjLs1JIzKvUUaiA0pVgmisFqiatNC%2B5JDM%2FT6HKxlFHwclOIx4srwlRlZanUaVgo%2BBXmpuUWqSj4J%2BUlZpcomCnoFGpqYlT0lahEixZAZQEWQwUQhfAVIKpBpsiTDHcqhGacMuANQEAPpF21y8BAAA%3D&config=H4sIAAAAAAAAA1VPOw7DIAzdOQXy3CHK0KF36CEQdSIqfsKOVBTl7oUE0maz38fveRVSwps0PORaxrJElQjTuReEsmf1KQhwjkg6mchw6yxTpSZlCXdoOxhglWbk6kIah3FoDrAhEHZHw5zxZsr%2FmTq4mJDoKqxS5WeL10TRUsGF17KT7Zfa92hwh5%2Boh52HwdCzOzktKLYvIO%2B2AhcBAAA%3D

Expected behavior

SWC should generate the same output as the TypeScript compiler does:

fn(z(y));
fn((z) = y);
fn(x < y, x > y);
fn(x < y, x >= y);
fn(x < y, x >> y);
fn(x < y, x >>= y);
fn(x < y, x >>>= y);
fn(x < y, x < y, x >>= y);
fn(x < y, x < y, x >>> y);
fn(x < y, x < y, x >>>= y);

Actual behavior

Starting with version 1.3.58, SWC fails to parse this code with a syntax error (due to the incorrect fix for #7387):

  x Expression expected
   ,-[input.ts:1:1]
 4 | fn(z < Number, Object > = y)
   :                         ^

This syntax error is a regression from 1.3.57.

And if that line is commented out, SWC still incorrectly transforms fn(x < y, x >>>= y) into fn(x >>= y) and fn(x < y, x < y, x >>>= y) into fn(x < y, x >>= y).

Version

1.3.58

Additional context

No response

@evanw evanw added the C-bug label May 16, 2023
@kdy1 kdy1 self-assigned this May 16, 2023
@kdy1 kdy1 added this to the Planned milestone May 16, 2023
kdy1 added a commit that referenced this issue May 18, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.59 May 19, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Jun 18, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Jun 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants