From d22a97ee3a80af6dda2d4887d86afdc2943ad3fb Mon Sep 17 00:00:00 2001 From: Sergey Golovin Date: Mon, 19 Feb 2018 21:13:54 +0300 Subject: [PATCH] module: replace "magic" numbers by constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add new constants - replace numbers by constants PR-URL: https://github.com/nodejs/node/pull/18869 Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso Reviewed-By: Ruben Bridgewater Reviewed-By: Matheus Marchini --- lib/internal/modules/cjs/helpers.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/internal/modules/cjs/helpers.js b/lib/internal/modules/cjs/helpers.js index 0bb1cea4050e16..000110d03ad5f3 100644 --- a/lib/internal/modules/cjs/helpers.js +++ b/lib/internal/modules/cjs/helpers.js @@ -1,5 +1,12 @@ 'use strict'; +const { + CHAR_LINE_FEED, + CHAR_CARRIAGE_RETURN, + CHAR_EXCLAMATION_MARK, + CHAR_HASH, +} = require('internal/constants'); + // Invoke with makeRequireFunction(module) where |module| is the Module object // to use as the context for the require() function. function makeRequireFunction(mod) { @@ -55,8 +62,8 @@ function stripShebang(content) { // Remove shebang var contLen = content.length; if (contLen >= 2) { - if (content.charCodeAt(0) === 35/*#*/ && - content.charCodeAt(1) === 33/*!*/) { + if (content.charCodeAt(0) === CHAR_HASH && + content.charCodeAt(1) === CHAR_EXCLAMATION_MARK) { if (contLen === 2) { // Exact match content = ''; @@ -65,7 +72,7 @@ function stripShebang(content) { var i = 2; for (; i < contLen; ++i) { var code = content.charCodeAt(i); - if (code === 10/*\n*/ || code === 13/*\r*/) + if (code === CHAR_LINE_FEED || code === CHAR_CARRIAGE_RETURN) break; } if (i === contLen)