commonmark / commonmark/commonmark.js

Would be nice if there was an iterable interface to the NodeWalker

Open
#130 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
231
Avg merge
2d 11h
Merged PRs (30d)
3

Description

Right now the NodeWalker instance returned by .walker() is not an actual javascript iterable.

Would be great to be able to do:

const walker = ast.walker()
for(event of walker) {
 // stuff here
}

But right now that doesn't work.

It should be pretty simple to add, the following works when I already have a walker instance so just adding that before it is returned will work...

		walker[Symbol.iterator] = function() {
			return {
				next() {
					const data = walker.next();
					if (data) {
						return {
							value: data
						};
					}
					return {done: true};
				}
			};
		};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the NodeWalker implementation returned by .walker() and inspect its existing next() behavior. Add iterable support so for...of yields the same walker events and ends when traversal is complete; verify the behavior with the project’s existing tests, though no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.