Skip to content

customTransformers 执行报错 #96

@l5oo00

Description

@l5oo00

发现自定义的 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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions