From 83d748d52250e3e93c72a14091f3e7570ffc3dc8 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 10 Oct 2016 13:38:39 +0200 Subject: [PATCH] Code style: Make all static "require" calls global The "global-require" rule is disabled in ESLint configuration used by PEG.js, but the idea is not bad, so let's make all static "require" calls global. Follow-up to #407. --- lib/compiler/index.js | 28 +++++++++++++++++++--------- lib/peg.js | 10 +++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/compiler/index.js b/lib/compiler/index.js index 121816a..7722ca1 100644 --- a/lib/compiler/index.js +++ b/lib/compiler/index.js @@ -1,5 +1,15 @@ "use strict"; +let generateBytecode = require("./passes/generate-bytecode"); +let generateJS = require("./passes/generate-js"); +let removeProxyRules = require("./passes/remove-proxy-rules"); +let reportDuplicateLabels = require("./passes/report-duplicate-labels"); +let reportDuplicateRules = require("./passes/report-duplicate-rules"); +let reportInfiniteRecursion = require("./passes/report-infinite-recursion"); +let reportInfiniteRepetition = require("./passes/report-infinite-repetition"); +let reportUndefinedRules = require("./passes/report-undefined-rules"); +let visitor = require("./visitor"); + function processOptions(options, defaults) { let processedOptions = {}; @@ -19,7 +29,7 @@ function processOptions(options, defaults) { let compiler = { // AST node visitor builder. Useful mainly for plugins which manipulate the // AST. - visitor: require("./visitor"), + visitor: visitor, // Compiler passes. // @@ -28,18 +38,18 @@ let compiler = { // |peg.GrammarError|. passes: { check: { - reportUndefinedRules: require("./passes/report-undefined-rules"), - reportDuplicateRules: require("./passes/report-duplicate-rules"), - reportDuplicateLabels: require("./passes/report-duplicate-labels"), - reportInfiniteRecursion: require("./passes/report-infinite-recursion"), - reportInfiniteRepetition: require("./passes/report-infinite-repetition") + reportUndefinedRules: reportUndefinedRules, + reportDuplicateRules: reportDuplicateRules, + reportDuplicateLabels: reportDuplicateLabels, + reportInfiniteRecursion: reportInfiniteRecursion, + reportInfiniteRepetition: reportInfiniteRepetition }, transform: { - removeProxyRules: require("./passes/remove-proxy-rules") + removeProxyRules: removeProxyRules }, generate: { - generateBytecode: require("./passes/generate-bytecode"), - generateJS: require("./passes/generate-js") + generateBytecode: generateBytecode, + generateJS: generateJS } }, diff --git a/lib/peg.js b/lib/peg.js index 9dfb7b0..a4639fe 100644 --- a/lib/peg.js +++ b/lib/peg.js @@ -1,12 +1,16 @@ "use strict"; +let GrammarError = require("./grammar-error"); +let compiler = require("./compiler"); +let parser = require("./parser"); + let peg = { // PEG.js version (uses semantic versioning). VERSION: "0.10.0", - GrammarError: require("./grammar-error"), - parser: require("./parser"), - compiler: require("./compiler"), + GrammarError: GrammarError, + parser: parser, + compiler: compiler, // Generates a parser from a specified grammar and returns it. //