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

是否可以把 class 上所有的静态方法和属性都延迟赋值? #94

Closed
l5oo00 opened this issue Nov 26, 2019 · 2 comments
Closed
Labels

Comments

@l5oo00
Copy link
Contributor

l5oo00 commented Nov 26, 2019

php 中初始化类时它的属性值只能是常量(文档说明), 而我们写 ts 经常会有如下代码:

const a = 'x';
class Demo {
    static x = a // a 是变量, 转换成 PHP 后会挂掉
}

之前的做法是将 static 属性延迟初始化, 想着 ts2php 是不是默认可以做这个事情,即将所有 static 的属性延迟初始化。

@meixg meixg closed this as completed in 8c791c5 Dec 6, 2019
@meixg
Copy link
Member

meixg commented Dec 6, 2019

初始化值不为数字或字符串时,都会编译为延迟赋值。
其他字面量不好判断,内部可能包含变量,需要遍历,例如 [a]。

cxtom pushed a commit that referenced this issue Dec 6, 2019
## [0.19.5](v0.19.4...v0.19.5) (2019-12-06)

### Bug Fixes

* [#94](#94) ([8c791c5](8c791c5))
@cxtom
Copy link
Collaborator

cxtom commented Dec 6, 2019

🎉 This issue has been resolved in version 0.19.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cxtom cxtom added the released label Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants