mirror of https://github.com/sveltejs/svelte
Merge pull request #2258 from sveltejs/collapse-whitespace
collapse consecutive whitespace characterspull/2269/head
commit
4348727fca
@ -1,11 +1,26 @@
|
|||||||
import Node from './shared/Node';
|
import Node from './shared/Node';
|
||||||
|
import Component from '../Component';
|
||||||
|
import TemplateScope from './shared/TemplateScope';
|
||||||
|
|
||||||
export default class Text extends Node {
|
export default class Text extends Node {
|
||||||
type: 'Text';
|
type: 'Text';
|
||||||
data: string;
|
data: string;
|
||||||
|
use_space = false;
|
||||||
|
|
||||||
constructor(component, parent, scope, info) {
|
constructor(component: Component, parent: Node, scope: TemplateScope, info: any) {
|
||||||
super(component, parent, scope, info);
|
super(component, parent, scope, info);
|
||||||
this.data = info.data;
|
this.data = info.data;
|
||||||
|
|
||||||
|
if (!component.component_options.preserveWhitespace && !/\S/.test(info.data)) {
|
||||||
|
let node = parent;
|
||||||
|
while (node) {
|
||||||
|
if (node.type === 'Element' && node.name === 'pre') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
node = node.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.use_space = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue