main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
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.