From 2ae20ae431a1152bf3815ef0fd2f74df504770db Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Wed, 8 Feb 2017 23:47:10 -0800 Subject: [PATCH] Fixed node.previousSibling and node.nextSibling --- compiler/ast/ArrayContainer.js | 6 +++++- compiler/ast/Node.js | 4 ++-- .../previousSibling-nextSibling/expected.html | 1 + .../render/previousSibling-nextSibling/marko.json | 5 +++++ .../span-transformer.js | 14 ++++++++++++++ .../previousSibling-nextSibling/template.marko | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/autotests/render/previousSibling-nextSibling/expected.html create mode 100644 test/autotests/render/previousSibling-nextSibling/marko.json create mode 100644 test/autotests/render/previousSibling-nextSibling/span-transformer.js create mode 100644 test/autotests/render/previousSibling-nextSibling/template.marko diff --git a/compiler/ast/ArrayContainer.js b/compiler/ast/ArrayContainer.js index bf84df750..06e3a5481 100644 --- a/compiler/ast/ArrayContainer.js +++ b/compiler/ast/ArrayContainer.js @@ -118,6 +118,8 @@ class ArrayContainer extends Container { } var array = this.array; + + for (var i=0; i= 0 ? array[i+1] : undefined; + console.log("ARRAY:", i-1 >= 0 ? array[i-1] : undefined); + + return i-1 >= 0 ? array[i-1] : undefined; } } } diff --git a/compiler/ast/Node.js b/compiler/ast/Node.js index 1411ce56a..74857c35b 100644 --- a/compiler/ast/Node.js +++ b/compiler/ast/Node.js @@ -160,7 +160,7 @@ class Node { var container = this.container; if (container) { - container.getPreviousSibling(this); + return container.getPreviousSibling(this); } } @@ -168,7 +168,7 @@ class Node { var container = this.container; if (container) { - container.getNextSibling(this); + return container.getNextSibling(this); } } diff --git a/test/autotests/render/previousSibling-nextSibling/expected.html b/test/autotests/render/previousSibling-nextSibling/expected.html new file mode 100644 index 000000000..59b78e67f --- /dev/null +++ b/test/autotests/render/previousSibling-nextSibling/expected.html @@ -0,0 +1 @@ +
AB
\ No newline at end of file diff --git a/test/autotests/render/previousSibling-nextSibling/marko.json b/test/autotests/render/previousSibling-nextSibling/marko.json new file mode 100644 index 000000000..02ef4c8de --- /dev/null +++ b/test/autotests/render/previousSibling-nextSibling/marko.json @@ -0,0 +1,5 @@ +{ + "": { + "transformer": "./span-transformer.js" + } +} \ No newline at end of file diff --git a/test/autotests/render/previousSibling-nextSibling/span-transformer.js b/test/autotests/render/previousSibling-nextSibling/span-transformer.js new file mode 100644 index 000000000..7f9d30c4e --- /dev/null +++ b/test/autotests/render/previousSibling-nextSibling/span-transformer.js @@ -0,0 +1,14 @@ +var expect = require('chai').expect; +module.exports = function(node, context) { + var previousSibling = node.previousSibling; + var nextSibling = node.nextSibling; + + expect(previousSibling).to.be.an('object'); + expect(nextSibling).to.be.an('object'); + + expect(previousSibling.tagName).to.equal('a'); + expect(nextSibling.tagName).to.equal('b'); + + previousSibling.appendChild(context.builder.text(context.builder.literal('A'))); + nextSibling.appendChild(context.builder.text(context.builder.literal('B'))); +}; \ No newline at end of file diff --git a/test/autotests/render/previousSibling-nextSibling/template.marko b/test/autotests/render/previousSibling-nextSibling/template.marko new file mode 100644 index 000000000..6a24cdb62 --- /dev/null +++ b/test/autotests/render/previousSibling-nextSibling/template.marko @@ -0,0 +1 @@ +
\ No newline at end of file