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;