Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

TypeScript Helpers aren't processed by later plugins #87

Closed
TimMensch opened this issue Feb 28, 2017 · 1 comment
Closed

TypeScript Helpers aren't processed by later plugins #87

TimMensch opened this issue Feb 28, 2017 · 1 comment

Comments

@TimMensch
Copy link

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.

@PaulBGD
Copy link
Collaborator

PaulBGD commented May 23, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants