refactor(compiler-vapor): remove createTextNode argument

This commit is contained in:
三咲智子 Kevin Deng 2024-01-31 13:16:03 +08:00
parent ccfadc1fb4
commit f7642ab77c
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
9 changed files with 23 additions and 30 deletions

View File

@ -7,7 +7,7 @@ export function render(_ctx) {
const t0 = _template("<div>count is <!>.</div>")
const n0 = t0()
const { 0: [n3, { 1: [n2],}],} = _children(n0)
const n1 = _createTextNode(_ctx.count)
const n1 = _createTextNode()
_insert(n1, n3, n2)
_renderEffect(() => {
_setText(n1, _ctx.count)
@ -139,7 +139,7 @@ export function render(_ctx) {
const t0 = _template("<div></div><div><Comp></Comp></div>")
const n0 = t0()
const { 1: [n2],} = _children(n0)
const n1 = _createTextNode(_ctx.bar)
const n1 = _createTextNode()
_append(n2, n1)
_renderEffect(() => {
_setText(n1, _ctx.bar)
@ -158,7 +158,7 @@ export function render(_ctx) {
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>")
const n0 = t0()
const { 1: [n2],} = _children(n0)
const n1 = _createTextNode(_ctx.bar)
const n1 = _createTextNode()
_append(n2, n1)
_renderEffect(() => {
_setText(n1, _ctx.bar)
@ -176,8 +176,8 @@ exports[`compile > dynamic root 1`] = `
export function render(_ctx) {
const t0 = _fragment()
const n0 = t0()
const n1 = _createTextNode(1)
const n2 = _createTextNode(2)
const n1 = _createTextNode()
const n2 = _createTextNode()
_append(n0, n1, n2)
_renderEffect(() => {
_setText(n1, 1)
@ -196,9 +196,9 @@ export function render(_ctx) {
const t0 = _template("<button>foo<!>foo</button>")
const n0 = t0()
const { 0: [n4, { 1: [n5],}],} = _children(n0)
const n1 = _createTextNode(_ctx.count)
const n2 = _createTextNode(_ctx.count)
const n3 = _createTextNode(_ctx.count)
const n1 = _createTextNode()
const n2 = _createTextNode()
const n3 = _createTextNode()
_prepend(n4, n1)
_insert(n2, n4, n5)
_append(n4, n3)
@ -217,7 +217,7 @@ exports[`compile > expression parsing > interpolation 1`] = `
"(() => {
const t0 = _fragment()
const n0 = t0()
const n1 = _createTextNode(a + b.value)
const n1 = _createTextNode()
_append(n0, n1)
_renderEffect(() => {
_setText(n1, a + b.value)
@ -255,14 +255,14 @@ export function render(_ctx) {
const t0 = _template("3<!>6<!>9")
const n0 = t0()
const { 1: [n9], 3: [n10],} = _children(n0)
const n1 = _createTextNode(1)
const n2 = _createTextNode(2)
const n3 = _createTextNode(4)
const n4 = _createTextNode(5)
const n5 = _createTextNode(7)
const n6 = _createTextNode(8)
const n7 = _createTextNode('A')
const n8 = _createTextNode('B')
const n1 = _createTextNode()
const n2 = _createTextNode()
const n3 = _createTextNode()
const n4 = _createTextNode()
const n5 = _createTextNode()
const n6 = _createTextNode()
const n7 = _createTextNode()
const n8 = _createTextNode()
_prepend(n0, n1, n2)
_insert([n3, n4], n0, n9)
_insert([n5, n6], n0, n10)

View File

@ -19,7 +19,7 @@ export function render(_ctx) {
const t0 = _template("<div> <span></span></div>")
const n0 = t0()
const { 0: [n3, { 1: [n2],}],} = _children(n0)
const n1 = _createTextNode(_ctx.msg)
const n1 = _createTextNode()
_setText(n1, _ctx.msg)
_setClass(n2, _ctx.clz)
_prepend(n3, n1)

View File

@ -31,11 +31,6 @@ describe('compiler: v-once', () => {
{
id: 1,
type: IRNodeTypes.CREATE_TEXT_NODE,
value: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'msg',
isStatic: false,
},
},
{
element: 1,

View File

@ -25,6 +25,6 @@ export function genCreateTextNode(
return [
newline(),
`const n${oper.id} = `,
...call(vaporHelper('createTextNode'), genExpression(oper.value, context)),
...call(vaporHelper('createTextNode')),
]
}

View File

@ -130,7 +130,6 @@ export interface SetModelValueIRNode extends BaseIRNode {
export interface CreateTextNodeIRNode extends BaseIRNode {
type: IRNodeTypes.CREATE_TEXT_NODE
id: number
value: IRExpression
}
export interface InsertNodeIRNode extends BaseIRNode {

View File

@ -32,7 +32,6 @@ export const transformInterpolation: NodeTransform = (node, ctx) => {
type: IRNodeTypes.CREATE_TEXT_NODE,
loc: node.loc,
id,
value: expr,
})
ctx.registerEffect(
[expr],

View File

@ -73,9 +73,9 @@ export function children(nodes: ChildNode[]): Children {
return result
}
export function createTextNode(val: unknown): Text {
export function createTextNode(val?: unknown): Text {
// eslint-disable-next-line no-restricted-globals
return document.createTextNode(toDisplayString(val))
return document.createTextNode(val === undefined ? '' : toDisplayString(val))
}
export function createComment(data: string): Comment {

View File

@ -24,7 +24,7 @@ export const createFor = (
let oldBlocks: ForBlock[] = []
let newBlocks: ForBlock[]
let parent: ParentNode | undefined | null
const parentAnchor = __DEV__ ? createComment('for') : createTextNode('')
const parentAnchor = __DEV__ ? createComment('for') : createTextNode()
const ref: Fragment = {
nodes: oldBlocks,
[fragmentKey]: true,

View File

@ -15,7 +15,7 @@ export const createIf = (
let parent: ParentNode | undefined | null
let block: Block | undefined
let scope: EffectScope | undefined
const anchor = __DEV__ ? createComment('if') : createTextNode('')
const anchor = __DEV__ ? createComment('if') : createTextNode()
const fragment: Fragment = {
nodes: [],
anchor,