Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 8cef55e

Browse files
sxzzLittleSound
authored andcommitted
refactor
1 parent db3200c commit 8cef55e

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

packages/compiler-vapor/src/transforms/transformSlotOutlet.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,44 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
3737

3838
let name: SimpleExpressionNode | undefined
3939
const nonNameProps: (AttributeNode | DirectiveNode)[] = []
40-
const customDirectives: DirectiveNode[] = []
41-
for (const p of props) {
42-
if (p.type === NodeTypes.ATTRIBUTE) {
43-
if (p.value) {
44-
if (p.name === 'name') {
45-
name = createSimpleExpression(p.value.content, true, p.loc)
40+
const directives: DirectiveNode[] = []
41+
for (const prop of props) {
42+
if (prop.type === NodeTypes.ATTRIBUTE) {
43+
if (prop.value) {
44+
if (prop.name === 'name') {
45+
name = createSimpleExpression(prop.value.content, true, prop.loc)
4646
} else {
47-
p.name = camelize(p.name)
48-
nonNameProps.push(p)
47+
prop.name = camelize(prop.name)
48+
nonNameProps.push(prop)
4949
}
5050
}
51+
} else if (prop.name === 'bind' && isStaticArgOf(prop.arg, 'name')) {
52+
if (prop.exp) {
53+
name = (prop as VaporDirectiveNode).exp!
54+
} else if (prop.arg && prop.arg.type === NodeTypes.SIMPLE_EXPRESSION) {
55+
// v-bind shorthand syntax
56+
name = createSimpleExpression(
57+
camelize(prop.arg.content),
58+
false,
59+
prop.arg.loc,
60+
)
61+
name.ast = null
62+
}
63+
} else if (!isBuiltInDirective(prop.name)) {
64+
directives.push(prop)
5165
} else {
52-
if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
53-
if (p.exp) {
54-
name = (p as VaporDirectiveNode).exp!
55-
} else if (p.arg && p.arg.type === NodeTypes.SIMPLE_EXPRESSION) {
56-
// v-bind shorthand syntax
57-
name = createSimpleExpression(
58-
camelize(p.arg.content),
59-
false,
60-
p.arg.loc,
61-
)
62-
name.ast = null
63-
}
64-
} else {
65-
if (!isBuiltInDirective(p.name)) {
66-
customDirectives.push(p)
67-
} else {
68-
if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
69-
p.arg.content = camelize(p.arg.content)
70-
}
71-
nonNameProps.push(p)
72-
}
66+
if (prop.name === 'bind' && prop.arg && isStaticExp(prop.arg)) {
67+
prop.arg.content = camelize(prop.arg.content)
7368
}
69+
nonNameProps.push(prop)
7470
}
7571
}
7672

77-
if (customDirectives.length) {
73+
if (directives.length) {
7874
context.options.onError(
7975
createCompilerError(
8076
ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
81-
customDirectives[0].loc,
77+
directives[0].loc,
8278
),
8379
)
8480
}
@@ -109,9 +105,9 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
109105
function createFallback(
110106
node: ElementNode,
111107
context: TransformContext<ElementNode>,
112-
): [BlockIRNode | undefined, (() => void) | undefined] {
108+
): [block?: BlockIRNode, exit?: () => void] {
113109
if (!node.children.length) {
114-
return [undefined, undefined]
110+
return []
115111
}
116112

117113
context.node = node = extend({}, node, {

0 commit comments

Comments
 (0)