Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ifdef-loader

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ifdef-loader - npm Package Compare versions

Comparing version 2.2.1 to 2.3.0

24

ifdef-loader.js
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};

@@ -37,4 +40,9 @@ var loaderUtils = require("loader-utils");

}
var uncommentPrefixFlag = "ifdef-uncomment-prefix";
var uncommentPrefix = data[uncommentPrefixFlag];
if (uncommentPrefix !== undefined) {
delete data[uncommentPrefixFlag];
}
try {
source = preprocessor_1.parse(source, data, verbose, tripleSlash, filePath, fillWithBlanks);
source = preprocessor_1.parse(source, data, verbose, tripleSlash, filePath, fillWithBlanks, uncommentPrefix);
this.callback(null, source, map);

@@ -41,0 +49,0 @@ }

@@ -36,4 +36,10 @@ import * as loaderUtils from 'loader-utils';

const uncommentPrefixFlag = "ifdef-uncomment-prefix";
const uncommentPrefix = data[uncommentPrefixFlag];
if(uncommentPrefix !== undefined) {
delete data[uncommentPrefixFlag];
}
try {
source = parse(source, data, verbose, tripleSlash, filePath, fillWithBlanks);
source = parse(source, data, verbose, tripleSlash, filePath, fillWithBlanks, uncommentPrefix);
this.callback(null, source, map);

@@ -40,0 +46,0 @@ } catch(err) {

{
"name": "ifdef-loader",
"version": "2.2.1",
"version": "2.3.0",
"description": "",

@@ -9,5 +9,5 @@ "main": "ifdef-loader.js",

"@types/loader-utils": "^1.1.3",
"@types/node": "^7.0.5",
"@types/node": "^7.10.14",
"jasmine": "^2.5.3",
"typescript": "^2.2.1",
"typescript": "^4.2.4",
"webpack": "^3.5.5"

@@ -14,0 +14,0 @@ },

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
var IfBlock = (function () {

@@ -45,3 +51,4 @@ function IfBlock(line_if, line_endif, elifs, line_else, inner_ifs) {

var fillCharacter;
function parse(source, defs, verbose, tripleSlash, filePath, fillWithBlanks) {
var uncommentPrefix;
function parse(source, defs, verbose, tripleSlash, filePath, fillWithBlanks, uncommentPrefixString) {
if (tripleSlash === undefined)

@@ -53,2 +60,3 @@ tripleSlash = true;

fillCharacter = fillWithBlanks ? ' ' : '/';
uncommentPrefix = uncommentPrefixString;
if (source.indexOf('#if') === -1)

@@ -173,2 +181,3 @@ return source;

blank_code(lines, includeRange.to, ifBlock.line_endif);
reveal_code(lines, includeRange.from, includeRange.to);
}

@@ -190,3 +199,3 @@ else {

try {
var f = new (Function.bind.apply(Function, [void 0].concat(args, [code])))();
var f = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], args), [code])))();
result = f.apply(void 0, args.map(function (k) { return defs[k]; }));

@@ -218,1 +227,12 @@ }

}
function reveal_code(lines, start, end) {
if (uncommentPrefix == undefined)
return;
var regex = new RegExp("^(?<before>s*" + uncommentPrefix + ")(?<line>.*)$");
for (var t = start; t <= end; t++) {
var r = regex.exec(lines[t]);
if (r !== null && r.groups !== undefined) {
lines[t] = " ".repeat(r.groups.before.length) + r.groups.line;
}
}
}

@@ -45,4 +45,5 @@ import { OptionObject } from 'loader-utils';

let fillCharacter: string;
let uncommentPrefix: string | undefined;
export function parse(source: string, defs: OptionObject, verbose?: boolean, tripleSlash?: boolean, filePath?: string, fillWithBlanks?: boolean): string {
export function parse(source: string, defs: OptionObject, verbose?: boolean, tripleSlash?: boolean, filePath?: string, fillWithBlanks?: boolean, uncommentPrefixString?: string): string {
if(tripleSlash === undefined) tripleSlash = true;

@@ -54,2 +55,4 @@ useTripleSlash = tripleSlash;

uncommentPrefix = uncommentPrefixString;
// early skip check: do not process file when no '#if' are contained

@@ -207,2 +210,3 @@ if(source.indexOf('#if') === -1) return source;

blank_code(lines, includeRange.to, ifBlock.line_endif); // blanks: "to" ... #endif
reveal_code(lines, includeRange.from, includeRange.to); // reveal: "from" ... "to"
} else {

@@ -259,1 +263,17 @@ blank_code(lines, ifBlock.line_if, ifBlock.line_endif); // blanks: #if ... #endif

}
function reveal_code(lines: string[], start: number, end: number) {
// early exit if no prefix is specifed
if(uncommentPrefix == undefined) return;
// create a regex capturing the line
let regex = new RegExp(`^(?<before>\s*${uncommentPrefix})(?<line>.*)$`);
// replace lines that match the uncomment prefix
for(let t=start; t<=end; t++) {
let r = regex.exec(lines[t]);
if(r!==null && r.groups!==undefined) {
lines[t] = " ".repeat(r.groups.before.length) + r.groups.line;
}
}
}

@@ -66,5 +66,6 @@ # ifdef-loader

version: 3,
"ifdef-verbose": true, // add this for verbose output
"ifdef-triple-slash": false, // add this to use double slash comment instead of default triple slash
"ifdef-fill-with-blanks": true // add this to remove code with blank spaces instead of "//" comments
"ifdef-verbose": true, // add this for verbose output
"ifdef-triple-slash": false, // add this to use double slash comment instead of default triple slash
"ifdef-fill-with-blanks": true // add this to remove code with blank spaces instead of "//" comments
"ifdef-uncomment-prefix": "// #code " // add this to uncomment code starting with "// #code "
};

@@ -110,2 +111,4 @@

- v2.3.0 added option `uncomment-prefix` to write code in comments allowing it to pass through linters and syntax checking
- v2.2.0 added option `fill-with-blanks` for removing code with blank spaces instead of `//` comments

@@ -112,0 +115,0 @@

@@ -5,3 +5,3 @@ {

"target": "es5",
"lib": ["es5", "es6"],
"lib": ["es5", "es6", "es2018"],
"forceConsistentCasingInFileNames": false,

@@ -8,0 +8,0 @@ "noFallthroughCasesInSwitch": true,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc