Support define API (PR #3181)

This commit is contained in:
the1812 2022-04-09 13:32:50 +08:00
parent 76cf6ff76e
commit 04a6b1da6c
2 changed files with 9 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import * as component from './component'
import * as userComponent from './user-component'
import * as styledComponent from './styled-component'
import * as define from './define'
import * as description from './description'
import * as feedsApis from './feeds/api'
import BangumiCard from './feeds/BangumiCard.vue'
@ -32,6 +33,7 @@ export const componentApis = {
component,
userComponent,
styledComponent,
define,
description,
switchOptions,
launchBar: {

View File

@ -5,7 +5,7 @@ module.exports = function (babel) {
const { types } = babel
return {
visitor: {
ExportNamedDeclaration(path, state) {
ExportNamedDeclaration (path, state) {
const { filename } = state.file.opts
const isFromRegistry = filename.startsWith(nodePath.resolve('./registry'))
const isEntryFile = nodePath.basename(filename) === 'index.ts'
@ -17,11 +17,14 @@ module.exports = function (babel) {
if (!['component', 'plugin'].includes(d.id?.name)) {
return
}
if (d.init.type !== 'ObjectExpression') {
const targetExpression = d.init.type === 'CallExpression' ? d.init.arguments[0] : d.init
if (targetExpression.type !== 'ObjectExpression') {
return
}
d.init.properties.push(types.objectProperty(types.identifier('commitHash'), types.stringLiteral(compilationInfo.commitHash)))
d.init.properties.push(types.objectProperty(types.identifier('coreVersion'), types.stringLiteral(compilationInfo.version)))
targetExpression.properties.push(...[
types.objectProperty(types.identifier('commitHash'), types.stringLiteral(compilationInfo.commitHash)),
types.objectProperty(types.identifier('coreVersion'), types.stringLiteral(compilationInfo.version)),
])
})
}
}