mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: Added Node.prototype.replaceWith(newNode)
This commit is contained in:
parent
ee91cf2ec6
commit
2ce5493c9a
@ -58,6 +58,12 @@ class Node {
|
||||
wrapperNode.appendChild(this);
|
||||
}
|
||||
|
||||
replaceWith(newNode) {
|
||||
ok(this.container, 'Node does not belong to a container: ' + this);
|
||||
var replaced = this.container.replaceChild(newNode, this);
|
||||
ok(replaced, 'Invalid state. Child does not belong to the container');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the provided `array` into a `ArrayContainer`. If the provided `array` is already an instance of a `Container` then it is simply returned.
|
||||
* @param {[type]} array [description]
|
||||
|
||||
12
test/fixtures/compiler/autotest/replaceWith/expected.js
vendored
Normal file
12
test/fixtures/compiler/autotest/replaceWith/expected.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
function create(__helpers) {
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne,
|
||||
escapeXml = __helpers.x;
|
||||
|
||||
return function render(data, out) {
|
||||
out.w("<div replaced=\"test-replaceWith\"></div>");
|
||||
};
|
||||
}
|
||||
|
||||
(module.exports = require("marko").c(__filename)).c(create);
|
||||
1
test/fixtures/compiler/autotest/replaceWith/template.marko
vendored
Normal file
1
test/fixtures/compiler/autotest/replaceWith/template.marko
vendored
Normal file
@ -0,0 +1 @@
|
||||
<test-replaceWith/>
|
||||
3
test/fixtures/taglib/scanned-tags/test-replaceWith/marko-tag.json
vendored
Normal file
3
test/fixtures/taglib/scanned-tags/test-replaceWith/marko-tag.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"transformer": "./transformer.js"
|
||||
}
|
||||
7
test/fixtures/taglib/scanned-tags/test-replaceWith/transformer.js
vendored
Normal file
7
test/fixtures/taglib/scanned-tags/test-replaceWith/transformer.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = function transform(el, context) {
|
||||
var div = context.builder.htmlElement('div', {
|
||||
replaced: context.builder.literal('test-replaceWith')
|
||||
});
|
||||
|
||||
el.replaceWith(div);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user