Skip to content

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

@milahu

Description

@milahu

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}>`);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions