Moved seperate utilities into util route.
parent
83e3b9edc4
commit
878421ab75
@ -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;
|
@ -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;
|
||||
|
||||
};
|
||||
|
@ -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;
|
Loading…
Reference in New Issue