@@ -11,6 +11,7 @@ import type {
1111 SvelteSpreadAttribute ,
1212 SvelteTransitionDirective ,
1313 SvelteStartTag ,
14+ SvelteName ,
1415} from "../../ast"
1516import type ESTree from "estree"
1617import type { Context } from "../../context"
@@ -399,9 +400,12 @@ function processDirective<
399400 node : D & { expression : null | E } ,
400401 directive : S ,
401402 ctx : Context ,
402- processExpression : ( expression : E ) => ScriptLetCallback < NonNullable < E > > [ ] ,
403+ processExpression : (
404+ expression : E ,
405+ shorthand : boolean ,
406+ ) => ScriptLetCallback < NonNullable < E > > [ ] ,
403407 processName ?: (
404- expression : ESTree . Identifier ,
408+ expression : SvelteName ,
405409 ) => ScriptLetCallback < ESTree . Identifier > [ ] ,
406410) {
407411 const colonIndex = ctx . code . indexOf ( ":" , directive . range [ 0 ] )
@@ -444,15 +448,22 @@ function processDirective<
444448 keyEndIndex = nextEnd
445449 }
446450
447- let isShorthand = false
451+ let isShorthandExpression = false
448452
449453 if ( node . expression ) {
450- isShorthand =
454+ isShorthandExpression =
451455 node . expression . type === "Identifier" &&
452456 node . expression . name === node . name &&
453- getWithLoc ( node . expression ) . start === nameRange . start &&
454- getWithLoc ( node . expression ) . end === nameRange . end
455- processExpression ( node . expression ) . push ( ( es ) => {
457+ getWithLoc ( node . expression ) . start === nameRange . start
458+ if (
459+ isShorthandExpression &&
460+ getWithLoc ( node . expression ) . end !== nameRange . end
461+ ) {
462+ // The identifier location may be incorrect in some edge cases.
463+ // e.g. bind:value=""
464+ getWithLoc ( node . expression ) . end = nameRange . end
465+ }
466+ processExpression ( node . expression , isShorthandExpression ) . push ( ( es ) => {
456467 directive . expression = es
457468 } )
458469 }
@@ -467,12 +478,12 @@ function processDirective<
467478
468479 // put name
469480 key . name = {
470- type : "Identifier " ,
481+ type : "SvelteName " ,
471482 name : node . name ,
472483 parent : key ,
473484 ...ctx . getConvertLocation ( nameRange ) ,
474485 }
475- if ( ! isShorthand ) {
486+ if ( ! isShorthandExpression ) {
476487 if ( processName ) {
477488 processName ( key . name ) . push ( ( es ) => {
478489 key . name = es
0 commit comments