Skip to content

Commit

Permalink
refactor(compiler): remove unused ATTACH_SHADOW API
Browse files Browse the repository at this point in the history
this commit removes the RUNTIME_APIS.ATTACH_SHADOW field that is no
longer used in the codebase. it's only usage was in tests for adding
runtime apis, and has been replaced with another field from
`RUNTIME_APIS`
  • Loading branch information
rwaskiewicz committed Jul 13, 2023
1 parent aa9d8e1 commit 7868b46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/compiler/transformers/core-runtime-apis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type * as d from '../../declarations';

export const ATTACH_SHADOW = '__stencil_attachShadow';
export const CREATE_EVENT = '__stencil_createEvent';
export const DEFINE_CUSTOM_ELEMENT = '__stencil_defineCustomElement';
export const GET_ELEMENT = '__stencil_getElement';
Expand All @@ -12,7 +11,6 @@ export const REGISTER_HOST = '__stencil_registerHost';
export const H = '__stencil_h';

export const RUNTIME_APIS = {
attachShadow: `attachShadow as ${ATTACH_SHADOW}`,
createEvent: `createEvent as ${CREATE_EVENT}`,
defineCustomElement: `defineCustomElement as ${DEFINE_CUSTOM_ELEMENT}`,
getElement: `getElement as ${GET_ELEMENT}`,
Expand Down
28 changes: 14 additions & 14 deletions src/compiler/transformers/test/core-runtime-apis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ describe('addCoreRuntimeApi()', () => {
expect(mockModule.coreRuntimeApis).toBeDefined();
expect(mockModule.coreRuntimeApis).toHaveLength(0);

addCoreRuntimeApi(mockModule, RUNTIME_APIS.attachShadow);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.attachShadow]);
addCoreRuntimeApi(mockModule, RUNTIME_APIS.Host);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.Host]);

addCoreRuntimeApi(mockModule, RUNTIME_APIS.createEvent);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.attachShadow, RUNTIME_APIS.createEvent]);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.Host, RUNTIME_APIS.createEvent]);
});

it("does not allow duplicate entries in a module's coreRuntimeApis", () => {
expect(mockModule.coreRuntimeApis).toBeDefined();
expect(mockModule.coreRuntimeApis).toHaveLength(0);

addCoreRuntimeApi(mockModule, RUNTIME_APIS.attachShadow);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.attachShadow]);
addCoreRuntimeApi(mockModule, RUNTIME_APIS.Host);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.Host]);

// attempt to add the api again, doing so shall not create a duplicate entry
addCoreRuntimeApi(mockModule, RUNTIME_APIS.attachShadow);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.attachShadow]);
addCoreRuntimeApi(mockModule, RUNTIME_APIS.Host);
expect(mockModule.coreRuntimeApis).toEqual([RUNTIME_APIS.Host]);
});
});

Expand All @@ -57,25 +57,25 @@ describe('addOutputTargetCoreRuntimeApi()', () => {
expect(mockModule.outputTargetCoreRuntimeApis).toBeDefined();
expect(Object.entries(mockModule.outputTargetCoreRuntimeApis)).toHaveLength(0);

addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.attachShadow);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({ [DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.attachShadow] });
addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.Host);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({ [DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.Host] });

addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.createEvent);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({
[DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.attachShadow, RUNTIME_APIS.createEvent],
[DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.Host, RUNTIME_APIS.createEvent],
});
});

it("does not allow duplicate entries in a module's outputTargetCoreRuntimeApis", () => {
expect(mockModule.outputTargetCoreRuntimeApis).toBeDefined();
expect(Object.entries(mockModule.outputTargetCoreRuntimeApis)).toHaveLength(0);

addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.attachShadow);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({ [DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.attachShadow] });
addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.Host);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({ [DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.Host] });

// attempt to add the api again, doing so shall not create a duplicate entry
addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.attachShadow);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({ [DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.attachShadow] });
addOutputTargetCoreRuntimeApi(mockModule, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.Host);
expect(mockModule.outputTargetCoreRuntimeApis).toEqual({ [DIST_CUSTOM_ELEMENTS]: [RUNTIME_APIS.Host] });
});
});

Expand Down

0 comments on commit 7868b46

Please sign in to comment.