Skip to content

Instantly share code, notes, and snippets.

@luiz
Last active August 12, 2019 15:37
Show Gist options
  • Save luiz/3161b4a986f1f5a82ba5cd667070b7f9 to your computer and use it in GitHub Desktop.
Save luiz/3161b4a986f1f5a82ba5cd667070b7f9 to your computer and use it in GitHub Desktop.
Code that does not compile with Svelte 3.8.0 and Typescript 3.5.3
import * as sass from 'node-sass';
import * as svelte from 'svelte/compiler';
import * as fs from 'fs';
import { promisify } from 'util';
const renderSass = promisify(sass.render);
const readFile = promisify(fs.readFile);
const preprocessSass = async (data: string) => {
const result = await renderSass({ data });
return {
code: result.css.toString(),
};
};
export const load = async (fileName: string) => {
const source = await readFile(fileName).then(buffer => buffer.toString());
const preprocessedSource = await svelte.preprocess(source, {
// compilation fails here
style: (input) => preprocessSass(input.content),
});
return svelte.parse(preprocessedSource.code);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment