From ccd885938a350b0dd29857ae517f690423a8b438 Mon Sep 17 00:00:00 2001 From: Jonathan Neal Date: Thu, 17 May 2018 00:38:34 -0400 Subject: [PATCH] Fix walk proxies --- lib/container.js | 4 ++-- test/api.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/container.js b/lib/container.js index af79d66..e3701a7 100644 --- a/lib/container.js +++ b/lib/container.js @@ -61,10 +61,10 @@ class Container extends Node { } // allow users to pass a constructor, or node type string; eg. Word. - type = type.name && type.prototype ? type.name : type; + const isTypeCallable = typeof type === 'function'; return this.walk((node, index) => { - if (node.type === type) { + if (isTypeCallable && node instanceof type || !isTypeCallable && node.type === type) { return callback.call(this, node, index); } }); diff --git a/test/api.js b/test/api.js index 3b062f1..bf7e256 100644 --- a/test/api.js +++ b/test/api.js @@ -71,7 +71,7 @@ describe('Parser → API', () => { it('should walk a type constructor', () => { let source = '/*1*/ 5px /* 2 */', ast = new Parser(source).parse(), - expected = ['1', '2'], + expected = ['1', ' 2 '], index = 0; expect(ast.first.walkComments).to.exist;