Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

traverse text now passes thanks to an ExpressionStatement fix using {…

…} blocks since non-bracketed statements were firing without their conditionals
  • Loading branch information...
commit 2b6512fd9eb7c078ff32e4cc14aa445bc60f6f5b 1 parent 444b437
@substack authored
Showing with 8 additions and 11 deletions.
  1. +5 −3 index.js
  2. +2 −1  test/sources/traverse.js
  3. +1 −7 test/traverse.js
View
8 index.js
@@ -78,8 +78,8 @@ Fritter.prototype.defineContext = function () {
};
context[names.callProperty] = function (ix, obj, name) {
+ var fn = obj[name];
return context[names.call](ix, function () {
- var fn = obj[name];
if (fn === undefined) {
throw new TypeError(
String(obj) + ' has no method \'' + name + '\''
@@ -91,7 +91,7 @@ Fritter.prototype.defineContext = function () {
+ String(obj) + ' is not a function'
);
}
- return obj[name].apply(obj, arguments);
+ return fn.apply(obj, arguments);
});
};
@@ -220,8 +220,10 @@ Fritter.prototype.include = function (src, opts) {
}
else if (node.type === 'ExpressionStatement') {
node.update(
- names.expr + '(' + nodes.length + ');'
+ '{'
+ + names.expr + '(' + nodes.length + ');'
+ node.source()
+ + '}'
);
pushNode(node);
}
View
3  test/sources/traverse.js
@@ -1,5 +1,4 @@
var xs = [];
-console.log(traverse.forEach);
traverse.forEach({ a : 1, b : 2, c : [ 3, 4 ]}, function (node) {
if (this.isLeaf) xs.push(node);
});
@@ -8,3 +7,5 @@ t.same(xs, [ 1, 2, 3, 4 ]);
traverse.forEach({ a : 1, b : 2, c : [ 3, 4 ]}, function (node) {
if (this.isRoot) throw 'beep';
});
+
+t.fail("shouldn't get this far");
View
8 test/traverse.js
@@ -8,7 +8,7 @@ var src = fs.readFileSync(require.resolve('traverse'), 'utf8')
;
test('fff', function (t) {
- t.plan(4);
+ t.plan(3);
var fry = fritter({
t : { same : t.same.bind(t) },
@@ -19,18 +19,12 @@ test('fff', function (t) {
fry.on('error', function (err, c) {
t.equal(err, 'beep');
- t.deepEqual(
- c.stack.map(function (s) { return fry.nameOf(s) }),
- []
- );
});
try {
-//console.log(fry.source);
vm.runInNewContext(fry.source, fry.context);
}
catch (err) {
-console.log(err.stack);
t.equal(err, 'beep');
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.