let propsOption = undefined let emitsOption = undefined let exposeOption = undefined let slotsOption = undefined // 遍历属性,查找有无props、emits、expose和slots if (ctx.optionsRuntimeDecl.type === 'ObjectExpression') { for (const prop of ctx.optionsRuntimeDecl.properties) { if ( (prop.type === 'ObjectProperty' || prop.type === 'ObjectMethod') && prop.key.type === 'Identifier' ) { if (prop.key.name === 'props') propsOption = prop if (prop.key.name === 'emits') emitsOption = prop if (prop.key.name === 'expose') exposeOption = prop if (prop.key.name === 'slots') slotsOption = prop } } }
// 如果有则报错 if (propsOption) { ctx.error( `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`, propsOption ) } if (emitsOption) { ctx.error( `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`, emitsOption ) } if (exposeOption) { ctx.error( `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`, exposeOption ) } if (slotsOption) { ctx.error( `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`, slotsOption ) }