Skip to content

Commit

Permalink
breaking: remove preserve option (#622)
Browse files Browse the repository at this point in the history
closes #305
closes #312

Turns out the preserve option doesn't actually do anything useful anymore because it's now looking at lang and not type as it was originally. The original issues are already fixed without specifying preserve at all.
  • Loading branch information
benmccann committed Jun 12, 2024
1 parent c435ebd commit e46b53e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 17 deletions.
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 @@ -107,20 +107,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 () => {
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

0 comments on commit e46b53e

Please sign in to comment.