From 878421ab7531cc7d6df9703d213da3823bfd451c Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Mon, 2 Apr 2018 20:59:13 +0100 Subject: [PATCH] Moved seperate utilities into util route. --- lib/typings/modules.d.ts | 12 ---------- lib/util/convert-passes.js | 30 ----------------------- lib/util/index.js | 48 ++++++++++++++++++++++++++++++++++--- lib/util/process-options.js | 16 ------------- 4 files changed, 45 insertions(+), 61 deletions(-) delete mode 100644 lib/util/convert-passes.js delete mode 100644 lib/util/process-options.js diff --git a/lib/typings/modules.d.ts b/lib/typings/modules.d.ts index 740296a..ebd6969 100644 --- a/lib/typings/modules.d.ts +++ b/lib/typings/modules.d.ts @@ -163,12 +163,6 @@ declare module "pegjs/lib/util" { } -declare module "pegjs/lib/util/convert-passes" { - - export default peg.util.convertPasses; - -} - declare module "pegjs/lib/util/index" { export default peg.util; @@ -181,9 +175,3 @@ declare module "pegjs/lib/util/objects" { export default objects; } - -declare module "pegjs/lib/util/process-options" { - - export default peg.util.processOptions; - -} diff --git a/lib/util/convert-passes.js b/lib/util/convert-passes.js deleted file mode 100644 index 317e41a..0000000 --- a/lib/util/convert-passes.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -// type Pass = ( ast: {}, options: {} ) => void; -// type StageMap = { [string]: { [string]: Pass } }; -// type PassMap = { [string]: Pass[] }; -// -// The PEG.js compiler runs each `Pass` on the `PassMap` (it's 2nd argument), -// but the compiler api exposes a `StageMap` so that it is easier for plugin -// developer's to access the built-in passes. -// -// This file exposes a method that will take a `StageMap`, and return a -// `PassMap` that can then be passed to the compiler. - -const objects = require( "./objects" ); - -function convertStage( passes ) { - - return Array.isArray( passes ) - ? passes - : objects.values( passes ); - -} - -function convertPasses( stages ) { - - return objects.map( stages, convertStage ); - -} - -module.exports = convertPasses; diff --git a/lib/util/index.js b/lib/util/index.js index ad6ebb3..4dcb5dc 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -1,10 +1,52 @@ "use strict"; const objects = require( "./objects" ); +objects.extend( exports, objects ); exports.noop = function noop() { }; -exports.convertPasses = require( "./convert-passes" ); -exports.processOptions = require( "./process-options" ); +/** + * ```ts + * type Session = peg.compiler.Session; + * type Pass = ( ast: {}, session: Session, options: {} ) => void; + * type StageMap = { [string]: { [string]: Pass } }; + * type PassMap = { [string]: Pass[] }; + * ``` + * + * The PEG.js compiler runs each `Pass` on the `PassMap` (the `passes` option on it's 2nd + * argument), but the compiler api exposes a `StageMap` so that it is easier for plugin + * developer's to access the built-in passes. + * + * This method takes a `StageMap`, returning a `PassMap` that can be used by the compiler. + */ +exports.convertPasses = ( () => { -objects.extend( exports, objects ); + function convertStage( passes ) { + + return Array.isArray( passes ) + ? passes + : objects.values( passes ); + + } + + function convertPasses( stages ) { + + return objects.map( stages, convertStage ); + + } + + return convertPasses; + +} )(); + + +exports.processOptions = function processOptions( options, defaults ) { + + const processedOptions = {}; + + objects.extend( processedOptions, options ); + objects.extend( processedOptions, defaults ); + + return processedOptions; + +}; diff --git a/lib/util/process-options.js b/lib/util/process-options.js deleted file mode 100644 index cf06a83..0000000 --- a/lib/util/process-options.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; - -const objects = require( "./objects" ); - -function processOptions( options, defaults ) { - - const processedOptions = {}; - - objects.extend( processedOptions, options ); - objects.extend( processedOptions, defaults ); - - return processedOptions; - -} - -module.exports = processOptions;