From 8003edafc9fd593f25bf12f48b039169187a9872 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 6 Aug 2016 18:05:03 +0200 Subject: [PATCH] Rename the "node" module format to "commonjs" Parsers generated in this format use module.exports, so they are not strictly CommonJS, but this is a common extension and the original name would be confusing once Node.js implements ES2015 modules. --- README.md | 10 +++++----- bin/pegjs | 10 +++++----- lib/compiler/passes/generate-js.js | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0ee3d45..ecf0b44 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,8 @@ You can tweak the generated parser with several options: `peg.generate` * `--extra-options-file` — file with additional options (in JSON format) to pass to `peg.generate` - * `--format` — format of the generated parser: `amd`, `globals`, `node`, `umd` - (default: `node`) + * `--format` — format of the generated parser: `amd`, `commonjs`, `globals`, + `umd` (default: `commonjs`) * `--optimize` — selects between optimizing the generated parser for parsing speed (`speed`) or code size (`size`) (default: `speed`) * `--plugin` — makes PEG.js use a specified plugin (can be specified multiple @@ -142,13 +142,13 @@ object to `peg.generate`. The following options are supported: `false`) * `dependencies` — parser dependencies, the value is an object which maps variables used to access the dependencies in the parser to module IDs used - to load them; valid only when `format` is set to `"amd"`, `"node"`, or + to load them; valid only when `format` is set to `"amd"`, `"commonjs"`, or `"umd"` (default: `{}`) * `exportVar` — name of a global variable into which the parser object is assigned to when no module loader is detected; valid only when `format` is set to `"globals"` or `"umd"` (default: `null`) - * `format` — format of the genreated parser (`"amd"`, `"bare"`, `"globals"`, - `"node"`, or `"umd"`); valid only when `output` is set to `"source"` + * `format` — format of the genreated parser (`"amd"`, `"bare"`, `"commonjs"`, + `"globals"`, or `"umd"`); valid only when `output` is set to `"source"` (default: `"bare"`) * `optimize`— selects between optimizing the generated parser for parsing speed (`"speed"`) or code size (`"size"`) (default: `"speed"`) diff --git a/bin/pegjs b/bin/pegjs index c83da16..1807da2 100755 --- a/bin/pegjs +++ b/bin/pegjs @@ -32,7 +32,7 @@ function printHelp() { console.log(" --extra-options-file file with additional options (in JSON"); console.log(" format) to pass to peg.generate"); console.log(" --format format of the generated parser: amd,"); - console.log(" globals, node, umd (default: node)"); + console.log(" commonjs, globals, umd (default: commonjs)"); console.log(" -h, --help print help and exit"); console.log(" -O, --optimize select optimization for speed or size"); console.log(" (default: speed)"); @@ -114,7 +114,7 @@ var options = { cache: false, dependencies: {}, exportVar: null, - format: "node", + format: "commonjs", optimize: "speed", output: "source", plugins: [], @@ -186,8 +186,8 @@ while (args.length > 0 && isOption(args[0])) { if (args.length === 0) { abort("Missing parameter of the --format option."); } - if (args[0] !== "amd" && args[0] !== "globals" && args[0] !== "node" && args[0] !== "umd") { - abort("Module format must be one of \"amd\", \"globals\", \"node\", and \"umd\"."); + if (args[0] !== "amd" && args[0] !== "commonjs" && args[0] !== "globals" && args[0] !== "umd") { + abort("Module format must be one of \"amd\", \"commonjs\", \"globals\", and \"umd\"."); } options.format = args[0]; break; @@ -257,7 +257,7 @@ while (args.length > 0 && isOption(args[0])) { } if (objects.keys(options.dependencies).length > 0) { - if (options.format !== "amd" && options.format !== "node" && options.format !== "umd") { + if (options.format !== "amd" && options.format !== "commonjs" && options.format !== "umd") { abort("Can't use the -d/--dependency option with the \"" + options.format + "\" module format."); } } diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 6bfb214..6c4197e 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -1264,7 +1264,7 @@ function generateJS(ast, options) { ].join('\n'); }, - node: function() { + commonjs: function() { var parts = [], dependencyVars = objects.keys(options.dependencies), requires = arrays.map(