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 3.0.1 to 4.0.2

74

dist/cli.js

@@ -32,13 +32,10 @@ #!/usr/bin/env node

alias: 'e',
describe: 'parsing engine',
choices: ['auto', 'babylon', 'typescript'],
describe: 'parsing engine. e.g. auto, babylon, typescript',
default: 'auto'
}).argv;
var _argv$_ = _slicedToArray(argv._, 2);
var _argv$_ = _slicedToArray(argv._, 2),
query = _argv$_[0],
filename = _argv$_[1];
var query = _argv$_[0];
var filename = _argv$_[1];
if (!query) {

@@ -52,18 +49,32 @@ _yargs2.default.showHelp();

// pick the parsing engine
switch (argv.engine) {
case 'babylon':
case 'typescript':
engine = argv.engine;
break;
case 'auto':
if (filename && filename.match(/\.tsx?/)) {
engine = 'typescript';
} else {
engine = 'babylon';
}
break;
default:
throw new Error('unknown engine: ' + argv.engine);
}
(function () {
switch (argv.engine) {
case 'babylon':
case 'typescript':
engine = argv.engine;
break;
case 'auto':
if (filename && filename.match(/\.tsx?/)) {
engine = 'typescript';
} else {
engine = 'babylon';
}
break;
default:
var foundEngine = false;
['@fullstackio/cq-' + engine + '-engine', 'cq-' + engine + '-engine', engine].map(function (potentialEngine) {
try {
if (!foundEngine) {
engine = require(potentialEngine);
foundEngine = true;
}
} catch (err) {}
});
if (!foundEngine) {
throw new Error('unknown engine: ' + argv.engine);
}
}
})();
var inputStream = filename ? _fs2.default.createReadStream(filename) : process.stdin;

@@ -77,13 +88,14 @@

inputStream.on('end', function () {
var result = (0, _index2.default)(content, query, { engine: engine });
(0, _index2.default)(content, query, { engine: engine }).then(function (result) {
if (argv.json === true) {
delete result['nodes'];
if (argv.short === true) {
delete result['code'];
if (argv.json === true) {
delete result['nodes'];
if (argv.short === true) {
delete result['code'];
}
console.log(JSON.stringify(result, null, 2));
} else {
console.log(result.code);
}
console.log(JSON.stringify(result, null, 2));
} else {
console.log(result.code);
}
});
});

@@ -95,7 +95,7 @@ "use strict";

function babylonEngine() {
var engineOpts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var engineOpts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return {
parse: function parse(code) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -102,0 +102,0 @@ var ast = babylon.parse(code, Object.assign({}, defaultBabylonConfig, opts));

@@ -87,7 +87,7 @@ 'use strict';

function typescriptEngine() {
var engineOpts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var engineOpts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return {
parse: function parse(code) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -102,8 +102,6 @@ return ts.createSourceFile(opts.filename || '(no filename)', code, ts.ScriptTarget.Latest, true);

commentRange: function commentRange(node, code, getLeading, getTrailing) {
var _nodeToRange = nodeToRange(node);
var _nodeToRange = nodeToRange(node),
start = _nodeToRange.start,
end = _nodeToRange.end;
var start = _nodeToRange.start;
var end = _nodeToRange.end;
if (getLeading) {

@@ -110,0 +108,0 @@ var nodePos = node.pos;

@@ -17,4 +17,4 @@ "use strict";

ranges.map(function (_ref) {
var rs = _ref.start;
var re = _ref.end;
var rs = _ref.start,
re = _ref.end;

@@ -21,0 +21,0 @@ start = Math.min(start, rs);

@@ -17,4 +17,2 @@ 'use strict';

exports.default = cq;
var _babelTraverse = require('babel-traverse');

@@ -38,4 +36,10 @@

var _debug = require('debug');
var _debug2 = _interopRequireDefault(_debug);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

@@ -45,2 +49,4 @@

var debug = (0, _debug2.default)('cq');
var NodeTypes = exports.NodeTypes = {

@@ -69,3 +75,3 @@ IDENTIFIER: 'IDENTIFIER',

function movePositionByLines(code, numLines, position) {
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

@@ -83,12 +89,12 @@ if (numLines < 0) {

} 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
}

@@ -99,4 +105,4 @@ return position;

function adjustRangeWithContext(code, linesBefore, linesAfter, _ref) {
var start = _ref.start;
var end = _ref.end;
var start = _ref.start,
end = _ref.end;

@@ -117,4 +123,4 @@ if (linesBefore && linesBefore !== 0) {

function adjustRangeWithWindow(code, startingLine, endingLine, _ref2) {
var start = _ref2.start;
var end = _ref2.end;
var start = _ref2.start,
end = _ref2.end;

@@ -144,5 +150,5 @@ // start, end are the range for the whole node

function adjustRangeForComments(ast, code, leading, trailing, engine, _ref3) {
var start = _ref3.start;
var end = _ref3.end;
var nodes = _ref3.nodes;
var start = _ref3.start,
end = _ref3.end,
nodes = _ref3.nodes;

@@ -161,5 +167,5 @@ // this is going to be part of the engine

function adjustRangeForDecorators(ast, code, leading, trailing, engine, _ref4) {
var start = _ref4.start;
var end = _ref4.end;
var nodes = _ref4.nodes;
var start = _ref4.start,
end = _ref4.end,
nodes = _ref4.nodes;

@@ -178,5 +184,5 @@ nodes.map(function (node) {

function modifyAnswerWithCall(ast, code, callee, args, engine, _ref5) {
var start = _ref5.start;
var end = _ref5.end;
var nodes = _ref5.nodes;
var start = _ref5.start,
end = _ref5.end,
nodes = _ref5.nodes;

@@ -194,15 +200,13 @@ switch (callee) {

case 'context':
var _args = _slicedToArray(args, 2);
var _args = _slicedToArray(args, 2),
linesBefore = _args[0],
linesAfter = _args[1];
var linesBefore = _args[0];
var linesAfter = _args[1];
return adjustRangeWithContext(code, linesBefore.value, linesAfter.value, { start: start, end: end });
break;
case 'window':
var _args2 = _slicedToArray(args, 2);
var _args2 = _slicedToArray(args, 2),
startingLine = _args2[0],
endingLine = _args2[1];
var startingLine = _args2[0];
var endingLine = _args2[1];
return adjustRangeWithWindow(code, startingLine.value, endingLine.value, { start: start, end: end });

@@ -295,10 +299,9 @@ break;

} else {
var _nodeToRangeLines = nodeToRangeLines(nextRoot, code, engine);
var _nodeToRangeLines = nodeToRangeLines(nextRoot, code, engine),
start = _nodeToRangeLines.start,
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 };
}
}

@@ -313,8 +316,6 @@

var _query$arguments = _toArray(query.arguments);
var _query$arguments = _toArray(query.arguments),
childQuery = _query$arguments[0],
args = _query$arguments.slice(1);
var childQuery = _query$arguments[0];
var args = _query$arguments.slice(1);
var handled = false;

@@ -328,6 +329,5 @@ // some operators modify before the target query

var _args3 = _slicedToArray(args, 1);
var _args3 = _slicedToArray(args, 1),
goalpostQuery = _args3[0];
var goalpostQuery = _args3[0];
var goalpostNode = resolveIndividualQuery(ast, root, code, goalpostQuery, engine, opts);

@@ -339,6 +339,5 @@ opts.after = goalpostNode.end;

var _args4 = _slicedToArray(args, 1);
var _args4 = _slicedToArray(args, 1),
nodeIdx = _args4[0];
var nodeIdx = _args4[0];
opts.nodeIdx = nodeIdx.value;

@@ -351,3 +350,3 @@ break;

// 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) {

@@ -409,3 +408,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

@@ -452,3 +451,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) {

@@ -482,34 +481,87 @@ var everythingUpUntilTheIndex = code.substring(0, idx);

function cq(code, query) {
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
exports.default = function () {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee(code, query) {
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var engine, ast, root, results;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
engine = opts.engine || (0, _babylon2.default)();
var engine = opts.engine || (0, _babylon2.default)();
if (typeof query === 'string') {
query = [_queryParser2.default.parse(query)]; // parser returns single object for now, but eventually an array
}
if (typeof query === 'string') {
query = [_queryParser2.default.parse(query)]; // parser returns single object for now, but eventually an array
}
if (typeof engine === 'string') {
switch (engine) {
case 'typescript':
engine = (0, _typescript2.default)();
break;
case 'babylon':
engine = (0, _babylon2.default)();
break;
default:
throw new Error('unknown engine: ' + engine);
}
}
if (!(typeof engine === 'string')) {
_context.next = 18;
break;
}
var ast = engine.parse(code, Object.assign({}, opts.parserOpts));
var root = engine.getInitialRoot(ast);
_context.t0 = engine;
_context.next = _context.t0 === 'typescript' ? 6 : _context.t0 === 'babylon' ? 8 : 10;
break;
var results = resolveListOfQueries(ast, root, code, query, engine, opts);
case 6:
engine = (0, _typescript2.default)();
return _context.abrupt('break', 18);
if (opts.undent) {
results.code = undent(results.code);
case 8:
engine = (0, _babylon2.default)();
return _context.abrupt('break', 18);
case 10:
_context.prev = 10;
engine = require('cq-' + engine + '-engine');
_context.next = 17;
break;
case 14:
_context.prev = 14;
_context.t1 = _context['catch'](10);
throw new Error('unknown engine: ' + engine);
case 17:
return _context.abrupt('break', 18);
case 18:
if (typeof engine === 'function') {
// then just use it
}
debug(code);
_context.next = 22;
return Promise.resolve(engine.parse(code, Object.assign({}, opts.parserOpts)));
case 22:
ast = _context.sent;
// debug(JSON.stringify(ast, null, 2));
root = engine.getInitialRoot(ast);
results = resolveListOfQueries(ast, root, code, query, engine, opts);
if (opts.undent) {
results.code = undent(results.code);
}
return _context.abrupt('return', results);
case 27:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[10, 14]]);
}));
function cq(_x2, _x3) {
return _ref6.apply(this, arguments);
}
return results;
}
return cq;
}();
{
"name": "@fullstackio/cq",
"version": "3.0.1",
"version": "4.0.2",
"description": "query code with selectors",

@@ -9,6 +9,6 @@ "main": "dist/index.js",

"compile": "./node_modules/.bin/babel -d dist/ src/",
"prepublish": "npm run generate-readme && git diff README.md && npm run generate-parser && npm run compile",
"prepublish": "npm run generate-readme && git diff ../../README.md && npm run generate-parser && npm run compile",
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register",
"watchtest": "./node_modules/.bin/mocha --compilers js:babel-core/register --watch --watch-extensions pegjs",
"generate-readme": "cqmd -o README.md -p . doc/readme/README.cq.md",
"generate-readme": "node ./node_modules/.bin/cqmd -o ../../README.md -p . doc/readme/README.cq.md",
"generate-parser": "./node_modules/.bin/pegjs src/query.pegjs src/query-parser.js"

@@ -26,2 +26,3 @@ },

"babylon": "^6.8.1",
"debug": "^2.4.4",
"typescript": "^1.8.10",

@@ -31,2 +32,3 @@ "yargs": "^4.7.1"

"devDependencies": {
"@fullstackio/cqmd": "^4.0.2",
"babel-cli": "^6.10.1",

@@ -36,2 +38,3 @@ "babel-core": "^6.9.1",

"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-preset-es2015": "^6.9.0",

@@ -38,0 +41,0 @@ "babel-preset-react": "^6.5.0",

@@ -24,4 +24,3 @@ #!/usr/bin/env node

alias: 'e',
describe: 'parsing engine',
choices: ['auto', 'babylon', 'typescript'],
describe: 'parsing engine. e.g. auto, babylon, typescript',
default: 'auto'

@@ -54,3 +53,19 @@ })

default:
throw new Error('unknown engine: ' + argv.engine);
let foundEngine = false;
[
`@fullstackio/cq-${engine}-engine`,
`cq-${engine}-engine`,
engine
].map((potentialEngine) => {
try {
if(!foundEngine) {
engine = require(potentialEngine);
foundEngine = true
}
} catch (err) {
}
})
if(!foundEngine) {
throw new Error('unknown engine: ' + argv.engine);
}
}

@@ -64,13 +79,14 @@

inputStream.on('end', function() {
let result = cq(content, query, { engine });
cq(content, query, { engine }).then((result) => {
if(argv.json === true) {
delete result['nodes'];
if(argv.short === true) {
delete result['code'];
if(argv.json === true) {
delete result['nodes'];
if(argv.short === true) {
delete result['code'];
}
console.log( JSON.stringify(result, null, 2) );
} else {
console.log( result.code );
}
console.log( JSON.stringify(result, null, 2) );
} else {
console.log( result.code );
}
})
});

@@ -15,2 +15,5 @@ /**

import debugLib from 'debug';
const debug = debugLib('cq');
export const NodeTypes = {

@@ -387,3 +390,3 @@ IDENTIFIER: 'IDENTIFIER',

export default function cq(code, query, opts={}) {
export default async function cq(code, query, opts={}) {
let engine = opts.engine || babylonEngine();

@@ -404,9 +407,20 @@

default:
throw new Error('unknown engine: ' + engine);
try {
engine = require(`cq-${engine}-engine`);
} catch (err) {
throw new Error('unknown engine: ' + engine);
}
break;
}
}
let ast = engine.parse(code, Object.assign({}, opts.parserOpts));
if(typeof engine === 'function') {
// then just use it
}
debug(code);
let ast = await Promise.resolve(engine.parse(code, Object.assign({}, opts.parserOpts)));
// debug(JSON.stringify(ast, null, 2));
let root = engine.getInitialRoot(ast);
let results = resolveListOfQueries(ast, root, code, query, engine, opts);

@@ -413,0 +427,0 @@

@@ -12,4 +12,4 @@ import 'babel-polyfill';

describe('babylon', () => {
describe('createClass', () => {
describe('babylon', async () => {
describe('createClass', async () => {
const src = `

@@ -27,3 +27,3 @@ import React, { PropTypes } from 'react';

it('should return a top level identifier', () => {
it('should return a top level identifier', async () => {
let query = [{

@@ -34,3 +34,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(src, query);
let { code } = await cq(src, query);
const wanted = lines(src, 3, 7);

@@ -40,3 +40,3 @@ assert.equal(code, wanted);

it('should return an inner function', () => {
it('should return an inner function', async () => {
let query = [{

@@ -51,3 +51,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(src, query);
let { code } = await cq(src, query);
const wanted = lines(src, 4, 6);

@@ -57,5 +57,5 @@ assert.equal(code, wanted);

it('should parse string queries', () => {
it('should parse string queries', async () => {
let query = '.Switch .render';
let { code } = cq(src, query);
let { code } = await cq(src, query);
const wanted = lines(src, 4, 6);

@@ -65,5 +65,5 @@ assert.equal(code, wanted);

it('should parse to the EOF', () => {
it('should parse to the EOF', async () => {
let query = '.Switch-EOF';
let { code } = cq(src, query);
let { code } = await cq(src, query);
const wanted = lines(src, 3, 10);

@@ -74,3 +74,3 @@ assert.equal(code, wanted);

describe('top level functions', () => {
describe('top level functions', async () => {
const someFunctions = `

@@ -90,3 +90,3 @@ function hello() {

it('should return a function definition', () => {
it('should return a function definition', async () => {
let query = [{

@@ -97,3 +97,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(someFunctions, query);
let { code } = await cq(someFunctions, query);
const wanted = lines(someFunctions, 1, 3);

@@ -103,3 +103,3 @@ assert.equal(code, wanted);

it('should return an anonymous function assigned to a variable', () => {
it('should return an anonymous function assigned to a variable', async () => {
let query = [{

@@ -110,3 +110,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(someFunctions, query);
let { code } = await cq(someFunctions, query);
const wanted = lines(someFunctions, 5, 7);

@@ -116,3 +116,3 @@ assert.equal(code, wanted);

it('should return an arrow function assigned to a variable', () => {
it('should return an arrow function assigned to a variable', async () => {
let query = [{

@@ -123,3 +123,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(someFunctions, query);
let { code } = await cq(someFunctions, query);
const wanted = lines(someFunctions, 9, 9);

@@ -129,4 +129,4 @@ assert.equal(code, wanted);

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

@@ -136,4 +136,4 @@ assert.equal(code, wanted);

it('should include extra lines given a modifier', () => {
let { code } = cq(someFunctions, 'context(.Farm, 2, 2)');
it('should include extra lines given a modifier', async () => {
let { code } = await cq(someFunctions, 'context(.Farm, 2, 2)');
const wanted = lines(someFunctions, 7, 11);

@@ -143,4 +143,4 @@ assert.equal(code, wanted);

it('should include upto something', () => {
let { code } = cq(someFunctions, '1-upto(.Farm)');
it('should include upto something', async () => {
let { code } = await cq(someFunctions, '1-upto(.Farm)');
const wanted = lines(someFunctions, 0, 7);

@@ -151,3 +151,3 @@ assert.equal(code, wanted);

it('should get a range', () => {
it('should get a range', async () => {
let query = [{

@@ -165,3 +165,3 @@ type: NodeTypes.RANGE,

let { code } = cq(someFunctions, query);
let { code } = await cq(someFunctions, query);
const wanted = lines(someFunctions, 1, 9);

@@ -171,3 +171,3 @@ assert.equal(code, wanted);

it('should get a range with line numbers', () => {
it('should get a range with line numbers', async () => {
let query = [{

@@ -185,3 +185,3 @@ type: NodeTypes.RANGE,

let { code } = cq(someFunctions, query);
let { code } = await cq(someFunctions, query);
const wanted = lines(someFunctions, 9, 11);

@@ -191,4 +191,4 @@ assert.equal(code, wanted);

it('should allow two modifiers', () => {
let { code } = cq(someFunctions, 'context(1-upto(.Farm), 2, 4)');
it('should allow two modifiers', async () => {
let { code } = await cq(someFunctions, 'context(1-upto(.Farm), 2, 4)');
const wanted = lines(someFunctions, 0, 11);

@@ -198,4 +198,4 @@ assert.equal(code, wanted);

it('should not fail to undent top-level code', () => {
let { code } = cq(someFunctions, '.hello', {undent: true});
it('should not fail to undent top-level code', async () => {
let { code } = await cq(someFunctions, '.hello', {undent: true});
const wanted = lines(someFunctions, 1, 3);

@@ -208,3 +208,3 @@ assert.equal(code, wanted);

describe('createClass Plus', () => {
describe('createClass Plus', async () => {
const reactCreateClass = `

@@ -230,3 +230,3 @@ import React, { PropTypes } from 'react';

it('should return an inner range function', () => {
it('should return an inner range function', async () => {
let query = [{

@@ -248,3 +248,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(reactCreateClass, query);
let { code } = await cq(reactCreateClass, query);
const wanted = lines(reactCreateClass, 8, 14);

@@ -257,3 +257,3 @@ // console.log('actual', code, 'wanted', wanted);

describe('ES6 Classes', () => {
describe('ES6 Classes', async () => {
const es6Class = `

@@ -286,3 +286,3 @@ class Polygon {

it('return an ES6 class', () => {
it('return an ES6 class', async () => {
let query = [{

@@ -293,3 +293,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(es6Class, query);
let { code } = await cq(es6Class, query);
const wanted = lines(es6Class, 1, 20);

@@ -300,3 +300,3 @@

it('return functions from within a class', () => {
it('return functions from within a class', async () => {
let query = [{

@@ -318,3 +318,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(es6Class, query);
let { code } = await cq(es6Class, query);
const wanted = lines(es6Class, 2, 15);

@@ -325,4 +325,4 @@

it('should allow negative context first', () => {
let { code } = cq(es6Class, 'context(.distance, -1, -1)');
it('should allow negative context first', async () => {
let { code } = await cq(es6Class, 'context(.distance, -1, -1)');
const wanted = lines(es6Class, 3, 5);

@@ -332,4 +332,4 @@ assert.equal(code, wanted);

it('should allow negative context', () => {
let { code } = cq(es6Class, 'context(.Polygon, -4, -4)');
it('should allow negative context', async () => {
let { code } = await cq(es6Class, 'context(.Polygon, -4, -4)');
const wanted = lines(es6Class, 5, 16);

@@ -339,4 +339,4 @@ assert.equal(code, wanted);

it('should get a constructor', () => {
let { code } = cq(es6Class, '.constructor');
it('should get a constructor', async () => {
let { code } = await cq(es6Class, '.constructor');
const wanted = lines(es6Class, 8, 11);

@@ -346,4 +346,4 @@ assert.equal(code, wanted);

it('should get a constructor as a child of the class', () => {
let { code } = cq(es6Class, '.Polygon .constructor');
it('should get a constructor as a child of the class', async () => {
let { code } = await cq(es6Class, '.Polygon .constructor');
const wanted = lines(es6Class, 8, 11);

@@ -353,4 +353,4 @@ assert.equal(code, wanted);

it('should get a constructor as a child of the class in a range', () => {
let { code } = cq(es6Class, '.Polygon-(.Polygon .constructor)');
it('should get a constructor as a child of the class in a range', async () => {
let { code } = await cq(es6Class, '.Polygon-(.Polygon .constructor)');
const wanted = lines(es6Class, 1, 11);

@@ -360,4 +360,4 @@ assert.equal(code, wanted);

it('should undent indented code', () => {
let { code } = cq(es6Class, '.area', {undent: true});
it('should undent indented code', async () => {
let { code } = await cq(es6Class, '.area', {undent: true});
const wanted = `get area() {

@@ -371,3 +371,3 @@ return this.calcArea();

describe('JSX', () => {
describe('JSX', async () => {
const funcWithJSX = `

@@ -394,3 +394,3 @@ function submitButton (props) {

it('returns a multi-line JSX element', () => {
it('returns a multi-line JSX element', async () => {
let query = [{

@@ -401,3 +401,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(funcWithJSX, query);
let { code } = await cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 12, 15);

@@ -408,3 +408,3 @@

it('returns a single-line JSX element', () => {
it('returns a single-line JSX element', async () => {
let query = [{

@@ -415,3 +415,3 @@ type: NodeTypes.IDENTIFIER,

let { code } = cq(funcWithJSX, query);
let { code } = await cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 6, 6);

@@ -422,6 +422,6 @@

it('returns an in-line code expression', () => {
it('returns an in-line code expression', async () => {
let query = 'choose(.submitText, 1)'
let { code } = cq(funcWithJSX, query);
let { code } = await cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 13, 13);

@@ -432,6 +432,6 @@

it('returns an attribute on a JSX element', () => {
it('returns an attribute on a JSX element', async () => {
let query = '.SubmitButton.onSubmit'
let { code } = cq(funcWithJSX, query);
let { code } = await cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 14, 14);

@@ -442,6 +442,6 @@

it('returns a range of attributes on a JSX element', () => {
it('returns a range of attributes on a JSX element', async () => {
let query = '.SubmitButton .submitText-.onSubmit'
let { code } = cq(funcWithJSX, query);
let { code } = await cq(funcWithJSX, query);
const wanted = lines(funcWithJSX, 13, 14);

@@ -453,3 +453,3 @@

describe('more ES6 Classes', () => {
describe('more ES6 Classes', async () => {
const src = `

@@ -469,4 +469,4 @@ class Square {

it('return disambiguate based on parent', () => {
let { code } = cq(src, '.Circle .area');
it('return disambiguate based on parent', async () => {
let { code } = await cq(src, '.Circle .area');
const wanted = lines(src, 8, 10);

@@ -478,8 +478,8 @@ assert.equal(code, wanted);

describe('searching for strings', () => {
describe('searching for strings', async () => {
const src = `
import foo from 'bar';
// here is a nice test
describe('My Test', () => {
it('should pass', () => {
describe('My Test', async () => {
it('should pass', async () => {
expect(1).toEqual(1);

@@ -489,4 +489,4 @@ })

describe('Other Test', () => {
it('should pass', () => {
describe('Other Test', async () => {
it('should pass', async () => {
expect(2).toEqual(2);

@@ -497,4 +497,4 @@ })

it('find a whole test', () => {
let { code } = cq(src, "'My Test'");
it('find a whole test', async () => {
let { code } = await cq(src, "'My Test'");
const wanted = lines(src, 3, 7);

@@ -504,4 +504,4 @@ assert.equal(code, wanted);

it('find a child should', () => {
let { code } = cq(src, "'My Test' 'should pass'");
it('find a child should', async () => {
let { code } = await cq(src, "'My Test' 'should pass'");
const wanted = lines(src, 4, 6);

@@ -511,4 +511,4 @@ assert.equal(code, wanted);

it('find a child should with the same name', () => {
let { code } = cq(src, "'Other Test' 'should pass'");
it('find a child should with the same name', async () => {
let { code } = await cq(src, "'Other Test' 'should pass'");
const wanted = lines(src, 10, 12);

@@ -518,4 +518,4 @@ assert.equal(code, wanted);

it('find strings in a range', () => {
let { code } = cq(src, "1-'My Test'");
it('find strings in a range', async () => {
let { code } = await cq(src, "1-'My Test'");
const wanted = lines(src, 0, 7);

@@ -526,3 +526,3 @@ assert.equal(code, wanted);

describe('getting comments', () => {
describe('getting comments', async () => {
const src = `

@@ -547,4 +547,4 @@ // hello says hello

it('find a group of single-line comments preceeding', () => {
let { code } = cq(src, "comments(.hello)");
it('find a group of single-line comments preceeding', async () => {
let { code } = await cq(src, "comments(.hello)");
const wanted = lines(src, 1, 5);

@@ -554,4 +554,4 @@ assert.equal(code, wanted);

it('find a block comment preceeding', () => {
let { code } = cq(src, "comments(.bye)");
it('find a block comment preceeding', async () => {
let { code } = await cq(src, "comments(.bye)");
const wanted = lines(src, 7, 12);

@@ -561,4 +561,4 @@ assert.equal(code, wanted);

it('shouldnt fail if you try to get comments where there are none', () => {
let { code } = cq(src, "comments(.noComments)");
it('shouldnt fail if you try to get comments where there are none', async () => {
let { code } = await cq(src, "comments(.noComments)");
const wanted = lines(src, 14, 16);

@@ -571,3 +571,3 @@ assert.equal(code, wanted);

describe('ranges', () => {
describe('ranges', async () => {
const src = `

@@ -593,4 +593,4 @@ import { bootstrap } from 'frobular';

it('should find ranges for identifiers only if they are beyond the start of the range', () => {
let { code } = cq(src, ".routes-.bootstrap");
it('should find ranges for identifiers only if they are beyond the start of the range', async () => {
let { code } = await cq(src, ".routes-.bootstrap");
const wanted = lines(src, 8, 17);

@@ -600,5 +600,5 @@ assert.equal(code, wanted);

it('should find ranges for strings only if they are beyond the start of the range', () => {
it('should find ranges for strings only if they are beyond the start of the range', async () => {
{
let { code } = cq(src, "'hi'");
let { code } = await cq(src, "'hi'");
const wanted = lines(src, 6, 6);

@@ -609,3 +609,3 @@ assert.equal(code, wanted);

{
let { code } = cq(src, ".routes-'hi'");
let { code } = await cq(src, ".routes-'hi'");
const wanted = lines(src, 8, 13);

@@ -617,3 +617,3 @@ assert.equal(code, wanted);

describe('disambiguation', () => {
describe('disambiguation', async () => {
const src = `

@@ -634,4 +634,4 @@ /*

it('choose should pick the right element', () => {
let { code } = cq(src, "choose(.search, 1)");
it('choose should pick the right element', async () => {
let { code } = await cq(src, "choose(.search, 1)");
const wanted = lines(src, 9, 11);

@@ -641,4 +641,4 @@ assert.equal(code, wanted);

it('choose should pick the right child selection', () => {
let { code } = cq(src, "choose(.PhotosComponent .search, 1)");
it('choose should pick the right child selection', async () => {
let { code } = await cq(src, "choose(.PhotosComponent .search, 1)");
const wanted = lines(src, 9, 11);

@@ -649,3 +649,3 @@ assert.equal(code, wanted);

describe('More JSX', () => {
describe('More JSX', async () => {
const src = `

@@ -686,4 +686,4 @@ const EditableTimerList = React.createClass({

it('Find a JSXIdentifier as an identifier', () => {
let { code } = cq(src, ".Timer");
it('Find a JSXIdentifier as an identifier', async () => {
let { code } = await cq(src, ".Timer");
const wanted = lines(src, 26, 29);

@@ -693,4 +693,4 @@ assert.equal(code, wanted);

it('Find a JSXIdentifier child identifier', () => {
let { code } = cq(src, ".EditableTimer .Timer");
it('Find a JSXIdentifier child identifier', async () => {
let { code } = await cq(src, ".EditableTimer .Timer");
const wanted = lines(src, 26, 29);

@@ -697,0 +697,0 @@ assert.equal(code, wanted);

@@ -11,3 +11,2 @@ import 'babel-polyfill'

describe('typescript', () => {
describe('top level functions', () => {

@@ -28,4 +27,4 @@ const someFunctions = `

it('should return a function definition', () => {
let { code } = cq(someFunctions, '.hello', {engine: 'typescript'});
it('should return a function definition', async () => {
let { code } = await cq(someFunctions, '.hello', {engine: 'typescript'});
const wanted = lines(someFunctions, 1, 3);

@@ -35,4 +34,4 @@ assert.equal(code, wanted);

it('should return an anonymous function assigned to a variable', () => {
let { code } = cq(someFunctions, '.bye', {engine: 'typescript'});
it('should return an anonymous function assigned to a variable', async () => {
let { code } = await cq(someFunctions, '.bye', {engine: 'typescript'});
const wanted = lines(someFunctions, 5, 7);

@@ -42,4 +41,4 @@ assert.equal(code, wanted);

it('should return an arrow function assigned to a variable', () => {
let { code } = cq(someFunctions, '.Farm', {engine: 'typescript'});
it('should return an arrow function assigned to a variable', async () => {
let { code } = await cq(someFunctions, '.Farm', {engine: 'typescript'});
const wanted = lines(someFunctions, 9, 9);

@@ -50,3 +49,3 @@ assert.equal(code, wanted);

describe('Angular Code', () => {
describe('Angular Code', async () => {
const src = `

@@ -83,4 +82,4 @@ import {Injectable, provide} from '@angular/core';

`
it('should extract a class', () => {
let { code } = cq(src, '.AuthService', {engine: 'typescript'});
it('should extract a class', async () => {
let { code } = await cq(src, '.AuthService', {engine: 'typescript'});
const wanted = lines(src, 4, 25);

@@ -90,4 +89,4 @@ assert.equal(code, wanted);

it('should extract a class with decorator', () => {
let { code } = cq(src, 'decorators(.AuthService)', {engine: 'typescript'});
it('should extract a class with decorator', async () => {
let { code } = await cq(src, 'decorators(.AuthService)', {engine: 'typescript'});
const wanted = lines(src, 3, 25);

@@ -97,4 +96,4 @@ assert.equal(code, wanted);

it('should extract a specific method', () => {
let { code } = cq(src, '.AuthService .login', {engine: 'typescript'});
it('should extract a specific method', async () => {
let { code } = await cq(src, '.AuthService .login', {engine: 'typescript'});
const wanted = lines(src, 5, 12);

@@ -104,4 +103,4 @@ assert.equal(code, wanted);

it('should extract export vars ', () => {
let { code } = cq(src, '.AUTH_PROVIDERS', {engine: 'typescript'});
it('should extract export vars ', async () => {
let { code } = await cq(src, '.AUTH_PROVIDERS', {engine: 'typescript'});
const wanted = lines(src, 27, 29);

@@ -111,4 +110,4 @@ assert.equal(code, wanted);

it('should extract export vars ', () => {
let { code } = cq(src, '1-(.AuthService .login)', {engine: 'typescript'});
it('should extract export vars ', async () => {
let { code } = await cq(src, '1-(.AuthService .login)', {engine: 'typescript'});
const wanted = lines(src, 0, 12);

@@ -118,4 +117,4 @@ assert.equal(code, wanted);

it('should extract ranges from children to parent vars ', () => {
let { code } = cq(src, '(.AuthService .isLoggedIn)-.AUTH_PROVIDERS', {engine: 'typescript'});
it('should extract ranges from children to parent vars ', async () => {
let { code } = await cq(src, '(.AuthService .isLoggedIn)-.AUTH_PROVIDERS', {engine: 'typescript'});
const wanted = lines(src, 22, 29);

@@ -127,8 +126,8 @@ assert.equal(code, wanted);

describe('searching for strings', () => {
describe('searching for strings', async () => {
const src = `
import foo from 'bar';
// here is a nice test
describe('My Test', () => {
it('should pass', () => {
describe('My Test', async () => {
it('should pass', async () => {
expect(1).toEqual(1);

@@ -138,4 +137,4 @@ })

describe('Other Test', () => {
it('should pass', () => {
describe('Other Test', async () => {
it('should pass', async () => {
expect(2).toEqual(2);

@@ -146,4 +145,4 @@ })

it('find a whole test', () => {
let { code } = cq(src, "'My Test'", {engine: 'typescript'});
it('find a whole test', async () => {
let { code } = await cq(src, "'My Test'", {engine: 'typescript'});
const wanted = lines(src, 3, 7);

@@ -153,4 +152,4 @@ assert.equal(code, wanted);

it('find a child should', () => {
let { code } = cq(src, "'My Test' 'should pass'", {engine: 'typescript'});
it('find a child should', async () => {
let { code } = await cq(src, "'My Test' 'should pass'", {engine: 'typescript'});
const wanted = lines(src, 4, 6);

@@ -160,4 +159,4 @@ assert.equal(code, wanted);

it('find a child should with the same name', () => {
let { code } = cq(src, "'Other Test' 'should pass'", {engine: 'typescript'});
it('find a child should with the same name', async () => {
let { code } = await cq(src, "'Other Test' 'should pass'", {engine: 'typescript'});
const wanted = lines(src, 10, 12);

@@ -167,4 +166,4 @@ assert.equal(code, wanted);

it('find strings in a range', () => {
let { code } = cq(src, "1-'My Test'", {engine: 'typescript'});
it('find strings in a range', async () => {
let { code } = await cq(src, "1-'My Test'", {engine: 'typescript'});
const wanted = lines(src, 0, 7);

@@ -175,3 +174,3 @@ assert.equal(code, wanted);

describe('getting comments', () => {
describe('getting comments', async () => {
const src = `

@@ -196,4 +195,4 @@ // hello says hello

it('find a group of single-line comments preceeding', () => {
let { code } = cq(src, "comments(.hello)", {engine: 'typescript'});
it('find a group of single-line comments preceeding', async () => {
let { code } = await cq(src, "comments(.hello)", {engine: 'typescript'});
const wanted = lines(src, 1, 5);

@@ -203,4 +202,4 @@ assert.equal(code, wanted);

it('find a block comment preceeding', () => {
let { code } = cq(src, "comments(.bye)");
it('find a block comment preceeding', async () => {
let { code } = await cq(src, "comments(.bye)");
const wanted = lines(src, 7, 12);

@@ -210,4 +209,4 @@ assert.equal(code, wanted);

it('shouldnt fail if you try to get comments where there are none', () => {
let { code } = cq(src, "comments(.noComments)");
it('shouldnt fail if you try to get comments where there are none', async () => {
let { code } = await cq(src, "comments(.noComments)");
const wanted = lines(src, 14, 16);

@@ -219,3 +218,3 @@ assert.equal(code, wanted);

describe('ranges', () => {
describe('ranges', async () => {
const src = `

@@ -241,4 +240,4 @@ import { bootstrap } from 'frobular';

it('should find ranges for identifiers only if they are beyond the start of the range', () => {
let { code } = cq(src, ".routes-.bootstrap");
it('should find ranges for identifiers only if they are beyond the start of the range', async () => {
let { code } = await cq(src, ".routes-.bootstrap");
const wanted = lines(src, 8, 17);

@@ -248,5 +247,5 @@ assert.equal(code, wanted);

it('should find ranges for strings only if they are beyond the start of the range', () => {
it('should find ranges for strings only if they are beyond the start of the range', async () => {
{
let { code } = cq(src, "'hi'");
let { code } = await cq(src, "'hi'");
const wanted = lines(src, 6, 6);

@@ -257,3 +256,3 @@ assert.equal(code, wanted);

{
let { code } = cq(src, ".routes-'hi'");
let { code } = await cq(src, ".routes-'hi'");
const wanted = lines(src, 8, 13);

@@ -265,3 +264,3 @@ assert.equal(code, wanted);

describe('window operator', () => {
describe('window operator', async () => {
const src = `

@@ -290,5 +289,5 @@ import { bootstrap, provideRouter } from 'frobular';

it('should get lines that are close below', () => {
it('should get lines that are close below', async () => {
{
let { code } = cq(src, "window(.template, 0, 0)", {engine: 'typescript'});
let { code } = await cq(src, "window(.template, 0, 0)", {engine: 'typescript'});
const wanted = lines(src, 4, 4);

@@ -298,3 +297,3 @@ assert.equal(code, wanted);

{
let { code } = cq(src, "window(.template, 0, 2)", {engine: 'typescript'});
let { code } = await cq(src, "window(.template, 0, 2)", {engine: 'typescript'});
const wanted = lines(src, 4, 6);

@@ -304,3 +303,3 @@ assert.equal(code, wanted);

{
let { code } = cq(src, "window(.template, 1, 2)", {engine: 'typescript'});
let { code } = await cq(src, "window(.template, 1, 2)", {engine: 'typescript'});
const wanted = lines(src, 5, 6);

@@ -310,3 +309,3 @@ assert.equal(code, wanted);

{
let { code } = cq(src, "window(.template, 3, 8)", {engine: 'typescript'});
let { code } = await cq(src, "window(.template, 3, 8)", {engine: 'typescript'});
const wanted = lines(src, 7, 12);

@@ -317,4 +316,4 @@ assert.equal(code, wanted);

it('should get lines that are close around', () => {
let { code } = cq(src, "window(.template, -1, 1)", {engine: 'typescript'});
it('should get lines that are close around', async () => {
let { code } = await cq(src, "window(.template, -1, 1)", {engine: 'typescript'});
const wanted = lines(src, 3, 5);

@@ -326,3 +325,3 @@ assert.equal(code, wanted);

describe('disambiguation', () => {
describe('disambiguation', async () => {
const src = `

@@ -337,4 +336,4 @@ import { bootstrap, provideRouter } from 'frobular';

it('should disambiguate children identifiers', () => {
let { code } = cq(src, ".bootstrap .RoutesDemoApp", {engine: 'typescript'});
it('should disambiguate children identifiers', async () => {
let { code } = await cq(src, ".bootstrap .RoutesDemoApp", {engine: 'typescript'});
const wanted = lines(src, 3, 6);

@@ -344,4 +343,4 @@ assert.equal(code, wanted);

it('after() should find things properly', () => {
let { code } = cq(src, "after(.bootstrap, .provideRouter)", {engine: 'typescript'});
it('after() should find things properly', async () => {
let { code } = await cq(src, "after(.bootstrap, .provideRouter)", {engine: 'typescript'});
const wanted = lines(src, 3, 6);

@@ -351,5 +350,5 @@ assert.equal(code, wanted);

it('choose() should pick a specific selection', () => {
it('choose() should pick a specific selection', async () => {
{
let { code } = cq(src, "choose(.bootstrap, 0)", {engine: 'typescript'});
let { code } = await cq(src, "choose(.bootstrap, 0)", {engine: 'typescript'});
const wanted = lines(src, 1, 1);

@@ -359,3 +358,3 @@ assert.equal(code, wanted);

{
let { code } = cq(src, "choose(.bootstrap, 1)", {engine: 'typescript'});
let { code } = await cq(src, "choose(.bootstrap, 1)", {engine: 'typescript'});
const wanted = lines(src, 3, 6);

@@ -368,3 +367,3 @@ assert.equal(code, wanted);

describe('Decorators', () => {
describe('Decorators', async () => {
const src = `

@@ -382,4 +381,4 @@ /*

it('should get the decorator alone as a child of the class', () => {
let { code } = cq(src, ".FooBar .Component", {engine: 'typescript'});
it('should get the decorator alone as a child of the class', async () => {
let { code } = await cq(src, ".FooBar .Component", {engine: 'typescript'});
const wanted = lines(src, 4, 7);

@@ -389,4 +388,4 @@ assert.equal(code, wanted);

it('should get decorator alone as an identifier', () => {
let { code } = cq(src, ".Component", {engine: 'typescript'});
it('should get decorator alone as an identifier', async () => {
let { code } = await cq(src, ".Component", {engine: 'typescript'});
const wanted = lines(src, 4, 7);

@@ -396,4 +395,4 @@ assert.equal(code, wanted);

it('should get the class alone as an identifier', () => {
let { code } = cq(src, ".FooBar", {engine: 'typescript'});
it('should get the class alone as an identifier', async () => {
let { code } = await cq(src, ".FooBar", {engine: 'typescript'});
const wanted = lines(src, 8, 9);

@@ -403,4 +402,4 @@ assert.equal(code, wanted);

it('should get the class with decorator when using decorators()', () => {
let { code } = cq(src, "decorators(.FooBar)", {engine: 'typescript'});
it('should get the class with decorator when using decorators()', async () => {
let { code } = await cq(src, "decorators(.FooBar)", {engine: 'typescript'});
const wanted = lines(src, 4, 9);

@@ -410,4 +409,4 @@ assert.equal(code, wanted);

it('should get the class with decorator and comments with operations', () => {
let { code } = cq(src, "comments(decorators(.FooBar))", {engine: 'typescript'});
it('should get the class with decorator and comments with operations', async () => {
let { code } = await cq(src, "comments(decorators(.FooBar))", {engine: 'typescript'});
const wanted = lines(src, 1, 9);

@@ -423,4 +422,4 @@ assert.equal(code, wanted);

it('should get a single-line decorator', () => {
let { code } = cq(src2, "decorators(.FooBar)", {engine: 'typescript'});
it('should get a single-line decorator', async () => {
let { code } = await cq(src2, "decorators(.FooBar)", {engine: 'typescript'});
const wanted = lines(src2, 1, 3);

@@ -437,4 +436,4 @@ assert.equal(code, wanted);

it('should get all decorators', () => {
let { code } = cq(src3, "decorators(.FooBar)", {engine: 'typescript'});
it('should get all decorators', async () => {
let { code } = await cq(src3, "decorators(.FooBar)", {engine: 'typescript'});
const wanted = lines(src3, 1, 4);

@@ -446,3 +445,3 @@ assert.equal(code, wanted);

describe('special identifiers', () => {
describe('special identifiers', async () => {
const src = `

@@ -461,4 +460,4 @@ /*

it('should get a constructor', () => {
let { code } = cq(src, ".Barn .constructor", {engine: 'typescript'});
it('should get a constructor', async () => {
let { code } = await cq(src, ".Barn .constructor", {engine: 'typescript'});
const wanted = lines(src, 7, 9);

@@ -468,4 +467,4 @@ assert.equal(code, wanted);

it('should get a constructor as part of a child range', () => {
let { code } = cq(src, ".Barn-(.Barn .constructor)", {engine: 'typescript'});
it('should get a constructor as part of a child range', async () => {
let { code } = await cq(src, ".Barn-(.Barn .constructor)", {engine: 'typescript'});
const wanted = lines(src, 4, 9);

@@ -472,0 +471,0 @@ assert.equal(code, wanted);

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