已关闭
[Bug修复] 修复Decorator转换后的AST节点源码位置信息丢失问题 #9651
ElevenDuan创建于  3月26日关闭于  3月31日
ElevenDuan
ElevenDuan成员
3月26日 创建

问题描述

在处理TypeScript装饰器(Decorator)转换时,生成的AST节点缺少正确的源码位置信息(source location/range),这会导致:

  1. 调试困难,无法准确定位问题代码的原始位置
  2. Source map生成不准确
  3. 错误提示信息无法指向正确的源码位置

修复内容

本次修改主要在 es2panda/parser/transformer/transformer.cpp 和 transformer.h 中,为所有decorator相关的AST节点添加了正确的源码范围设置:

主要修改点:

  1. 函数签名更新 - 为以下函数增加 originalNode 参数:

    • CreateReferenceIdentifier() - 添加 ir::AstNode *originalNode 参数
    • CreateDecoratorTarget() - 添加 const ir::AstNode *originalNode 参数
    • CreateClassPrototype() - 添加 const ir::AstNode *originalNode 参数
    • CreateGetOwnPropertyDescriptorCall() - 添加 const ir::AstNode *originalNode 参数
    • CreateDefinePropertyCall() - 添加 const ir::AstNode *originalNode 参数
  2. 添加源码范围设置:

    • 在创建变量声明(VariableDeclaration)时,使用 SetRangeRecursively() 设置范围
    • 在创建表达式语句(ExpressionStatement)时,设置正确的源码范围
    • 在创建调用表达式(CallExpression)时,传递原始节点信息
  3. 具体修改位置:

    • VisitClassDeclaration() - 为类装饰器的变量声明和赋值表达式设置范围
    • CreateVariableDeclarationForDecorators() - 为方法装饰器和参数装饰器的变量声明设置范围
    • CreateParamDecorators() - 为参数装饰器调用设置范围
    • CreatePropertyDecorators() - 为属性装饰器调用设置范围
    • CreateMethodDecorators() - 为方法装饰器调用设置范围
    • CreateClassDecorators() - 为类装饰器调用设置范围

影响范围

  • 涉及文件:
    • es2panda/parser/transformer/transformer.h
    • es2panda/parser/transformer/transformer.cpp
  • 影响功能:TypeScript装饰器转换(Decorator Transformation)
  • 兼容性:向后兼容,不影响现有功能

测试

修改后的测试用例预期输出已更新:

  • test-class-decorator-1-transformed-expected.txt
  • test-class-decorator-2-transformed-expected.txt
  • test-decorator-1-transformed-expected.txt

关联信息

  • 修改分支:基于 gitcode/master
  • 修改类型:Bug修复
likedislike
openharmony_ci
openharmony_ci成员
3月26日 评论:

感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 [@xucheng46](https://gitcode.com/xucheng46) [@gavin1012_hw](https://gitcode.com/gavin1012_hw) [@trubachevilya](https://gitcode.com/trubachevilya) [@vpukhov](https://gitcode.com/vpukhov) [@chernykhsergey](https://gitcode.com/chernykhsergey) [@zhuoli](https://gitcode.com/zhuoli) 。如果需要调整订阅PR、Issue的变更状态,请访问链接。


Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer gitcode for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
3月26日 添加了label:waiting_for_assign
ElevenDuanElevenDuan成员
3月26日 关联了pull request:Fix decorator AST node source location
ElevenDuanElevenDuan成员
3月26日 修改了issue 的描述
ElevenDuanElevenDuan成员
3月26日 修改了issue 的描述
openharmony_ciopenharmony_ci成员
3月31日 关闭了 issue
openharmony_ciopenharmony_ci成员
3月31日 issue状态由 待办的 改变为 已完成
ElevenDuanElevenDuan成员
5月27日 issue类型由 任务 改变为 缺陷