Skip to content

Commit 5913e01

Browse files
committed
wip: whitespace behavior compat
1 parent 091e6d6 commit 5913e01

File tree

5 files changed

+76
-53
lines changed

5 files changed

+76
-53
lines changed

packages/runtime-core/src/compat/compatConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const enum DeprecationTypes {
2424
CONFIG_KEY_CODES = 'CONFIG_KEY_CODES',
2525
CONFIG_PRODUCTION_TIP = 'CONFIG_PRODUCTION_TIP',
2626
CONFIG_IGNORED_ELEMENTS = 'CONFIG_IGNORED_ELEMENTS',
27+
CONFIG_WHITESPACE = 'CONFIG_WHITESPACE',
2728

2829
INSTANCE_SET = 'INSTANCE_SET',
2930
INSTANCE_DELETE = 'INSTANCE_DELETE',
@@ -162,6 +163,15 @@ const deprecationData: Record<DeprecationTypes, DeprecationData> = {
162163
link: `https://v3.vuejs.org/guide/migration/global-api.html#config-ignoredelements-is-now-config-iscustomelement`
163164
},
164165

166+
[DeprecationTypes.CONFIG_WHITESPACE]: {
167+
// this warning is only relevant in the full build when using runtime
168+
// compilation, so it's put in the runtime compatConfig list.
169+
message:
170+
`Vue 3 compiler's whitespace option will default to "condense" instead of ` +
171+
`"preserve". To suppress this warning, provide an explicit value for ` +
172+
`\`config.compilerOptions.whitespace\`.`
173+
},
174+
165175
[DeprecationTypes.INSTANCE_SET]: {
166176
message:
167177
`vm.$set() has been removed as it is no longer needed in Vue 3. ` +

packages/runtime-core/src/compat/global.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ export function createCompatVue(
141141
// copy over global config mutations
142142
isCopyingConfig = true
143143
for (const key in singletonApp.config) {
144+
if (key === 'isNativeTag') continue
144145
if (
145-
key !== 'isNativeTag' &&
146-
!(key === 'isCustomElement' && isRuntimeOnly())
146+
isRuntimeOnly() &&
147+
(key === 'isCustomElement' || key === 'compilerOptions')
147148
) {
148-
// @ts-ignore
149-
app.config[key] = singletonApp.config[key]
149+
continue
150150
}
151+
// @ts-ignore
152+
app.config[key] = singletonApp.config[key]
151153
}
152154
isCopyingConfig = false
153155

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This entry exports the runtime only, and is built as
2+
// `dist/vue.esm-bundler.js` which is used by default for bundlers.
3+
import { initDev } from './dev'
4+
import {
5+
compatUtils,
6+
createApp,
7+
Transition,
8+
TransitionGroup,
9+
KeepAlive,
10+
DeprecationTypes,
11+
vShow,
12+
vModelDynamic
13+
} from '@vue/runtime-dom'
14+
import { extend } from '@vue/shared'
15+
16+
if (__DEV__) {
17+
initDev()
18+
}
19+
20+
import * as runtimeDom from '@vue/runtime-dom'
21+
22+
function wrappedCreateApp(...args: any[]) {
23+
// @ts-ignore
24+
const app = createApp(...args)
25+
if (compatUtils.isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, null)) {
26+
// register built-in components so that they can be resolved via strings
27+
// in the legacy h() call. The __compat__ prefix is to ensure that v3 h()
28+
// doesn't get affected.
29+
app.component('__compat__transition', Transition)
30+
app.component('__compat__transition-group', TransitionGroup)
31+
app.component('__compat__keep-alive', KeepAlive)
32+
// built-in directives. No need for prefix since there's no render fn API
33+
// for resolving directives via string in v3.
34+
app._context.directives.show = vShow
35+
app._context.directives.model = vModelDynamic
36+
}
37+
return app
38+
}
39+
40+
export function createCompatVue() {
41+
const Vue = compatUtils.createCompatVue(wrappedCreateApp)
42+
extend(Vue, runtimeDom)
43+
// @ts-ignore
44+
Vue.createApp = wrappedCreateApp
45+
return Vue
46+
}

packages/vue-compat/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// This entry is the "full-build" that includes both the runtime
22
// and the compiler, and supports on-the-fly compilation of the template option.
3-
import { initDev } from './dev'
3+
import { createCompatVue } from './createCompatVue'
44
import { compile, CompilerError, CompilerOptions } from '@vue/compiler-dom'
55
import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
66
import { isString, NOOP, generateCodeFrame, extend } from '@vue/shared'
77
import { InternalRenderFunction } from 'packages/runtime-core/src/component'
88
import * as runtimeDom from '@vue/runtime-dom'
9-
import Vue from './runtime'
10-
11-
if (__DEV__) {
12-
initDev()
13-
}
9+
import {
10+
DeprecationTypes,
11+
warnDeprecation
12+
} from '../../runtime-core/src/compat/compatConfig'
1413

1514
const compileCache: Record<string, RenderFunction> = Object.create(null)
1615

@@ -45,11 +44,16 @@ function compileToFunction(
4544
template = el ? el.innerHTML : ``
4645
}
4746

47+
if (__DEV__ && !__TEST__ && (!options || !options.whitespace)) {
48+
warnDeprecation(DeprecationTypes.CONFIG_WHITESPACE, null)
49+
}
50+
4851
const { code } = compile(
4952
template,
5053
extend(
5154
{
5255
hoistStatic: true,
56+
whitespace: 'preserve',
5357
onError: __DEV__ ? onError : undefined,
5458
onWarn: __DEV__ ? e => onError(e, true) : NOOP
5559
} as CompilerOptions,
@@ -87,6 +91,7 @@ function compileToFunction(
8791

8892
registerRuntimeCompiler(compileToFunction)
8993

94+
const Vue = createCompatVue()
9095
Vue.compile = compileToFunction
9196

9297
export default Vue

packages/vue-compat/src/runtime.ts

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,9 @@
11
// This entry exports the runtime only, and is built as
22
// `dist/vue.esm-bundler.js` which is used by default for bundlers.
3-
import { initDev } from './dev'
4-
import {
5-
compatUtils,
6-
createApp,
7-
warn,
8-
Transition,
9-
TransitionGroup,
10-
KeepAlive,
11-
DeprecationTypes,
12-
vShow,
13-
vModelDynamic
14-
} from '@vue/runtime-dom'
15-
import { extend } from '@vue/shared'
3+
import { createCompatVue } from './createCompatVue'
4+
import { warn } from '@vue/runtime-core'
165

17-
if (__DEV__) {
18-
initDev()
19-
}
20-
21-
import * as runtimeDom from '@vue/runtime-dom'
22-
23-
function wrappedCreateApp(...args: any[]) {
24-
// @ts-ignore
25-
const app = createApp(...args)
26-
if (compatUtils.isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, null)) {
27-
// register built-in components so that they can be resolved via strings
28-
// in the legacy h() call. The __compat__ prefix is to ensure that v3 h()
29-
// doesn't get affected.
30-
app.component('__compat__transition', Transition)
31-
app.component('__compat__transition-group', TransitionGroup)
32-
app.component('__compat__keep-alive', KeepAlive)
33-
// built-in directives. No need for prefix since there's no render fn API
34-
// for resolving directives via string in v3.
35-
app._context.directives.show = vShow
36-
app._context.directives.model = vModelDynamic
37-
}
38-
return app
39-
}
40-
41-
const Vue = compatUtils.createCompatVue(wrappedCreateApp)
6+
const Vue = createCompatVue()
427

438
Vue.compile = (() => {
449
if (__DEV__) {
@@ -55,9 +20,4 @@ Vue.compile = (() => {
5520
}
5621
}) as any
5722

58-
extend(Vue, runtimeDom)
59-
60-
// @ts-ignore
61-
Vue.createApp = wrappedCreateApp
62-
6323
export default Vue

0 commit comments

Comments
 (0)