2018-01-14 21:44:53 +01:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-03 04:16:10 +02:00
|
|
|
const js = require( "./js" );
|
2018-01-14 21:44:53 +01:00
|
|
|
const objects = require( "./objects" );
|
2018-04-04 21:21:31 +02:00
|
|
|
const vm = require( "./vm" );
|
2018-04-03 04:16:10 +02:00
|
|
|
|
|
|
|
objects.extend( exports, js );
|
2018-04-02 21:59:13 +02:00
|
|
|
objects.extend( exports, objects );
|
2018-04-04 21:21:31 +02:00
|
|
|
objects.extend( exports, vm );
|
2018-01-14 21:44:53 +01:00
|
|
|
|
|
|
|
exports.noop = function noop() { };
|
|
|
|
|
2018-04-02 21:59:13 +02:00
|
|
|
/**
|
|
|
|
* ```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 = ( () => {
|
2018-01-14 21:44:53 +01:00
|
|
|
|
2018-04-02 21:59:13 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
};
|