benjamn / benjamn/ast-types

Implement a flexible pattern-matching syntax

Open
#14 1 comment 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
1.2k
Forks
194
Avg merge
22h 43m
Merged PRs (30d)
10

Description

Just as we currently have `.namedTypes.MemberExpression` and `.builders.memberExpression`, perhaps we could also have an auto-generated `.patterns` namespace containing functions like `.patterns.MemberExpression` for building arbitrary pattern-matching types, e.g.

``` js
var types = require("ast-types");
var p = types.patterns;

var thisFooPattern = p.MemberExpression(
p.ThisExpression(),
p.Identifier("foo")
);

types.traverse(ast, function(node) {
if (thisFooPattern.check(node)) {
console.log("found this.foo:", node);
}
});
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start from the ast-types public API exposed through require("ast-types") and examine how namedTypes and builders are generated. Define the scope of the patterns namespace and its check behavior from the MemberExpression example, then add coverage showing that nested patterns match the intended AST nodes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.