File tree 2 files changed +37
-0
lines changed
test/unit/modules/compiler
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -454,6 +454,18 @@ function processOnce (el) {
454
454
function processSlot ( el ) {
455
455
if ( el . tag === 'slot' ) {
456
456
el . slotName = getBindingAttr ( el , 'name' )
457
+ // Fixes: #9038
458
+ if ( process . env . NODE_ENV !== 'production' ) {
459
+ const slotName = el . attrsMap [ 'name' ]
460
+ if ( ! dirRE . test ( slotName ) && parseText ( slotName , delimiters ) ) {
461
+ warn (
462
+ `name="${ slotName } ": ` +
463
+ 'Interpolation inside attributes has been removed. ' +
464
+ 'Use v-bind or the colon shorthand instead. For example, ' +
465
+ `instead of <slot name="{{ val }}">, use <slot :name="val">.`
466
+ )
467
+ }
468
+ }
457
469
if ( process . env . NODE_ENV !== 'production' && el . key ) {
458
470
warn (
459
471
`\`key\` does not work on <slot> because slots are abstract outlets ` +
Original file line number Diff line number Diff line change @@ -737,4 +737,29 @@ describe('parser', () => {
737
737
const ast = parse ( `<p>{{\r\nmsg\r\n}}</p>` , baseOptions )
738
738
expect ( ast . children [ 0 ] . expression ) . toBe ( '_s(msg)' )
739
739
} )
740
+
741
+ // #9038
742
+ it ( 'should warn if interpolation is used in slot name attribute' , ( ) => {
743
+ parse ( `
744
+ <div class="wrapper">
745
+ <slot name="line-{{ index }}"></slot>
746
+ </div>` , baseOptions )
747
+
748
+ expect ( 'name="line-{{ index }}": Interpolation inside attributes has been removed. ' +
749
+ 'Use v-bind or the colon shorthand instead. ' +
750
+ 'For example, instead of <slot name="{{ val }}">, use <slot :name="val">.' )
751
+ . toHaveBeenWarned ( )
752
+ } )
753
+
754
+ it ( 'should not warn if interpolation is not used in slot name attribute' , ( ) => {
755
+ parse ( `
756
+ <div class="wrapper">
757
+ <slot :name="'line-' + index"></slot>
758
+ </div>` , baseOptions )
759
+
760
+ expect ( 'name="line-{{ index }}": Interpolation inside attributes has been removed. ' +
761
+ 'Use v-bind or the colon shorthand instead. ' +
762
+ 'For example, instead of <slot name="{{ val }}">, use <slot :name="val">.' )
763
+ . not . toHaveBeenWarned ( )
764
+ } )
740
765
} )
You can’t perform that action at this time.
0 commit comments