Skip to content

Commit

Permalink
fix(mini-runner): 加入 preval 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent 60e522a commit 5b771ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/taro-mini-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"babel-generator": "^6.26.1",
"babel-loader": "^8.0.6",
"babel-plugin-danger-remove-unused-import": "^1.1.2",
"babel-plugin-preval": "1.6.4",
"babel-plugin-transform-define": "^1.3.1",
"babel-traverse": "^6.26.0",
"babel-types": "^6.26.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/taro-mini-runner/src/utils/parseAst.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config as IConfig } from '@tarojs/taro'
import * as t from 'babel-types'
import traverse from 'babel-traverse'
import { transformFromAst } from 'babel-core'

import { BUILD_TYPES, taroJsComponents, QUICKAPP_SPECIAL_COMPONENTS } from './constants'
import { traverseObjectNode, isNpmPkg } from '../utils'
Expand All @@ -19,7 +20,13 @@ export default function parseAst (
const taroSelfComponents = new Set<string>()
const isQuickApp = buildAdapter === BUILD_TYPES.QUICKAPP

traverse(ast, {
const newAst = transformFromAst(ast, '', {
plugins: [
[require('babel-plugin-preval')]
]
}).ast as t.File

traverse(newAst, {
ClassDeclaration (astPath) {
const node = astPath.node
let hasCreateData = false
Expand Down

0 comments on commit 5b771ff

Please sign in to comment.