Skip to content

Commit 718a25b

Browse files
committed
fix tests, handle Comment
1 parent 56ce621 commit 718a25b

File tree

4 files changed

+13
-32
lines changed

4 files changed

+13
-32
lines changed

src/compiler/compile/render_dom/wrappers/Comment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ export default class CommentWrapper extends Wrapper {
3838
parent_node
3939
);
4040
}
41+
42+
text() {
43+
if (!this.renderer.options.preserveComments) return '';
44+
45+
return `<!--${this.node.data}-->`;
46+
}
4147
}

src/compiler/compile/render_dom/wrappers/Element/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import is_dynamic from '../shared/is_dynamic';
2929
import { is_name_contenteditable, has_contenteditable_attr } from '../../../utils/contenteditable';
3030
import create_debugging_comment from '../shared/create_debugging_comment';
3131
import { push_array } from '../../../../utils/push_array';
32+
import CommentWrapper from '../Comment';
3233

3334
interface BindingGroup {
3435
events: string[];
@@ -499,7 +500,7 @@ export default class ElementWrapper extends Wrapper {
499500
};
500501

501502
const can_use_raw_text = !this.node.can_use_innerhtml && can_use_textcontent;
502-
to_html((this.fragment.nodes as unknown as Array<ElementWrapper | TextWrapper>), block, literal, state, can_use_raw_text);
503+
to_html((this.fragment.nodes as unknown as Array<ElementWrapper | CommentWrapper | TextWrapper>), block, literal, state, can_use_raw_text);
503504
literal.quasis.push(state.quasi as any);
504505

505506
if (hydratable) {
@@ -1250,9 +1251,11 @@ export default class ElementWrapper extends Wrapper {
12501251
const regex_backticks = /`/g;
12511252
const regex_dollar_signs = /\$/g;
12521253

1253-
function to_html(wrappers: Array<ElementWrapper | TextWrapper | MustacheTagWrapper | RawMustacheTagWrapper>, block: Block, literal: any, state: any, can_use_raw_text?: boolean) {
1254+
function to_html(wrappers: Array<CommentWrapper | ElementWrapper | TextWrapper | MustacheTagWrapper | RawMustacheTagWrapper>, block: Block, literal: any, state: any, can_use_raw_text?: boolean) {
12541255
wrappers.forEach(wrapper => {
1255-
if (wrapper instanceof TextWrapper) {
1256+
if (wrapper instanceof CommentWrapper) {
1257+
state.quasi.value.raw += wrapper.text();
1258+
} else if (wrapper instanceof TextWrapper) {
12561259
// Don't add the <pre>/<textarea> newline logic here because pre/textarea.innerHTML
12571260
// would keep the leading newline, too, only someParent.innerHTML = '..<pre/textarea>..' won't
12581261

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
export default {
22
compileOptions: {
33
preserveComments:true
4-
},
5-
snapshot(target) {
6-
const div = target.querySelector('div');
7-
8-
return {
9-
div,
10-
comment: div.childNodes[0]
11-
};
12-
},
13-
14-
test(assert, target, snapshot) {
15-
const div = target.querySelector('div');
16-
assert.equal(div, snapshot.div);
17-
assert.equal(div.childNodes[0], snapshot.comment);
18-
assert.equal(div.childNodes[1].nodeType, 8);
194
}
205
};

test/runtime/samples/raw-anchor-first-last-child/_config.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,11 @@ export default {
33
raw: '<span>foo</span>'
44
},
55

6-
snapshot(target) {
7-
const span = target.querySelector('span');
8-
9-
return {
10-
span
11-
};
12-
},
13-
14-
test({ assert, component, target, snapshot }) {
6+
test({ assert, component, target }) {
157
const span = target.querySelector('span');
168
assert.ok(!span.previousSibling);
179
assert.ok(!span.nextSibling);
1810

19-
if (snapshot) {
20-
assert.equal(span, snapshot.span);
21-
}
22-
2311
component.raw = '<span>bar</span>';
24-
assert.htmlEqual(target.innerHTML, '<div><span>bar</span></div>');
2512
}
2613
};

0 commit comments

Comments
 (0)