Skip to content

Comments

feat(ast): add and auto-generate WithBindingIdentifier trait#5362

Closed
DonIsaac wants to merge 2 commits intomainfrom
don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait
Closed

feat(ast): add and auto-generate WithBindingIdentifier trait#5362
DonIsaac wants to merge 2 commits intomainfrom
don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait

Conversation

@DonIsaac
Copy link
Contributor

@DonIsaac DonIsaac commented Aug 31, 2024

What This PR Does

  1. adds a WithBindingIdentifier trait for accessing BindingIdentifiers on relevant AST nodes in a standard way.
  2. adds a generator to ast_tools that auto-implements this trait for most AST nodes.
  3. Minor cleanup and docs for ast_tools that I did as I figured out how things worked.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 31, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Contributor Author

DonIsaac commented Aug 31, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @DonIsaac and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added A-ast Area - AST A-ast-tools Area - AST tools labels Aug 31, 2024
@DonIsaac DonIsaac changed the title rename GetBindingIdentifier to WithBindingIdentifier feat(ast): add and auto-generate WithBindingIdentifier trait Aug 31, 2024
@DonIsaac DonIsaac added the C-enhancement Category - New feature or request label Aug 31, 2024 — with Graphite App
@DonIsaac DonIsaac marked this pull request as ready for review August 31, 2024 03:38
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 31, 2024

CodSpeed Performance Report

Merging #5362 will not alter performance

Comparing don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait (cda09d4) with main (180b1a1)

Summary

✅ 28 untouched benchmarks

@Boshen Boshen changed the base branch from don/08-30-feat_ast_add_function_name_ to graphite-base/5362 August 31, 2024 03:45
@Boshen
Copy link
Member

Boshen commented Aug 31, 2024

adds a WithBindingIdentifier trait for accessing BindingIdentifiers on relevant AST nodes in a standard way.

Isn't this

/// [`BoundName`](https://tc39.es/ecma262/#sec-static-semantics-boundnames)
pub trait BoundName<'a> {
fn bound_name<F: FnMut(&BindingIdentifier<'a>)>(&self, f: &mut F);
}
pub trait BoundNames<'a> {
fn bound_names<F: FnMut(&BindingIdentifier<'a>)>(&self, f: &mut F);
}

@Boshen Boshen force-pushed the don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait branch from 0ac603c to 1bc6271 Compare August 31, 2024 03:49
@Boshen Boshen force-pushed the graphite-base/5362 branch from 2e4dd6b to 180b1a1 Compare August 31, 2024 03:49
@Boshen Boshen changed the base branch from graphite-base/5362 to main August 31, 2024 03:50
@Boshen Boshen force-pushed the don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait branch from 1bc6271 to 95f5189 Compare August 31, 2024 03:50
@DonIsaac DonIsaac force-pushed the don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait branch from 95f5189 to cda09d4 Compare August 31, 2024 04:03
@DonIsaac
Copy link
Contributor Author

DonIsaac commented Aug 31, 2024

adds a WithBindingIdentifier trait for accessing BindingIdentifiers on relevant AST nodes in a standard way.

Isn't this

/// [`BoundName`](https://tc39.es/ecma262/#sec-static-semantics-boundnames)
pub trait BoundName<'a> {
fn bound_name<F: FnMut(&BindingIdentifier<'a>)>(&self, f: &mut F);
}
pub trait BoundNames<'a> {
fn bound_names<F: FnMut(&BindingIdentifier<'a>)>(&self, f: &mut F);
}

Just about... sigh...

I'm noticing that BoundNames isn't used at all in the linter, but decl.id.as_ref().and_then(|id| get_span_or_name_or_symbol_id(id)) is, maybe its an ergonomics thing? Especially if you want to get it as an option, you'll need to do this:

let mut id: Option<&BindingIdentifier<'a>> = None;
node.bound_names(|found| {
  debug_assert!(id.is_none());
  *id = Some(found)
}

@DonIsaac DonIsaac closed this Aug 31, 2024
@Boshen Boshen deleted the don/08-30-feat_ast_ast_tools_add_getbindingidentifier_trait branch September 11, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants