define.js 598 B

12345678910111213141516171819202122232425
  1. var utils = require('../utils')
  2. , nodes = require('../nodes');
  3. /**
  4. * Set a variable `name` on current scope.
  5. *
  6. * @param {String} name
  7. * @param {Expression} expr
  8. * @param {Boolean} [global]
  9. * @api public
  10. */
  11. function define(name, expr, global){
  12. utils.assertType(name, 'string', 'name');
  13. expr = utils.unwrap(expr);
  14. var scope = this.currentScope;
  15. if (global && global.toBoolean().isTrue) {
  16. scope = this.global.scope;
  17. }
  18. var node = new nodes.Ident(name.val, expr);
  19. scope.add(node);
  20. return nodes.null;
  21. };
  22. define.params = ['name', 'expr', 'global'];
  23. module.exports = define;