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

Support for self-closing tags #299

Open
TheComputerM opened this issue Jul 9, 2020 · 5 comments
Open

Support for self-closing tags #299

TheComputerM opened this issue Jul 9, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@TheComputerM
Copy link

As of Svelte v3.24.0, support has been added for self-closing tags: sveltejs/svelte#5080.

However when implementing this, a syntax error is shown, the build is working just fine.

image

I do not know if this is the correct place to file this bug, or prettier-plugin-svelte so please guide me.

Thanks

@TheComputerM TheComputerM added the bug Something isn't working label Jul 9, 2020
@jasonlyu123
Copy link
Member

The parser(parse5) we use doesn't recognize the self-closing style tag. probably because it's not valid HTML. Need to find a way to work around it.

const doc = parse5.parseFragment(htmlx, parseOpts) as DefaultTreeDocumentFragment;

@dummdidumm
Copy link
Member

If it's only about finding the script and styles tag there, we could do the same as in extractTag in svelte-language-server and use the parser of the html-language-server which supports this I think.

@jasonlyu123
Copy link
Member

@dummdidumm what about we also use the preprocess regex in the compiler to remove style in svelte2tsx for now.
https://github.com/sveltejs/svelte/blob/a62d7362150bacc6c84fe8c813ba9b8849216763/src/compiler/preprocess/index.ts#L117
The html-language-service approach also has some problem that needs to be taking care of.

@dummdidumm
Copy link
Member

Good idea! It's only about blanking them out, finding the top level script is done elsewhere.

@dummdidumm
Copy link
Member

dummdidumm commented Aug 10, 2020

I started implementing this for svelte2tsx.parseHtmlx but now found that we actually have more to do than just parse it differently: The support was implemented for preprocessors, not the compiler itself. So that means svelte.compile('<style />') will still throw an error. For us this means we would somehow have to transform /> to ></style while at the same time keeping the source mappings correct. EDIT: Maybe we could just blank the tag out completely then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants