Skip to content

Commit f3df8b0

Browse files
committed
fix: πŸ› language specific options not being set
βœ… Closes: #231
1 parent 3903e0d commit f3df8b0

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

Diff for: β€Ž.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
- run: 'npm i && npm run lint'
1212

1313
Tests:
14-
needs: [Lint]
1514
runs-on: ${{ matrix.os }}
1615
strategy:
1716
matrix:

Diff for: β€Žsrc/autoProcess.ts

+4-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
addLanguageAlias,
1414
getLanguageFromAlias,
1515
SOURCE_MAP_PROP_MAP,
16+
LANG_SPECIFIC_OPTIONS,
1617
} from './modules/language';
1718
import { prepareContent } from './modules/prepareContent';
1819
import { transformMarkup } from './modules/markup';
@@ -54,22 +55,6 @@ type AutoPreprocessOptions = {
5455
[languageName: string]: TransformerOptions;
5556
};
5657

57-
const LANG_SPECIFIC_OPTIONS: Record<string, any> = {
58-
sass: {
59-
indentedSyntax: true,
60-
stripIndent: true,
61-
},
62-
pug: {
63-
stripIndent: true,
64-
},
65-
coffeescript: {
66-
stripIndent: true,
67-
},
68-
stylus: {
69-
stripIndent: true,
70-
},
71-
};
72-
7358
export const runTransformer = async (
7459
name: string,
7560
options: TransformerOptions,
@@ -133,12 +118,10 @@ export function sveltePreprocess(
133118
Object.assign(opts, nameOpts);
134119
}
135120

136-
if (name !== alias) {
137-
Object.assign(opts, LANG_SPECIFIC_OPTIONS[alias] || null);
121+
Object.assign(opts, LANG_SPECIFIC_OPTIONS[alias]);
138122

139-
if (typeof aliasOpts === 'object') {
140-
Object.assign(opts, aliasOpts);
141-
}
123+
if (name !== alias && typeof aliasOpts === 'object') {
124+
Object.assign(opts, aliasOpts);
142125
}
143126

144127
if (sourceMap && name in SOURCE_MAP_PROP_MAP) {

Diff for: β€Žsrc/modules/language.ts

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ import { basename } from 'path';
22

33
import { PreprocessorArgs } from '../types';
44

5+
export const LANG_SPECIFIC_OPTIONS: Record<string, any> = {
6+
sass: {
7+
indentedSyntax: true,
8+
stripIndent: true,
9+
},
10+
pug: {
11+
stripIndent: true,
12+
},
13+
coffeescript: {
14+
stripIndent: true,
15+
},
16+
stylus: {
17+
stripIndent: true,
18+
},
19+
};
20+
521
export const SOURCE_MAP_PROP_MAP: Record<string, [string, any]> = {
622
babel: ['sourceMaps', true],
723
typescript: ['sourceMap', true],

Diff for: β€Žtest/autoProcess/sourceMaps.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ describe(`sourcemap generation`, () => {
8989
await preprocess(template, opts);
9090

9191
expect(transformer).toHaveBeenCalledWith(
92-
expect.objectContaining({ options: { [key]: val } }),
92+
expect.objectContaining({
93+
options: expect.objectContaining({ [key]: val }),
94+
}),
9395
);
9496
});
9597
},

Diff for: β€Žtest/transformers/pug.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import sveltePreprocess from '../../src';
44
import { preprocess } from '../utils';
55

66
describe('transformer - pug', () => {
7+
it('should de-indent if necessary', async () => {
8+
const template = `<template lang="pug">
9+
main
10+
header
11+
h1</template>`;
12+
13+
const opts = sveltePreprocess();
14+
const preprocessed = await preprocess(template, opts);
15+
16+
expect(preprocessed.code).toBe('<main><header><h1></h1></header></main>');
17+
});
718
it('should correctly prepend mixins with space TABS', async () => {
819
const template = `<template lang="pug">
920
main

0 commit comments

Comments
Β (0)