Skip to content

Commit a5d7342

Browse files
authored
Merge pull request #5 from stenciljs/johnjenkins-patch-1
fix: serializer and deserializer decorators
2 parents 7948505 + 8fe0453 commit a5d7342

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ export enum CMP_FLAGS {
119119
* to have its styles scoped during SSR as opposed to using DSD.
120120
*/
121121
shadowNeedsScopedCss = 1 << 7,
122+
123+
/**
124+
* Determines if a component has a render function.
125+
*/
126+
hasRenderFn = 1 << 8,
127+
128+
/**
129+
* Determines if a component uses modern class property declarations.
130+
*/
131+
hasModernPropertyDecls = 1 << 9,
122132
}
123133

124134
/**

src/utils.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,30 @@ export const formatComponentRuntimeMeta = (
3535
if (compilerMeta.encapsulation !== 'shadow' && compilerMeta.htmlTagNames.includes('slot')) {
3636
flags |= CMP_FLAGS.hasSlotRelocation;
3737
}
38+
if (compilerMeta.hasRenderFn) {
39+
flags |= CMP_FLAGS.hasRenderFn;
40+
}
3841
if (compilerMeta.hasMode) {
3942
flags |= CMP_FLAGS.hasMode;
4043
}
44+
if (compilerMeta.hasModernPropertyDecls) {
45+
flags |= CMP_FLAGS.hasModernPropertyDecls;
46+
}
4147

4248
const members = formatComponentRuntimeMembers(compilerMeta, includeMethods);
4349
const hostListeners = formatHostListeners(compilerMeta);
44-
const watchers = formatComponentRuntimeWatchers(compilerMeta);
50+
const watchers = formatComponentRuntimeReactiveHandlers(compilerMeta);
51+
const serializers = formatComponentRuntimeReactiveHandlers(compilerMeta, 'serializers');
52+
const deserializers = formatComponentRuntimeReactiveHandlers(compilerMeta, 'deserializers');
53+
4554
return trimFalsy([
4655
flags,
4756
compilerMeta.tagName,
4857
Object.keys(members).length > 0 ? members : undefined,
4958
hostListeners.length > 0 ? hostListeners : undefined,
5059
Object.keys(watchers).length > 0 ? watchers : undefined,
60+
Object.keys(serializers).length > 0 ? serializers : undefined,
61+
Object.keys(deserializers).length > 0 ? deserializers : undefined,
5162
]);
5263
};
5364

@@ -63,21 +74,25 @@ export const stringifyRuntimeData = (data: any) => {
6374

6475
/**
6576
* Transforms Stencil compiler metadata into a {@link d.ComponentCompilerMeta} object.
66-
* This handles processing any compiler metadata transformed from components' uses of `@Watch()`.
67-
* The map of watched attributes to their callback(s) will be immediately available
77+
* This handles processing any compiler metadata transformed from components' uses of `@Watch()`, `@PropSerialize()`, and `@AttrDeserialize()`.
78+
* The map of watched properties to their callback(s) will be immediately available
6879
* to the runtime at bootstrap.
6980
*
7081
* @param compilerMeta Component metadata gathered during compilation
71-
* @returns An object mapping watched attributes to their respective callback(s)
82+
* @param decorator The decorator type to be processed: 'watchers', 'serializers', or 'deserializers'
83+
* @returns An object mapping watched properties to their respective callback(s)
7284
*/
73-
const formatComponentRuntimeWatchers = (compilerMeta: d.ComponentCompilerMeta) => {
74-
const watchers: d.ComponentConstructorWatchers = {};
85+
const formatComponentRuntimeReactiveHandlers = (
86+
compilerMeta: d.ComponentCompilerMeta,
87+
decorator: 'watchers' | 'serializers' | 'deserializers',
88+
) => {
89+
const handlers: d.ComponentConstructorChangeHandlers = {};
7590

76-
compilerMeta.watchers.forEach(({ propName, methodName }) => {
77-
watchers[propName] = [...(watchers[propName] ?? []), methodName];
91+
compilerMeta[decorator]?.forEach(({ propName, methodName }) => {
92+
handlers[propName] = [...(handlers[propName] ?? []), methodName];
7893
});
7994

80-
return watchers;
95+
return handlers;
8196
};
8297

8398
const formatComponentRuntimeMembers = (

0 commit comments

Comments
 (0)