Socket
Socket
Sign inDemoInstall

ast-types

Package Overview
Dependencies
11
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.13 to 0.2.14

16

lib/types.js

@@ -521,2 +521,18 @@ var assert = require("assert");

// Iterate over all defined fields of an object, including those missing
// or undefined, passing each field name and effective value (as returned
// by getFieldValue) to the callback. If the object has no corresponding
// Def, the callback will never be called.
Object.defineProperty(exports, "eachField", {
value: function(object, callback, context) {
var d = Def.fromValue(object);
if (d) {
var all = d.allFields;
Object.keys(all).forEach(function(name) {
callback.call(this, name, all[name].getValue(object));
}, context);
}
}
});
// This property will be overridden as true by individual Def instances

@@ -523,0 +539,0 @@ // when they are finalized.

1

main.js

@@ -19,2 +19,3 @@ var types = require("./lib/types");

exports.getFieldValue = types.getFieldValue;
exports.eachField = types.eachField;
exports.finalize = types.finalize;

2

package.json

@@ -21,3 +21,3 @@ {

],
"version": "0.2.13",
"version": "0.2.14",
"homepage": "http://github.com/benjamn/ast-types",

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

@@ -209,1 +209,38 @@ var types = require("../main");

};
exports.testEachField = function(t, assert) {
var context = {};
function check(node, names) {
var seen = [];
types.eachField(node, function(name, value) {
assert.strictEqual(this, context);
if (name === "type")
assert.strictEqual(node.type, value);
seen.push(name);
}, context);
assert.deepEqual(seen.sort(), names.sort());
}
check({ type: "Expression" }, [
"type", "loc"
]);
check({ type: "SourceLocation" }, [
"type", "start", "end", "source"
]);
check({ type: "TryStatement" }, [
"type", "block", "handlers", "guardedHandlers", "finalizer", "loc"
]);
check({ type: "CatchClause" }, [
"type", "param", "guard", "body", "loc"
]);
check({ type: "asdf" }, []);
t.finish();
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc