mirror of https://github.com/sveltejs/svelte
parent
941de39523
commit
a1225d5adf
@ -0,0 +1,29 @@
|
|||||||
|
const LINE = {};
|
||||||
|
const BLOCK = {};
|
||||||
|
|
||||||
|
export default class CodeBuilder {
|
||||||
|
constructor () {
|
||||||
|
this.result = '';
|
||||||
|
this.last = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
addLine ( line ) {
|
||||||
|
if ( this.last === BLOCK ) {
|
||||||
|
this.result += `\n\n${line}`;
|
||||||
|
} else {
|
||||||
|
this.result += `\n${line}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.last = LINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
addBlock ( block ) {
|
||||||
|
this.result += `\n\n${block}`;
|
||||||
|
|
||||||
|
this.last = BLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
toString () {
|
||||||
|
return this.result.trim();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue