Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (var i = 0; i < flatChildren.length; ++i) {
var child = flatChildren[i];
// Restore any discarded whitespace between this node and the previous one.
if (child.source.startIdx > prevEndIdx) {
code += node.source.sourceString.slice(prevEndIdx, child.source.startIdx);
}
code += child.toES5();
prevEndIdx = child.source.endIdx;
}
return code;
}
// Instantiate the ES5 grammar.
var contents = fs.readFileSync(path.join(__dirname, 'es5.ohm'));
var g = ohm.grammars(contents).ES5;
var semantics = g.createSemantics();
semantics.addOperation('toES5()', {
Program: function(_, sourceElements) {
// Top-level leading and trailing whitespace is not handled by nodeToES5(), so do it here.
var sourceString = this.source.sourceString;
return sourceString.slice(0, this.source.startIdx) +
nodeToES5(this, [sourceElements]) +
sourceString.slice(this.source.endIdx);
},
_nonterminal: function(children) {
return nodeToES5(this, children);
},
_terminal: function() {
return this.sourceString;
}
function makeGrammars(source, optNamespace) {
if (Array.isArray(source)) {
source = source.join('\n');
}
return ohm.grammars(source, optNamespace);
}