From d3cbd02b3d9de6cbfb518c31f9c70472508912c3 Mon Sep 17 00:00:00 2001 From: Rens Baardman Date: Tue, 11 Jun 2019 14:11:16 +0200 Subject: Change line endings from carriage returns to line feeds --- lib/__get__.js | 40 +++++++++++++++++------------------ lib/detectStrictMode.js | 56 ++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 48 deletions(-) (limited to 'lib') diff --git a/lib/__get__.js b/lib/__get__.js index 74e652f..cb6fe68 100644 --- a/lib/__get__.js +++ b/lib/__get__.js @@ -1,21 +1,21 @@ -/** - * This function will be stringified and then injected into every rewired module. - * Then you can leak private variables by calling myModule.__get__("myPrivateVar"); - * - * All variables within this function are namespaced in the arguments array because every - * var declaration could possibly clash with a variable in the module scope. - * - * @param {!String} name name of the variable to retrieve - * @throws {TypeError} - * @return {*} - */ -function __get__() { - arguments.varName = arguments[0]; - if (arguments.varName && typeof arguments.varName === "string") { - return eval(arguments.varName); - } else { - throw new TypeError("__get__ expects a non-empty string"); - } -} - +/** + * This function will be stringified and then injected into every rewired module. + * Then you can leak private variables by calling myModule.__get__("myPrivateVar"); + * + * All variables within this function are namespaced in the arguments array because every + * var declaration could possibly clash with a variable in the module scope. + * + * @param {!String} name name of the variable to retrieve + * @throws {TypeError} + * @return {*} + */ +function __get__() { + arguments.varName = arguments[0]; + if (arguments.varName && typeof arguments.varName === "string") { + return eval(arguments.varName); + } else { + throw new TypeError("__get__ expects a non-empty string"); + } +} + module.exports = __get__; \ No newline at end of file diff --git a/lib/detectStrictMode.js b/lib/detectStrictMode.js index 57dc14d..30f59fd 100644 --- a/lib/detectStrictMode.js +++ b/lib/detectStrictMode.js @@ -1,28 +1,28 @@ -var multiLineComment = /^\s*\/\*.*?\*\//; -var singleLineComment = /^\s*\/\/.*?[\r\n]/; -var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/; - -/** - * Returns true if the source code is intended to run in strict mode. Does not detect - * "use strict" if it occurs in a nested function. - * - * @param {String} src - * @return {Boolean} - */ -function detectStrictMode(src) { - var singleLine; - var multiLine; - - while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) { - if (singleLine) { - src = src.replace(singleLineComment, ""); - } - if (multiLine) { - src = src.replace(multiLineComment, ""); - } - } - - return strictMode.test(src); -} - -module.exports = detectStrictMode; +var multiLineComment = /^\s*\/\*.*?\*\//; +var singleLineComment = /^\s*\/\/.*?[\r\n]/; +var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/; + +/** + * Returns true if the source code is intended to run in strict mode. Does not detect + * "use strict" if it occurs in a nested function. + * + * @param {String} src + * @return {Boolean} + */ +function detectStrictMode(src) { + var singleLine; + var multiLine; + + while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) { + if (singleLine) { + src = src.replace(singleLineComment, ""); + } + if (multiLine) { + src = src.replace(multiLineComment, ""); + } + } + + return strictMode.test(src); +} + +module.exports = detectStrictMode; -- cgit v1.2.3 From 7bec7f88e01bad4829ee2ac3f90fe5d9d2616888 Mon Sep 17 00:00:00 2001 From: Rens Baardman Date: Tue, 11 Jun 2019 13:41:59 +0200 Subject: Fix #167: non-enumerable globals are now also prefixed with `var` --- lib/getImportGlobalsSrc.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/getImportGlobalsSrc.js b/lib/getImportGlobalsSrc.js index 3c29c56..fcce0d0 100644 --- a/lib/getImportGlobalsSrc.js +++ b/lib/getImportGlobalsSrc.js @@ -9,7 +9,6 @@ */ function getImportGlobalsSrc(ignore) { var key, - value, src = "", globalObj = typeof global === "undefined"? window: global; @@ -20,12 +19,21 @@ function getImportGlobalsSrc(ignore) { // shadow the module-internal variables // @see https://github.com/jhnns/rewire-webpack/pull/6 ignore.push("module", "exports", "require"); + // strict mode doesn't allow to (re)define 'undefined', 'eval' & 'arguments' + ignore.push("undefined", "eval", "arguments"); + // 'GLOBAL' and 'root' are deprecated in Node + // (assigning them causes a DeprecationWarning) + ignore.push("GLOBAL", "root"); + // 'NaN' and 'Infinity' are immutable + // (doesn't throw an error if you set 'var NaN = ...', but doesn't work either) + ignore.push("NaN", "Infinity"); - for (key in globalObj) { /* jshint forin: false */ + const globals = Object.getOwnPropertyNames(globalObj); + + for (key of globals) { if (ignore.indexOf(key) !== -1) { continue; } - value = globalObj[key]; // key may be an invalid variable name (e.g. 'a-b') try { -- cgit v1.2.3