New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fullstackio/cq

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fullstackio/cq - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

66

dist/index.js

@@ -49,2 +49,30 @@ 'use strict';

function movePositionByLines(code, numLines, position) {
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
if (numLines < 0) {
var numPreviousLines = numLines * -1;
position--;
while (position > 0 && numPreviousLines > 0) {
position--;
if (code[position] === '\n') {
numPreviousLines--;
}
}
if (opts.trimNewline) position++; // don't include prior newline
} else if (numLines > 0) {
var numFollowingLines = numLines;
position++;
while (position < code.length && numFollowingLines > 0) {
if (code[position] === '\n') {
numFollowingLines--;
}
position++;
}
if (opts.trimNewline) position--; // don't include the last newline
}
return position;
}
function adjustRangeWithContext(code, linesBefore, linesAfter, _ref) {

@@ -54,38 +82,12 @@ var start = _ref.start;

// get any extra lines, if requested
var numPreviousLines = 0;
var numFollowingLines = 0;
var hasPreviousLines = false;
var hasFollowingLines = false;
if (linesBefore > 0) {
numPreviousLines = linesBefore;
hasPreviousLines = true;
if (linesBefore && linesBefore !== 0) {
var trimNewline = linesBefore > 0 ? true : false;
start = movePositionByLines(code, -1 * linesBefore, start, { trimNewline: trimNewline });
}
if (linesAfter > 0) {
numFollowingLines = linesAfter + 1;
hasFollowingLines = true;
if (linesAfter && linesAfter !== 0) {
var _trimNewline = linesAfter > 0 ? true : false;
end = movePositionByLines(code, linesAfter, end, { trimNewline: _trimNewline });
}
if (hasPreviousLines) {
while (start > 0 && numPreviousLines >= 0) {
start--;
if (code[start] === '\n') {
numPreviousLines--;
}
}
start++; // don't include prior newline
}
if (hasFollowingLines) {
while (end < code.length && numFollowingLines > 0) {
if (code[end] === '\n') {
numFollowingLines--;
}
end++;
}
end--; // don't include the last newline
}
return { start: start, end: end };

@@ -92,0 +94,0 @@ }

@@ -750,37 +750,49 @@ "use strict";

function peg$parseInteger() {
var s0, s1, s2;
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
if (peg$c16.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c17);
s1 = peg$parsedash();
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c16.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c17);
}
}
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
if (peg$c16.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c17);
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c16.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c17);
}
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c18();
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
s1 = peg$FAILED;
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c18();
}
s0 = s1;
peg$silentFails--;

@@ -787,0 +799,0 @@ if (s0 === peg$FAILED) {

{
"name": "@fullstackio/cq",
"version": "1.2.0",
"version": "1.3.0",
"description": "query code with selectors",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -22,39 +22,39 @@ /**

function adjustRangeWithContext(code, linesBefore, linesAfter, {start, end}) {
// get any extra lines, if requested
let numPreviousLines = 0;
let numFollowingLines = 0;
let hasPreviousLines = false;
let hasFollowingLines = false;
if(linesBefore > 0) {
numPreviousLines = linesBefore;
hasPreviousLines = true;
}
if(linesAfter > 0) {
numFollowingLines = linesAfter + 1;
hasFollowingLines = true;
}
if(hasPreviousLines) {
while(start > 0 && numPreviousLines >= 0) {
start--;
if(code[start] === '\n') {
function movePositionByLines(code, numLines, position, opts={}) {
if(numLines < 0) {
let numPreviousLines = numLines * -1;
position--;
while(position > 0 && numPreviousLines > 0) {
position--;
if(code[position] === '\n') {
numPreviousLines--;
}
}
start++; // don't include prior newline
}
if(hasFollowingLines) {
while(end < code.length && numFollowingLines > 0) {
if(code[end] === '\n') {
if(opts.trimNewline) position++; // don't include prior newline
} else if(numLines > 0) {
let numFollowingLines = numLines;
position++;
while(position < code.length && numFollowingLines > 0) {
if(code[position] === '\n') {
numFollowingLines--;
}
end++;
position++;
}
end--; // don't include the last newline
if(opts.trimNewline) position--; // don't include the last newline
}
return position;
}
function adjustRangeWithContext(code, linesBefore, linesAfter, {start, end}) {
if(linesBefore && linesBefore !== 0) {
let trimNewline = linesBefore > 0 ? true : false;
start = movePositionByLines(code, -1 * linesBefore, start, {trimNewline});
}
if(linesAfter && linesAfter !== 0) {
let trimNewline = linesAfter > 0 ? true : false;
end = movePositionByLines(code, linesAfter, end, {trimNewline});
}
return {start, end};

@@ -61,0 +61,0 @@ }

@@ -750,33 +750,45 @@ module.exports = (function() {

function peg$parseInteger() {
var s0, s1, s2;
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
if (peg$c16.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
s1 = peg$parsedash();
if (s1 === peg$FAILED) {
s1 = null;
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
if (peg$c16.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c16.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c16.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c18();
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
s1 = peg$FAILED;
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c18();
}
s0 = s1;
peg$silentFails--;

@@ -783,0 +795,0 @@ if (s0 === peg$FAILED) {

@@ -77,3 +77,3 @@ import 'babel-polyfill';

let Farm = () => 'cow';
let Farm = () => 'cow';
bye(); // -> 'bye'

@@ -116,2 +116,8 @@ // never say goodbye

it('should include extra lines after given a modifier', () => {
let { code } = cq(someFunctions, 'context(.Farm, 0, 1)');
const wanted = lines(someFunctions, 9, 10);
assert.equal(code, wanted);
})
it('should include extra lines given a modifier', () => {

@@ -168,3 +174,3 @@ let { code } = cq(someFunctions, 'context(.Farm, 2, 2)');

let { code } = cq(someFunctions, 'context(1-upto(.Farm), 2, 4)');
const wanted = lines(someFunctions, 1, 11);
const wanted = lines(someFunctions, 0, 11);
assert.equal(code, wanted);

@@ -284,2 +290,16 @@ })

});
it('should allow negative context first', () => {
let { code } = cq(es6Class, 'context(.distance, -1, -1)');
console.log(code);
const wanted = lines(es6Class, 3, 5);
assert.equal(code, wanted);
});
it('should allow negative context', () => {
let { code } = cq(es6Class, 'context(.Polygon, -4, -4)');
const wanted = lines(es6Class, 5, 16);
assert.equal(code, wanted);
});
});

@@ -286,0 +306,0 @@

@@ -253,2 +253,21 @@ import 'babel-polyfill'

it('should parse functions with negative numbers as arguments', () => {
let actual = parser.parse('context(.foo, -2, -3)');
let expected = {
type: NodeTypes.CALL_EXPRESSION,
callee: 'context',
arguments: [{
matcher: 'foo',
type: NodeTypes.IDENTIFIER,
}, {
type: NodeTypes.LINE_NUMBER,
value: -2
}, {
type: NodeTypes.LINE_NUMBER,
value: -3
}]
};
assert.deepEqual(actual, expected);
});
it('should parse functions in ranges', () => {

@@ -255,0 +274,0 @@ let actual = parser.parse('upto(.foo)-30');

Sorry, the diff of this file is not supported yet

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