Skip to content

Commit

Permalink
Svelte: Fix parsing of ecma v12 by sveltedoc-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
j3rem1e committed Sep 9, 2023
1 parent ff7b7e1 commit 4f6667d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ import { logger } from '@storybook/node-logger';
import { preprocess } from 'svelte/compiler';
import { createFilter } from 'vite';

/*
* Patch sveltedoc-parser internal options.
* Waiting for a fix for https://github.com/alexprey/sveltedoc-parser/issues/87
*/
const svelteDocParserOptions = require('sveltedoc-parser/lib/options.js');

svelteDocParserOptions.getAstDefaultOptions = () => ({
range: true,
loc: true,
comment: true,
tokens: true,
ecmaVersion: 12,
sourceType: 'module',
ecmaFeatures: {},
});

// Most of the code here should probably be exported by @storybook/svelte and reused here.
// See: https://github.com/storybookjs/storybook/blob/next/app/svelte/src/server/svelte-docgen-loader.ts

Expand Down
16 changes: 16 additions & 0 deletions code/presets/svelte-webpack/src/svelte-docgen-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ import * as fs from 'fs';
import { preprocess } from 'svelte/compiler';
import { logger } from '@storybook/node-logger';

/*
* Patch sveltedoc-parser internal options.
* Waiting for a fix for https://github.com/alexprey/sveltedoc-parser/issues/87
*/
const svelteDocParserOptions = require('sveltedoc-parser/lib/options.js');

svelteDocParserOptions.getAstDefaultOptions = () => ({
range: true,
loc: true,
comment: true,
tokens: true,
ecmaVersion: 12,
sourceType: 'module',
ecmaFeatures: {},
});

// From https://github.com/sveltejs/svelte/blob/8db3e8d0297e052556f0b6dde310ef6e197b8d18/src/compiler/compile/utils/get_name_from_filename.ts
// Copied because it is not exported from the compiler
function getNameFromFilename(filename: string) {
Expand Down

0 comments on commit 4f6667d

Please sign in to comment.