searchfe / searchfe/ts2php

customTransformers 执行报错

Open
#96 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
98
Forks
20
Avg merge
5m
Merged PRs (30d)
3

Description

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

猜测是这里的处理有问题:
https://github.com/searchfe/ts2php/blob/f511257b223c2366881acdc0577f5f37791f89fd/src/transformer.ts#L215

报错时正在处理这一行源码: 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()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/transformer.ts around line 215 and reproduce the failure while transforming const {name, data, outputData} = originalParams;. Compare the AST before and after the built-in transformer, then inspect the custom transformer’s ts.visitEachChild traversal and the node.getChildCount() stack location. Done means customTransformers can traverse the resulting AST without the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.