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

Cannot break generic parameter declarations into multiple lines #2094

Open
svallory opened this issue Jan 29, 2024 · 3 comments
Open

Cannot break generic parameter declarations into multiple lines #2094

svallory opened this issue Jan 29, 2024 · 3 comments
Labels
type:unverified bug A bug report that has not been verified

Comments

@svallory
Copy link

Marko Version: 5.32.7

VS Code Extension Version: 1.1.18

Details

When declaring an Input type with generic parameters, breaking the generic parameters into multiple lines breaks the compiler

Expected Behavior

image

Actual Behavior

One generic param

export interface Input<
  A
> {}

image

image

$ mtc          
src/components/generics-bug.marko - error TS1005
',' expected.

src/components/generics-bug.marko - error TS1359
Identifier expected. 'class' is a reserved word that cannot be used here.

Two generic params of one with trailing comma

export interface Input<
  A,
  B
> {}

or

export interface Input<
  A,
> {}

image

image

 npm run build

> @tokilabs/[email protected] build
> npm run clean && mtc


> @tokilabs/[email protected] clean
> rm -rf coverage dist node_modules/.{cache,vite,vitest}

src/components/generics-bug.marko - error TS1359
Identifier expected. 'class' is a reserved word that cannot be used here.
Additional Info

Your Environment

VS Code on Mac

Steps to Reproduce

Create an Input type with at least one generic parameter declaring each parameter in its own line

Stack Trace

@svallory svallory added the type:unverified bug A bug report that has not been verified label Jan 29, 2024
@AngusMorton
Copy link

My understanding is that this is a limitation/issue in the htmljs parser. There is no native representation of import/export in the parser, they are parsed as concise mode tags.

One solution would be to give the htmljs-parser the ability to parse import and export statements natively. There may be an easier fix, but I don't have a good enough understanding of the htmljs-parser to know!

@DylanPiercey
Copy link
Contributor

@AngusMorton @svallory the htmljs parser tries hard not to do a full parse of the javascript sections of code. For import, export and friends they are parsed in "statement" mode (previously it was parsed as a concise mode tag but now it goes directly into our expression parsing similar to attribute values).

When the parser is scanning for the end of an expression it will skip over strings, matched bracket pairs, regexps and some javascript operators and keywords. The problem is that this logic does not currently account for generics and since the statement parse state exits when there is a newline (assuming the expression isn't continued because of being a string, bracketed, etc) it will error when you have multiline generics outside of a bracketed section.

We need to think of a good way to make the parser aware of generics, while still allowing it to do as little processing as possible.

@svallory
Copy link
Author

svallory commented Feb 10, 2024

@DylanPiercey I don't see many options other balancing < in htmljs like it does for other tokens in EXPRESSION.ts. The trick part will be differentiating a "less than" from a generic section start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:unverified bug A bug report that has not been verified
Projects
None yet
Development

No branches or pull requests

3 participants