|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
988 bytes
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Extractor function for a BindExpression type value node.
|
|---|
| 3 | * A bind expression looks like `::this.foo`
|
|---|
| 4 | * This will return `this.foo.bind(this)` as the value to indicate its existence,
|
|---|
| 5 | * since we can not execute the function this.foo.bind(this) in a static environment.
|
|---|
| 6 | *
|
|---|
| 7 | * @param - value - AST Value object with type `BindExpression`
|
|---|
| 8 | * @returns - The extracted value converted to correct type.
|
|---|
| 9 | */
|
|---|
| 10 | export default function extractValueFromBindExpression(value) {
|
|---|
| 11 | // eslint-disable-next-line global-require
|
|---|
| 12 | const getValue = require('.').default;
|
|---|
| 13 | const callee = getValue(value.callee);
|
|---|
| 14 |
|
|---|
| 15 | // If value.object === null, the callee must be a MemberExpression.
|
|---|
| 16 | // https://github.com/babel/babylon/blob/master/ast/spec.md#bindexpression
|
|---|
| 17 | const object = value.object === null ? getValue(value.callee.object) : getValue(value.object);
|
|---|
| 18 |
|
|---|
| 19 | if (value.object && value.object.property) {
|
|---|
| 20 | return `${object}.${callee}.bind(${object})`;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | return `${callee}.bind(${object})`;
|
|---|
| 24 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.