main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = extractValueFromBindExpression;
|
---|
| 7 | /**
|
---|
| 8 | * Extractor function for a BindExpression type value node.
|
---|
| 9 | * A bind expression looks like `::this.foo`
|
---|
| 10 | * This will return `this.foo.bind(this)` as the value to indicate its existence,
|
---|
| 11 | * since we can not execute the function this.foo.bind(this) in a static environment.
|
---|
| 12 | *
|
---|
| 13 | * @param - value - AST Value object with type `BindExpression`
|
---|
| 14 | * @returns - The extracted value converted to correct type.
|
---|
| 15 | */
|
---|
| 16 | function extractValueFromBindExpression(value) {
|
---|
| 17 | // eslint-disable-next-line global-require
|
---|
| 18 | var getValue = require('.').default;
|
---|
| 19 | var callee = getValue(value.callee);
|
---|
| 20 |
|
---|
| 21 | // If value.object === null, the callee must be a MemberExpression.
|
---|
| 22 | // https://github.com/babel/babylon/blob/master/ast/spec.md#bindexpression
|
---|
| 23 | var object = value.object === null ? getValue(value.callee.object) : getValue(value.object);
|
---|
| 24 |
|
---|
| 25 | if (value.object && value.object.property) {
|
---|
| 26 | return object + '.' + callee + '.bind(' + object + ')';
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | return callee + '.bind(' + object + ')';
|
---|
| 30 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.