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

breaking: remove preserve option #622

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ The following options can be passed to the preprocessor. None are required:
| --------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `markupTagName` | `"template"` | `string` that sets the name of the tag `svelte-preprocess` looks for markup in custom languages.<br><br>i.e `markup` makes it possible to write your markup between `<markup lang="..."></markup>` tag. |
| `aliases` | `null` | A list of tuples `[alias: string, language: string]` that correlates an `alias` to a `language`<br><br>i.e `['cst', 'customLanguage']` means<br>`<... src="./file.cst">`<br>`<... lang="cst">`<br>are treated as `customLanguage`. |
| `preserve` | `[]` | A `string` list of languages/aliases that shouldn't pass through the preprocessor. (i.e `ld+json`) |
| `sourceMap` | `false` | If `true`, `svelte-preprocess` generates sourcemap for every language that supports it. |

##### Configuring preprocessors
Expand Down
5 changes: 0 additions & 5 deletions src/autoProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function sveltePreprocess(
{
aliases,
markupTagName = 'template',
preserve = [],
sourceMap = process?.env?.NODE_ENV === 'development' ?? false,
...rest
} = {} as AutoPreprocessOptions,
Expand Down Expand Up @@ -128,10 +127,6 @@ export function sveltePreprocess(
lang = getLanguageFromAlias(alias);
}

if ((lang && preserve.includes(lang)) || preserve.includes(alias)) {
return { code: content };
}

const transformerOptions = getTransformerOptions(lang, alias);

content = prepareContent({
Expand Down
1 change: 0 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export type AutoPreprocessGroup = PreprocessorGroup;
export type AutoPreprocessOptions = {
markupTagName?: string;
aliases?: Array<[string, string]>;
preserve?: string[];
sourceMap?: boolean;

// transformers
Expand Down
14 changes: 4 additions & 10 deletions test/autoProcess/autoProcess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,14 @@ describe('options', () => {
expect(preprocessed.toString?.()).toContain('div{}');
});

it('should NOT preprocess preserved languages', async () => {
const input = `<div></div><script lang="ld+json">{"json":true}</script>`;
const opts = sveltePreprocess({
preserve: ['ld+json'],
aliases: [['ld+json', 'structuredData']],
structuredData() {
return { code: '', map: '' };
},
});
it('should NOT preprocess unrecognized languages', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that I forgot how the auto preprocessor is working 😅 I didn't remember it's skipping unknown languages 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point in the past it wasn't, but it's nice that it is now. Saved me from having to implement it!

I think it's not really that it's skipping unknown languages but that it's looking at the lang field, so you can specify whatever you want in type since it's not using that field. Then since this doesn't specify a lang it gets skipped.

const input = `<div></div><script type="ld+json">{"json":true}</script>`;
const opts = sveltePreprocess();

const preprocessed = await preprocess(input, opts);

expect(preprocessed.toString?.()).toContain(
`<script lang="ld+json">{"json":true}</script>`,
`<script type="ld+json">{"json":true}</script>`,
);
});

Expand Down