substack/html-select — pull request #3 by parshap (2014-06-02 22:34:23+00:00)
Title: Add failing test case for selecting nested nodes

```
/home/parshap/projects/html-select/node_modules/tape/index.js:75
throw err
^
Error: write after end
at writeAfterEnd (/home/parshap/projects/html-select/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:156:12)
at Transform.Writable.write (/home/parshap/projects/html-select/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:203:5)
at Select._writeFirst (/home/parshap/projects/html-select/lib/select.js:97:16)
at Select._exec (/home/parshap/projects/html-select/lib/select.js:72:18)
at /home/parshap/projects/html-select/index.js:154:40
at Plex._pull (/home/parshap/projects/html-select/index.js:121:9)
at Plex._advance (/home/parshap/projects/html-select/index.js:142:10)
at Select.pull [as _pull] (/home/parshap/projects/html-select/index.js:69:35)
at Readable.r._read (/home/parshap/projects/html-select/lib/select.js:107:33)
at Readable.read (/home/parshap/projects/html-select/node_modules/readable-stream/lib/_stream_readable.js:342:10)
```

Using multiple `s.select` calls on nested nodes causes a write to an ended stream. This seems to happen when you select a parent node (e.g., "ul") and then also select its children (e.g., "li"). When matching the second child, `lib/select.js` writes to the `this.input` stream, which has already ended.

I came up with a way to prevent this error from happening, but it doesn't seem like a great fix. See parshap/node-html-select@590dce9755aca5d822d665a002e4d6ca9eaa81a1. There is probably a better place to call `this.reset()` than inspecting the stream's `_writableState.ended` state.