Skip to content

Commit e2f84fc

Browse files
committed
wip: save
1 parent 2807a8b commit e2f84fc

File tree

13 files changed

+64
-55
lines changed

13 files changed

+64
-55
lines changed

packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ describe('compiler: element transform', () => {
579579
const template = '<div id="foo" class="bar"></div>'
580580
expect(code).toMatchSnapshot()
581581
expect(code).contains(JSON.stringify(template))
582-
expect(ir.template).toMatchObject([template])
582+
expect([...ir.template.keys()]).toMatchObject([template])
583583
expect(ir.block.effect).lengthOf(0)
584584
})
585585

@@ -591,7 +591,7 @@ describe('compiler: element transform', () => {
591591
const template = '<div id="foo"><span></span></div>'
592592
expect(code).toMatchSnapshot()
593593
expect(code).contains(JSON.stringify(template))
594-
expect(ir.template).toMatchObject([template])
594+
expect([...ir.template.keys()]).toMatchObject([template])
595595
expect(ir.block.effect).lengthOf(0)
596596
})
597597

@@ -937,7 +937,11 @@ describe('compiler: element transform', () => {
937937
<form><form/></form>`,
938938
)
939939
expect(code).toMatchSnapshot()
940-
expect(ir.template).toEqual(['<div>123</div>', '<p></p>', '<form></form>'])
940+
expect([...ir.template.keys()]).toEqual([
941+
'<div>123</div>',
942+
'<p></p>',
943+
'<form></form>',
944+
])
941945
expect(ir.block.dynamic).toMatchObject({
942946
children: [
943947
{ id: 1, template: 1, children: [{ id: 0, template: 0 }] },
@@ -964,8 +968,8 @@ describe('compiler: element transform', () => {
964968
expect(code).contains(
965969
'_template("<svg><circle r=\\"40\\"></circle></svg>", true, 1)',
966970
)
967-
expect(ir.template).toMatchObject([t])
968-
expect(ir.templateNS.get(t)).toBe(1)
971+
expect([...ir.template.keys()]).toMatchObject([t])
972+
expect(ir.template.get(t)).toBe(1)
969973
})
970974

971975
test('MathML', () => {
@@ -975,7 +979,7 @@ describe('compiler: element transform', () => {
975979
expect(code).contains(
976980
'_template("<math><mrow><mi>x</mi></mrow></math>", true, 2)',
977981
)
978-
expect(ir.template).toMatchObject([t])
979-
expect(ir.templateNS.get(t)).toBe(2)
982+
expect([...ir.template.keys()]).toMatchObject([t])
983+
expect(ir.template.get(t)).toBe(2)
980984
})
981985
})

packages/compiler-vapor/__tests__/transforms/transformSlotOutlet.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe('compiler: transform <slot> outlets', () => {
155155
test('default slot outlet with fallback', () => {
156156
const { ir, code } = compileWithSlotsOutlet(`<slot><div/></slot>`)
157157
expect(code).toMatchSnapshot()
158-
expect(ir.template[0]).toBe('<div></div>')
158+
expect([...ir.template.keys()][0]).toBe('<div></div>')
159159
expect(ir.block.dynamic.children[0].operation).toMatchObject({
160160
type: IRNodeTypes.SLOT_OUTLET_NODE,
161161
id: 0,
@@ -175,7 +175,7 @@ describe('compiler: transform <slot> outlets', () => {
175175
`<slot name="foo"><div/></slot>`,
176176
)
177177
expect(code).toMatchSnapshot()
178-
expect(ir.template[0]).toBe('<div></div>')
178+
expect([...ir.template.keys()][0]).toBe('<div></div>')
179179
expect(ir.block.dynamic.children[0].operation).toMatchObject({
180180
type: IRNodeTypes.SLOT_OUTLET_NODE,
181181
id: 0,
@@ -195,7 +195,7 @@ describe('compiler: transform <slot> outlets', () => {
195195
`<slot :foo="bar"><div/></slot>`,
196196
)
197197
expect(code).toMatchSnapshot()
198-
expect(ir.template[0]).toBe('<div></div>')
198+
expect([...ir.template.keys()][0]).toBe('<div></div>')
199199
expect(ir.block.dynamic.children[0].operation).toMatchObject({
200200
type: IRNodeTypes.SLOT_OUTLET_NODE,
201201
id: 0,
@@ -216,7 +216,7 @@ describe('compiler: transform <slot> outlets', () => {
216216
`<slot name="foo" :foo="bar"><div/></slot>`,
217217
)
218218
expect(code).toMatchSnapshot()
219-
expect(ir.template[0]).toBe('<div></div>')
219+
expect([...ir.template.keys()][0]).toBe('<div></div>')
220220
expect(ir.block.dynamic.children[0].operation).toMatchObject({
221221
type: IRNodeTypes.SLOT_OUTLET_NODE,
222222
id: 0,

packages/compiler-vapor/__tests__/transforms/transformTemplateRef.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('compiler: template ref transform', () => {
3030
id: 0,
3131
flags: DynamicFlag.REFERENCED,
3232
})
33-
expect(ir.template).toEqual(['<div></div>'])
33+
expect([...ir.template.keys()]).toEqual(['<div></div>'])
3434
expect(ir.block.operation).lengthOf(1)
3535
expect(ir.block.operation[0]).toMatchObject({
3636
type: IRNodeTypes.SET_TEMPLATE_REF,
@@ -66,7 +66,7 @@ describe('compiler: template ref transform', () => {
6666
id: 0,
6767
flags: DynamicFlag.REFERENCED,
6868
})
69-
expect(ir.template).toEqual(['<div></div>'])
69+
expect([...ir.template.keys()]).toEqual(['<div></div>'])
7070
expect(ir.block.operation).toMatchObject([
7171
{
7272
type: IRNodeTypes.DECLARE_OLD_REF,
@@ -104,7 +104,7 @@ describe('compiler: template ref transform', () => {
104104
id: 0,
105105
flags: DynamicFlag.REFERENCED,
106106
})
107-
expect(ir.template).toEqual(['<div></div>'])
107+
expect([...ir.template.keys()]).toEqual(['<div></div>'])
108108
expect(ir.block.operation).toMatchObject([
109109
{
110110
type: IRNodeTypes.DECLARE_OLD_REF,

packages/compiler-vapor/__tests__/transforms/vBind.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('compiler v-bind', () => {
2323
id: 0,
2424
flags: DynamicFlag.REFERENCED,
2525
})
26-
expect(ir.template).toEqual(['<div></div>'])
26+
expect([...ir.template.keys()]).toEqual(['<div></div>'])
2727
expect(ir.block.effect).lengthOf(1)
2828
expect(ir.block.effect[0].expressions).lengthOf(1)
2929
expect(ir.block.effect[0].operations).lengthOf(1)
@@ -241,7 +241,7 @@ describe('compiler v-bind', () => {
241241
end: { line: 1, column: 19 },
242242
},
243243
})
244-
expect(ir.template).toEqual(['<div arg></div>'])
244+
expect([...ir.template.keys()]).toEqual(['<div arg></div>'])
245245

246246
expect(code).matchSnapshot()
247247
expect(code).contains(JSON.stringify('<div arg></div>'))

packages/compiler-vapor/__tests__/transforms/vFor.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('compiler: v-for', () => {
3232

3333
expect(code).matchSnapshot()
3434
expect(helpers).contains('createFor')
35-
expect(ir.template).toEqual(['<div> </div>'])
35+
expect([...ir.template.keys()]).toEqual(['<div> </div>'])
3636
expect(ir.block.dynamic.children[0].operation).toMatchObject({
3737
type: IRNodeTypes.FOR,
3838
id: 0,
@@ -156,7 +156,7 @@ describe('compiler: v-for', () => {
156156
`_createFor(() => (_for_item0.value), (_for_item1) => {`,
157157
)
158158
expect(code).contains(`_for_item1.value+_for_item0.value`)
159-
expect(ir.template).toEqual(['<span> </span>', '<div></div>'])
159+
expect([...ir.template.keys()]).toEqual(['<span> </span>', '<div></div>'])
160160
const parentOp = ir.block.dynamic.children[0].operation
161161
expect(parentOp).toMatchObject({
162162
type: IRNodeTypes.FOR,

packages/compiler-vapor/__tests__/transforms/vHtml.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('v-html', () => {
6666
expect(helpers).contains('setHtml')
6767

6868
// children should have been removed
69-
expect(ir.template).toEqual(['<div></div>'])
69+
expect([...ir.template.keys()]).toEqual(['<div></div>'])
7070

7171
expect(ir.block.operation).toMatchObject([])
7272
expect(ir.block.effect).toMatchObject([

packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('compiler: v-if', () => {
3232

3333
expect(helpers).contains('createIf')
3434

35-
expect(ir.template).toEqual(['<div> </div>'])
35+
expect([...ir.template.keys()]).toEqual(['<div> </div>'])
3636

3737
const op = ir.block.dynamic.children[0].operation
3838
expect(op).toMatchObject({
@@ -68,7 +68,11 @@ describe('compiler: v-if', () => {
6868
)
6969
expect(code).matchSnapshot()
7070

71-
expect(ir.template).toEqual(['<div></div>', 'hello', '<p> </p>'])
71+
expect([...ir.template.keys()]).toEqual([
72+
'<div></div>',
73+
'hello',
74+
'<p> </p>',
75+
])
7276
expect(ir.block.effect).toEqual([])
7377
const op = ir.block.dynamic.children[0].operation as IfIRNode
7478
expect(op.positive.effect).toMatchObject([
@@ -103,7 +107,7 @@ describe('compiler: v-if', () => {
103107
`<div v-if="ok">hello</div><div v-if="ok">hello</div>`,
104108
)
105109
expect(code).matchSnapshot()
106-
expect(ir.template).toEqual(['<div>hello</div>'])
110+
expect([...ir.template.keys()]).toEqual(['<div>hello</div>'])
107111
expect(ir.block.returns).toEqual([0, 3])
108112
})
109113

@@ -113,7 +117,7 @@ describe('compiler: v-if', () => {
113117
test('v-if + v-else', () => {
114118
const { code, ir, helpers } = compileWithVIf(`<div v-if="ok"/><p v-else/>`)
115119
expect(code).matchSnapshot()
116-
expect(ir.template).toEqual(['<div></div>', '<p></p>'])
120+
expect([...ir.template.keys()]).toEqual(['<div></div>', '<p></p>'])
117121

118122
expect(helpers).contains('createIf')
119123
expect(ir.block.effect).lengthOf(0)
@@ -146,7 +150,7 @@ describe('compiler: v-if', () => {
146150
`<div v-if="ok"/><p v-else-if="orNot"/>`,
147151
)
148152
expect(code).matchSnapshot()
149-
expect(ir.template).toEqual(['<div></div>', '<p></p>'])
153+
expect([...ir.template.keys()]).toEqual(['<div></div>', '<p></p>'])
150154

151155
expect(ir.block.dynamic.children[0].operation).toMatchObject({
152156
type: IRNodeTypes.IF,
@@ -185,7 +189,7 @@ describe('compiler: v-if', () => {
185189
`<div v-if="ok"/><p v-else-if="orNot"/><template v-else>fine</template>`,
186190
)
187191
expect(code).matchSnapshot()
188-
expect(ir.template).toEqual(['<div></div>', '<p></p>', 'fine'])
192+
expect([...ir.template.keys()]).toEqual(['<div></div>', '<p></p>', 'fine'])
189193

190194
expect(ir.block.returns).toEqual([0])
191195
expect(ir.block.dynamic.children[0].operation).toMatchObject({
@@ -236,7 +240,7 @@ describe('compiler: v-if', () => {
236240
<div v-text="text" />
237241
`)
238242
expect(code).matchSnapshot()
239-
expect(ir.template).toEqual([
243+
expect([...ir.template.keys()]).toEqual([
240244
'<div></div>',
241245
'<!--foo-->',
242246
'<p></p>',

packages/compiler-vapor/__tests__/transforms/vSlot.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('compiler: transform slot', () => {
3535
const { ir, code } = compileWithSlots(`<Comp><div/></Comp>`)
3636
expect(code).toMatchSnapshot()
3737

38-
expect(ir.template).toEqual(['<div></div>'])
38+
expect([...ir.template.keys()]).toEqual(['<div></div>'])
3939
expect(ir.block.dynamic.children[0].operation).toMatchObject({
4040
type: IRNodeTypes.CREATE_COMPONENT_NODE,
4141
id: 1,
@@ -163,7 +163,7 @@ describe('compiler: transform slot', () => {
163163
)
164164
expect(code).toMatchSnapshot()
165165

166-
expect(ir.template).toEqual(['foo', 'bar', '<span></span>'])
166+
expect([...ir.template.keys()]).toEqual(['foo', 'bar', '<span></span>'])
167167
expect(ir.block.dynamic.children[0].operation).toMatchObject({
168168
type: IRNodeTypes.CREATE_COMPONENT_NODE,
169169
id: 4,

packages/compiler-vapor/__tests__/transforms/vText.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('v-text', () => {
6868
])
6969

7070
// children should have been removed
71-
expect(ir.template).toEqual(['<div> </div>'])
71+
expect([...ir.template.keys()]).toEqual(['<div> </div>'])
7272

7373
expect(ir.block.effect).toMatchObject([
7474
{

packages/compiler-vapor/src/generators/template.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import { genOperationWithInsertionState } from './operation'
55
import { type CodeFragment, NEWLINE, buildCodeFragment, genCall } from './utils'
66

77
export function genTemplates(
8-
templates: string[],
8+
templates: Map<string, number>,
99
rootIndex: number | undefined,
10-
{ helper, ir: { templateNS } }: CodegenContext,
10+
{ helper }: CodegenContext,
1111
): string {
12-
return templates
13-
.map((template, i) => {
14-
const ns = templateNS.get(template)
15-
return `const t${i} = ${helper('template')}(${JSON.stringify(
12+
const result: string[] = []
13+
let i = 0
14+
templates.forEach((ns, template) => {
15+
result.push(
16+
`const t${i} = ${helper('template')}(${JSON.stringify(
1617
template,
17-
)}${i === rootIndex ? ', true' : ns ? ', false' : ''}${ns ? `, ${ns}` : ''})\n`
18-
})
19-
.join('')
18+
)}${i === rootIndex ? ', true' : ns ? ', false' : ''}${ns ? `, ${ns}` : ''})\n`,
19+
)
20+
i++
21+
})
22+
return result.join('')
2023
}
2124

2225
export function genSelf(

0 commit comments

Comments
 (0)