Skip to content

Commit

Permalink
chore: yagni i guess
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhsf committed Dec 20, 2024
1 parent c6da63a commit 3fcc1ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 43 deletions.
43 changes: 3 additions & 40 deletions packages/@lwc/engine-dom/src/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,7 @@

// Like @lwc/shared, but for DOM APIs

const ElementDescriptors = Object.getOwnPropertyDescriptors(Element.prototype);
/** Binds `fn.call` to `fn` so you don't need `.call`. */
const uncall = <Args extends unknown[], Ret>(
fn: (this: Element, ...args: Args) => Ret
): ((element: Element, ...args: Args) => Ret) => {
return (element, ...args) => fn.apply(element, args);
};
export const ElementDescriptors = Object.getOwnPropertyDescriptors(Element.prototype);

export const ElementAttachShadow = uncall(ElementDescriptors.attachShadow.value!);
export const ElementChildren = uncall(ElementDescriptors.children.get!);
export const ElementClassList = uncall(ElementDescriptors.classList.get!);
export const ElementFirstElementChild = uncall(ElementDescriptors.firstElementChild.get!);
export const ElementGetAttribute = uncall(ElementDescriptors.getAttribute.value!);
export const ElementGetAttributeNS = uncall(ElementDescriptors.getAttributeNS.value!);
export const ElementGetBoundingClientRect = uncall(ElementDescriptors.getBoundingClientRect.value!);
export const ElementGetElementsByClassName = uncall(
ElementDescriptors.getElementsByClassName.value!
);
export const ElementGetElementsByTagName = uncall(ElementDescriptors.getElementsByTagName.value!);
export const ElementHasAttribute = uncall(ElementDescriptors.hasAttribute.value!);
export const ElementHasAttributeNS = uncall(ElementDescriptors.hasAttributeNS.value!);
export const ElementId = uncall(ElementDescriptors.id.get!);
export const ElementLastElementChild = uncall(ElementDescriptors.lastElementChild.get!);
export const ElementQuerySelector = uncall(ElementDescriptors.querySelector.value!);
export const ElementQuerySelectorAll = uncall(ElementDescriptors.querySelectorAll.value!);
export const ElementRemoveAttribute = uncall(ElementDescriptors.removeAttribute.value!);
export const ElementRemoveAttributeNS = uncall(ElementDescriptors.removeAttributeNS.value!);
export const ElementSetAttribute = uncall(ElementDescriptors.setAttribute.value!);
export const ElementSetAttributeNS = uncall(ElementDescriptors.setAttributeNS.value!);
export const ElementShadowRoot = uncall(ElementDescriptors.shadowRoot.get!);
export const ElementTagName = uncall(ElementDescriptors.tagName.get!);

// Present in `HTMLElementTheGoodParts`, but from a superclass of `Element`
// addEventListener
// childNodes
// dispatchEvent
// firstChild
// isConnected
// lastChild
// ownerDocument
// removeEventListener
export const ElementAttachShadow = ElementDescriptors.attachShadow.value!;
export const ElementShadowRootGetter = ElementDescriptors.shadowRoot.get!;
6 changes: 3 additions & 3 deletions packages/@lwc/engine-dom/src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { assert, isNull, isUndefined } from '@lwc/shared';
import { ElementAttachShadow, ElementShadowRoot } from '../language';
import { ElementAttachShadow, ElementShadowRootGetter } from '../language';

function cloneNode(node: Node, deep: boolean): Node {
return node.cloneNode(deep);
Expand Down Expand Up @@ -59,11 +59,11 @@ function attachShadow(element: Element, options: ShadowRootInit): ShadowRoot {
// 2. when a webapp author places <c-app> in their static HTML and mounts their
// root component with customElement.define('c-app', Ctor)
// see W-17441501
const shadowRoot = ElementShadowRoot(element);
const shadowRoot = ElementShadowRootGetter.call(element);
if (!isNull(shadowRoot)) {
return shadowRoot;
}
return ElementAttachShadow(element, options);
return ElementAttachShadow.call(element, options);
}

function setText(node: Node, content: string): void {
Expand Down

0 comments on commit 3fcc1ab

Please sign in to comment.