Tzach
Tzach

Reputation: 13386

Closure Compiler failing to compile reserved word "default"

I'm using Babel (actually Babelify) and Google Closure Compiler.

Babel transforms the following line of code:

import `React` from 'react'
React.createClass(...);

to something like

var _react = require(402);
var _react2 = _interopRequireDefault(_react);
_react2.default.createClass(...);

The problem is that Closure Compiler doesn't like the .default literal, and omits the following warning:

WARNING - Keywords and reserved words are not allowed as unquoted property names in older versions of JavaScript. If you are targeting newer versions of JavaScript, set the appropriate language_in option. exports.default = {

I tried using the babel es3 plugins such as transform-es3-member-expression-literals, but they don't seem to work, probably because the problematic code is generated by another plugin.

Is there a way to solve this without telling Closure Compiler to ignore this warning? (I want ES3 support).

Upvotes: 2

Views: 651

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

The message tells you exactly - set the --language_in (and optionally the --language_out) flags.

The latest version of the compiler, v20151216, now defaults to ES6 as the input language (ES3 as the output).

Upvotes: 3

Related Questions