dsherret / dsherret/ts-morph

how to change parameters of a decorator

Open
#917 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

Similar to my question about adding params to a super, I need some help on modifying the parameters of a class decorator.

I want to add some extra entries to the "x" property of the decorators first property

```
@AclPath({
x: ['foo','bar],
})
class Test {}
```

in my "parsing" code I have this

```
console.log(
classDef.getDecorator('AclPath').getArguments()[0].getText()
);
```

which gives me the text of the argument. I've tried looking at the ast viewer

![image](https://user-images.githubusercontent.com/929523/103458653-1e62d900-4d02-11eb-906a-e2627780360a.png)

looking at this, I thought that "symbol" would be the way to go ... however - if I use `getSymbol()` on `classDef.getDecorator('AclPath').getArguments()[0]` I get undefined

Is there any way of getting the arguments of `imports` and directly manipulating that ? at the moment, I'm messing about with
string manipulation which just feels dirty ;)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.