Repository: sveltejs/svelte-preprocess
Pull request #622 (2023-12-17 15:51:14)

breaking: remove preserve option
closes https://github.com/sveltejs/svelte-preprocess/issues/305
closes https://github.com/sveltejs/svelte-preprocess/issues/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.


Patch:
diff --git a/docs/preprocessing.md b/docs/preprocessing.md
index ef33ffd..fe738c5 100644
--- a/docs/preprocessing.md
+++ b/docs/preprocessing.md
@@ -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
diff --git a/src/autoProcess.ts b/src/autoProcess.ts
index 4db8509..09da514 100644
--- a/src/autoProcess.ts
+++ b/src/autoProcess.ts
@@ -58,7 +58,6 @@ export function sveltePreprocess(
   {
     aliases,
     markupTagName = 'template',
-    preserve = [],
     sourceMap = process?.env?.NODE_ENV === 'development' ?? false,
     ...rest
   } = {} as AutoPreprocessOptions,
@@ -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({
diff --git a/src/types/index.ts b/src/types/index.ts
index 2bf98ad..fe8a0eb 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -68,7 +68,6 @@ export type AutoPreprocessGroup = PreprocessorGroup;
 export type AutoPreprocessOptions = {
   markupTagName?: string;
   aliases?: Array<[string, string]>;
-  preserve?: string[];
   sourceMap?: boolean;
 
   // transformers


Test patch:
diff --git a/test/autoProcess/autoProcess.test.ts b/test/autoProcess/autoProcess.test.ts
index d663cb4..89c6b40 100644
--- a/test/autoProcess/autoProcess.test.ts
+++ b/test/autoProcess/autoProcess.test.ts
@@ -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>`,
     );
   });