prefer rest and spread

master
Futago-za Ryuu 6 years ago
parent 60f69d6558
commit f66751ba39

@ -7,7 +7,6 @@ module.exports = {
"rules": { "rules": {
"no-eval": 0, "no-eval": 0,
"prefer-rest-params": 0,
}, },

@ -1,12 +0,0 @@
"use strict";
module.exports = {
"rules": {
"prefer-spread": 0,
"strict": 0,
},
};

@ -17,7 +17,7 @@ class ASTVisitor {
// istanbul ignore next // istanbul ignore next
if ( ! fn ) throw new Error( `Visitor function for node type "${ node.type }" not defined` ); if ( ! fn ) throw new Error( `Visitor function for node type "${ node.type }" not defined` );
return fn.apply( this, arguments ); return fn.apply( this, arguments ); // eslint-disable-line prefer-rest-params
} }
@ -45,14 +45,13 @@ const on = ASTVisitor.on = {
// Visit a node that is defined as a property on another node // Visit a node that is defined as a property on another node
property( name ) { property( name ) {
return function visitProperty( node ) { return function visitProperty( node, ...extraArgs ) {
const extraArgs = __slice.call( arguments, 1 );
const value = node[ name ]; const value = node[ name ];
if ( extraArgs.length ) if ( extraArgs.length )
this.visit.apply( this, [ value ].concat( extraArgs ) ); this.visit( value, ...extraArgs );
else else
@ -65,13 +64,12 @@ const on = ASTVisitor.on = {
// Visit an array of nodes that are defined as a property on another node // Visit an array of nodes that are defined as a property on another node
children( name ) { children( name ) {
return function visitProperty( node ) { return function visitProperty( node, ...extraArgs ) {
const args = __slice.call( arguments, 0 );
const children = node[ name ]; const children = node[ name ];
const visitor = this; const visitor = this;
const cb = args.length < 2 const cb = extraArgs.length < 1
? function withoutArgs( child ) { ? function withoutArgs( child ) {
visitor.visit( child ); visitor.visit( child );
@ -79,8 +77,7 @@ const on = ASTVisitor.on = {
} }
: function withArgs( child ) { : function withArgs( child ) {
args[ 0 ] = child; visitor.visit( child, ...extraArgs );
visitor.visit.apply( visitor, args );
}; };
@ -99,21 +96,17 @@ const visitExpression = on.property( "expression" );
const DEFAULT_FUNCTIONS = { const DEFAULT_FUNCTIONS = {
grammar( node ) { grammar( node, ...extraArgs ) {
const args = [ void 0 ].concat( __slice.call( arguments, 1 ) );
if ( node.initializer ) { if ( node.initializer ) {
args[ 0 ] = node.initializer; this.visit( node.initializer, ...extraArgs );
this.visit.apply( this, args );
} }
node.rules.forEach( rule => { node.rules.forEach( rule => {
args[ 0 ] = rule; this.visit( rule, ...extraArgs );
this.visit.apply( this, args );
} ); } );

@ -244,11 +244,7 @@ function generateBytecode( ast, session ) {
} }
function buildSequence() { const buildSequence = ( ...parts ) => [].concat( ...parts );
return Array.prototype.concat.apply( [], arguments );
}
function buildCondition( match, condCode, thenCode, elseCode ) { function buildCondition( match, condCode, thenCode, elseCode ) {

Loading…
Cancel
Save