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

feature: preprocessor can change tag attributes like <script lang="ts"> #5900

Open
milahu opened this issue Jan 18, 2021 · 2 comments
Open

Comments

@milahu
Copy link
Contributor

milahu commented Jan 18, 2021

How important is this feature to you?
zero to low priority, mostly cosmetic. browsers ignore extra attributes like <script lang="ts">

Is your feature request related to a problem? Please describe.
currently, preprocessors can not change tag attributes

for example

<script lang="ts">export let name: string</script>

can only be transformed to

<script lang="ts">export let name</script>

but not to

<script>export let name</script>

because preprocessors can only read attributes, but not change them

Describe the solution you'd like
allow preprocessors to to modify attributes
by returning the new attributes in result.attributes

for example, the typescript preprocessor could do

if (attributes.lang != 'ts') return;
delete attributes.lang;
code = compile(code);
return { code, map, attributes };

Describe alternatives you've considered
do nothing, and let browsers ignore extra attributes

related code

const processed = await preprocessor({
content,
attributes: parse_attributes(attributes),
filename
});
if (processed && processed.dependencies) {
dependencies.push(...processed.dependencies);
}
if (!processed || !processed.map && processed.code === content) {
return no_change();
}
return get_replacement(file_basename, offset, get_location, content, processed, `<${tag_name}${attributes}>`, `</${tag_name}>`);

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants