From dbdba75b15f287ed7552da387035a7e5a52ee8c3 Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Thu, 29 Mar 2018 01:20:57 +0100 Subject: [PATCH] run plugins optionally --- lib/peg.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/peg.js b/lib/peg.js index fc1a24e..027b424 100644 --- a/lib/peg.js +++ b/lib/peg.js @@ -29,16 +29,19 @@ const peg = { options = typeof options !== "undefined" ? options : {}; - const plugins = "plugins" in options ? options.plugins : []; const session = new compiler.Session( { passes: util.convertPasses( compiler.passes ) } ); - plugins.forEach( p => { + if ( Array.isArray( options.plugins ) ) - p.use( session, options ); + options.plugins.forEach( p => { - } ); + if ( typeof p.use !== "function" ) return; + + p.use( session, options ); + + } ); return compiler.compile( session.parse( grammar, options.parser || {} ),