diff --git a/src/autoProcess.ts b/src/autoProcess.ts index d846fe0e..4db85095 100644 --- a/src/autoProcess.ts +++ b/src/autoProcess.ts @@ -22,6 +22,12 @@ import type { Transformers, } from './types'; +const TARGET_LANGUAGES = Object.freeze({ + markup: 'html', + style: 'css', + script: 'javascript', +}); + export const transform = async ( name: string | null | undefined, options: TransformerOptions, @@ -53,25 +59,10 @@ export function sveltePreprocess( aliases, markupTagName = 'template', preserve = [], - defaults, sourceMap = process?.env?.NODE_ENV === 'development' ?? false, ...rest } = {} as AutoPreprocessOptions, ): AutoPreprocessGroup { - const defaultLanguages = Object.freeze({ - markup: 'html', - style: 'css', - script: 'javascript', - ...defaults, - }); - - // todo: remove this on v5 - if (defaults != null) { - console.warn( - '[svelte-preprocess] Deprecation notice: using the "defaults" option is no longer recommended and will be removed in the next major version. Instead, define the language being used explicitly via the lang attribute.\n\nSee https://github.com/sveltejs/svelte-preprocess/issues/362', - ); - } - const transformers = rest as Transformers; if (aliases?.length) { @@ -133,7 +124,7 @@ export function sveltePreprocess( await getTagInfo(svelteFile); if (lang == null || alias == null) { - alias = defaultLanguages[type]; + alias = TARGET_LANGUAGES[type]; lang = getLanguageFromAlias(alias); } @@ -284,7 +275,6 @@ export function sveltePreprocess( }; return { - defaultLanguages, markup, script, style, diff --git a/src/types/index.ts b/src/types/index.ts index cb1811a2..d7b19a68 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -63,24 +63,12 @@ export interface Transformers { [language: string]: TransformerOptions; } -export type AutoPreprocessGroup = PreprocessorGroup & { - defaultLanguages: Readonly<{ - markup: string; - style: string; - script: string; - }>; -}; +export type AutoPreprocessGroup = PreprocessorGroup; export type AutoPreprocessOptions = { markupTagName?: string; aliases?: Array<[string, string]>; preserve?: string[]; - /** @deprecated Don't use "defaults" anymore, define the language being used explicitly instead */ - defaults?: { - markup?: string; - style?: string; - script?: string; - }; sourceMap?: boolean; // transformers diff --git a/test/autoProcess/autoProcess.test.ts b/test/autoProcess/autoProcess.test.ts index 07086e6e..c13afc9a 100644 --- a/test/autoProcess/autoProcess.test.ts +++ b/test/autoProcess/autoProcess.test.ts @@ -137,34 +137,6 @@ describe('options', () => { expect(await doesCompileThrow(input, opts)).toBe(true); }); - it('should accept other languages as default', async () => { - const input = ``; - - const opts = sveltePreprocess({ - defaults: { - markup: 'customMarkup', - script: 'customScript', - style: 'customStyle', - }, - globalStyle: false, - customMarkup({ content }: any) { - return { code: content.replace('markup', 'potato') }; - }, - customScript({ content }: any) { - return { code: content.replace('script', 'potato') }; - }, - customStyle({ content }: any) { - return { code: content.replace('style', 'potato') }; - }, - }); - - const preprocessed = await preprocess(input, opts); - - expect(preprocessed.toString?.()).toContain( - 'potato', - ); - }); - it('should respect lang/type attributes even if another default language is set', async () => { const input = ``; @@ -186,21 +158,4 @@ describe('options', () => { '', ); }); - - it('should be able to use default markup language with template tags', async () => { - const input = `potato`; - - const opts = sveltePreprocess({ - defaults: { - markup: 'potatoScript', - }, - potatoScript({ content }: any) { - return { code: content.replace('potato', 'french-fries') }; - }, - }); - - const preprocessed = await preprocess(input, opts); - - expect(preprocessed.toString?.()).toContain('french-fries'); - }); });