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

Parse imported variables #163

Open
privatenumber opened this issue Nov 10, 2023 · 1 comment
Open

Parse imported variables #163

privatenumber opened this issue Nov 10, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@privatenumber
Copy link

privatenumber commented Nov 10, 2023

I believe this is a duplicate of #100. It was resolved by providing information on exported variables, but the actual request was for imports.

In my use-case, I'd like to be able to extract the variables (a & c) from a statement like this:

import/*
long comment
*/{
		a,
		b as c
}from/*
long comment
*/'file'

Additionally, I'd like to know the ranges for where the import names start and end: { a, b as c}

@guybedford
Copy link
Owner

I'm open to adding this feature, if we can try to keep the footprint overhead down.

@guybedford guybedford added the enhancement New feature or request label Nov 12, 2023
Boshen added a commit to oxc-project/oxc that referenced this issue Mar 9, 2024
# Oxc Module Lexer

This is not a lexer. The name "lexer" is used for easier recognition.

## [es-module-lexer](https://github.com/guybedford/es-module-lexer)

Outputs the list of exports and locations of import specifiers,
including dynamic import and import meta handling.

Does not have any
[limitations](https://github.com/guybedford/es-module-lexer?tab=readme-ov-file#limitations)
mentioned in `es-module-lexer`.

I'll also work on the following cases to make this feature complete.

- [ ] get imported variables
guybedford/es-module-lexer#163
- [ ] track star exports as imports as well
guybedford/es-module-lexer#76
- [ ] TypeScript specific syntax
- [ ] TypeScript `type` import / export keyword

## [cjs-module-lexer](https://github.com/nodejs/cjs-module-lexer)

- [ ] TODO

## Benchmark

This is 2 times slower than `es-module-lexer`, but will be significantly
faster when TypeScript is processed.

The difference is around 10ms vs 20ms on a large file (700k).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants