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

fix(es/parser): Fix bin expr parsed as instantiation expr #4992

Merged
merged 1 commit into from
Jun 18, 2022
Merged

fix(es/parser): Fix bin expr parsed as instantiation expr #4992

merged 1 commit into from
Jun 18, 2022

Conversation

g-plane
Copy link
Contributor

@g-plane g-plane commented Jun 18, 2022

Description:

This PR fixes binary expression parsed as instantiation expression.

Input:

a<b>>c<d>

Before:

a > c

After:

a < b >> c

Note that expressions like f<x> & g<y> aren't valid any more, as TypeScript does.

BREAKING CHANGE:

No.

Related issue (if exists):

Fixes #4990

@kdy1 kdy1 added this to the Planned milestone Jun 18, 2022
@kdy1
Copy link
Member

kdy1 commented Jun 18, 2022

Did you try https://www.typescriptlang.org/play?#code/GYHgHgfABAZFDmICeEBQ7gFcB2BjALgJYD22UoAKhABQCUA3qlM1AE4Cm+mrZArANyoAvhhwESZRFTqMWbTtz6ChQA

f<x> & g<y>


function f<T>(){
    return 5;
}

function g<T>(){
    return 5;
}

It fails with

The '&' operator is not allowed for boolean types. Consider using '&&' instead.
Cannot find name 'x'.
Operator '>' cannot be applied to types 'boolean' and '<T>() => number'.

which implies it's parsed as

((f<x)>)&(g<y>)

I'm not sure if this PR is identical

@g-plane
Copy link
Contributor Author

g-plane commented Jun 18, 2022

image

See the second error message "Expression expected".

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you!


swc-bump:

  • swc_ecma_parser

@kdy1 kdy1 enabled auto-merge (squash) June 18, 2022 03:11
@kdy1 kdy1 merged commit 36ef3e4 into swc-project:main Jun 18, 2022
@g-plane g-plane deleted the issue-4990 branch June 18, 2022 03:28
@kdy1 kdy1 modified the milestones: Planned, v1.2.204 Jun 18, 2022
@nicolo-ribaudo
Copy link

Heads up: microsoft/TypeScript#49353 changes the parsing of f<x> & g<y>.

@kdy1
Copy link
Member

kdy1 commented Jun 18, 2022

Oops
cc @g-plane

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Less than and right shift operators are parsed as generics
3 participants