grasp-equery
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -1,2 +0,2 @@ | ||
// Generated by LiveScript 1.3.1 | ||
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
@@ -6,3 +6,3 @@ var parse, matchNode, VERSION, query, queryParsed; | ||
matchNode = require('./match').matchNode; | ||
VERSION = '0.2.3'; | ||
VERSION = '0.3.0'; | ||
query = function(selector, ast){ | ||
@@ -9,0 +9,0 @@ return queryParsed(parse(selector), ast); |
@@ -1,40 +0,44 @@ | ||
// Generated by LiveScript 1.3.1 | ||
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
var ref$, primitiveOnlyAttributes, eitherAttributes, all, tail, getNodeAtPath, toString$ = {}.toString, slice$ = [].slice; | ||
ref$ = require('grasp-syntax-javascript'), primitiveOnlyAttributes = ref$.primitiveOnlyAttributes, eitherAttributes = ref$.eitherAttributes; | ||
var ref$, primitiveOnlyAttributes, eitherAttributes, syntaxFlat, all, tail, getNodeAtPath, toString$ = {}.toString, slice$ = [].slice; | ||
ref$ = require('grasp-syntax-javascript'), primitiveOnlyAttributes = ref$.primitiveOnlyAttributes, eitherAttributes = ref$.eitherAttributes, syntaxFlat = ref$.syntaxFlat; | ||
ref$ = require('prelude-ls'), all = ref$.all, tail = ref$.tail; | ||
getNodeAtPath = require('./common').getNodeAtPath; | ||
function matchNode(results, query, mainNode){ | ||
var key, val, ref$; | ||
var spec, i$, ref$, len$, key, j$, ref1$, len1$, subNode; | ||
if (eq(mainNode, query)) { | ||
results.push(mainNode); | ||
} | ||
for (key in mainNode) { | ||
val = mainNode[key]; | ||
if ((key !== 'loc' && key !== 'start' && key !== 'end' && key !== '_named') && ((ref$ = toString$.call(val).slice(8, -1)) === 'Object' || ref$ === 'Array')) { | ||
matchNode(results, query, val); | ||
spec = syntaxFlat[mainNode.type]; | ||
for (i$ = 0, len$ = (ref$ = spec.nodes || []).length; i$ < len$; ++i$) { | ||
key = ref$[i$]; | ||
if (mainNode[key]) { | ||
matchNode(results, query, mainNode[key]); | ||
} | ||
} | ||
for (i$ = 0, len$ = (ref$ = spec.nodeArrays || []).length; i$ < len$; ++i$) { | ||
key = ref$[i$]; | ||
for (j$ = 0, len1$ = (ref1$ = mainNode[key]).length; j$ < len1$; ++j$) { | ||
subNode = ref1$[j$]; | ||
if (subNode) { | ||
matchNode(results, query, subNode); | ||
} | ||
} | ||
} | ||
function eq(targetNode, selectorNode){ | ||
var selectorNodeType, prop; | ||
selectorNodeType = toString$.call(selectorNode).slice(8, -1); | ||
if (selectorNode === targetNode) { | ||
var type, spec; | ||
if (targetNode === selectorNode) { | ||
return true; | ||
} else if (selectorNodeType !== toString$.call(targetNode).slice(8, -1)) { | ||
return false; | ||
} else if (selectorNodeType === 'Object') { | ||
if (selectorNode.type === 'Grasp') { | ||
return matchSpecial(targetNode, selectorNode); | ||
} else { | ||
for (prop in targetNode) { | ||
if (prop !== 'loc' && prop !== 'start' && prop !== 'end' && prop !== '_named' && prop !== 'raw') { | ||
if (!eq(targetNode[prop], selectorNode[prop])) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} else if (selectorNodeType === 'Array') { | ||
return matchArray(selectorNode, targetNode); | ||
} else if (selectorNode.type === 'Grasp') { | ||
return matchSpecial(targetNode, selectorNode); | ||
} else if (selectorNode.type === targetNode.type) { | ||
type = selectorNode.type; | ||
spec = syntaxFlat[type]; | ||
return all(function(it){ | ||
return eq(targetNode[it], selectorNode[it]); | ||
}, spec.nodes || []) && all(function(it){ | ||
return matchArray(targetNode[it], selectorNode[it]); | ||
}, spec.nodeArrays || []) && all(function(it){ | ||
return targetNode[it] === selectorNode[it]; | ||
}, spec.primitives || []); | ||
} else { | ||
@@ -44,8 +48,10 @@ return false; | ||
} | ||
function matchArray(pattern, input){ | ||
var patternLen, that, ref$, patternFirst, patternRest, inputFirst, inputRest, arrayWildcardName, wildcardName; | ||
patternLen = pattern.length; | ||
if (patternLen === 0) { | ||
function matchArray(input, pattern){ | ||
var that, ref$, patternFirst, patternRest, inputFirst, inputRest, arrayWildcardName, wildcardName; | ||
if (toString$.call(pattern).slice(8, -1) === 'Object' && pattern.type === 'Grasp') { | ||
return matchSpecial(input, pattern); | ||
} | ||
if (pattern.length === 0) { | ||
return input.length === 0; | ||
} else if (patternLen === 1) { | ||
} else if (pattern.length === 1) { | ||
if (that = isArrayWildcard(pattern[0])) { | ||
@@ -74,3 +80,3 @@ if (that = that.name) { | ||
wildcardName = that; | ||
if (matchArray(tail(patternRest), inputRest)) { | ||
if (matchArray(inputRest, tail(patternRest))) { | ||
return true; | ||
@@ -81,3 +87,3 @@ } else { | ||
} | ||
return matchArray(pattern, inputRest); | ||
return matchArray(inputRest, pattern); | ||
} | ||
@@ -88,6 +94,6 @@ } else { | ||
} | ||
return matchArray(pattern, inputRest); | ||
return matchArray(inputRest, pattern); | ||
} | ||
} else { | ||
return eq(inputFirst, patternFirst) && matchArray(patternRest, inputRest); | ||
return eq(inputFirst, patternFirst) && matchArray(inputRest, patternRest); | ||
} | ||
@@ -94,0 +100,0 @@ } |
@@ -1,2 +0,2 @@ | ||
// Generated by LiveScript 1.3.1 | ||
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
@@ -17,2 +17,5 @@ var acorn, ref$, aliasMap, matchesMap, matchesAliasMap, literalMap, getNodeAtPath, toString$ = {}.toString; | ||
}, { | ||
code: "function* f(){ " + selector + "; }", | ||
path: ['body', 'body', 0] | ||
}, { | ||
code: "(" + selector + ")", | ||
@@ -34,3 +37,6 @@ path: [] | ||
try { | ||
parsedSelector = acorn.parse(code); | ||
parsedSelector = acorn.parse(code, { | ||
ecmaVersion: 6, | ||
sourceType: 'module' | ||
}); | ||
path = attempt.path; | ||
@@ -88,3 +94,3 @@ break; | ||
function processNode(node){ | ||
var name, that, ident, attrs, n, processedAttrs, i$, len$, attr, nodeKey, nodeValue; | ||
var name, that, ident, attrs, n, processedAttrs, i$, len$, attr; | ||
switch (node.type) { | ||
@@ -172,11 +178,7 @@ case 'Identifier': | ||
return processNode(node.expression); | ||
default: | ||
if (!(!node.type && node.key != null && node.value != null)) { | ||
case 'Property': | ||
if (!(node.key.type === 'Identifier' && node.value.type === 'Identifier')) { | ||
return; | ||
} | ||
nodeKey = node.key, nodeValue = node.value; | ||
if (!(nodeKey.type === 'Identifier' && nodeValue.type === 'Identifier')) { | ||
return; | ||
} | ||
if (nodeKey.name === '_') { | ||
if (node.key.name === '_') { | ||
if (node.value.name === '_') { | ||
@@ -187,14 +189,14 @@ return { | ||
}; | ||
} else if (/^\$/.test(nodeValue.name)) { | ||
} else if (/^\$/.test(node.value.name)) { | ||
return { | ||
type: 'Grasp', | ||
graspType: 'array-wildcard', | ||
name: /^\$(\w*)$/.exec(nodeValue.name)[1] | ||
name: /^\$(\w*)$/.exec(node.value.name)[1] | ||
}; | ||
} | ||
} else if (nodeKey.name === '$') { | ||
} else if (node.key.name === '$') { | ||
return { | ||
type: 'Grasp', | ||
graspType: 'named-wildcard', | ||
name: nodeValue.name | ||
name: node.value.name | ||
}; | ||
@@ -201,0 +203,0 @@ } |
{ | ||
"name": "grasp-equery", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"author": "George Zahariev <z@georgezahariev.com>", | ||
@@ -22,8 +22,3 @@ "description": "grasp query using example code with wildcards", | ||
"bugs": "https://github.com/gkz/grasp-equery/issues", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://raw.github.com/gkz/grasp-equery/master/LICENSE" | ||
} | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
@@ -40,8 +35,8 @@ "node": ">= 0.8.0" | ||
"dependencies": { | ||
"prelude-ls": "~1.1.1", | ||
"acorn": "~0.6.0", | ||
"grasp-syntax-javascript": "~0.1.0" | ||
"prelude-ls": "~1.1.2", | ||
"acorn": "~2.5.0", | ||
"grasp-syntax-javascript": "~0.2.0" | ||
}, | ||
"devDependencies": { | ||
"LiveScript": "~1.3.1", | ||
"livescript": "~1.4.0", | ||
"mocha": "~2.1.0", | ||
@@ -48,0 +43,0 @@ "istanbul": "~0.3.5" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17952
472
+ Addedacorn@2.5.2(transitive)
+ Addedgrasp-syntax-javascript@0.2.2(transitive)
- Removedacorn@0.6.0(transitive)
- Removedgrasp-syntax-javascript@0.1.0(transitive)
- Removedprelude-ls@1.0.3(transitive)
Updatedacorn@~2.5.0
Updatedprelude-ls@~1.1.2