Change module exporting style

Modules now generally store the exported object in a named variable or
function first and only assign |module.exports| at the very end. This is
a difference when compared to style used until now, where most modules
started with a |module.exports| assignment.

I think the explicit name helps readability and understandability.
redux
David Majda 10 years ago
parent 11aab6374f
commit ff8e877fce

@ -1,6 +1,6 @@
var utils = require("./utils"); var utils = require("./utils");
module.exports = { var compiler = {
/* /*
* Compiler passes. * Compiler passes.
* *
@ -51,3 +51,5 @@ module.exports = {
} }
} }
}; };
module.exports = compiler;

@ -1,5 +1,5 @@
/* Bytecode instruction opcodes. */ /* Bytecode instruction opcodes. */
module.exports = { var opcodes = {
/* Stack Manipulation */ /* Stack Manipulation */
PUSH: 0, // PUSH c PUSH: 0, // PUSH c
@ -44,3 +44,5 @@ module.exports = {
SILENT_FAILS_ON: 24, // SILENT_FAILS_ON SILENT_FAILS_ON: 24, // SILENT_FAILS_ON
SILENT_FAILS_OFF: 25 // SILENT_FAILS_FF SILENT_FAILS_OFF: 25 // SILENT_FAILS_FF
}; };
module.exports = opcodes;

@ -169,7 +169,7 @@ var utils = require("../../utils"),
* *
* silentFails--; * silentFails--;
*/ */
module.exports = function(ast) { function generateBytecode(ast) {
var consts = []; var consts = [];
function addConst(value) { function addConst(value) {
@ -595,4 +595,6 @@ module.exports = function(ast) {
}); });
generate(ast); generate(ast);
}; }
module.exports = generateBytecode;

@ -2,7 +2,7 @@ var utils = require("../../utils"),
op = require("../opcodes"); op = require("../opcodes");
/* Generates parser JavaScript code. */ /* Generates parser JavaScript code. */
module.exports = function(ast, options) { function generateJavaScript(ast, options) {
/* These only indent non-empty lines to avoid trailing whitespace. */ /* These only indent non-empty lines to avoid trailing whitespace. */
function indent2(code) { return code.replace(/^(.+)$/gm, ' $1'); } function indent2(code) { return code.replace(/^(.+)$/gm, ' $1'); }
function indent4(code) { return code.replace(/^(.+)$/gm, ' $1'); } function indent4(code) { return code.replace(/^(.+)$/gm, ' $1'); }
@ -974,4 +974,6 @@ module.exports = function(ast, options) {
].join('\n')); ].join('\n'));
ast.code = parts.join('\n'); ast.code = parts.join('\n');
}; }
module.exports = generateJavaScript;

@ -3,7 +3,7 @@ var utils = require("../../utils");
/* /*
* Removes proxy rules -- that is, rules that only delegate to other rule. * Removes proxy rules -- that is, rules that only delegate to other rule.
*/ */
module.exports = function(ast, options) { function removeProxyRules(ast, options) {
function isProxyRule(node) { function isProxyRule(node) {
return node.type === "rule" && node.expression.type === "rule_ref"; return node.type === "rule" && node.expression.type === "rule_ref";
} }
@ -71,4 +71,6 @@ module.exports = function(ast, options) {
utils.each(indices, function(index) { utils.each(indices, function(index) {
ast.rules.splice(index, 1); ast.rules.splice(index, 1);
}); });
}; }
module.exports = removeProxyRules;

@ -2,7 +2,7 @@ var utils = require("../../utils"),
GrammarError = require("../../grammar-error"); GrammarError = require("../../grammar-error");
/* Checks that no left recursion is present. */ /* Checks that no left recursion is present. */
module.exports = function(ast) { function reportLeftRecursion(ast) {
function nop() {} function nop() {}
function checkExpression(node, appliedRules) { function checkExpression(node, appliedRules) {
@ -62,4 +62,6 @@ module.exports = function(ast) {
}); });
check(ast, []); check(ast, []);
}; }
module.exports = reportLeftRecursion;

@ -2,7 +2,7 @@ var utils = require("../../utils"),
GrammarError = require("../../grammar-error"); GrammarError = require("../../grammar-error");
/* Checks that all referenced rules exist. */ /* Checks that all referenced rules exist. */
module.exports = function(ast) { function reportMissingRules(ast) {
function nop() {} function nop() {}
function checkExpression(node) { check(node.expression); } function checkExpression(node) { check(node.expression); }
@ -43,4 +43,6 @@ module.exports = function(ast) {
}); });
check(ast); check(ast);
}; }
module.exports = reportMissingRules;

@ -1,9 +1,11 @@
var utils = require("./utils"); var utils = require("./utils");
/* Thrown when the grammar contains an error. */ /* Thrown when the grammar contains an error. */
module.exports = function(message) { function GrammarError(message) {
this.name = "GrammarError"; this.name = "GrammarError";
this.message = message; this.message = message;
}; }
utils.subclass(module.exports, Error); utils.subclass(GrammarError, Error);
module.exports = GrammarError;

@ -1,6 +1,6 @@
var utils = require("./utils"); var utils = require("./utils");
module.exports = { var PEG = {
/* PEG.js version (uses semantic versioning). */ /* PEG.js version (uses semantic versioning). */
VERSION: "0.8.0", VERSION: "0.8.0",
@ -48,3 +48,5 @@ module.exports = {
); );
} }
}; };
module.exports = PEG;

Loading…
Cancel
Save