How to create an "Expression" with babylon?

520 views Asked by At

I need to add an objectProperty, but it requires key and value:

t.objectProperty(key, value, ...)

And the value must be an "Expression". I assumed that it must be object expression:

t.objectExpression(properties)

Where "properties" must be an array of ObjectMethod || ObjectProperty || SpreadProperty.

But I wanted to create an ObjectProperty in the first place! So what is an "Expression" and how can I create it in order to create an ObjectProperty?

1

There are 1 answers

0
Alex Tumanov On

Thanks to Bergi, I found an answer. An example where an object's property value is a string:

t.objectExpression([
  t.objectProperty(
  t.identifier('key'),
  t.stringLiteral('value'),
)]);