Skip to content

Commit 4b323ce

Browse files
author
Christopher J Baker
committed
core: check for transform before using
1 parent e02de10 commit 4b323ce

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/core/src/core.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ export default function r2wc<Props, Context>(
9494
const attribute = mapPropAttribute[prop]
9595
const value = this.getAttribute(attribute)
9696
const type = propTypes[prop]
97+
const transform = transforms[type]
9798

98-
if (value) {
99+
if (value && transform?.parse) {
99100
//@ts-ignore
100-
this[propsSymbol][prop] = transforms[type].parse(value, this)
101+
this[propsSymbol][prop] = transform.parse(value, this)
101102
}
102103
}
103104
}
@@ -122,10 +123,11 @@ export default function r2wc<Props, Context>(
122123
) {
123124
const prop = mapAttributeProp[attribute]
124125
const type = propTypes[prop]
126+
const transform = transforms[type]
125127

126-
if (prop in propTypes) {
128+
if (prop in propTypes && transform?.parse) {
127129
//@ts-ignore
128-
this[propsSymbol][prop] = transforms[type].parse(value, this)
130+
this[propsSymbol][prop] = transform.parse(value, this)
129131

130132
this[renderSymbol]()
131133
}
@@ -159,10 +161,10 @@ export default function r2wc<Props, Context>(
159161
set(value) {
160162
this[propsSymbol][prop] = value
161163

162-
const stringify = transforms[type].stringify
163-
if (stringify) {
164+
const transform = transforms[type]
165+
if (transform?.stringify) {
164166
//@ts-ignore
165-
const attributeValue = stringify(value)
167+
const attributeValue = transform.stringify(value)
166168
const oldAttributeValue = this.getAttribute(attribute)
167169

168170
if (oldAttributeValue !== attributeValue) {

0 commit comments

Comments
 (0)