Socket
Socket
Sign inDemoInstall

recast

Package Overview
Dependencies
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recast - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

.travis.yml

75

lib/patcher.js
var assert = require("assert");
var linesModule = require("./lines");
var Syntax = require("./types").Syntax;
var util = require("./util");

@@ -69,4 +70,3 @@ function Patcher(lines) {

if (!orig ||
!findReprints(node, reprints))
if (!lines || !findReprints(node, reprints))
return;

@@ -98,3 +98,4 @@

var canReprint = findChildReprints(node.original, node, reprints);
var path = null; // Just a placeholder for now.
var canReprint = findChildReprints(path, node, node.original, reprints);

@@ -110,11 +111,11 @@ if (!canReprint) {

function findAnyReprints(a, b, reprints) {
if (a === b)
function findAnyReprints(path, newNode, oldNode, reprints) {
if (newNode === oldNode)
return true;
if (a instanceof Array)
return findArrayReprints(a, b, reprints);
if (newNode instanceof Array)
return findArrayReprints(path, newNode, oldNode, reprints);
if (typeof a === "object")
return findObjectReprints(a, b, reprints);
if (typeof newNode === "object")
return findObjectReprints(path, newNode, oldNode, reprints);

@@ -124,12 +125,12 @@ return false;

function findArrayReprints(a, b, reprints) {
assert.ok(a instanceof Array);
var len = a.length;
function findArrayReprints(path, newNode, oldNode, reprints) {
assert.ok(newNode instanceof Array);
var len = newNode.length;
if (!(b instanceof Array &&
b.length === len))
if (!(oldNode instanceof Array &&
oldNode.length === len))
return false;
for (var i = 0; i < len; ++i)
if (!findAnyReprints(a[i], b[i], reprints))
if (!findAnyReprints(path, newNode[i], oldNode[i], reprints))
return false;

@@ -140,13 +141,13 @@

function findObjectReprints(a, b, reprints) {
assert.strictEqual(typeof a, "object");
if (!a || !b || typeof b !== "object")
function findObjectReprints(path, newNode, oldNode, reprints) {
assert.strictEqual(typeof newNode, "object");
if (!newNode || !oldNode || typeof oldNode !== "object")
return false;
var childReprints = [];
var canReprintChildren = findChildReprints(a, b, childReprints);
var canReprintChildren = findChildReprints(path, newNode, oldNode, childReprints);
if (a.type in Syntax) {
// TODO Decompose this check: if (!printTheSame(a, b))
if (a.type !== b.type)
if (newNode.type in Syntax) {
// TODO Decompose this check: if (!printTheSame(newNode, oldNode))
if (newNode.type !== oldNode.type)
return false;

@@ -156,4 +157,4 @@

reprints.push({
oldNode: a,
newNode: b
newNode: newNode,
oldNode: oldNode
});

@@ -169,11 +170,11 @@

function findChildReprints(a, b, reprints) {
assert.strictEqual(typeof a, "object");
assert.strictEqual(typeof b, "object");
function findChildReprints(path, newNode, oldNode, reprints) {
assert.strictEqual(typeof newNode, "object");
assert.strictEqual(typeof oldNode, "object");
for (var k in getUnionOfKeys(a, b)) {
for (var k in util.getUnionOfKeys(newNode, oldNode)) {
if (k === "loc")
continue;
if (!findAnyReprints(a[k], b[k], reprints))
if (!findAnyReprints(path, newNode[k], oldNode[k], reprints))
return false;

@@ -184,17 +185,1 @@ }

}
function getUnionOfKeys(obj) {
for (var i = 0, key,
result = {},
objs = arguments,
argc = objs.length;
i < argc;
i += 1)
{
obj = objs[i];
for (key in obj)
if (obj.hasOwnProperty(key))
result[key] = true;
}
return result;
}

2

lib/printer.js

@@ -87,3 +87,3 @@ var assert = require("assert"),

case Syntax.ExpressionStatement:
return print(n.expression);
return concat([print(n.expression), ";"]);

@@ -90,0 +90,0 @@ case Syntax.BinaryExpression:

@@ -15,3 +15,3 @@ {

],
"version": "0.3.4",
"version": "0.3.5",
"homepage": "http://github.com/benjamn/recast",

@@ -18,0 +18,0 @@ "repository": {

@@ -1,2 +0,2 @@

# recast, _v_.
# recast, _v_. [![Build Status](https://travis-ci.org/benjamn/recast.png?branch=master)](https://travis-ci.org/benjamn/recast)
1. to give (a metal object) a different form by melting it down and reshaping it.

@@ -3,0 +3,0 @@ 1. to form, fashion, or arrange again.

@@ -1,7 +0,8 @@

var assert = require("assert"),
fs = require("fs"),
path = require("path");
var assert = require("assert");
var fs = require("fs");
var path = require("path");
var util = require("../lib/util");
function identity(ast, callback) {
assert.deepEqual(ast.original, ast);
assert.ok(util.deepEquivalent(ast.original, ast));
callback(ast);

@@ -15,3 +16,3 @@ }

require("recast").runString(source, identity, {
require("../main").runString(source, identity, {
writeback: function(code) {

@@ -18,0 +19,0 @@ assert.strictEqual(source, code);

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