简体   繁体   中英

How to create an “Expression” with babylon?

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?

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'),
)]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM