Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jul 28, 2024
1 parent 0c343dc commit 69d4e81
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
3 changes: 3 additions & 0 deletions packages/repl-sdk/src/compilers/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export async function compiler(config = {}, api) {

function isPreview(meta) {
if (!meta) return false;

return meta.includes('preview');
}

function isBelow(meta) {
if (!meta) return false;

return meta.includes('below');
}

Expand Down Expand Up @@ -148,6 +150,7 @@ export async function compiler(config = {}, api) {
if (!lang) {
return 'skip';
}

/**
* Sometimes, meta is not required,
* like with the `mermaid` language
Expand Down
3 changes: 1 addition & 2 deletions packages/repl-sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ export class Compiler {
* @returns {import('./types.ts').ResolvedCompilerOptions)}
*/
optionsFor = (format, flavor) => {
const { compiler: _, needsLiveMeta, ...rest } = this.#resolveFormat(format, flavor);
const { needsLiveMeta } = this.#resolveFormat(format, flavor);

return {
...rest,
needsLiveMeta: needsLiveMeta ?? true,
importMap: this.#options.importMap ?? {},
resolve: this.#options.resolve ?? {},
Expand Down
38 changes: 21 additions & 17 deletions packages/repl-sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
interface PublicMethods {
compile: (format: string, text: string, options?: {
flavor?: string;
fileName?: string;
}) => Promise<HTMLElement>
compile: (
format: string,
text: string,
options?: {
flavor?: string;
fileName?: string;
}
) => Promise<HTMLElement>;

optionsFor: (format: string, flavor?: string) => Omit<CompilerConfig, 'compiler'>
optionsFor: (format: string, flavor?: string) => Omit<CompilerConfig, 'compiler'>;
}
export interface ResolvedCompilerOptions {
importMap?: { [importPath: string]: string; };
resolve?: { [importPath: string]: unknown; };
importMap?: { [importPath: string]: string };
resolve?: { [importPath: string]: unknown };
needsLiveMeta?: boolean;
versions?: { [packageName: string]: string };
}
Expand Down Expand Up @@ -82,7 +86,7 @@ export interface CompilerConfig {
element: HTMLElement,
defaultExport: any,
extras: { compiled: string } & Record<string, unknown>,
compiler: PublicMethods,
compiler: PublicMethods
) => void;
}>;
}
Expand All @@ -93,26 +97,26 @@ export interface Options {
*
* Thehse will take precedence over the default CDN fallback.
*/
importMap?: { [importPath: string]: string; };
importMap?: { [importPath: string]: string };
/**
* Map of pre-resolved JS values to use as the import map
* These could assume the role of runtime virtual modules.
*
* These will take precedence over the importMap, and implicit CDN fallback.
*/
resolve?: { [importPath: string]: unknown; }
resolve?: { [importPath: string]: unknown };

/**
* Specifies which vesions of dependencies to when pulling from a CDN.
* Defaults to latest.
*/
* Specifies which vesions of dependencies to when pulling from a CDN.
* Defaults to latest.
*/
versions?: { [packageName: string]: string };

formats: {
[fileExtension: string]:
| CompilerConfig
| {
[flavor: string]: CompilerConfig;
};
| CompilerConfig
| {
[flavor: string]: CompilerConfig;
};
};
}
27 changes: 11 additions & 16 deletions packages/repl-sdk/tests-self/tests/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,20 @@ graph TD;
test('jsx requires a flavor to be specified', async () => {
let compiler = new Compiler();

expect(compiler.compile(
'md',
`# Hello\n\n` +
fenced(jsxReact, 'jsx react live') +
'\n\n' +
fenced(`export default <>hi</>`, 'jsx live')
)).rejects.toThrow('make sure you specify the flavor.');
expect(
compiler.compile(
'md',
`# Hello\n\n` +
fenced(jsxReact, 'jsx react live') +
'\n\n' +
fenced(`export default <>hi</>`, 'jsx live')
)
).rejects.toThrow('make sure you specify the flavor.');
});

test('svelte live', async () => {
let compiler = new Compiler();
let element = await compiler.compile(
'md',
fenced(svelte, 'svelte live')
);
let element = await compiler.compile('md', fenced(svelte, 'svelte live'));

let h1 = element.querySelector('h1');

Expand All @@ -114,11 +113,7 @@ graph TD;

test('mermaid (no live)', async () => {
let compiler = new Compiler();
let element = await compiler.compile(
'md',
fenced(mermaid, 'mermaid')
);

let element = await compiler.compile('md', fenced(mermaid, 'mermaid'));

let rootSVG = element.querySelector('svg');

Expand Down

0 comments on commit 69d4e81

Please sign in to comment.