Commit 87b781ed by Rich Harris

Merge branch 'named-function-expr' into 'master'

Option to not emit named function expressions

See issue #130.

I added a flag to the command line tool too, but I couldn't find the sources to https://buble.surge.sh/guide/ , which should also be updated.

See merge request !90
parents 772ef241 7ca67fff
Pipeline #5382377 passed with stage
in 2 minutes 9 seconds
......@@ -15,6 +15,7 @@ Basic options:
-n, --no Transforms to always skip (overrides --target)
--jsx Custom JSX pragma
--objectAssign Specify Object.assign or equivalent polyfill
--no-named-function-expr Don't output named function expressions
Examples:
......
......@@ -49,6 +49,7 @@ function compileFile ( from, to, command, options ) {
file: to,
jsx: options.jsx,
objectAssign: options.objectAssign,
namedFunctionExpressions: options.namedFunctionExpressions
});
write( result, to, command );
......@@ -91,6 +92,7 @@ module.exports = function ( command ) {
transforms: {},
jsx: command.jsx,
objectAssign: command.objectAssign === true ? "Object.assign" : command.objectAssign,
namedFunctionExpressions: command["named-function-expr"] !== false
};
if ( command.target ) {
......
......@@ -7,7 +7,7 @@ export default function Program ( source, ast, transforms, options ) {
// options
this.jsx = options.jsx || 'React.createElement';
this.objectAssign = options.objectAssign;
this.options = options;
this.source = source;
this.magicString = new MagicString( source );
......
......@@ -67,6 +67,7 @@ export default class ClassBody extends Node {
let staticGettersAndSetters = [];
let prototypeAccessors;
let staticAccessors;
let namedFunctions = this.program.options.namedFunctionExpressions !== false
this.body.forEach( ( method, i ) => {
if ( method.kind === 'constructor' ) {
......@@ -137,7 +138,7 @@ export default class ClassBody extends Node {
code.insertRight( method.start, lhs );
const rhs = ( isAccessor ? `.${method.kind}` : '' ) + ` = function` + ( method.value.generator ? '* ' : ' ' ) + ( method.computed || isAccessor ? '' : `${methodName} ` );
const rhs = ( isAccessor ? `.${method.kind}` : '' ) + ` = function` + ( method.value.generator ? '* ' : ' ' ) + ( method.computed || isAccessor || !namedFunctions ? '' : `${methodName} ` );
code.remove( c, method.value.start );
code.insertRight( method.value.start, rhs );
code.insertLeft( method.end, ';' );
......
......@@ -53,10 +53,10 @@ export default class JSXOpeningElement extends Node {
if ( len === 1 ) {
before = html ? `',` : ',';
} else {
if (!this.program.objectAssign) {
if (!this.program.options.objectAssign) {
throw new CompileError( this, 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.' );
}
before = html ? `', ${this.program.objectAssign}({},` : `, ${this.program.objectAssign}({},`;
before = html ? `', ${this.program.options.objectAssign}({},` : `, ${this.program.objectAssign}({},`;
after = ')';
}
} else {
......
......@@ -21,7 +21,7 @@ export default class ObjectExpression extends Node {
}
if ( spreadPropertyCount ) {
if ( !this.program.objectAssign ) {
if ( !this.program.options.objectAssign ) {
throw new CompileError( this, 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.' );
}
// enclose run of non-spread properties in curlies
......@@ -47,7 +47,7 @@ export default class ObjectExpression extends Node {
// wrap the whole thing in Object.assign
firstPropertyStart = this.properties[0].start;
code.overwrite( this.start, firstPropertyStart, `${this.program.objectAssign}({}, `);
code.overwrite( this.start, firstPropertyStart, `${this.program.options.objectAssign}({}, `);
code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment