refactor: use proper type guards

This commit is contained in:
Kael 2021-09-05 23:03:00 +10:00
parent cb21ed9f39
commit 6e91245a56

View File

@ -288,16 +288,16 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
propsExpression = t.objectExpression(dedupeProperties(properties, mergeProps)); propsExpression = t.objectExpression(dedupeProperties(properties, mergeProps));
if (optimize) { if (optimize) {
if (hasClassBinding) { if (hasClassBinding) {
const klass = (propsExpression.properties as t.ObjectProperty[]) const klass = propsExpression.properties
.find((prop) => 'value' in prop.key && prop.key.value === 'class'); .find((prop) => t.isObjectProperty(prop) && t.isStringLiteral(prop.key) && prop.key.value === 'class');
if (klass?.type === 'ObjectProperty') { if (t.isObjectProperty(klass)) {
klass.value = t.callExpression(createIdentifier(state, 'normalizeClass'), [klass.value as any]); klass.value = t.callExpression(createIdentifier(state, 'normalizeClass'), [klass.value as any]);
} }
} }
if (hasStyleBinding) { if (hasStyleBinding) {
const style = (propsExpression.properties as t.ObjectProperty[]) const style = propsExpression.properties
.find((prop) => 'value' in prop.key && prop.key.value === 'style'); .find((prop) => t.isObjectProperty(prop) && t.isStringLiteral(prop.key) && prop.key.value === 'style');
if (style?.type === 'ObjectProperty') { if (t.isObjectProperty(style)) {
style.value = t.callExpression(createIdentifier(state, 'normalizeStyle'), [style.value as any]); style.value = t.callExpression(createIdentifier(state, 'normalizeStyle'), [style.value as any]);
} }
} }