Skip to content

Commit

Permalink
refactor(compiler-core): use more concise marker for compiled slots
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 12, 2020
1 parent 175f8aa commit 1389d7b
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const render = _withId(function render(_ctx, _cache) {
default: _withId(() => [
_createVNode(\\"div\\")
]),
_compiled: true
_: 1
}))
})"
`;
Expand All @@ -41,7 +41,7 @@ const _withId = _withScopeId(\\"test\\")
export const render = _withId(function render(_ctx, _cache) {
const _component_Child = _resolveComponent(\\"Child\\")
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _compiled: true }, [
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 1 }, [
(_ctx.ok)
? {
name: \\"foo\\",
Expand Down Expand Up @@ -76,7 +76,7 @@ export const render = _withId(function render(_ctx, _cache) {
bar: _withId(() => [
_createVNode(\\"div\\")
]),
_compiled: true
_: 1
}))
})"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ return function render(_ctx, _cache) {
default: ({ foo }) => [
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */)
],
_compiled: true
_: 1
}))
}
}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
[_ctx.one]: ({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)],
[_ctx.two]: ({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)],
_compiled: true
_: 1
}, 512 /* DYNAMIC_SLOTS */))
}"
`;
Expand All @@ -24,7 +24,7 @@ return function render(_ctx, _cache) {
default: () => [
_createVNode(\\"div\\")
],
_compiled: true
_: 1
}))
}"
`;
Expand All @@ -35,7 +35,7 @@ exports[`compiler: transform component slots named slot with v-for w/ prefixIden
return function render(_ctx, _cache) {
const _component_Comp = _resolveComponent(\\"Comp\\")
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
_renderList(_ctx.list, (name) => {
return {
name: name,
Expand All @@ -52,7 +52,7 @@ exports[`compiler: transform component slots named slot with v-if + prefixIdenti
return function render(_ctx, _cache) {
const _component_Comp = _resolveComponent(\\"Comp\\")
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
(_ctx.ok)
? {
name: \\"one\\",
Expand All @@ -72,7 +72,7 @@ return function render(_ctx, _cache) {
const _component_Comp = _resolveComponent(\\"Comp\\")
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
ok
? {
name: \\"one\\",
Expand Down Expand Up @@ -101,7 +101,7 @@ return function render(_ctx, _cache) {
const _component_Comp = _resolveComponent(\\"Comp\\")
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
ok
? {
name: \\"one\\",
Expand All @@ -122,7 +122,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
one: ({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)],
two: ({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)],
_compiled: true
_: 1
}))
}"
`;
Expand All @@ -142,7 +142,7 @@ return function render(_ctx, _cache) {
\\"bar\\",
_createVNode(\\"span\\")
],
_compiled: true
_: 1
}))
}
}"
Expand All @@ -159,14 +159,14 @@ return function render(_ctx, _cache) {
default: ({ foo }) => [
_createVNode(_component_Inner, null, {
default: ({ bar }) => [_toDisplayString(foo), _toDisplayString(bar), _toDisplayString(_ctx.baz)],
_compiled: true
_: 1
}, 512 /* DYNAMIC_SLOTS */),
\\" \\",
_toDisplayString(foo),
_toDisplayString(_ctx.bar),
_toDisplayString(_ctx.baz)
],
_compiled: true
_: 1
}))
}"
`;
Expand All @@ -179,7 +179,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
default: ({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)],
_compiled: true
_: 1
}))
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ describe('compiler: element transform', () => {
fallback: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_compiled: `[true]`
_: `[1]`
})
: createObjectMatcher({
default: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_compiled: `[true]`
_: `[1]`
})
})
}
Expand Down Expand Up @@ -381,7 +381,7 @@ describe('compiler: element transform', () => {
default: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_compiled: `[true]`
_: `[1]`
})
})
}
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler-core/__tests__/transforms/vSlot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function createSlotMatcher(obj: Record<string, any>) {
} as any
})
.concat({
key: { content: `_compiled` },
value: { content: `true` }
key: { content: `_` },
value: { content: `1`, isStatic: false }
})
}
}
Expand Down Expand Up @@ -456,7 +456,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_compiled: `[true]`
_: `[1]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_compiled: `[true]`
_: `[1]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -547,7 +547,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_compiled: `[true]`
_: `[1]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -606,7 +606,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_compiled: `[true]`
_: `[1]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transforms/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export function buildSlots(

let slots = createObjectExpression(
slotsProperties.concat(
createObjectProperty(`_compiled`, createSimpleExpression(`true`, false))
createObjectProperty(`_`, createSimpleExpression(`1`, false))
),
loc
) as SlotsExpression
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler-ssr/__tests__/ssrComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('ssr: components', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand All @@ -86,7 +86,7 @@ describe('ssr: components', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('ssr: components', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand All @@ -142,7 +142,7 @@ describe('ssr: components', () => {
return function ssrRender(_ctx, _push, _parent) {
const _component_foo = _resolveComponent(\\"foo\\")
_push(_ssrRenderComponent(_component_foo, null, _createSlots({ _compiled: true }, [
_push(_ssrRenderComponent(_component_foo, null, _createSlots({ _: 1 }, [
(_ctx.ok)
? {
name: \\"named\\",
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('ssr: components', () => {
return function ssrRender(_ctx, _push, _parent) {
const _component_foo = _resolveComponent(\\"foo\\")
_push(_ssrRenderComponent(_component_foo, null, _createSlots({ _compiled: true }, [
_push(_ssrRenderComponent(_component_foo, null, _createSlots({ _: 1 }, [
_renderList(_ctx.names, (key) => {
return {
name: key,
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('ssr: components', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand Down
10 changes: 5 additions & 5 deletions packages/compiler-ssr/__tests__/ssrScopeId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('ssr: scopeId', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('ssr: scopeId', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('ssr: scopeId', () => {
]
}
},
_compiled: true
_: 1
}, _parent))
} else {
return [
Expand All @@ -109,12 +109,12 @@ describe('ssr: scopeId', () => {
default: () => [
_createVNode(\\"span\\")
],
_compiled: true
_: 1
})
]
}
},
_compiled: true
_: 1
}, _parent))
}"
`)
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type RawSlots = {
// manual render fn hint to skip forced children updates
$stable?: boolean
// internal, indicates compiler generated slots = can skip normalization
_compiled?: boolean
_?: 1
}

const normalizeSlotValue = (value: unknown): VNode[] =>
Expand Down Expand Up @@ -51,7 +51,7 @@ export function resolveSlots(
let slots: InternalSlots | void
if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
const rawSlots = children as RawSlots
if (rawSlots._compiled) {
if (rawSlots._ === 1) {
// pre-normalized slots object generated by compiler
slots = children as Slots
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function renderSlot(
Fragment,
{ key: props.key },
slot ? slot(props) : fallback || [],
slots._compiled ? 0 : PatchFlags.BAIL
slots._ ? 0 : PatchFlags.BAIL
)
)
}
2 changes: 1 addition & 1 deletion packages/server-renderer/__tests__/renderToString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('ssr: renderToString', () => {
push(`<span>${msg}</span>`)
},
// important to avoid slots being normalized
_compiled: true as any
_: 1 as any
},
parent
)
Expand Down

0 comments on commit 1389d7b

Please sign in to comment.