From 75a41016225033ed9e6f65db5a039f8b7f8bcaea Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Thu, 18 Jan 2018 01:47:13 +0000 Subject: [PATCH] Some cosmetic changes - Remove unused '__slice' variable - Nicely indent a map/concat chain - 'forEach' instead of 'map' in emitted code --- lib/compiler/passes/generate-js.js | 23 +++++++++++++---------- lib/util/objects.js | 1 - 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 76166cd..68d0b19 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -127,15 +127,18 @@ function generateJS( ast, options ) { } - return ast.literals.map( - ( c, i ) => "var " + l( i ) + " = " + buildLiteral( c ) + ";" - ).concat( "", ast.classes.map( - ( c, i ) => "var " + r( i ) + " = " + buildRegexp( c ) + ";" ) - ).concat( "", ast.expectations.map( - ( c, i ) => "var " + e( i ) + " = " + buildExpectation( c ) + ";" ) - ).concat( "", ast.functions.map( - ( c, i ) => "var " + f( i ) + " = " + buildFunc( c ) + ";" - ) ).join( "\n" ); + return ast.literals + .map( ( c, i ) => "var " + l( i ) + " = " + buildLiteral( c ) + ";" ) + .concat( "", ast.classes.map( + ( c, i ) => "var " + r( i ) + " = " + buildRegexp( c ) + ";" + ) ) + .concat( "", ast.expectations.map( + ( c, i ) => "var " + e( i ) + " = " + buildExpectation( c ) + ";" + ) ) + .concat( "", ast.functions.map( + ( c, i ) => "var " + f( i ) + " = " + buildFunc( c ) + ";" + ) ) + .join( "\n" ); } @@ -179,7 +182,7 @@ function generateJS( ast, options ) { "", " rule$expectations = cached.expectations;", " if (peg$silentFails === 0) {", - " rule$expectations.map(peg$expect);", + " rule$expectations.forEach(peg$expect);", " }", "" ].join( "\n" ) ); diff --git a/lib/util/objects.js b/lib/util/objects.js index 325e2df..4fccc0f 100644 --- a/lib/util/objects.js +++ b/lib/util/objects.js @@ -1,7 +1,6 @@ "use strict"; const __hasOwnProperty = Object.prototype.hasOwnProperty; -const __slice = Array.prototype.slice; const objects = {