Browse Source

prefer rest and spread

master
Futago-za Ryuu 3 years ago
parent
commit
f66751ba39
  1. 1
      .eslintrc.js
  2. 12
      lib/.eslintrc.js
  3. 25
      lib/ast/visitor.js
  4. 6
      lib/compiler/passes/generate-bytecode.js

1
.eslintrc.js

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

12
lib/.eslintrc.js

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

25
lib/ast/visitor.js

@ -17,7 +17,7 @@ class ASTVisitor {
// istanbul ignore next
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
property( name ) {
return function visitProperty( node ) {
return function visitProperty( node, ...extraArgs ) {
const extraArgs = __slice.call( arguments, 1 );
const value = node[ name ];
if ( extraArgs.length )
this.visit.apply( this, [ value ].concat( extraArgs ) );
this.visit( value, ...extraArgs );
else
@ -65,13 +64,12 @@ const on = ASTVisitor.on = {
// Visit an array of nodes that are defined as a property on another node
children( name ) {
return function visitProperty( node ) {
return function visitProperty( node, ...extraArgs ) {
const args = __slice.call( arguments, 0 );
const children = node[ name ];
const visitor = this;
const cb = args.length < 2
const cb = extraArgs.length < 1
? function withoutArgs( child ) {
visitor.visit( child );
@ -79,8 +77,7 @@ const on = ASTVisitor.on = {
}
: function withArgs( child ) {
args[ 0 ] = child;
visitor.visit.apply( visitor, args );
visitor.visit( child, ...extraArgs );
};
@ -99,21 +96,17 @@ const visitExpression = on.property( "expression" );
const DEFAULT_FUNCTIONS = {
grammar( node ) {
const args = [ void 0 ].concat( __slice.call( arguments, 1 ) );
grammar( node, ...extraArgs ) {
if ( node.initializer ) {
args[ 0 ] = node.initializer;
this.visit.apply( this, args );
this.visit( node.initializer, ...extraArgs );
}
node.rules.forEach( rule => {
args[ 0 ] = rule;
this.visit.apply( this, args );
this.visit( rule, ...extraArgs );
} );

6
lib/compiler/passes/generate-bytecode.js

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

Loading…
Cancel
Save