Browse Source

Some cosmetic changes

- Remove unused '__slice' variable
- Nicely indent a map/concat chain
- 'forEach' instead of 'map' in emitted code
master
Futago-za Ryuu 5 years ago
parent
commit
75a4101622
  1. 23
      lib/compiler/passes/generate-js.js
  2. 1
      lib/util/objects.js

23
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" ) );

1
lib/util/objects.js

@ -1,7 +1,6 @@
"use strict";
const __hasOwnProperty = Object.prototype.hasOwnProperty;
const __slice = Array.prototype.slice;
const objects = {

Loading…
Cancel
Save