pegjs/lib/util/convert-passes.js
Futago-za Ryuu 7cdfc03e9f Added utility methods for objects
Before there used to be some internal utility methods for arrays and objects, but as the code base moved to ES5+ use  case only, these were removed in favour of native alternatives, but most of these were only beneficial for arrays.

This commit add's common utility methods for objects, and also exposes these as they can be used by plugin developer's on the PEG.js AST.
2018-01-14 20:44:53 +00:00

31 lines
779 B
JavaScript

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