wip: filters compat

This commit is contained in:
Evan You
2021-04-19 12:08:26 -04:00
parent 467076361a
commit 7dc681c196
18 changed files with 349 additions and 41 deletions

View File

@@ -56,7 +56,9 @@ export const enum DeprecationTypes {
COMPONENT_FUNCTIONAL = 'COMPONENT_FUNCTIONAL',
COMPONENT_V_MODEL = 'COMPONENT_V_MODEL',
RENDER_FUNCTION = 'RENDER_FUNCTION'
RENDER_FUNCTION = 'RENDER_FUNCTION',
FILTERS = 'FILTERS'
}
type DeprecationData = {
@@ -392,6 +394,14 @@ const deprecationData: Record<DeprecationTypes, DeprecationData> = {
}: false })\n` +
`\n (This can also be done per-component via the "compatConfig" option.)`,
link: `https://v3.vuejs.org/guide/migration/render-function-api.html`
},
[DeprecationTypes.FILTERS]: {
message:
`filters have been removed in Vue 3. ` +
`The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
`Use method calls or computed properties instead.`,
link: `https://v3.vuejs.org/guide/migration/filters.html`
}
}

View File

@@ -0,0 +1,18 @@
import { App, AppContext } from '../apiCreateApp'
import { warn } from '../warning'
import { assertCompatEnabled, DeprecationTypes } from './compatConfig'
export function installGlobalFilterMethod(app: App, context: AppContext) {
context.filters = {}
app.filter = (name: string, filter?: Function): any => {
assertCompatEnabled(DeprecationTypes.FILTERS, null)
if (!filter) {
return context.filters![name]
}
if (__DEV__ && context.filters![name]) {
warn(`Filter "${name}" has already been registered.`)
}
context.filters![name] = filter
return app
}
}