Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/internal/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
CHAR_COLON: 58, /* : */
CHAR_QUESTION_MARK: 63, /* ? */
CHAR_UNDERSCORE: 95, /* _ */
CHAR_LINE_FEED: 10, /* \n */
CHAR_CARRIAGE_RETURN: 13, /* \r */
CHAR_EXCLAMATION_MARK: 33, /* ! */
CHAR_HASH: 35, /* # */

// Digits
CHAR_0: 48, /* 0 */
Expand Down
13 changes: 10 additions & 3 deletions lib/internal/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

const errors = require('internal/errors');

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) {
Expand Down Expand Up @@ -65,8 +72,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 = '';
Expand All @@ -75,7 +82,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)
Expand Down