1 | 'use strict';
|
2 |
|
3 | const t = require('babel-types');
|
4 | const canEvaluate = require('./canEvaluate');
|
5 |
|
6 | function canEvaluateObject(staticNamespace, exprNode) {
|
7 | if (!t.isObjectExpression(exprNode)) {
|
8 | return false;
|
9 | }
|
10 |
|
11 | for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {
|
12 | const value = exprNode.properties[idx];
|
13 |
|
14 | if (value.computed) {
|
15 | if (!canEvaluate(staticNamespace, value.key)) {
|
16 | return false;
|
17 | }
|
18 | continue;
|
19 | }
|
20 |
|
21 |
|
22 | if (!t.isIdentifier(value.key)) {
|
23 | return false;
|
24 | }
|
25 |
|
26 | if (!canEvaluate(staticNamespace, value.value)) {
|
27 | return false;
|
28 | }
|
29 | }
|
30 |
|
31 | return true;
|
32 | }
|
33 |
|
34 | module.exports = canEvaluateObject;
|