Slide 36
Slide 36 text
ts-morphの活用
AST操作
// key1の中身を取り出す
const key1 = argAsObj.getProperty('key1')?.asKind(SyntaxKind.PropertyAssignment);
if (!key1) continue;
const key1Value = key1.getInitializerOrThrow().getText();
// 引数の置き換え
callExpression.removeArgument(arg0);
callExpression.insertArgument(0, key1Value);
call({
key1: {
key2: 'value',
key3: {
key4: 'value',
},
},
})
call({
key2: 'value',
key3: {
key4: 'value',
},
})