rollup/rollup-plugin-typescript

TypeScript Helpers aren't processed by later plugins

TimMensch opened this issue · 1 comments

I just had an issue where I was getting a crash on older browsers, and I traced it to this bit of code from the TypeScript helpers:

const __assign = Object.assign || function (target) {
    for (var source, i = 1; i < arguments.length; i++) {
        source = arguments[i];
        for (var prop in source) {
            if (Object.prototype.hasOwnProperty.call(source, prop)) {
                target[prop] = source[prop];
            }
        }
    }
    return target;
};

This is how the code looked in the final output, including the ES6 const keyword, even though I was running the code through the rollup-buble-plugin:

    plugins: [
        json(),
        typescript({
            typescript: require('typescript'), // TypeScript 2.1.5
        }),
        nodeResolve({
            jsnext: true, 
            browser: true,
            extensions: [ '.js', '.json', '.ts' ], 
            sourceMap: true,
            preferBuiltins: false
        }),
        commonjs({
            extensions: [ '.js', '.ts' ],
            namedExports: {
                "javascript-astar": [ "Graph", "astar" ],
                "screenfull": [ "request" ],
                "marked": ["Renderer","setOptions","parse"],
            }
        }),
        buble({transforms: { dangerousForOf: true, dangerousTaggedTemplateString: true }})
    ]

All the other TypeScript output was correctly being run through Buble, but not this one excerpt.

I've worked around it by adding these lines to my tsconfig.json:

        "noEmitHelpers": true,
        "importHelpers": true,

...so TypeScript is importing its own helpers now, and the TypeScript helpers from rollup-plugin-typescript are being stripped by Rollup. But it seems like the way the "helpers" are being injected is preventing the helpers from being run through later plugins.

I'm doing this two step transpile (TypeScript creating ES6, Buble creating ES5) for better import behavior. I'm not sure if there's a better way where all of the Node imports still work as expected (and can include ES6 code from node_modules), but this is what I've come up with.

In any event, I've listed my workaround, and I'm not going to personally dig into this any more.

Fixed by #91, as now TypeScript inserts import statements for tslib which rollup can process.

Closing issues that I've integrated into #91, will be merged into master soon.