Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial implementation of deno_ast #1

Merged
merged 9 commits into from Sep 6, 2021
Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Sep 2, 2021

This is a very rough initial implementation. There is not much documentation and barely any tests (just the bare minimum to get going).

After we've agreed on the implementation I'll spend some time adding tests and do the CI.

Downstream PRs:

I will integrate this later into dprint-plugin-typescript.

typescript = ["swc_ecmascript/typescript"]
view = ["dprint-swc-ecma-ast-view"]
visit = ["swc_ecmascript/visit"]
utils = ["swc_ecmascript/utils"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These features will allow us to only use what we need in each crate.

@@ -0,0 +1,123 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is from the CLI.

pub use swc_ecmascript::utils;
#[cfg(feature = "visit")]
pub use swc_ecmascript::visit;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These re-exports makes things a lot nicer because then we only have to depend on deno_ast and not a bunch of swc crates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on a call with David, I'm in favor of this approach as well, it's good to contain SWC to a single crate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.


pub fn parse_program_with_post_process(
params: ParseParams,
post_process: impl FnOnce(Program) -> Program,
Copy link
Member Author

@dsherret dsherret Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to maybe add a comment here with that example from deno_lint?

Copy link
Member Author

@dsherret dsherret Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add documentation comments everywhere in the second pass once everything looks ok and is integrated (so I don't waste my time documenting stuff that will change). Right now the crate is super bare, but yes I'll do that then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my previous comments then! 😉

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'm in favor of this crate

Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good and a great idea.

src/lexing.rs Show resolved Hide resolved
pub use swc_ecmascript::utils;
#[cfg(feature = "visit")]
pub use swc_ecmascript::visit;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

pub inner: TokenOrComment,
}

pub fn lex(source: &str, media_type: MediaType) -> Vec<LexedItem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some sort of doc comment for public functions should be there

tokens
}

fn flatten_comments(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, a docblock


pub fn parse_program_with_post_process(
params: ParseParams,
post_process: impl FnOnce(Program) -> Program,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my previous comments then! 😉

src/text_info.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (noting that doc will be added)

@dsherret
Copy link
Member Author

dsherret commented Sep 5, 2021

@kitsonk yup, I’m going to move ahead with integration in the other repos with this API then open another PR in this repo for docs, CI, and other housekeeping.

Edit: Opened #2

@dsherret dsherret merged commit a2f7e8c into main Sep 6, 2021
@dsherret dsherret deleted the initial-implementation branch September 6, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants