frame.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*!
  2. * Stylus - stack - Frame
  3. * Copyright (c) Automattic <developer.wordpress.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module dependencies.
  8. */
  9. var Scope = require('./scope');
  10. /**
  11. * Initialize a new `Frame` with the given `block`.
  12. *
  13. * @param {Block} block
  14. * @api private
  15. */
  16. var Frame = module.exports = function Frame(block) {
  17. this._scope = false === block.scope
  18. ? null
  19. : new Scope;
  20. this.block = block;
  21. };
  22. /**
  23. * Return this frame's scope or the parent scope
  24. * for scope-less blocks.
  25. *
  26. * @return {Scope}
  27. * @api public
  28. */
  29. Frame.prototype.__defineGetter__('scope', function(){
  30. return this._scope || this.parent.scope;
  31. });
  32. /**
  33. * Lookup the given local variable `name`.
  34. *
  35. * @param {String} name
  36. * @return {Node}
  37. * @api private
  38. */
  39. Frame.prototype.lookup = function(name){
  40. return this.scope.lookup(name)
  41. };
  42. /**
  43. * Custom inspect.
  44. *
  45. * @return {String}
  46. * @api public
  47. */
  48. Frame.prototype.inspect = function(){
  49. return '[Frame '
  50. + (false === this.block.scope
  51. ? 'scope-less'
  52. : this.scope.inspect())
  53. + ']';
  54. };