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

Feature: Destructured imports in variable declarations, Refactor parser with Babel type guards #101

Conversation

MajorLift
Copy link

@MajorLift MajorLift commented Nov 30, 2021

Love this project, and having a ton of fun going through the code!

1) Features

  • Newly supports object destructuring with alias assignment in variable declaration imports
    • e.g. const { foo1: bar1, foo2 } = import("module");
  • Also adds support for array destructuring in variable declaration imports
    • e.g. const [foo, bar] = import("module");
  • This needs more work:
    Adds support for subset of "export * from 'module'" syntax (Components exported with "export * from ..." are shown in error in the drawer #99), where an index.js,ts file containing such export statements can be used to import the parent folder as a module (a.k.a "barrel" files or batch exports) (Fixes Issue 85).

2) SaplingParser

  • Extensive rewrites in .getImports(), .findVarDecImports() methods.
  • Explicit checks with strong typing for all possible variations in import statements.
  • Passes all previously written tests.
  • Readability, modularity, extensibility improvements.
  • WIP: Glob imports with namespace specifiers (import * as namespace from "module")

3) ComponentTree, TreeItem

  • These class object implementations are tentative proposals.
  • Referenced vscode-treeview's TreeDataProvider/TreeItem design pattern and API.
  • Seems advisable to decouple tree state data/methods from parsing logic (MVC: Model - data objects, Controller - parser, View - webview).
  • The parser could be made into a static class with only .parse() exposed as public without any loss in functionality.
  • TreeItems only contain reference ids to self, children, ancestors, while nodes themselves are kept in a normalized data store in ComponentTree. Therefore currently a breaking change. Vscode messaging and webview would need to be updated as well.
  • WIP: Should make implementing expandAll/collapseAll more straightforward and performant.

4) Linter config revamp

  • Stronger typing and stricter checks.
  • Promotes best practices.

Water for the tree :)

labaird and others added 30 commits October 1, 2021 18:42
Github Actions CI/CD added to repo for PRs onto dev and master
Dev branch into master with initial version of website
Merge Dev into Master, remove parser_setup folder from repo
Refractor A Few Files For Readability And Improved TypeScript
- relaxed some superfluous style rules
- set eslint scope to include webviews/
- Record<string, unknown> is default recommended by @typescript-eslint/ban-types.
- Using Array<T> when T is composite data type, and T[] when T is primitive is useful visual cue.
* test 14: Folders as modules / batch exports / barrel files
- export * from './File'
import { File } from './dir'

* test 15:
- Variable declaration with..
a) object destructuring alias assignment
b) array destructuring
- Import Decaration with...
* glob import and namespace specifier

* See: Issue oslabs-beta#85, oslabs-beta#99
- Extensive rewrites in getImports(), findVarDecImports() methods
- Explicit checks with strong typing for all possible variations in import statements
- Passes all previously written tests
- Readability, modularity, extensibility improvements
- passes test 14
- glob exports in general not yet supported

Fixes: Issue oslabs-beta#85
See: Issue oslabs-beta#99
- files that are imported by multiple parents show up as duplicates in tree
- may be useful to keep track of these, while leaving nonce id as an access key for all instances
- These class object implementations are tentative propsals
- May be advisable to decouple tree state data/logic from parsing functionality
- Parser can be converted to static class with no loss in utility
- passes test 14
- glob exports in general not yet supported

Fixes: Issue oslabs-beta#85
See: Issue oslabs-beta#99
- Extensive rewrites in getImports(), findVarDecImports() methods
- Explicit checks with strong typing for all possible variations in import statements
- Passes all previously written tests
- Readability, modularity, extensibility improvements
@MajorLift MajorLift changed the base branch from master to dev November 30, 2021 18:51
@MajorLift MajorLift changed the title Add folder module import support (Fixes #85), Refactor parser with Babel type guards Feature: folder module import support (Fixes #85), Feature: Destructured imports in variable declarations, Refactor parser with Babel type guards Dec 1, 2021
- Also, barrel file feature needs more work
- Design decision on how to display glob imports required. Currently shows imported module in tree as single node.
@MajorLift MajorLift changed the title Feature: folder module import support (Fixes #85), Feature: Destructured imports in variable declarations, Refactor parser with Babel type guards Feature: Destructured imports in variable declarations, Refactor parser with Babel type guards Dec 1, 2021
@MajorLift MajorLift closed this Dec 1, 2021
@MajorLift MajorLift reopened this Dec 1, 2021
@MajorLift MajorLift closed this Dec 1, 2021
@MajorLift
Copy link
Author

Closing and creating new PR to keep Issue 85 open.

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.

Not able to traverse more than 1 level of hierarchy
6 participants