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

jsstana

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsstana - npm Package Compare versions

Comparing version 0.0.22 to 0.1.1

.jscsrc

5

bin/jsgrep.js

@@ -21,2 +21,3 @@ #!/usr/bin/env node

program.usage("[options] pattern file.js [file2.js] [dir]");
program.version(pkgJson.version);
program.option("-n, --line-number", "Each output line is preceded by its relative line number in the file.", false);

@@ -142,3 +143,3 @@ program.option("-H, --file-name", "Always print filename headers with output lines.", false);

estraverse.traverse(syntax, {
enter: function(node /* , parent */) {
enter: function (node /* , parent */) {
var match = pattern(node);

@@ -181,3 +182,3 @@ if (match) {

var start = Math.max(0, steps[0].pos - 10);
var linePrefix = (start === 0 ? "" : "..." );
var linePrefix = (start === 0 ? "" : "...");
var lineSuffix = (start + LONG_LINE_LENGTH < line.length ? "..." : "");

@@ -184,0 +185,0 @@

8

lib/jsstana.js

@@ -96,7 +96,7 @@ /**

function findClose(key) {
var d = new levenshtein(rator, key).distance;
var d = new levenshtein(rator, key).distance;
if (d <= 2) {
suggest.push(key);
}
if (d <= 2) {
suggest.push(key);
}
}

@@ -103,0 +103,0 @@

@@ -8,30 +8,65 @@ "use strict";

var dotted = false;
var dottedM;
var len = args.length;
if (args.length > 1 && args[args.length - 2] === ".") {
dotted = args[args.length - 1];
args = args.slice(0, -2);
if (dotted === "?") {
dottedM = function () {
return {};
};
} else if (dotted[0] === "?") {
dotted = dotted.substr(1);
dottedM = function(v) {
var res = {};
res[dotted] = v;
return res;
};
} else {
throw new Error("call should have pattern variable after dot");
var multi = false;
for (var i = 0; i < len; i++) {
if (typeof args[i] === "string" && args[i].substr(0, 2) === "??") {
if (multi === false) {
multi = i;
} else {
throw new Error("Only single multi-pattern allowed in (call)");
}
}
}
var argumentMatchers = args.map(this.matcher, this);
var argumentsMatcher;
if (multi === false) {
var argumentMatchers = args.map(this.matcher, this);
argumentsMatcher = function (nodes) {
var result = {};
for (var j = 0; j < len; j++) {
var argumentM = argumentMatchers[j](nodes[j]);
if (argumentM === undefined) { return undefined; }
result = _.extend(result, argumentM);
}
return result;
};
} else {
var prefixMatchers = args.slice(0, multi).map(this.matcher, this);
var postfixMatchers = args.slice(multi + 1).map(this.matcher, this);
var postfixLen = postfixMatchers.length;
argumentsMatcher = function (nodes) {
var j;
var argumentM;
var result = {};
for (j = 0; j < multi; j++) {
argumentM = prefixMatchers[j](nodes[j]);
if (argumentM === undefined) { return undefined; }
result = _.extend(result, argumentM);
}
var shift = nodes.length - postfixLen;
if (args[multi] !== "??") {
var multiVar = args[multi].substr(2);
result[multiVar] = nodes.slice(multi, shift);
}
for (j = 0; j < postfixMatchers.length; j++) {
argumentM = postfixMatchers[j](nodes[shift + j]);
if (argumentM === undefined) { return undefined; }
result = _.extend(result, argumentM);
}
return result;
};
}
return {
dottedMatcher: dottedM,
argumentMatchers: argumentMatchers,
argumentsMatcher: argumentsMatcher,
minArguments: args.length,
variableArguments: multi !== false,
};

@@ -47,3 +82,3 @@ }

for arbitrary arguments use
`(call fun . ?)` or similar dotted list syntax.
`(call fun ??params)`

@@ -62,4 +97,5 @@ #### (new class arg0...argn)

var compiled = compileCallMatcher.call(this, args);
var dottedM = compiled.dottedMatcher;
var argumentMatchers = compiled.argumentMatchers;
var argumentsMatcher = compiled.argumentsMatcher;
var minArguments = compiled.minArguments;
var variableArguments = compiled.variableArguments;

@@ -69,18 +105,18 @@ return function (node) {

// Check the length of arguments list
if (variableArguments) {
if (node.arguments.length < minArguments) { return undefined; }
} else {
if (node.arguments.length !== minArguments) { return undefined; }
}
// callee
var calleeM = calleeMatcher(node.callee);
if (calleeM === undefined) { return undefined; }
if (!dottedM && argumentMatchers.length !== node.arguments.length) { return undefined; }
for (var i = 0; i < argumentMatchers.length; i++) {
var argumentM = argumentMatchers[i](node.arguments[i]);
if (argumentM === undefined) { return undefined; }
// arguments
var argumentsM = argumentsMatcher(node.arguments);
if (argumentsM === undefined) { return undefined; }
calleeM = _.extend(calleeM, argumentM);
}
if (dottedM) {
calleeM = _.extend(calleeM, dottedM(node.arguments.slice(argumentMatchers.length)));
}
return calleeM;
return _.extend(calleeM, argumentsM);
};

@@ -87,0 +123,0 @@ }

@@ -70,6 +70,6 @@ "use strict";

if (value === "?") {
valueCapture = function() { return {}; };
valueCapture = function () { return {}; };
} else {
value = value.substr(1);
valueCapture = function(v) {
valueCapture = function (v) {
var res = {};

@@ -76,0 +76,0 @@ res[value] = v;

@@ -11,3 +11,3 @@ "use strict";

operator = operator.substr(1);
return function(op) {
return function (op) {
var res = {};

@@ -14,0 +14,0 @@ res[operator] = op;

@@ -31,3 +31,3 @@ "use strict";

lexemeP(p.regex(/'((?:[^']|\\.)*?)'/)).onMatch(unquote),
lexemeP(p.regex(/[0-9]+/)).onMatch(function (m) { return parseInt(m[0], 10); } )
lexemeP(p.regex(/[0-9]+/)).onMatch(function (m) { return parseInt(m[0], 10); })
);

@@ -62,3 +62,3 @@

} else if (_.isNumber(sexpr)) {
return ""+sexpr;
return "" + sexpr;
} else if (_.isArray(sexpr)) {

@@ -65,0 +65,0 @@ return "(" + sexpr.map(stringify).join(" ") + ")";

{
"name": "jsstana",
"description": "s-expression match patterns for Mozilla Parser AST",
"version": "0.0.22",
"version": "0.1.1",
"homepage": "https://github.com/phadej/jsstana",

@@ -35,7 +35,10 @@ "author": {

"devDependencies": {
"david": "^5.0.0",
"escodegen": "~1.4.0",
"mocha": "~1.21.4",
"eslint": "^0.9.1",
"istanbul": "~0.3.0",
"jscs": "^1.7.3",
"jshint": "~2.5.1",
"ljs": "~0.2.0",
"jshint": "~2.5.1",
"istanbul": "~0.3.0"
"mocha": "~2.0.1"
},

@@ -55,5 +58,5 @@ "keywords": [

"walkdir": "0.0.7",
"commander": "~2.3.0",
"commander": "~2.5.0",
"esprima": "~1.2.2",
"estraverse": "~1.5.0",
"estraverse": "~1.7.0",
"levenshtein": "~1.0.2",

@@ -60,0 +63,0 @@ "chalk": "~0.5.1"

@@ -85,3 +85,3 @@ # jsstana

for arbitrary arguments use
`(call fun . ?)` or similar dotted list syntax.
`(call fun ??params)`

@@ -277,2 +277,4 @@ #### (new class arg0...argn)

- 0.1.1 New (call) syntax
- `(call ?fun ?param ?params ?last-one)`
- 0.0.22 dependency updates

@@ -283,32 +285,32 @@ - 0.0.21 Use commander

- 0.0.18 null checks
- Also updated dependencies
- Also updated dependencies
- 0.0.17 this, break &amp; continue
- Added forementioned matchers
- Added forementioned matchers
- 0.0.16 Updates
- Dependencies updated
- `fn-expr` matches function expressions
- Dependencies updated
- `fn-expr` matches function expressions
- 0.0.15 Updates
- Dependencies updated
- Dependencies updated
- Introduce eslint
- Fix logical expressions: `&&` and `||`
- 0.0.14 Better cli experience
- Strip shebang by default
- Truncate long output lines
- Fancier colorize of jsgrep output
- Catch parse errors and unexisting files
- Strip shebang by default
- Truncate long output lines
- Fancier colorize of jsgrep output
- Catch parse errors and unexisting files
- 0.0.13 nand, nor and ?
- node capturing
- nand and nor
- instanceof, typeof, delete and void operators
- node capturing
- nand and nor
- instanceof, typeof, delete and void operators
- 0.0.12 Code reogranization
- 0.0.11 User-provided patterns
- fixed installing on Windows
- assignment pattern
- anonymous matchers
- fixed installing on Windows
- assignment pattern
- anonymous matchers
- 0.0.10 ident pattern
- 0.0.9 Boolean patterns
- 0.0.8 Even more rands
- unary and update expressions
- drop `literal-` prefix (eg plain `string` now)
- shorthand binary op syntax `(+ a b)`
- unary and update expressions
- drop `literal-` prefix (eg plain `string` now)
- shorthand binary op syntax `(+ a b)`
- shorthand lookup syntax

@@ -318,9 +320,9 @@ - 0.0.7 jsgrep, third try

- 0.0.5 jsgrep
- also new expression
- also new expression
- 0.0.4 Binary and throw
- 0.0.3 More rands
- call dotted syntax
- literals
- expr - expression statement
- use grunt-literate to generate README.md
- call dotted syntax
- literals
- expr - expression statement
- use grunt-literate to generate README.md
- 0.0.2 Dev setup

@@ -327,0 +329,0 @@ - 0.0.1 Preview release

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