Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完善 San 的编译提示信息 #463

Closed
PengXing opened this issue Dec 19, 2019 · 3 comments
Closed

完善 San 的编译提示信息 #463

PengXing opened this issue Dec 19, 2019 · 3 comments

Comments

@PengXing
Copy link

ref: baidu/san-ssr#32

目前接受输入为 ts 文件 / js 文件,但错误时输出不包括文件名。例如:

[SAN WARNING] Component template must have a root element.

期望类似:

Error while compiling '/home/hartt.../component.ts': [SAN WARNING] Component template must have a root element.
@PengXing
Copy link
Author

思考了一下,起初是想打印出哪个文件没有 root element,但是 San 还要用在浏览器端,不一定有文件信息,因此有两种解决办法:

  • 打印标签名、类名 this.subTag || this.name || clazz.name,一定程度能帮助排查错误
  • 只在需要的时候将 warn 信息收集起来,并返回,如 createComponent(clazz),返回值是错误、警告信息和实例,编译脚本决定打印完整错误信息

1. 打印标签名、类名

可行,成本最低,灵活性不是很好,依赖于 San 的修改,并且 San 项目中不止一处,但不是每个地方都能获取到类名。

2. 通过 createComponent 创建实例

San 目前的实现方式是有 warn 直接 console.warn,如果需要改成第二种方式,改动比较大,但一劳永逸

短期还是第一种方式先优化一下。

@errorrik
Copy link
Contributor

提pr?

@errorrik errorrik reopened this Dec 20, 2019
@PengXing
Copy link
Author

采用 defineComponent 定义的 San 组件,类名都是 ComponentClass,这个问题不太好解。

暂时 close 吧,想到好的解决方案再来看这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants