@@ -104,6 +104,9 @@ export function transformAST(
104
104
rootVars : string [ ]
105
105
importedHelpers : string [ ]
106
106
} {
107
+ // TODO remove when out of experimental
108
+ warnExperimental ( )
109
+
107
110
const importedHelpers = new Set < string > ( )
108
111
const rootScope : Scope = { }
109
112
const scopeStack : Scope [ ] = [ rootScope ]
@@ -148,7 +151,12 @@ export function transformAST(
148
151
if ( stmt . declare ) continue
149
152
for ( const decl of stmt . declarations ) {
150
153
let toVarCall
151
- if ( decl . init && ( toVarCall = isToVarCall ( decl . init ) ) ) {
154
+ if (
155
+ decl . init &&
156
+ decl . init . type === 'CallExpression' &&
157
+ decl . init . callee . type === 'Identifier' &&
158
+ ( toVarCall = isToVarCall ( decl . init . callee . name ) )
159
+ ) {
152
160
processRefDeclaration (
153
161
toVarCall ,
154
162
decl . init as CallExpression ,
@@ -369,18 +377,38 @@ export function transformAST(
369
377
}
370
378
}
371
379
372
- const toVarCall = isToVarCall ( node )
373
- if ( toVarCall && ( ! parent || parent . type !== 'VariableDeclarator' ) ) {
374
- return error (
375
- `${ toVarCall } can only be used as the initializer of ` +
376
- `a variable declaration.` ,
377
- node
378
- )
379
- }
380
+ if ( node . type === 'CallExpression' && node . callee . type === 'Identifier' ) {
381
+ const callee = node . callee . name
380
382
381
- if ( isToRefCall ( node ) ) {
382
- s . remove ( node . callee . start ! + offset , node . callee . end ! + offset )
383
- return this . skip ( )
383
+ const toVarCall = isToVarCall ( callee )
384
+ if ( toVarCall && ( ! parent || parent . type !== 'VariableDeclarator' ) ) {
385
+ return error (
386
+ `${ toVarCall } can only be used as the initializer of ` +
387
+ `a variable declaration.` ,
388
+ node
389
+ )
390
+ }
391
+
392
+ if ( callee === TO_REF_SYMBOL ) {
393
+ s . remove ( node . callee . start ! + offset , node . callee . end ! + offset )
394
+ return this . skip ( )
395
+ }
396
+
397
+ // TODO remove when out of experimental
398
+ if ( callee === '$raw' ) {
399
+ error (
400
+ `$raw() has been replaced by $$(). ` +
401
+ `See ${ RFC_LINK } for latest updates.` ,
402
+ node
403
+ )
404
+ }
405
+ if ( callee === '$fromRef' ) {
406
+ error (
407
+ `$fromRef() has been replaced by $(). ` +
408
+ `See ${ RFC_LINK } for latest updates.` ,
409
+ node
410
+ )
411
+ }
384
412
}
385
413
} ,
386
414
leave ( node : Node , parent ?: Node ) {
@@ -401,11 +429,7 @@ export function transformAST(
401
429
}
402
430
}
403
431
404
- function isToVarCall ( node : Node ) : string | false {
405
- if ( node . type !== 'CallExpression' || node . callee . type !== 'Identifier' ) {
406
- return false
407
- }
408
- const callee = node . callee . name
432
+ function isToVarCall ( callee : string ) : string | false {
409
433
if ( callee === TO_VAR_SYMBOL ) {
410
434
return TO_VAR_SYMBOL
411
435
}
@@ -415,9 +439,33 @@ function isToVarCall(node: Node): string | false {
415
439
return false
416
440
}
417
441
418
- function isToRefCall ( node : Node ) : node is CallExpression {
419
- return (
420
- node . type === 'CallExpression' &&
421
- ( node . callee as Identifier ) . name === TO_REF_SYMBOL
442
+ const RFC_LINK = `https://github.com/vuejs/rfcs/discussions/369`
443
+ const hasWarned : Record < string , boolean > = { }
444
+
445
+ function warnExperimental ( ) {
446
+ // eslint-disable-next-line
447
+ if ( typeof window !== 'undefined' ) {
448
+ return
449
+ }
450
+ warnOnce (
451
+ `@vue/ref-transform is an experimental feature.\n` +
452
+ `Experimental features may change behavior between patch versions.\n` +
453
+ `It is recommended to pin your vue dependencies to exact versions to avoid breakage.\n` +
454
+ `You can follow the proposal's status at ${ RFC_LINK } .`
455
+ )
456
+ }
457
+
458
+ function warnOnce ( msg : string ) {
459
+ const isNodeProd =
460
+ typeof process !== 'undefined' && process . env . NODE_ENV === 'production'
461
+ if ( ! isNodeProd && ! __TEST__ && ! hasWarned [ msg ] ) {
462
+ hasWarned [ msg ] = true
463
+ warn ( msg )
464
+ }
465
+ }
466
+
467
+ function warn ( msg : string ) {
468
+ console . warn (
469
+ `\x1b[1m\x1b[33m[@vue/compiler-sfc]\x1b[0m\x1b[33m ${ msg } \x1b[0m\n`
422
470
)
423
471
}
0 commit comments