Use one var/let/const per variable (fixup)

Fix few instances in generated code which I missed in the previous
commit.

See #443.
redux
David Majda 8 years ago
parent 516023546d
commit 1da6abc458

@ -718,20 +718,15 @@ function generateJS(ast, options) {
parts.push('function peg$parse' + rule.name + '() {');
if (options.trace) {
parts.push(' var startPos = peg$currPos;');
}
for (let i = 0; i <= stack.maxSp; i++) {
stackVars[i] = s(i);
}
if (options.trace) {
parts.push([
' var ' + stackVars.join(', ') + ',',
' startPos = peg$currPos;'
].join('\n'));
} else {
parts.push(
' var ' + stackVars.join(', ') + ';'
);
}
parts.push(' var ' + stackVars.join(', ') + ';');
parts.push(indent2(generateRuleHeader(
'"' + js.stringEscape(rule.name) + '"',
@ -1248,12 +1243,6 @@ function generateJS(ast, options) {
commonjs: function() {
let parts = [];
let dependencyVars = Object.keys(options.dependencies);
let requires = dependencyVars.map(
variable => variable
+ ' = require("'
+ js.stringEscape(options.dependencies[variable])
+ '")'
);
parts.push([
generateGeneratedByComment(),
@ -1262,8 +1251,14 @@ function generateJS(ast, options) {
''
].join('\n'));
if (requires.length > 0) {
parts.push('var ' + requires.join(', ') + ';');
if (dependencyVars.length > 0) {
dependencyVars.forEach(variable => {
parts.push('var ' + variable
+ ' = require("'
+ js.stringEscape(options.dependencies[variable])
+ '");'
);
});
parts.push('');
}

Loading…
Cancel
Save