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

customTransformers 执行报错 #96

Open
l5oo00 opened this issue Nov 26, 2019 · 1 comment
Open

customTransformers 执行报错 #96

l5oo00 opened this issue Nov 26, 2019 · 1 comment

Comments

@l5oo00
Copy link
Contributor

l5oo00 commented Nov 26, 2019

发现自定义的 customTransformers 执行会报错, 貌似是 ts2php 内置的 transformer 会破坏原 ast 的结构, 导致自定义的 transformer 里遍历 ast 会报错, 用的是 ts.visitEachChild 来遍历。

猜测是这里的处理有问题:

function visitVariableDeclarationList(node: ts.VariableDeclarationList) {

报错时正在处理这一行源码: const {name, data, outputData} = originalParams;

报错的 node 如下:
image

报错的调用是: node.getChildCount()

错误堆栈:

internal/process/warning.js:18 (node:56266) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'text' of undefined
    at createChildren (/Project/node_modules/typescript/lib/typescript.js:120256:65)
    at NodeObject.getChildren (/Project/node_modules/typescript/lib/typescript.js:120219:56)
    at NodeObject.getChildCount (/Project/node_modules/typescript/lib/typescript.js:120212:25)
    at SanIdTransformer.visitor (/Project/ts2phprc.js:105:27) // 在这里调用的 node.getChildCount()
@meixg
Copy link
Member

meixg commented Dec 9, 2019

可以发下要转换的代码,以及 transformer 的代码不

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