From f93388dec0f2401a0f8cb09a080d06564d447ecd Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Wed, 17 Dec 2014 15:24:27 -0500 Subject: [PATCH] Converting getAnchor into a property --- src/js/parser/javascript/charset.js | 26 ++++++++++---------- src/js/parser/javascript/match.js | 28 ++++++++++++---------- src/js/parser/javascript/match_fragment.js | 24 ++++++++++--------- src/js/parser/javascript/node.js | 28 ++++++++++------------ src/js/parser/javascript/subexp.js | 24 ++++++++++--------- 5 files changed, 68 insertions(+), 62 deletions(-) diff --git a/src/js/parser/javascript/charset.js b/src/js/parser/javascript/charset.js index 415489b..95d72eb 100644 --- a/src/js/parser/javascript/charset.js +++ b/src/js/parser/javascript/charset.js @@ -20,18 +20,6 @@ export default { }); }, - _getAnchor() { - var box = this.container.getBBox(), - matrix = this.transform().localMatrix; - - return { - atype: this.type, - ax: box.x, - ax2: box.x2, - ay: matrix.y(0, this.partContainer.getBBox().cy) - }; - }, - setup() { this.invert = this.properties.invert !== ''; this.elements = _.unique(this.properties.parts.elements, part => { @@ -41,5 +29,19 @@ export default { return part.textValue; } }); + + Object.defineProperty(this, '_anchor', { + get: function() { + var box = this.container.getBBox(), + matrix = this.transform().localMatrix; + + return { + atype: this.type, + ax: box.x, + ax2: box.x2, + ay: matrix.y(0, this.partContainer.getBBox().cy) + }; + } + }); } }; diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index 0291299..267ed5d 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -47,19 +47,6 @@ export default { }); }, - _getAnchor() { - var start = this.normalizeBBox(_.first(this.items).getBBox()), - end = this.normalizeBBox(_.last(this.items).getBBox()), - matrix = this.transform().localMatrix; - - return { - atype: [start.atype, end.atype].join('/'), - ax: matrix.x(start.ax, start.ay), - ax2: matrix.x(end.ax2, end.ay), - ay: matrix.y(start.ax, start.ay) - }; - }, - setup() { this.parts = _.reduce(this.properties.parts.elements, function(result, node) { var last = _.last(result); @@ -79,5 +66,20 @@ export default { if (!this.anchorStart && !this.anchorEnd && this.parts.length === 1) { this.proxy = this.parts[0]; } + + Object.defineProperty(this, '_anchor', { + get: function() { + var start = this.normalizeBBox(_.first(this.items).getBBox()), + end = this.normalizeBBox(_.last(this.items).getBBox()), + matrix = this.transform().localMatrix; + + return { + atype: [start.atype, end.atype].join('/'), + ax: matrix.x(start.ax, start.ay), + ax2: matrix.x(end.ax2, end.ay), + ay: matrix.y(start.ax, start.ay) + }; + } + }); } }; diff --git a/src/js/parser/javascript/match_fragment.js b/src/js/parser/javascript/match_fragment.js index 5c2d280..0985c36 100644 --- a/src/js/parser/javascript/match_fragment.js +++ b/src/js/parser/javascript/match_fragment.js @@ -55,17 +55,6 @@ export default { }); }, - _getAnchor() { - var anchor = this.content.getAnchor(), - matrix = this.transform().localMatrix; - - return _.extend(anchor, { - ax: matrix.x(anchor.ax, anchor.ay), - ax2: matrix.x(anchor.ax2, anchor.ay), - ay: matrix.y(anchor.ax, anchor.ay) - }); - }, - setup() { this.content = this.properties.content; this.canMerge = (this.elements[0].type === 'literal' && this.elements[1].textValue === ''); @@ -75,5 +64,18 @@ export default { } else { this.proxy = this.content; } + + Object.defineProperty(this, '_anchor', { + get: function() { + var anchor = this.content.anchor, + matrix = this.transform().localMatrix; + + return _.extend(anchor, { + ax: matrix.x(anchor.ax, anchor.ay), + ax2: matrix.x(anchor.ax2, anchor.ay), + ay: matrix.y(anchor.ax, anchor.ay) + }); + } + }); } }; diff --git a/src/js/parser/javascript/node.js b/src/js/parser/javascript/node.js index 5f518e2..721d640 100644 --- a/src/js/parser/javascript/node.js +++ b/src/js/parser/javascript/node.js @@ -29,27 +29,25 @@ export default class Node { return this._container; } - getAnchor() { + get anchor() { + var box; + if (this.proxy) { - return this.proxy.getAnchor(); + return this.proxy.anchor; } else { - return this._getAnchor(); + box = this.container.getBBox(); + + return _.extend({ + atype: this.type, + ax: box.x, + ax2: box.x2, + ay: box.cy + }, this._anchor || {}); } } - _getAnchor() { - var box = this.container.getBBox(); - - return { - atype: this.type, - ax: box.x, - ax2: box.x2, - ay: box.cy - }; - } - getBBox() { - return _.extend(this.container.getBBox(), this.getAnchor()); + return _.extend(this.container.getBBox(), this.anchor); } normalizeBBox(box) { diff --git a/src/js/parser/javascript/subexp.js b/src/js/parser/javascript/subexp.js index 4932528..948b94b 100644 --- a/src/js/parser/javascript/subexp.js +++ b/src/js/parser/javascript/subexp.js @@ -22,17 +22,6 @@ export default { groupCounter = 1; }, - _getAnchor() { - var anchor = this.regexp.getAnchor(), - matrix = this.transform().localMatrix; - - return _.extend(anchor, { - ax: matrix.x(anchor.ax, anchor.ay), - ax2: matrix.x(anchor.ax2, anchor.ay), - ay: matrix.y(anchor.ax, anchor.ay) - }); - }, - setup() { if (_.has(this.labelMap, this.properties.capture.textValue)) { this.label = this.labelMap[this.properties.capture.textValue]; @@ -45,5 +34,18 @@ export default { if (!this.label) { this.proxy = this.regexp; } + + Object.defineProperty(this, '_anchor', { + get: function() { + var anchor = this.regexp.anchor, + matrix = this.transform().localMatrix; + + return _.extend(anchor, { + ax: matrix.x(anchor.ax, anchor.ay), + ax2: matrix.x(anchor.ax2, anchor.ay), + ay: matrix.y(anchor.ax, anchor.ay) + }); + } + }); } };