@ -14,7 +14,6 @@ import {
} from '../utils/ast.js' ;
import { is _reserved , is _rune } from '../../utils.js' ;
import { determine _slot } from '../utils/slot.js' ;
import { validate _identifier _name } from './2-analyze/visitors/shared/utils.js' ;
const UNKNOWN = Symbol ( 'unknown' ) ;
/** Includes `BigInt` */
@ -1507,3 +1506,41 @@ export function should_proxy(node, scope) {
return true ;
}
/ * *
* Checks if the name is valid , which it is when it 's not starting with (or is) a dollar sign or if it' s a function parameter .
* The second argument is the depth of the scope , which is there for backwards compatibility reasons : In Svelte 4 , you
* were allowed to define ` $ ` - prefixed variables anywhere below the top level of components . Once legacy mode is gone , this
* argument can be removed / the call sites adjusted accordingly .
* @ param { Binding | null } binding
* @ param { number | undefined } [ function _depth ]
* /
export function validate _identifier _name ( binding , function _depth ) {
if ( ! binding ) return ;
const declaration _kind = binding . declaration _kind ;
if (
declaration _kind !== 'synthetic' &&
declaration _kind !== 'param' &&
declaration _kind !== 'rest_param' &&
( ! function _depth || function _depth <= 1 )
) {
const node = binding . node ;
if ( node . name === '$' ) {
e . dollar _binding _invalid ( node ) ;
} else if (
node . name . startsWith ( '$' ) &&
// import type { $Type } from "" - these are normally already filtered out,
// but for the migration they aren't, and throwing here is preventing the migration to complete
// TODO -> once migration script is gone we can remove this check
! (
binding . initial ? . type === 'ImportDeclaration' &&
/** @type {any} */ ( binding . initial ) . importKind === 'type'
)
) {
e . dollar _prefix _invalid ( node ) ;
}
}
}