Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
我本凡人 一念云泥
uni-app
提交
35963d01
uni-app
项目概览
我本凡人 一念云泥
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
35963d01
编写于
1月 06, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(cli): log
上级
704b6827
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
79 addition
and
12 deletion
+79
-12
packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js
packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js
+49
-0
packages/vue-cli-plugin-hbuilderx/__tests__/demo.js
packages/vue-cli-plugin-hbuilderx/__tests__/demo.js
+14
-0
packages/vue-cli-plugin-hbuilderx/packages/babel-plugin-console/dist/index.js
...gin-hbuilderx/packages/babel-plugin-console/dist/index.js
+8
-7
packages/vue-cli-plugin-uni/lib/format-log.js
packages/vue-cli-plugin-uni/lib/format-log.js
+8
-5
未找到文件。
packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js
0 → 100644
浏览文件 @
35963d01
const
path
=
require
(
'
path
'
)
const
{
transformSync
}
=
require
(
'
@babel/core
'
)
const
options
=
{
filename
:
'
/index.vue
'
,
configFile
:
false
,
minified
:
true
,
plugins
:
[
path
.
resolve
(
__dirname
,
'
../packages/babel-plugin-console/dist/index.js
'
)]
}
describe
(
'
console
'
,
()
=>
{
it
(
'
log
'
,
()
=>
{
expect
(
transformSync
(
`console.log('123')`
,
options
).
code
)
.
toBe
(
`__f__("log","123"," at /index.vue:1");`
)
expect
(
transformSync
(
`console.log('123',a,{a:1,b:2})`
,
options
).
code
)
.
toBe
(
`__f__("log","123",a,{a:1,b:2}," at /index.vue:1");`
)
})
it
(
'
debug
'
,
()
=>
{
expect
(
transformSync
(
`console.log('123')`
,
options
).
code
)
.
toBe
(
`__f__("log","123"," at /index.vue:1");`
)
expect
(
transformSync
(
`console.log('123',a,{a:1,b:2})`
,
options
).
code
)
.
toBe
(
`__f__("log","123",a,{a:1,b:2}," at /index.vue:1");`
)
})
it
(
'
info
'
,
()
=>
{
expect
(
transformSync
(
`console.info('123')`
,
options
).
code
)
.
toBe
(
`__f__("info","123"," at /index.vue:1");`
)
expect
(
transformSync
(
`console.info('123',a,{a:1,b:2})`
,
options
).
code
)
.
toBe
(
`__f__("info","123",a,{a:1,b:2}," at /index.vue:1");`
)
})
it
(
'
warn
'
,
()
=>
{
expect
(
transformSync
(
`console.warn('123')`
,
options
).
code
)
.
toBe
(
`__f__("warn","123"," at /index.vue:1");`
)
expect
(
transformSync
(
`console.warn('123',a,{a:1,b:2})`
,
options
).
code
)
.
toBe
(
`__f__("warn","123",a,{a:1,b:2}," at /index.vue:1");`
)
})
it
(
'
error
'
,
()
=>
{
expect
(
transformSync
(
`console.error('123')`
,
options
).
code
)
.
toBe
(
`__f__("error","123"," at /index.vue:1");`
)
expect
(
transformSync
(
`console.error('123',a,{a:1,b:2})`
,
options
).
code
)
.
toBe
(
`__f__("error","123",a,{a:1,b:2}," at /index.vue:1");`
)
})
})
packages/vue-cli-plugin-hbuilderx/__tests__/demo.js
0 → 100644
浏览文件 @
35963d01
const
path
=
require
(
'
path
'
)
const
{
transform
}
=
require
(
'
@babel/core
'
)
transform
(
`console.log('123')`
,
{
filename
:
'
/index.vue
'
,
configFile
:
false
,
minified
:
true
,
plugins
:
[
path
.
resolve
(
__dirname
,
'
../packages/babel-plugin-console/dist/index.js
'
)]
},
function
(
err
,
result
)
{
console
.
log
(
err
,
result
)
})
packages/vue-cli-plugin-hbuilderx/packages/babel-plugin-console/dist/index.js
浏览文件 @
35963d01
...
...
@@ -7,7 +7,6 @@ module.exports = function({
return
{
visitor
:
{
CallExpression
(
path
,
state
)
{
const
opts
=
state
.
opts
if
(
path
.
node
.
callee
.
object
&&
...
...
@@ -36,12 +35,14 @@ module.exports = function({
type
:
'
StringLiteral
'
,
value
:
` at
${
file
}
:
${
path
.
node
.
loc
.
start
.
line
}
`
})
path
.
node
.
arguments
=
[
t
.
callExpression
(
t
.
identifier
(
FORMAT_LOG
),
args
)
]
args
.
unshift
(
t
.
stringLiteral
(
path
.
node
.
callee
.
property
.
name
))
path
.
replaceWith
(
t
.
callExpression
(
t
.
identifier
(
FORMAT_LOG
),
args
))
// path.node.arguments = [
// t.callExpression(
// t.identifier(FORMAT_LOG),
// args
// )
// ]
}
}
}
...
...
packages/vue-cli-plugin-uni/lib/format-log.js
浏览文件 @
35963d01
...
...
@@ -4,15 +4,18 @@ function typof (v) {
}
function
isDebugMode
()
{
return
typeof
name
===
'
string
'
&&
name
===
'
uni-app
'
/* eslint-disable no-undef */
return
typeof
__channelId__
===
'
string
'
&&
__channelId__
}
export
default
function
formatLog
()
{
for
(
var
_len
=
arguments
.
length
,
args
=
new
Array
(
_len
),
_key
=
0
;
_key
<
_len
;
_key
++
)
{
args
[
_key
]
=
arguments
[
_key
]
}
const
type
=
args
.
shift
()
if
(
isDebugMode
())
{
return
args
args
.
push
(
args
.
pop
().
replace
(
'
at
'
,
'
uni-app:///
'
))
return
console
[
type
][
'
apply
'
](
console
,
args
)
}
var
msgs
=
args
.
map
(
function
(
v
)
{
...
...
@@ -57,5 +60,5 @@ export default function formatLog () {
msg
=
msgs
[
0
]
}
return
msg
console
[
type
](
msg
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录