mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-09-20 12:54:44 +08:00
refactor: use proper type guards
This commit is contained in:
parent
cb21ed9f39
commit
6e91245a56
@ -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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user