1
1
import { is_html , is_svg , is_void } from '../../../shared/utils/names.js' ;
2
2
import Node from './shared/Node.js' ;
3
+ import { walk } from 'estree-walker' ;
3
4
import Attribute from './Attribute.js' ;
4
5
import Binding from './Binding.js' ;
5
6
import EventHandler from './EventHandler.js' ;
@@ -430,7 +431,7 @@ export default class Element extends Node {
430
431
}
431
432
if ( this . name === 'textarea' ) {
432
433
if ( info . children . length > 0 ) {
433
- const value_attribute = info . attributes . find ( ( node ) => node . name === 'value' ) ;
434
+ const value_attribute = get_value_attribute ( info . attributes ) ;
434
435
if ( value_attribute ) {
435
436
component . error ( value_attribute , compiler_errors . textarea_duplicate_value ) ;
436
437
return ;
@@ -449,7 +450,7 @@ export default class Element extends Node {
449
450
// Special case — treat these the same way:
450
451
// <option>{foo}</option>
451
452
// <option value={foo}>{foo}</option>
452
- const value_attribute = info . attributes . find ( ( attribute ) => attribute . name === 'value' ) ;
453
+ const value_attribute = get_value_attribute ( info . attributes ) ;
453
454
if ( ! value_attribute ) {
454
455
info . attributes . push ( {
455
456
type : 'Attribute' ,
@@ -1420,3 +1421,30 @@ function within_custom_element(parent) {
1420
1421
}
1421
1422
return false ;
1422
1423
}
1424
+
1425
+ /**
1426
+ * @param {any[] } attributes
1427
+ */
1428
+ function get_value_attribute ( attributes ) {
1429
+ let node_value ;
1430
+ attributes . forEach ( ( node ) => {
1431
+ if ( node . type !== 'Spread' && node . name . toLowerCase ( ) === 'value' ) {
1432
+ node_value = node ;
1433
+ }
1434
+ if ( node . type === 'Spread' ) {
1435
+ walk ( /** @type {any } */ ( node . expression ) , {
1436
+ enter ( /** @type {import('estree').Node } */ node ) {
1437
+ if ( node_value ) {
1438
+ this . skip ( ) ;
1439
+ }
1440
+ if ( node . type === 'Identifier' ) {
1441
+ if ( /** @type {import('estree').Identifier } */ ( node ) . name . toLowerCase ( ) === 'value' ) {
1442
+ node_value = node ;
1443
+ }
1444
+ }
1445
+ }
1446
+ } ) ;
1447
+ }
1448
+ } ) ;
1449
+ return node_value ;
1450
+ }
0 commit comments