wip: better experimental feature warnings
This commit is contained in:
parent
9db42889e6
commit
62830f8fa4
@ -27,7 +27,7 @@ import { walk } from 'estree-walker'
|
|||||||
import { RawSourceMap } from 'source-map'
|
import { RawSourceMap } from 'source-map'
|
||||||
import { CSS_VARS_HELPER, genCssVarsCode, injectCssVarsCalls } from './cssVars'
|
import { CSS_VARS_HELPER, genCssVarsCode, injectCssVarsCalls } from './cssVars'
|
||||||
import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate'
|
import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate'
|
||||||
import { warnOnce } from './warn'
|
import { warnExperimental, warnOnce } from './warn'
|
||||||
|
|
||||||
const DEFINE_OPTIONS = 'defineOptions'
|
const DEFINE_OPTIONS = 'defineOptions'
|
||||||
|
|
||||||
@ -73,13 +73,8 @@ export function compileScript(
|
|||||||
): SFCScriptBlock {
|
): SFCScriptBlock {
|
||||||
const { script, scriptSetup, source, filename } = sfc
|
const { script, scriptSetup, source, filename } = sfc
|
||||||
|
|
||||||
if (__DEV__ && !__TEST__ && scriptSetup) {
|
if (scriptSetup) {
|
||||||
warnOnce(
|
warnExperimental(`<script setup>`, 227)
|
||||||
`<script setup> is still an experimental proposal.\n` +
|
|
||||||
`Follow its status at https://github.com/vuejs/rfcs/pull/227.\n` +
|
|
||||||
`It's also recommended to pin your vue dependencies to exact versions ` +
|
|
||||||
`to avoid breakage.`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for backwards compat
|
// for backwards compat
|
||||||
@ -523,15 +518,7 @@ export function compileScript(
|
|||||||
node.body.type === 'ExpressionStatement'
|
node.body.type === 'ExpressionStatement'
|
||||||
) {
|
) {
|
||||||
if (enableRefSugar) {
|
if (enableRefSugar) {
|
||||||
if (__DEV__ && !__TEST__) {
|
warnExperimental(`ref: sugar`, 228)
|
||||||
warnOnce(
|
|
||||||
`ref: sugar is still an experimental proposal and is not ` +
|
|
||||||
`guaranteed to be a part of <script setup>.\n` +
|
|
||||||
`Follow its status at https://github.com/vuejs/rfcs/pull/228.\n` +
|
|
||||||
`It's also recommended to pin your vue dependencies to exact versions ` +
|
|
||||||
`to avoid breakage.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
s.overwrite(
|
s.overwrite(
|
||||||
node.label.start! + startOffset,
|
node.label.start! + startOffset,
|
||||||
node.body.start! + startOffset,
|
node.body.start! + startOffset,
|
||||||
|
@ -11,6 +11,7 @@ import { RawSourceMap, SourceMapGenerator } from 'source-map'
|
|||||||
import { TemplateCompiler } from './compileTemplate'
|
import { TemplateCompiler } from './compileTemplate'
|
||||||
import { Statement } from '@babel/types'
|
import { Statement } from '@babel/types'
|
||||||
import { parseCssVars } from './cssVars'
|
import { parseCssVars } from './cssVars'
|
||||||
|
import { warnExperimental, warnOnce } from './warn'
|
||||||
|
|
||||||
export interface SFCParseOptions {
|
export interface SFCParseOptions {
|
||||||
filename?: string
|
filename?: string
|
||||||
@ -165,7 +166,14 @@ export function parse(
|
|||||||
errors.push(createDuplicateBlockError(node, isSetup))
|
errors.push(createDuplicateBlockError(node, isSetup))
|
||||||
break
|
break
|
||||||
case 'style':
|
case 'style':
|
||||||
descriptor.styles.push(createBlock(node, source, pad) as SFCStyleBlock)
|
const style = createBlock(node, source, pad) as SFCStyleBlock
|
||||||
|
if (style.attrs.vars) {
|
||||||
|
warnOnce(
|
||||||
|
`<style vars> has been replaced by a new proposal: ` +
|
||||||
|
`https://github.com/vuejs/rfcs/pull/231`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
descriptor.styles.push(style)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
descriptor.customBlocks.push(createBlock(node, source, pad))
|
descriptor.customBlocks.push(createBlock(node, source, pad))
|
||||||
@ -214,6 +222,9 @@ export function parse(
|
|||||||
|
|
||||||
// parse CSS vars
|
// parse CSS vars
|
||||||
descriptor.cssVars = parseCssVars(descriptor)
|
descriptor.cssVars = parseCssVars(descriptor)
|
||||||
|
if (descriptor.cssVars.length) {
|
||||||
|
warnExperimental(`v-bind() CSS variable injection`, 231)
|
||||||
|
}
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
descriptor,
|
descriptor,
|
||||||
|
@ -1,12 +1,27 @@
|
|||||||
const hasWarned: Record<string, boolean> = {}
|
const hasWarned: Record<string, boolean> = {}
|
||||||
|
|
||||||
export function warnOnce(msg: string) {
|
export function warnOnce(msg: string) {
|
||||||
if (!hasWarned[msg]) {
|
const isNodeProd =
|
||||||
|
typeof process !== 'undefined' && process.env.NODE_ENV === 'production'
|
||||||
|
if (!isNodeProd && !__TEST__ && !hasWarned[msg]) {
|
||||||
hasWarned[msg] = true
|
hasWarned[msg] = true
|
||||||
warn(msg)
|
warn(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function warn(msg: string) {
|
export function warn(msg: string) {
|
||||||
console.warn(`\x1b[33m[@vue/compiler-sfc] ${msg}\x1b[0m\n`)
|
console.warn(
|
||||||
|
`\x1b[1m\x1b[33m[@vue/compiler-sfc]\x1b[0m\x1b[33m ${msg}\x1b[0m\n`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function warnExperimental(feature: string, rfcId: number) {
|
||||||
|
warnOnce(
|
||||||
|
`${feature} is still an experimental proposal.\n` +
|
||||||
|
`Follow its status at https://github.com/vuejs/rfcs/pull/${rfcId}.`
|
||||||
|
)
|
||||||
|
warnOnce(
|
||||||
|
`When using experimental features,\n` +
|
||||||
|
`it is recommended to pin your vue dependencies to exact versions to avoid breakage.`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user