Open
Description
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:
- Type guards (e.g.
isClassDeclaration
) - Traversal functions (various
find
-like functions mostly) - Assertion functions (e.g.
exportHasCustomElementExport
) - Getters (e.g.
getAllExportsOfKind
)
Type guards
isJavaScriptModule
isJavaScriptExport
isCustomElementExport
isDeclaration
isCustomElementDeclaration
isClassDeclaration
isFunctionDeclaration
isMixinDeclaration
isVariableDeclaration
isCustomElement
isCustomElementDeclaration
isCustomElementMixinDeclaration
Traversal functions
findParent(manifests, node, assertion)
- Finds the first parent of the specified node which matches the assertion function
find(manifests, node, assertion)
- Finds the first child which matches the assertion function
findAll(manifests, node, assertion)
- Finds all children matching the assertion function
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
- Filters the exports by a particular
kind
- Filters the exports by a particular
getAllDeclarationsOfKind
- Filters the declarations by a particular
kind
- Filters the declarations by a particular
getInheritanceTree
- Gets the inheritance hierarchy of a given class name, as an array of
class names
- Gets the inheritance hierarchy of a given class name, as an array of
getModuleFromManifests
- Finds a particular module by
path
in a set of manifests
- Finds a particular module by
getModuleForClassLike
- Finds a particular module's path which contains a class or mixin with the
specified name
- Finds a particular module's path which contains a class or mixin with the
getClassMemberDoc
- Finds a class by name within a given module, then finds a member by name
within that class.
- Finds a class by name within a given module, then finds a member by name
CE language server
findClassForTagName
- Finds the class from a set of manifests which has the specified tag name
associated with it
- Finds the class from a set of manifests which has the specified tag name
findCustomElementDeclarationFromModule
- Finds the first custom element class declared in a given module
findDeclarationForTagName
- Finds the custom element declaration from a set of manifests which
has the specified tag name associated with it
- Finds the custom element declaration from a set of manifests which
findCustomElementTagLike
- Finds a registered tag which contains the specified string
getCustomElementTags
- Finds all the registered tags from a set of manifests
findCustomElementDefinitionModule
- Finds the module from a set of manifests which registered a given tag name
findTagNameForClass
- Finds the tag name associated with the specified class name from a set of
manifests
- Finds the tag name associated with the specified class name from a set of
moduleHasCustomElementExport
- Determines if a module exports a custom element
exportHasCustomElementExport
- Determines if an export is a custom element export
moduleHasCustomElementExportByName
- Determines if a module exports the specified tag name
exportHascustomElementExportByName
- Determines if an export is a custom element definition with a particular
name
- Determines if an export is a custom element definition with a particular
findModuleByPath
- Finds a module from a set of manifests which has the specified
path
- Finds a module from a set of manifests which has the specified
modulePathEquals
- Determines if a module's path matches a given path
isCustomElementDeclaration
- Determines if a declaration is a custom element declaration
webcomponents.org
getCustomElements
- Finds all custom elements exported by a given package, returning their
export and declaration amongst other things
- Finds all custom elements exported by a given package, returning their
getModule
- Finds the module in a given package which has a path matching the one
specified
- Finds the module in a given package which has a path matching the one
isClassDeclaration
- Determines if a declaration is a class declaration
isFunctionDeclaration
- Determines if a declaration is a function declaration
isMixinDeclaration
- Determines if a declaration is a mixin declaration
isVariableDeclaration
- Determines if a declaration is a variable declaration
isCustomElement
- Determines if a declaration is a custom element declaration or a
custom element mixin declaration
- Determines if a declaration is a custom element declaration or a
isCustomElementDeclaration
- Determines if a declaration is a custom element declaration
isCustomElementMixinDeclaration
- Determines if a declaration is a custom element mixin declaration
resolveReference
- Resolves a
Reference
to an actualModule
from a set of manifests
- Resolves a
Open questions
Type guards
- do we want to do what typescript did here and basically provide an
is*
function for every possibly type? e.g. we'd also haveisClassMethod
,isAttribute
, etc etc.
Traversals
- do we want these functions to consume
(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 something - of course everything can be simplified to
find
/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 much
Metadata
Metadata
Assignees
Labels
No labels