Skip to content

Commit 3d60856

Browse files
committedDec 10, 2022
fix: 🐛 remove support for custom default languages
BREAKING CHANGE: 🧨 Languages must be explicitly defined via the lang attribute.
1 parent 2806ada commit 3d60856

File tree

3 files changed

+8
-75
lines changed

3 files changed

+8
-75
lines changed
 

‎src/autoProcess.ts

+7-17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import type {
2222
Transformers,
2323
} from './types';
2424

25+
const TARGET_LANGUAGES = Object.freeze({
26+
markup: 'html',
27+
style: 'css',
28+
script: 'javascript',
29+
});
30+
2531
export const transform = async (
2632
name: string | null | undefined,
2733
options: TransformerOptions,
@@ -53,25 +59,10 @@ export function sveltePreprocess(
5359
aliases,
5460
markupTagName = 'template',
5561
preserve = [],
56-
defaults,
5762
sourceMap = process?.env?.NODE_ENV === 'development' ?? false,
5863
...rest
5964
} = {} as AutoPreprocessOptions,
6065
): AutoPreprocessGroup {
61-
const defaultLanguages = Object.freeze({
62-
markup: 'html',
63-
style: 'css',
64-
script: 'javascript',
65-
...defaults,
66-
});
67-
68-
// todo: remove this on v5
69-
if (defaults != null) {
70-
console.warn(
71-
'[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',
72-
);
73-
}
74-
7566
const transformers = rest as Transformers;
7667

7768
if (aliases?.length) {
@@ -133,7 +124,7 @@ export function sveltePreprocess(
133124
await getTagInfo(svelteFile);
134125

135126
if (lang == null || alias == null) {
136-
alias = defaultLanguages[type];
127+
alias = TARGET_LANGUAGES[type];
137128
lang = getLanguageFromAlias(alias);
138129
}
139130

@@ -284,7 +275,6 @@ export function sveltePreprocess(
284275
};
285276

286277
return {
287-
defaultLanguages,
288278
markup,
289279
script,
290280
style,

‎src/types/index.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,12 @@ export interface Transformers {
6363
[language: string]: TransformerOptions;
6464
}
6565

66-
export type AutoPreprocessGroup = PreprocessorGroup & {
67-
defaultLanguages: Readonly<{
68-
markup: string;
69-
style: string;
70-
script: string;
71-
}>;
72-
};
66+
export type AutoPreprocessGroup = PreprocessorGroup;
7367

7468
export type AutoPreprocessOptions = {
7569
markupTagName?: string;
7670
aliases?: Array<[string, string]>;
7771
preserve?: string[];
78-
/** @deprecated Don't use "defaults" anymore, define the language being used explicitly instead */
79-
defaults?: {
80-
markup?: string;
81-
style?: string;
82-
script?: string;
83-
};
8472
sourceMap?: boolean;
8573

8674
// transformers

‎test/autoProcess/autoProcess.test.ts

-45
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,6 @@ describe('options', () => {
137137
expect(await doesCompileThrow(input, opts)).toBe(true);
138138
});
139139

140-
it('should accept other languages as default', async () => {
141-
const input = `<template>markup</template><style>style</style><script>script</script>`;
142-
143-
const opts = sveltePreprocess({
144-
defaults: {
145-
markup: 'customMarkup',
146-
script: 'customScript',
147-
style: 'customStyle',
148-
},
149-
globalStyle: false,
150-
customMarkup({ content }: any) {
151-
return { code: content.replace('markup', 'potato') };
152-
},
153-
customScript({ content }: any) {
154-
return { code: content.replace('script', 'potato') };
155-
},
156-
customStyle({ content }: any) {
157-
return { code: content.replace('style', 'potato') };
158-
},
159-
});
160-
161-
const preprocessed = await preprocess(input, opts);
162-
163-
expect(preprocessed.toString?.()).toContain(
164-
'potato<style>potato</style><script>potato</script>',
165-
);
166-
});
167-
168140
it('should respect lang/type attributes even if another default language is set', async () => {
169141
const input = `<script lang="tomatoScript">script</script>`;
170142

@@ -186,21 +158,4 @@ describe('options', () => {
186158
'<script lang="tomatoScript">tomato</script>',
187159
);
188160
});
189-
190-
it('should be able to use default markup language with template tags', async () => {
191-
const input = `potato`;
192-
193-
const opts = sveltePreprocess({
194-
defaults: {
195-
markup: 'potatoScript',
196-
},
197-
potatoScript({ content }: any) {
198-
return { code: content.replace('potato', 'french-fries') };
199-
},
200-
});
201-
202-
const preprocessed = await preprocess(input, opts);
203-
204-
expect(preprocessed.toString?.()).toContain('french-fries');
205-
});
206161
});

0 commit comments

Comments
 (0)
Please sign in to comment.