Skip to content

Transpile helpers functions injected by Babel #5876

@xtuc

Description

@xtuc

This is a feature request (even if that the behavior was not expected).

I'm creating a JavaScript application for MediaWiki. They are using an old JavaScript parser (I don't exactly know its support). default is an expected keyword.

Input Code

import test from "foo"
test()

Output

var _foo = require("foo")
var _foo2 = _interopRequireDefault(_foo)

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {default: obj}
                                         ^^^^^
}

(0, _foo2.default)()
           ^^^^^

MediaWiki parser will throw a parser error due to the default keywords.

As a workaround i'm adding an additional compilation step:

browserify -d -t [ babelify ] src/index.js -o dist/pre-script.js
babel --plugins transform-es3-modules-literals dist/pre-script.js --out-file dist/script.js

I can't use the plugin in the first pass because the helpers are not transpiled.

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": ["es2015"],
  "comments": false,
  "minified": true,
  "retainLines": false,
  "sourceMaps": "map"
}

Expected Behavior

Transpile helpers.

Current Behavior

Not transpiling helpers.

Possible Solution

This is not an easy issue. We could use the plugin ordering capability to let Babel know what feature are used in the helpers. Then if it detect the transform-es3-modules-literals plugin Babel could apply the transformation to helpers as well.

Context

I might be the only one with that issue. I'm OK with my current workaround but I still created the issue because this is maybe something to consider in the future.

Your Environment

software version(s)
Babel 6.24.1 (babel-core 6.25.0)
MediaWiki < 1.30

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: helpersoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions