Skip to content

Commit

Permalink
feat(alita-core wx-react): 添加直接渲染Fragment的警告提示
Browse files Browse the repository at this point in the history
affects: @areslabs/alita-core, @areslabs/wx-react
  • Loading branch information
ykforerlang committed Apr 30, 2020
1 parent 96c7b92 commit e4596c7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/alita-core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
touchableOpacityOrigin,
touchableHighlightOrigin,
errorViewOrigin,
reactFragmentFlag
} from '@shared/constants'


Expand Down
5 changes: 4 additions & 1 deletion packages/alita-core/src/tran/fragmentHadnler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import * as t from '@babel/types'
import errorLogTraverse from '../util/ErrorLogTraverse'
import {isReactFragment} from '../util/uast'
import {reactFragmentFlag} from '../constants'

/**
* 处理 <> xxx </> 和 <React.Fragment> xxx </React.Fragment>
Expand Down Expand Up @@ -42,7 +43,9 @@ function replaceElement(path) {
let newEle = t.jsxElement(
t.jsxOpeningElement(
t.jsxIdentifier('block'),
[]
[
t.jsxAttribute(t.jsxIdentifier(reactFragmentFlag), t.jsxExpressionContainer(t.booleanLiteral(true)))
]
),
t.jsxClosingElement(
t.jsxIdentifier('block')
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ export const outerTextOrigin = "4"
export const errorViewOrigin = "5"
export const touchableWithoutFeedbackOrigin = "6"
export const touchableOpacityOrigin = "7"
export const touchableHighlightOrigin = "8"
export const touchableHighlightOrigin = "8"


export const reactFragmentFlag = "_FF"
13 changes: 7 additions & 6 deletions packages/wx-react/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
originElementAttrName,
touchableWithoutFeedbackOrigin,
touchableOpacityOrigin,
touchableHighlightOrigin
touchableHighlightOrigin,
reactFragmentFlag
} from '../../shared/constants'

export function renderNextValidComps(inst) {
Expand Down Expand Up @@ -106,11 +107,6 @@ export function renderNextValidComps(inst) {
export default function render(vnode, parentInst, parentContext, data, oldData, dataPath) {

try {
if (Array.isArray(vnode)) {
console.warn('小程序暂不支持渲染数组!')
return
}

if (typeof vnode === 'string'
|| typeof vnode === 'number'
|| typeof vnode === 'boolean'
Expand All @@ -121,6 +117,11 @@ export default function render(vnode, parentInst, parentContext, data, oldData,
return
}

if (Array.isArray(vnode) || (vnode.props && vnode.props[reactFragmentFlag])) {
console.warn('组件暂不支持直接render数组/Fragment!')
return
}

const {ref, nodeName, tempName} = vnode

if (typeof ref === "string") {
Expand Down

0 comments on commit e4596c7

Please sign in to comment.