Skip to content

Commit

Permalink
fix: 🐛 rename scss prepend option from data to prependData
Browse files Browse the repository at this point in the history
Aligning the prop value with the
[`sass-loader`](https://webpack.js.org/loaders/sass-loader/) option.

BREAKING CHANGE: 🧨 Content passed through the `data` property won't be prepended anymore.
  • Loading branch information
kaisermann committed Jul 5, 2020
1 parent 8a1f8af commit 16b1325
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/modules/typescript/compileFromMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function createImportTransformerFromProgram(program: ts.Program) {
continue;
}
}

newElements.push(spec);
}

Expand Down
7 changes: 5 additions & 2 deletions src/transformers/scss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ const transformer: Transformer<Options.Sass> = async ({
implementation = sass = mod.default;
}

const { renderSync, ...sassOptions }: Options.Sass = {
const { renderSync, prependData, ...restOptions } = {
sourceMap: true,
...options,
includePaths: getIncludePaths(filename, options.includePaths),
outFile: `${filename}.css`,
};

sassOptions.data = options.data ? options.data + content : content;
const sassOptions = {
...restOptions,
data: prependData ? prependData + content : content,
};

// scss errors if passed an empty string
if (sassOptions.data.length === 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export interface Babel extends BabelOptions {
}

export type Pug = PugOptions;
export type Sass = Omit<SassOptions, 'file'> & {
export type Sass = Omit<SassOptions, 'file' | 'data'> & {
implementation?: {
render?: typeof render;
renderSync?: typeof renderSync;
};
renderSync?: boolean;
prependData?: string;
};
// from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/less/index.d.ts#L80
export interface Less {
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type AType = "test1" | "test2"
export type AType = 'test1' | 'test2';
export interface AInterface {
test: string
test: string;
}
export const AValue: string = "test"
export const AValue: string = 'test';

export default "String"
export default 'String';
4 changes: 2 additions & 2 deletions test/transformers/scss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('transformer - scss', () => {
const template = `<style lang="scss"></style>`;
const opts = getAutoPreprocess({
scss: {
data: '$color:red;div{color:$color}',
prependData: '$color:red;div{color:$color}',
},
});

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('transformer - scss', () => {
const template = `<style lang="scss"></style>`;
const opts = getAutoPreprocess({
scss: {
data: '$color:blue;div{color:$color}',
prependData: '$color:blue;div{color:$color}',
renderSync: true,
},
});
Expand Down

0 comments on commit 16b1325

Please sign in to comment.