Skip to content

Disallow newline after as after function instantiationΒ #55806

Open
@nicolo-ribaudo

Description

@nicolo-ribaudo

πŸ”Ž Search Terms

as newline ASI function type parameters spec difference

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwB4AVAPgAoBKALnhIChRJYFUoBbEAZwAcowCAGLwA3vBAAPXjhgZ4GAJ68EAcxAYMIGPAC88KKkXwAvk3DQ48CBoPc6hxQwY35kvQRzwi8AEzwyOwYhADp1TW0GIA

πŸ’» Code

let x = foo < 2 > as
F.getter

πŸ™ Actual behavior

It is parsed as

let x = foo<2> as F.getter;

πŸ™‚ Expected behavior

It should be parsed as

let x = (foo < 2) > as;
F.getter;

Additional information about the issue

The linked code is valid JavaScript code, and it would be great if tsc could parse as such.

I know that TS is not in general a syntactic superset of JavaScript, but both Babel and SWC already parse this example (when in TS mode) according to JS semantics. We could change our parsers, but it would be better if this ambiguity could be solved in tsc.

cc @kdy1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions