Huge News!Announcing our $40M Series B led by Abstract Ventures.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 2.0.6 to 3.0.0

RELEASING.md

12

dist/engines/babylon.js

@@ -128,8 +128,10 @@ "use strict";

var paths = [];
var nodeCb = function nodeCb(node) {
if (node.name === query.matcher) {
paths = [].concat(_toConsumableArray(paths), [node.parent]);
}
};
traverse(root, {
Identifier: function Identifier(node) {
if (node.name === query.matcher) {
paths = [].concat(_toConsumableArray(paths), [node.parent]);
}
}
Identifier: nodeCb,
JSXIdentifier: nodeCb
});

@@ -136,0 +138,0 @@ return paths;

@@ -79,12 +79,12 @@ 'use strict';

} else if (numLines > 0) {
var numFollowingLines = numLines;
var numFollowingLines = numLines;
position++;
while (position < code.length && numFollowingLines > 0) {
if (code[position] === '\n') {
numFollowingLines--;
}
position++;
while (position < code.length && numFollowingLines > 0) {
if (code[position] === '\n') {
numFollowingLines--;
}
position++;
}
if (opts.trimNewline) position--; // don't include the last newline
}
if (opts.trimNewline) position--; // don't include the last newline
}

@@ -285,10 +285,10 @@ return position;

} else {
var _nodeToRangeLines = nodeToRangeLines(nextRoot, code, engine);
var _nodeToRangeLines = nodeToRangeLines(nextRoot, code, engine);
var start = _nodeToRangeLines.start;
var end = _nodeToRangeLines.end;
var start = _nodeToRangeLines.start;
var end = _nodeToRangeLines.end;
var codeSlice = code.substring(start, end);
return { code: codeSlice, nodes: [nextRoot], start: start, end: end };
}
var codeSlice = code.substring(start, end);
return { code: codeSlice, nodes: [nextRoot], start: start, end: end };
}
}

@@ -338,3 +338,3 @@

// whatever the child answer is, now we modify it given our callee
// TODO - modifying the asnwer needs to be given not only the answer start and end range, but the child node which returned that start and end
// TODO - modifying the asnwer needs to be given not only the answer start and end range, but the child node which returned that start and end
if (!handled) {

@@ -396,3 +396,3 @@ answer = modifyAnswerWithCall(ast, code, callee, args, engine, answer);

var lines = code.split('\n');
var line = lines[query.value - 1]; // one-indexed arguments to LINE_NUMBER
var line = lines[query.value - 1]; // one-indexed arguments to LINE_NUMBER

@@ -439,3 +439,3 @@ // to get the starting index of this line...

// given character index idx in code, returns the 1-indexed line number
// given character index idx in code, returns the 1-indexed line number
function lineNumberOfCharacterIndex(code, idx) {

@@ -442,0 +442,0 @@ var everythingUpUntilTheIndex = code.substring(0, idx);

{
"name": "@fullstackio/cq",
"version": "2.0.6",
"version": "3.0.0",
"description": "query code with selectors",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"scripts": {
"compile": "babel -d dist/ src/",
"compile": "./node_modules/.bin/babel -d dist/ src/",
"prepublish": "npm run generate-readme && git diff README.md && npm run generate-parser && npm run compile",

@@ -11,0 +11,0 @@ "test": "./node_modules/.bin/mocha --compilers js:babel-core/register",

@@ -122,8 +122,10 @@ /**

let paths = [];
const nodeCb = (node) => {
if(node.name === query.matcher) {
paths = [...paths, node.parent];
}
};
traverse(root, {
Identifier: function (node) {
if(node.name === query.matcher) {
paths = [...paths, node.parent];
}
}
Identifier: nodeCb,
JSXIdentifier: nodeCb
});

@@ -130,0 +132,0 @@ return paths;

@@ -334,2 +334,76 @@ import 'babel-polyfill';

describe('JSX', () => {
const funcWithJSX = `
function submitButton (props) {
const submitText = props.isCreate ? 'Create' : 'Update';
return (
<div className='content'>
<div className='field'>
<label>Add Name</label>
<input
type='text'
ref='name'
/>
</div>
<SubmitButton
text={submitText}
onSubmit={props.onSubmit}
/>
</div>
);
}
`;
it('returns a multi-line JSX element', () => {
let query = [{
type: NodeTypes.IDENTIFIER,
matcher: 'SubmitButton',
}];
let { code } = cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 12, 15);
assert.equal(code, wanted);
});
it('returns a single-line JSX element', () => {
let query = [{
type: NodeTypes.IDENTIFIER,
matcher: 'label',
}];
let { code } = cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 6, 6);
assert.equal(code, wanted);
});
it('returns an in-line code expression', () => {
let query = 'choose(.submitText, 1)'
let { code } = cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 13, 13);
assert.equal(code, wanted);
});
it('returns an attribute on a JSX element', () => {
let query = '.SubmitButton.onSubmit'
let { code } = cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 14, 14);
assert.equal(code, wanted);
});
it('returns a range of attributes on a JSX element', () => {
let query = '.SubmitButton .submitText-.onSubmit'
let { code } = cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 13, 14);
assert.equal(code, wanted);
});
});
describe('more ES6 Classes', () => {

@@ -336,0 +410,0 @@ const src = `

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