mirror of https://github.com/sveltejs/svelte
parent
a0c7d25cf1
commit
94368af07b
@ -1,59 +1,72 @@
|
|||||||
import Renderer from '../Renderer';
|
import Wrapper from './shared/Wrapper.js';
|
||||||
import Block from '../Block';
|
|
||||||
import Text from '../../nodes/Text';
|
|
||||||
import Wrapper from './shared/Wrapper';
|
|
||||||
import { x } from 'code-red';
|
import { x } from 'code-red';
|
||||||
import { Identifier } from 'estree';
|
|
||||||
|
|
||||||
|
/** @extends Wrapper */
|
||||||
export default class TextWrapper extends Wrapper {
|
export default class TextWrapper extends Wrapper {
|
||||||
node: Text;
|
|
||||||
_data: string;
|
/** @type {import('../../nodes/Text.js').default} */
|
||||||
skip: boolean;
|
node;
|
||||||
var: Identifier;
|
|
||||||
|
/** @type {string} */
|
||||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: Text, data: string) {
|
_data;
|
||||||
super(renderer, block, parent, node);
|
|
||||||
|
/** @type {boolean} */
|
||||||
this.skip = this.node.should_skip();
|
skip;
|
||||||
this._data = data;
|
|
||||||
this.var = (this.skip ? null : x`t`) as unknown as Identifier;
|
/** @type {import('estree').Identifier} */
|
||||||
}
|
var;
|
||||||
|
|
||||||
use_space() {
|
/**
|
||||||
return this.node.use_space();
|
* @param {import('../Renderer.js').default} renderer
|
||||||
}
|
* @param {import('../Block.js').default} block
|
||||||
|
* @param {import('./shared/Wrapper.js').default} parent
|
||||||
set data(value: string) {
|
* @param {import('../../nodes/Text.js').default} node
|
||||||
// when updating `this.data` during optimisation
|
* @param {string} data
|
||||||
// propagate the changes over to the underlying node
|
*/
|
||||||
// so that the node.use_space reflects on the latest `data` value
|
constructor(renderer, block, parent, node, data) {
|
||||||
this.node.data = this._data = value;
|
super(renderer, block, parent, node);
|
||||||
}
|
this.skip = this.node.should_skip();
|
||||||
get data() {
|
this._data = data;
|
||||||
return this._data;
|
this.var = /** @type {unknown} */ /** @type {import('estree').Identifier} */ (((this.skip ? null : x `t`)));
|
||||||
}
|
}
|
||||||
|
use_space() {
|
||||||
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
|
return this.node.use_space();
|
||||||
if (this.skip) return;
|
}
|
||||||
const use_space = this.use_space();
|
set data(value) {
|
||||||
|
// when updating `this.data` during optimisation
|
||||||
const string_literal = {
|
// propagate the changes over to the underlying node
|
||||||
type: 'Literal',
|
// so that the node.use_space reflects on the latest `data` value
|
||||||
value: this.data,
|
this.node.data = this._data = value;
|
||||||
loc: {
|
}
|
||||||
start: this.renderer.locate(this.node.start),
|
get data() {
|
||||||
end: this.renderer.locate(this.node.end)
|
return this._data;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
/**
|
||||||
block.add_element(
|
* @param {import('../Block.js').default} block
|
||||||
this.var,
|
* @param {import('estree').Identifier} parent_node
|
||||||
use_space ? x`@space()` : x`@text(${string_literal})`,
|
* @param {import('estree').Identifier} parent_nodes
|
||||||
parent_nodes &&
|
*/
|
||||||
(use_space
|
render(block, parent_node, parent_nodes) {
|
||||||
? x`@claim_space(${parent_nodes})`
|
if (this.skip)
|
||||||
: x`@claim_text(${parent_nodes}, ${string_literal})`),
|
return;
|
||||||
parent_node as Identifier
|
const use_space = this.use_space();
|
||||||
);
|
const string_literal = {
|
||||||
}
|
type: 'Literal',
|
||||||
|
value: this.data,
|
||||||
|
loc: {
|
||||||
|
start: this.renderer.locate(this.node.start),
|
||||||
|
end: this.renderer.locate(this.node.end)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
block.add_element(this.var, use_space ? x `@space()` : x `@text(${string_literal})`, parent_nodes &&
|
||||||
|
(use_space
|
||||||
|
? x `@claim_space(${parent_nodes})`
|
||||||
|
: x `@claim_text(${parent_nodes}, ${string_literal})`),
|
||||||
|
/** @type {import('estree').Identifier} */ (parent_node));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in new issue