Skip to content

Commit

Permalink
fix: emit comment 处理 interpExpr 的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Dec 27, 2021
1 parent 2e12b1d commit 2fda583
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/compilers/anode-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,8 @@ export class ANodeCompiler {
break
}

assert(!TypeGuards.isExprInterpNode(c.textExpr))

if (!c.textExpr.value || c.textExpr.value.trim() !== '') {
const textExprValue = TypeGuards.isExprInterpNode(c.textExpr) ? (c.textExpr.expr as StringLiteral).value : c.textExpr.value
if (!textExprValue || textExprValue.trim() !== '') {
return true
}
i++
Expand Down
24 changes: 24 additions & 0 deletions test/unit/compilers/renderer-compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ describe('compilers/renderer-compiler', () => {
const compiler = new RendererCompiler({})
const body = [...compiler.compileToRenderer(sourceFile.componentInfos[0]).body]

const assignmentNode = body.find(item =>
item.kind === SyntaxKind.AssignmentStatement &&
item.rhs.kind === SyntaxKind.SlotRendererDefinition
) as AssignmentStatement
expect(assignmentNode).toBeTruthy()
const SlotRendererDefinitionNode = assignmentNode.rhs as SlotRendererDefinition
expect([...SlotRendererDefinitionNode.body].find(item => {
return item.kind === SyntaxKind.ExpressionStatement &&
item.value.kind === SyntaxKind.BinaryExpression &&
item.value.rhs.kind === SyntaxKind.Literal &&
item.value.rhs.value.indexOf('s-slot') !== -1
})).toBeTruthy()
})
it('should emit slot comment(with filter)', () => {
const ComponentClass = defineComponent({
components: {
ccc: defineComponent({ template: '<div><slot/></div>' })
},
template: '<ccc>{{ \nassa | aaa | bbb}}</ccc>'
})
const sourceFile = new ComponentClassParser(ComponentClass, '/tmp/foo.js').parse()
const compiler = new RendererCompiler({})
const body = [...compiler.compileToRenderer(sourceFile.componentInfos[0]).body]

const assignmentNode = body.find(item =>
item.kind === SyntaxKind.AssignmentStatement &&
item.rhs.kind === SyntaxKind.SlotRendererDefinition
Expand Down

0 comments on commit 2fda583

Please sign in to comment.