【发布时间】:2020-04-14 17:18:20
【问题描述】:
typescript 编译器 API 对我来说是新的,看起来我错过了一些东西。 我正在寻找使用编译器 API 更新 ts 文件中特定对象的方法
现有文件 - some-constant.ts
export const someConstant = {
name: 'Jhon',
lastName: 'Doe',
additionalData: {
age: 44,
height: 145,
someProp: 'OLD_Value'
/**
* Some comments that describes what's going on here
*/
}
};
毕竟,我想得到这样的东西:
export const someConstant = {
name: 'Jhon',
lastName: 'Doe',
additionalData: {
age: 999,
height: 3333,
someProp: 'NEW_Value'
eyeColor: 'brown',
email: 'someemail@gmail.com',
otherProp: 'with some value'
}
};
【问题讨论】:
-
这是您想在编译时发射时做的事情,还是您想直接对源文件进行此更改?如果是后者,那么您可能需要查看ts-morph。
-
我需要直接在源文件上制作。我尝试了 ts-morph,也没有成功:(
标签: javascript typescript compiler-construction typescript-compiler-api