@@ -36,7 +36,14 @@ export interface SFCScriptCompileOptions {
36
36
refSugar ?: boolean
37
37
}
38
38
39
- let hasWarned = false
39
+ const hasWarned : Record < string , boolean > = { }
40
+
41
+ function warnOnce ( msg : string ) {
42
+ if ( ! hasWarned [ msg ] ) {
43
+ hasWarned [ msg ] = true
44
+ console . log ( `\n\x1b[33m[@vue/compiler-sfc] %s\x1b[0m\n` , msg )
45
+ }
46
+ }
40
47
41
48
/**
42
49
* Compile `<script setup>`
@@ -49,12 +56,10 @@ export function compileScript(
49
56
) : SFCScriptBlock {
50
57
const { script, scriptSetup, styles, source, filename } = sfc
51
58
52
- if ( __DEV__ && ! __TEST__ && ! hasWarned && scriptSetup ) {
53
- hasWarned = true
54
- // @ts -ignore `console.info` cannot be null error
55
- console [ console . info ? 'info' : 'log' ] (
56
- `\n[@vue/compiler-sfc] <script setup> is still an experimental proposal.\n` +
57
- `Follow https://github.com/vuejs/rfcs/pull/182 for its status.\n`
59
+ if ( __DEV__ && ! __TEST__ && scriptSetup ) {
60
+ warnOnce (
61
+ `<script setup> is still an experimental proposal.\n` +
62
+ `Follow https://github.com/vuejs/rfcs/pull/227 for its status.`
58
63
)
59
64
}
60
65
@@ -450,17 +455,30 @@ export function compileScript(
450
455
451
456
// process `ref: x` bindings (convert to refs)
452
457
if (
453
- enableRefSugar &&
454
458
node . type === 'LabeledStatement' &&
455
459
node . label . name === 'ref' &&
456
460
node . body . type === 'ExpressionStatement'
457
461
) {
458
- s . overwrite (
459
- node . label . start ! + startOffset ,
460
- node . body . start ! + startOffset ,
461
- 'const '
462
- )
463
- processRefExpression ( node . body . expression , node )
462
+ if ( enableRefSugar ) {
463
+ warnOnce (
464
+ `ref: sugar is still an experimental proposal and is not\n` +
465
+ `guaranteed to be a part of <script setup>.\n` +
466
+ `Follow its status at https://github.com/vuejs/rfcs/pull/228`
467
+ )
468
+ s . overwrite (
469
+ node . label . start ! + startOffset ,
470
+ node . body . start ! + startOffset ,
471
+ 'const '
472
+ )
473
+ processRefExpression ( node . body . expression , node )
474
+ } else {
475
+ // TODO if we end up shipping ref: sugar as an opt-in feature,
476
+ // need to proxy the option in vite, vue-loader and rollup-plugin-vue.
477
+ error (
478
+ `ref: sugar needs to be explicitly enabled via vite or vue-loader options.` ,
479
+ node
480
+ )
481
+ }
464
482
}
465
483
466
484
if ( node . type === 'ImportDeclaration' ) {
@@ -487,13 +505,16 @@ export function compileScript(
487
505
}
488
506
}
489
507
490
- if ( node . type === 'ExportNamedDeclaration' && node . exportKind !== 'type' ) {
491
- // TODO warn
492
- error ( `<script setup> cannot contain non-type named exports.` , node )
493
- }
494
-
495
- if ( node . type === 'ExportAllDeclaration' ) {
496
- // TODO warn
508
+ if (
509
+ ( node . type === 'ExportNamedDeclaration' && node . exportKind !== 'type' ) ||
510
+ node . type === 'ExportAllDeclaration'
511
+ ) {
512
+ error (
513
+ `<script setup> cannot contain non-type named or * exports. ` +
514
+ `If you are using a previous version of <script setup>, please ` +
515
+ `consult the updated RFC at https://github.com/vuejs/rfcs/pull/227.` ,
516
+ node
517
+ )
497
518
}
498
519
499
520
if ( node . type === 'ExportDefaultDeclaration' ) {
0 commit comments