-
Notifications
You must be signed in to change notification settings - Fork 150
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
Strip preprocessor lang attribute from output #260
Comments
Since we need to remove these attributes, we'll need to do it in the |
Trying to think of issues, Only 2 concerns I see
Concern 1 is probably a non-issue as it probably isn't done often in practice. But it could be easily worked around by placing the other preprocessor inside svelte-preprocess. Concern 2 is probably doesn't matter much in practice, but doesn't have an obvious solution. It is impossible for the preprocessor to know what language the code is currently in and if it can safely apply its modifications to it. Since I cannot imagine any benefit to having this done in separate steps anymore (Concern 1 removes all benefits I could foresee), and can conceive of issues that may occur because of it. I believe it would be better to alter them at the same time. |
We can solve number 2 by making this preprocessor terminal in the markup phase. That is, we preprocess the scripts/style and remove the lang tag during our markup phase. This can be easily done by parsing the markup (which we need to do to some extent anyways for aliases and template detection) or by calling If we do terminate at the markup phase. There is no real need to modify the existing preprocessors to run in markup phase either. We just need a wrapper. function markupTerminator(langs: string[],preprocessors: PreprocessorGroup|PreprocessorGroup[]): PreprocessorGroup {
return {
async markup({ content ,filename }): Promise<Processed> {
const preprocessed = svelte.preprocess(content ,preprocessors ,{ filename })
// Insert magic-string code to strip lang tags that match langs string from preprocessed.code here
return preprocessed
}
}
}
// Example usage
import { typescript } from 'svelte-preprocess';
// Better names needed. Some name to distinguish it from the version that doesn't strip markup.
// Or possibly remove ability to run on script/style completely, and instead only offer versions that strip the markup
export function typescriptTerminalPreprocessor(config) {
return markupTerminator(['ts','typescript','script/ts','script/typescript','text/typescript'], typescript(config))
} Usage (naturally I do not recommend this name) import { typescriptTerminalPreprocessor } from 'svelte-preprocess';
module.exports = {
"preprocess": typescriptTerminalPreprocessor({sourceMap: true})
} |
Svelte 5 will support |
Is your feature request related to a problem? Please describe.
svelte-preprocess utilizes the
lang
attribute to identify the languages used, but leaves them in the output after preprocessing.Describe the solution you'd like
I would like the
lang
attribute to be removed from the generated output, primarily for cleanliness.How important is this feature to you?
Not important at all, but seems like something that should be done, and should be done here.
Additional context
Originally noticed by bluwy
The text was updated successfully, but these errors were encountered: