UNPKG

725 BJavaScriptView Raw
1'use strict';
2
3const t = require('babel-types');
4const canEvaluate = require('./canEvaluate');
5
6function 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 // TODO: allow other types of key types (literal?)
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
34module.exports = canEvaluateObject;