You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get the value of a given node if it can decide the value statically.
280
+
281
+
If the 2nd parameter `initialScope` was given, this function tries to resolve identifier references which are in the given node as much as possible.
282
+
In the resolving way, it does on the assumption that built-in global objects have not been modified.
283
+
For example, it considers `Symbol.iterator`, ``String.raw`hello` ``, and `Object.freeze({a: 1}).a` as static.
284
+
285
+
For another complex example, this function can evaluate the following cases on AST:
286
+
287
+
```js{6}
288
+
const eventName = "click"
289
+
const aMap = Object.freeze({
290
+
click: 777
291
+
})
292
+
293
+
;`on${eventName} : ${aMap[eventName]}` // evaluated to "onclick : 777"
294
+
```
280
295
281
296
### Parameters
282
297
283
298
Name | Type | Description
284
299
:-----|:-----|:------------
285
-
node | Node | The node to get that string value.
286
-
initialScope | Scope or undefined | Optional. The scope object to find variables. If this scope was given and the node is an Identifier node, it finds the variable of the identifier, and if the variable is a `const` variable, it returns the value of the `const` variable.
300
+
node | Node | The node to get that the value.
301
+
initialScope | Scope or undefined | Optional. The scope object to find variables.
287
302
288
303
### Return value
289
304
290
-
The string value of the node.
291
-
If the node is not constant then it returns `null`.
305
+
The `{ value: any }` shaped object. The `value` property is the static value.
306
+
307
+
If it couldn't compute the static value of the node, it returns `null`.
0 commit comments