提交 411997cb 编写于 作者: fxy060608's avatar fxy060608

chore(mp): improve error messages

上级 d299f87a
const path = require('path')
const t = require('@babel/types')
const babelTraverse = require('@babel/traverse').default
const { parseComponents } = require('./util')
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const {
parseComponents
} = require('./util')
const uniI18n = require('@dcloudio/uni-cli-i18n')
module.exports = function (ast, state = {}) {
const imports = []
let nodePath = false
try {
babelTraverse(ast, {
CallExpression (path) {
const callee = path.node.callee
......@@ -50,6 +56,12 @@ module.exports = function (ast, state = {}) {
} else {
state.components = []
}
} catch (e) {
if (state.filename) {
console.error('at ' + normalizePath(path.relative(process.env.UNI_INPUT_DIR, state.filename)) + ':1')
}
throw e
}
return {
ast,
state
......
const path = require('path')
const t = require('@babel/types')
const babelTraverse = require('@babel/traverse').default
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const {
parseComponents
} = require('./util')
......@@ -107,6 +110,7 @@ module.exports = function (ast, state = {
components: [],
options: {}
}) {
try {
babelTraverse(ast, {
CallExpression (path) {
const callee = path.node.callee
......@@ -167,7 +171,8 @@ module.exports = function (ast, state = {
}
} else if (t.isClassDeclaration(declaration) &&
declaration.decorators &&
declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue
declaration.decorators.length
) { // export default @Component({components:{}}) class MyComponent extend Vue
const componentDecorator = declaration.decorators[0]
if (t.isCallExpression(componentDecorator.expression)) {
const args = componentDecorator.expression.arguments
......@@ -178,6 +183,12 @@ module.exports = function (ast, state = {
}
}
})
} catch (e) {
if (state.filename) {
console.error('at ' + normalizePath(path.relative(process.env.UNI_INPUT_DIR, state.filename)) + ':1')
}
throw e
}
return {
ast,
state
......
......@@ -92,12 +92,15 @@ createPage(Page)
components
}
} = traverse(parser.parse(content, getBabelParserOptions()), {
filename: this.resourcePath,
components: []
})
const babelLoader = findBabelLoader(this.loaders)
if (!babelLoader) {
throw new Error(uniI18n.__('mpLoader.findFail', { 0: 'babel-loader' }))
throw new Error(uniI18n.__('mpLoader.findFail', {
0: 'babel-loader'
}))
} else {
addCreateApp(babelLoader)
}
......
......@@ -83,7 +83,8 @@ module.exports = function (content, map) {
}
} = traverse(parser.parse(content, getBabelParserOptions()), {
type,
components: []
components: [],
filename: this.resourcePath
})
const callback = this.async()
......@@ -126,7 +127,9 @@ module.exports = function (content, map) {
const babelLoader = findBabelLoader(this.loaders)
if (!babelLoader) {
callback(new Error(uniI18n.__('mpLoader.findFail', { 0: 'babel-loader' })), content)
callback(new Error(uniI18n.__('mpLoader.findFail', {
0: 'babel-loader'
})), content)
} else {
addDynamicImport(babelLoader, resourcePath, dynamicImports)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册