Skip to content

Commit

Permalink
feat: replace instance creation with object literal in template compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
meixg committed May 24, 2022
1 parent 10cd768 commit 7a59118
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compilers/renderer-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class RendererCompiler {
body.push(STATEMENT(new CreateComponentPrototype(info)))
}
// context
body.push(this.compileGenInstance(info))
body.push(DEF('instance', new CreateComponentInstance(info)))
body.push(...this.compileTemplateComponentContext())
body.push(...this.emitInitData())
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/target-js/js-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ export class JSEmitter extends Emitter {
this.write(')')
break
case SyntaxKind.CreateComponentInstance:
this.write(`_.createFromPrototype(sanSSRResolver.getPrototype("${node.info.id}"));`)
if (node.info.componentType === 'template') {
this.write(`{initData: sanSSRResolver.getPrototype("${node.info.id}").initData};`)
} else {
this.write(`_.createFromPrototype(sanSSRResolver.getPrototype("${node.info.id}"));`)
}
break
case SyntaxKind.CreateComponentPrototype:
this.write(`if (!sanSSRResolver.getPrototype("${node.info.id}")) {`)
Expand Down

0 comments on commit 7a59118

Please sign in to comment.