Skip to content

Can't extend jsc parser options #10

@alirezamirian

Description

@alirezamirian

Storybook documentation suggests you can customize swc config, by a function that accepts the default config:

swc: (config: Options, options): Options => {
    return {
      ...config,
      // Apply your custom SWC configuration
    };
  },

But the config parameter passed to this function is an empty object

Looking at the code, it seems like the returned object is meant to be deep merged with the default options:

const swcFinalOptions: SwcOptions = {
...swcOptions,
env: {
...(swcOptions?.env ?? {}),
// Transpiles the broken syntax to the closest non-broken modern syntax.
// E.g. it won't transpile parameter destructuring in Safari
// which would break how we detect if the mount context property is used in the play function.
bugfixes: swcOptions?.env?.bugfixes ?? true,
},
jsc: {
...(swcOptions.jsc ?? {}),
parser: swcOptions.jsc?.parser ?? {
syntax: "typescript",
tsx: true,
dynamicImport: true,
},
},
};

But then for parser options, that's not the case. If it exists in the returned config, it will overwrite the default parser options.

My use case was to add decorators: true but then other things stop working, and I had to see the source and copy the default options (syntax: "typescript", tsx: true, dynamicImport: true) as well.

It should either be that:

  • the returned options is truly deep merged into the default options, overwriting the existing keys. In this case there shouldn't even be a config object passed as the first argument of the configuring function, and the documentation should be updated to state that.
  • the default options should be passed to the configuring function, leaving it up to the user to deep merge or overwrite branches of the config object.

I can open a PR for either case if you agree with one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions