resolve-variable-name.js 428 B

1234567891011121314151617181920
  1. 'use strict';
  2. /**
  3. Finds a variable named `name` in the scope `scope` (or it's parents).
  4. @param {string} name - The variable name to be resolve.
  5. @param {Scope} scope - The scope to look for the variable in.
  6. @returns {Variable?} - The found variable, if any.
  7. */
  8. module.exports = (name, scope) => {
  9. while (scope) {
  10. const variable = scope.set.get(name);
  11. if (variable) {
  12. return variable;
  13. }
  14. scope = scope.upper;
  15. }
  16. };