Skip to content

Commit

Permalink
chore: annotate generated slot flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 30, 2020
1 parent 5f2a853 commit e41b46c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
default: _withId(() => [
_createVNode(\\"div\\")
]),
_: 1
_: 1 /* STABLE */
}))
})"
`;
Expand All @@ -41,7 +41,7 @@ const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
const _component_Child = _resolveComponent(\\"Child\\")
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 2 }, [
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
(_ctx.ok)
? {
name: \\"foo\\",
Expand Down Expand Up @@ -76,7 +76,7 @@ export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
bar: _withId(() => [
_createVNode(\\"div\\")
]),
_: 1
_: 1 /* STABLE */
}))
})"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ return function render(_ctx, _cache) {
default: _withCtx(({ foo }) => [
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */)
]),
_: 1
_: 1 /* STABLE */
}))
}
}"
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]: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
[_ctx.two]: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]),
_: 2
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */))
}"
`;
Expand All @@ -24,7 +24,7 @@ return function render(_ctx, _cache) {
default: _withCtx(() => [
_createVNode(\\"div\\")
]),
_: 1
_: 1 /* STABLE */
}))
}"
`;
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({ _: 2 }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
_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({ _: 2 }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
(_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({ _: 2 }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
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({ _: 2 }, [
return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
ok
? {
name: \\"one\\",
Expand All @@ -128,7 +128,7 @@ return function render(_ctx, _cache) {
\\"bar\\",
_createVNode(\\"span\\")
]),
_: 1
_: 1 /* STABLE */
}))
}
}"
Expand All @@ -145,14 +145,14 @@ return function render(_ctx, _cache) {
default: _withCtx(({ foo }) => [
_createVNode(_component_Inner, null, {
default: _withCtx(({ bar }) => [_toDisplayString(foo), _toDisplayString(bar), _toDisplayString(_ctx.baz)]),
_: 2
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */),
\\" \\",
_toDisplayString(foo),
_toDisplayString(_ctx.bar),
_toDisplayString(_ctx.baz)
]),
_: 1
_: 1 /* STABLE */
}))
}"
`;
Expand All @@ -165,7 +165,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
[_ctx.named]: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
_: 2
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */))
}"
`;
Expand All @@ -178,7 +178,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
named: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
_: 1
_: 1 /* STABLE */
}))
}"
`;
Expand All @@ -191,7 +191,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
default: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
_: 1
_: 1 /* STABLE */
}))
}"
`;
Expand All @@ -205,7 +205,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
one: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
two: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]),
_: 1
_: 1 /* STABLE */
}))
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ describe('compiler: element transform', () => {
fallback: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_: `[1]`
_: `[1 /* STABLE */]`
})
: createObjectMatcher({
default: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_: `[1]`
_: `[1 /* STABLE */]`
})
})
}
Expand Down Expand Up @@ -389,7 +389,7 @@ describe('compiler: element transform', () => {
default: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_: `[1]`
_: `[1 /* STABLE */]`
})
})
}
Expand Down
15 changes: 9 additions & 6 deletions packages/compiler-core/__tests__/transforms/vSlot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function createSlotMatcher(obj: Record<string, any>, isDynamic = false) {
})
.concat({
key: { content: `_` },
value: { content: isDynamic ? `2` : `1`, isStatic: false }
value: {
content: isDynamic ? `2 /* DYNAMIC */` : `1 /* STABLE */`,
isStatic: false
}
})
}
}
Expand Down Expand Up @@ -531,7 +534,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_: `[2]`
_: `[2 /* DYNAMIC */]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -573,7 +576,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_: `[2]`
_: `[2 /* DYNAMIC */]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -622,7 +625,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_: `[2]`
_: `[2 /* DYNAMIC */]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -681,7 +684,7 @@ describe('compiler: transform component slots', () => {
callee: CREATE_SLOTS,
arguments: [
createObjectMatcher({
_: `[2]`
_: `[2 /* DYNAMIC */]`
}),
{
type: NodeTypes.JS_ARRAY_EXPRESSION,
Expand Down Expand Up @@ -730,7 +733,7 @@ describe('compiler: transform component slots', () => {
},
{
key: { content: `_` },
value: { content: `3` } // forwarded
value: { content: `3 /* FORWARDED */` }
}
]
})
Expand Down
7 changes: 5 additions & 2 deletions packages/compiler-core/src/transforms/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '../utils'
import { CREATE_SLOTS, RENDER_LIST, WITH_CTX } from '../runtimeHelpers'
import { parseForExpression, createForLoopParams } from './vFor'
import { SlotFlags } from '@vue/shared'
import { SlotFlags, slotFlagsText } from '@vue/shared'

const defaultFallback = createSimpleExpression(`undefined`, false)

Expand Down Expand Up @@ -334,7 +334,10 @@ export function buildSlots(
`_`,
// 2 = compiled but dynamic = can skip normalization, but must run diff
// 1 = compiled and static = can skip normalization AND diff as optimized
createSimpleExpression('' + slotFlag, false)
createSimpleExpression(
slotFlag + (__DEV__ ? ` /* ${slotFlagsText[slotFlag]} */` : ``),
false
)
)
),
loc
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 @@ -59,7 +59,7 @@ describe('ssr: components', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
}"
`)
Expand All @@ -84,7 +84,7 @@ describe('ssr: components', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
}"
`)
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('ssr: components', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
}"
`)
Expand All @@ -140,7 +140,7 @@ describe('ssr: components', () => {
return function ssrRender(_ctx, _push, _parent, _attrs) {
const _component_foo = _resolveComponent(\\"foo\\")
_push(_ssrRenderComponent(_component_foo, _attrs, _createSlots({ _: 2 }, [
_push(_ssrRenderComponent(_component_foo, _attrs, _createSlots({ _: 2 /* DYNAMIC */ }, [
(_ctx.ok)
? {
name: \\"named\\",
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('ssr: components', () => {
return function ssrRender(_ctx, _push, _parent, _attrs) {
const _component_foo = _resolveComponent(\\"foo\\")
_push(_ssrRenderComponent(_component_foo, _attrs, _createSlots({ _: 2 }, [
_push(_ssrRenderComponent(_component_foo, _attrs, _createSlots({ _: 2 /* DYNAMIC */ }, [
_renderList(_ctx.names, (key) => {
return {
name: key,
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('ssr: components', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
}"
`)
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-ssr/__tests__/ssrInjectCssVars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('ssr: inject <style vars>', () => {
default: () => {
_push(\`<div\${_ssrRenderAttrs(_cssVars)}>ok</div>\`)
},
_: 1
_: 1 /* STABLE */
})
}"
`)
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 @@ -45,7 +45,7 @@ describe('ssr: scopeId', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
})"
`)
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('ssr: scopeId', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
})"
`)
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('ssr: scopeId', () => {
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
} else {
return [
Expand All @@ -119,12 +119,12 @@ describe('ssr: scopeId', () => {
default: _withId(() => [
_createVNode(\\"span\\")
]),
_: 1
_: 1 /* STABLE */
})
]
}
}),
_: 1
_: 1 /* STABLE */
}, _parent))
})"
`)
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-ssr/__tests__/ssrSuspense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('ssr compile: suspense', () => {
default: () => {
_push(_ssrRenderComponent(_component_foo, null, null, _parent))
},
_: 1
_: 1 /* STABLE */
})
}"
`)
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('ssr compile: suspense', () => {
fallback: () => {
_push(\` loading... \`)
},
_: 1
_: 1 /* STABLE */
})
}"
`)
Expand Down
9 changes: 9 additions & 0 deletions packages/shared/src/slotFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ export const enum SlotFlags {
*/
FORWARDED = 3
}

/**
* Dev only
*/
export const slotFlagsText = {
[SlotFlags.STABLE]: 'STABLE',
[SlotFlags.DYNAMIC]: 'DYNAMIC',
[SlotFlags.FORWARDED]: 'FORWARDED'
}

0 comments on commit e41b46c

Please sign in to comment.