property.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var node_1 = tslib_1.__importDefault(require("./node"));
  5. var declaration_1 = tslib_1.__importDefault(require("./declaration"));
  6. var Property = function (name, index, currentFileInfo) {
  7. this.name = name;
  8. this._index = index;
  9. this._fileInfo = currentFileInfo;
  10. };
  11. Property.prototype = Object.assign(new node_1.default(), {
  12. type: 'Property',
  13. eval: function (context) {
  14. var property;
  15. var name = this.name;
  16. // TODO: shorten this reference
  17. var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
  18. if (this.evaluating) {
  19. throw { type: 'Name',
  20. message: "Recursive property reference for " + name,
  21. filename: this.fileInfo().filename,
  22. index: this.getIndex() };
  23. }
  24. this.evaluating = true;
  25. property = this.find(context.frames, function (frame) {
  26. var v;
  27. var vArr = frame.property(name);
  28. if (vArr) {
  29. for (var i = 0; i < vArr.length; i++) {
  30. v = vArr[i];
  31. vArr[i] = new declaration_1.default(v.name, v.value, v.important, v.merge, v.index, v.currentFileInfo, v.inline, v.variable);
  32. }
  33. mergeRules(vArr);
  34. v = vArr[vArr.length - 1];
  35. if (v.important) {
  36. var importantScope = context.importantScope[context.importantScope.length - 1];
  37. importantScope.important = v.important;
  38. }
  39. v = v.value.eval(context);
  40. return v;
  41. }
  42. });
  43. if (property) {
  44. this.evaluating = false;
  45. return property;
  46. }
  47. else {
  48. throw { type: 'Name',
  49. message: "Property '" + name + "' is undefined",
  50. filename: this.currentFileInfo.filename,
  51. index: this.index };
  52. }
  53. },
  54. find: function (obj, fun) {
  55. for (var i = 0, r = void 0; i < obj.length; i++) {
  56. r = fun.call(obj, obj[i]);
  57. if (r) {
  58. return r;
  59. }
  60. }
  61. return null;
  62. }
  63. });
  64. exports.default = Property;
  65. //# sourceMappingURL=property.js.map