-
Notifications
You must be signed in to change notification settings - Fork 1
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
[RFC/discussion] tools API design #2
Comments
Thanks @43081j ! I think a first and high-level question we need to answer is what kind of package organization we want. I can think of a few broad categories:
The first three categories may differer in scope/purpose, but should be environment agnostic. They could be three packages, or a single one. The lines could blur a bit: resolving references across manifests might require a loader. The validator could cleanly be a separate package, though it's not strictly necessary. The next three would differ in dependencies and environments: a local loader might have Node-specific API requirements. What I put up in #1 and #3 are separate environment-agnostic utilities package and a validator package, taken from the webcomponents.org work, but these could be re-arranged as we like...
|
i'd be tempted to do it the same way babel did babel has so in our case we'd have:
i guess my original post here is really the first two of those |
I agree that this approach could work the best. A clear split between the packages for different use cases. Wether the loader should be 2 packages or one, I don't know yet. Having an API like typescript where you can create your own IO layer could work but at the same time, we could just write those 2 implementations ourselves since they will differ quite a lot |
I'm not sure what we really gain from separating traverse* from type guards. I don't see a downside to keeping them in on e package, but there is a downside to making too many packages - and of need future utilities that don't fit cleanly into traverse or types, requiring another one.
With the goal of separate loader packages being to divide the be environment requirements and dependencies, I think we need a spot for just the loader interface. That could go in its own package, or the general tools package.
This is the idea with the loader interface. Something like the WC catalog needs to load manifests from an online registry, a VS Code plugin needs to load it from disk. |
you're right i think, so we should have a package that contains all the traversal/getters/assertions/etc. which i guess is the tools package you created in the other PR. the interface of that package is what im trying to define in the original post |
i feel like the validator package should stay separate, just to keep it focused. though maybe "tools" might end up too generic? bit of a grey area as that package could easily end up bloated with random utils if we're not careful |
I'd like an object oriented API that I could deliver to 11ty etempaltes: <template webc:nokeep
webc:for="declaration of
cemPackageNameMap
.get(package)
.getDeclarationsForModule(module)">
<cem-class webc:if="declaration.kind === 'class'" :@declaration="declaration"></cem-class>
<cem-mixin webc:if="declaration.kind === 'mixin'" :@declaration="declaration"></cem-mixin>
<cem-function webc:if="declaration.kind === 'function'" :@declaration="declaration"></cem-function>
<cem-variable webc:if="declaration.kind === 'variable'" :@declaration="declaration"></cem-variable>
</template> |
Copying most of this from my notes.
Motivation
We should provide the core functionality already duplicated across the various
CEM projects in the wild.
Proposed design
It seems we need a few areas of utilities:
isClassDeclaration
)find
-like functions mostly)exportHasCustomElementExport
)getAllExportsOfKind
)Type guards
isJavaScriptModule
isJavaScriptExport
isCustomElementExport
isDeclaration
isCustomElementDeclaration
isClassDeclaration
isFunctionDeclaration
isMixinDeclaration
isVariableDeclaration
isCustomElement
isCustomElementDeclaration
isCustomElementMixinDeclaration
Traversal functions
findParent(manifests, node, assertion)
find(manifests, node, assertion)
findAll(manifests, node, assertion)
TBD
These traversal functions would be paired often with the type guards and assertion functions.
For example,
find(package, null, (n) => isJavaScriptExport(n))
.Assertion functions
TBD
Getters
TBD
Prior art
CEM analyzer
getAllExportsOfKind
kind
getAllDeclarationsOfKind
kind
getInheritanceTree
class names
getModuleFromManifests
path
in a set of manifestsgetModuleForClassLike
specified name
getClassMemberDoc
within that class.
CE language server
findClassForTagName
associated with it
findCustomElementDeclarationFromModule
findDeclarationForTagName
has the specified tag name associated with it
findCustomElementTagLike
getCustomElementTags
findCustomElementDefinitionModule
findTagNameForClass
manifests
moduleHasCustomElementExport
exportHasCustomElementExport
moduleHasCustomElementExportByName
exportHascustomElementExportByName
name
findModuleByPath
path
modulePathEquals
isCustomElementDeclaration
webcomponents.org
getCustomElements
export and declaration amongst other things
getModule
specified
isClassDeclaration
isFunctionDeclaration
isMixinDeclaration
isVariableDeclaration
isCustomElement
custom element mixin declaration
isCustomElementDeclaration
isCustomElementMixinDeclaration
resolveReference
Reference
to an actualModule
from a set of manifestsOpen questions
Type guards
is*
function for every possibly type? e.g. we'd also haveisClassMethod
,isAttribute
, etc etc.Traversals
(manifest, nodeOrCallback, callback)
? im not such a fan or these messy overloads. but(manifest, node|null, callback)
isn't much better. as in, you could traverse a manifest for something, or you could traverse a node within a manifest for somethingfind
/findAll
, but do we also want to provide some higher level helpers? likefindExports
,findDeclarations
,findElement
, etc etc. we probably do otherwise this package won't reduce boilerplate/duplication muchcc @justinfagnani @Matsuuu @rictic
The text was updated successfully, but these errors were encountered: