notlmn / rollup-plugin-transform-tagged-template

Apply transformations on static contents of tagged template string literals
https://npmjs.com/package/rollup-plugin-transform-tagged-template
MIT License
5 stars 4 forks source link

Allow passing options to Babel Parser #1

Closed radium-v closed 4 years ago

radium-v commented 4 years ago

Hello! I came across this package and really appreciate the work put into it.

Our source templates are in Typescript files which use decorators, and the Babel Parser throws errors since we can't set config options.

By adding a parserOptions property and passing it to the parser, I can get working results:

const {
    parserOptions = {},
    tagsToProcess = [],
    transformer = code => code
} = options;

const ast = parse(content, parserOptions);

This would allow me to add the required options to my rollup:

...
plugins: [
    transformTaggedTemplate({
        parserOptions: {
            sourceType: "module",
            plugins: [
                "typescript",
                [ "decorators", { decoratorsBeforeExport: true } ]
            ]
        },
        tagsToProcess: ['html'],
        transformer: transformHTMLTaggedTemplate
    }),
...

I'd be happy to submit a pull request both here and for rollup-plugin-minify-tagged-css-template to add this option.