|
|
|
@ -1,29 +1,38 @@
|
|
|
|
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;
|
|
|
|
|
|
|
|
skip: boolean;
|
|
|
|
|
|
|
|
var: Identifier;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: Text, data: string) {
|
|
|
|
/** @type {import('../../nodes/Text.js').default} */
|
|
|
|
super(renderer, block, parent, node);
|
|
|
|
node;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {string} */
|
|
|
|
|
|
|
|
_data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {boolean} */
|
|
|
|
|
|
|
|
skip;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('estree').Identifier} */
|
|
|
|
|
|
|
|
var;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {import('../Renderer.js').default} renderer
|
|
|
|
|
|
|
|
* @param {import('../Block.js').default} block
|
|
|
|
|
|
|
|
* @param {import('./shared/Wrapper.js').default} parent
|
|
|
|
|
|
|
|
* @param {import('../../nodes/Text.js').default} node
|
|
|
|
|
|
|
|
* @param {string} data
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
constructor(renderer, block, parent, node, data) {
|
|
|
|
|
|
|
|
super(renderer, block, parent, node);
|
|
|
|
this.skip = this.node.should_skip();
|
|
|
|
this.skip = this.node.should_skip();
|
|
|
|
this._data = data;
|
|
|
|
this._data = data;
|
|
|
|
this.var = (this.skip ? null : x`t`) as unknown as Identifier;
|
|
|
|
this.var = /** @type {unknown} */ /** @type {import('estree').Identifier} */ (((this.skip ? null : x `t`)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
use_space() {
|
|
|
|
use_space() {
|
|
|
|
return this.node.use_space();
|
|
|
|
return this.node.use_space();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set data(value) {
|
|
|
|
set data(value: string) {
|
|
|
|
|
|
|
|
// when updating `this.data` during optimisation
|
|
|
|
// when updating `this.data` during optimisation
|
|
|
|
// propagate the changes over to the underlying node
|
|
|
|
// propagate the changes over to the underlying node
|
|
|
|
// so that the node.use_space reflects on the latest `data` value
|
|
|
|
// so that the node.use_space reflects on the latest `data` value
|
|
|
|
@ -33,10 +42,15 @@ export default class TextWrapper extends Wrapper {
|
|
|
|
return this._data;
|
|
|
|
return this._data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
|
|
|
|
/**
|
|
|
|
if (this.skip) return;
|
|
|
|
* @param {import('../Block.js').default} block
|
|
|
|
|
|
|
|
* @param {import('estree').Identifier} parent_node
|
|
|
|
|
|
|
|
* @param {import('estree').Identifier} parent_nodes
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
render(block, parent_node, parent_nodes) {
|
|
|
|
|
|
|
|
if (this.skip)
|
|
|
|
|
|
|
|
return;
|
|
|
|
const use_space = this.use_space();
|
|
|
|
const use_space = this.use_space();
|
|
|
|
|
|
|
|
|
|
|
|
const string_literal = {
|
|
|
|
const string_literal = {
|
|
|
|
type: 'Literal',
|
|
|
|
type: 'Literal',
|
|
|
|
value: this.data,
|
|
|
|
value: this.data,
|
|
|
|
@ -45,15 +59,14 @@ export default class TextWrapper extends Wrapper {
|
|
|
|
end: this.renderer.locate(this.node.end)
|
|
|
|
end: this.renderer.locate(this.node.end)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
block.add_element(this.var, use_space ? x `@space()` : x `@text(${string_literal})`, parent_nodes &&
|
|
|
|
block.add_element(
|
|
|
|
|
|
|
|
this.var,
|
|
|
|
|
|
|
|
use_space ? x`@space()` : x`@text(${string_literal})`,
|
|
|
|
|
|
|
|
parent_nodes &&
|
|
|
|
|
|
|
|
(use_space
|
|
|
|
(use_space
|
|
|
|
? x`@claim_space(${parent_nodes})`
|
|
|
|
? x `@claim_space(${parent_nodes})`
|
|
|
|
: x`@claim_text(${parent_nodes}, ${string_literal})`),
|
|
|
|
: x `@claim_text(${parent_nodes}, ${string_literal})`),
|
|
|
|
parent_node as Identifier
|
|
|
|
/** @type {import('estree').Identifier} */ (parent_node));
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|