Commit 7ca67fff by Marijn Haverbeke

Add a namedFunctionExpressions option

Which defaults to true, but can be set to false to suppress
names in method function expressions.

Issue #130
parent 3f39acaf
......@@ -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 ) {
......
......@@ -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, ';' );
......
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 to comment