@@ -1448,61 +1448,64 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
1448
1448
}
1449
1449
}
1450
1450
1451
- if ( state . tag !== null && state . tag !== '!' ) {
1452
- if ( state . tag === '?' ) {
1453
- // Implicit resolving is not allowed for non-scalar types, and '?'
1454
- // non-specific tag is only automatically assigned to plain scalars.
1455
- //
1456
- // We only need to check kind conformity in case user explicitly assigns '?'
1457
- // tag, for example like this: "!<?> [0]"
1458
- //
1459
- if ( state . result !== null && state . kind !== 'scalar' ) {
1460
- throwError ( state , 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state . kind + '"' ) ;
1461
- }
1451
+ if ( state . tag === null ) {
1452
+ if ( state . anchor !== null ) {
1453
+ state . anchorMap [ state . anchor ] = state . result ;
1454
+ }
1462
1455
1463
- for ( typeIndex = 0 , typeQuantity = state . implicitTypes . length ; typeIndex < typeQuantity ; typeIndex += 1 ) {
1464
- type = state . implicitTypes [ typeIndex ] ;
1456
+ } else if ( state . tag === '?' ) {
1457
+ // Implicit resolving is not allowed for non-scalar types, and '?'
1458
+ // non-specific tag is only automatically assigned to plain scalars.
1459
+ //
1460
+ // We only need to check kind conformity in case user explicitly assigns '?'
1461
+ // tag, for example like this: "!<?> [0]"
1462
+ //
1463
+ if ( state . result !== null && state . kind !== 'scalar' ) {
1464
+ throwError ( state , 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state . kind + '"' ) ;
1465
+ }
1465
1466
1466
- if ( type . resolve ( state . result ) ) { // `state.result` updated in resolver if matched
1467
- state . result = type . construct ( state . result ) ;
1468
- state . tag = type . tag ;
1469
- if ( state . anchor !== null ) {
1470
- state . anchorMap [ state . anchor ] = state . result ;
1471
- }
1472
- break ;
1467
+ for ( typeIndex = 0 , typeQuantity = state . implicitTypes . length ; typeIndex < typeQuantity ; typeIndex += 1 ) {
1468
+ type = state . implicitTypes [ typeIndex ] ;
1469
+
1470
+ if ( type . resolve ( state . result ) ) { // `state.result` updated in resolver if matched
1471
+ state . result = type . construct ( state . result ) ;
1472
+ state . tag = type . tag ;
1473
+ if ( state . anchor !== null ) {
1474
+ state . anchorMap [ state . anchor ] = state . result ;
1473
1475
}
1476
+ break ;
1474
1477
}
1478
+ }
1479
+ } else if ( state . tag !== '!' ) {
1480
+ if ( _hasOwnProperty . call ( state . typeMap [ state . kind || 'fallback' ] , state . tag ) ) {
1481
+ type = state . typeMap [ state . kind || 'fallback' ] [ state . tag ] ;
1475
1482
} else {
1476
- if ( _hasOwnProperty . call ( state . typeMap [ state . kind || 'fallback' ] , state . tag ) ) {
1477
- type = state . typeMap [ state . kind || 'fallback' ] [ state . tag ] ;
1478
- } else {
1479
- // looking for multi type
1480
- type = null ;
1481
- typeList = state . typeMap . multi [ state . kind || 'fallback' ] ;
1482
-
1483
- for ( typeIndex = 0 , typeQuantity = typeList . length ; typeIndex < typeQuantity ; typeIndex += 1 ) {
1484
- if ( state . tag . slice ( 0 , typeList [ typeIndex ] . tag . length ) === typeList [ typeIndex ] . tag ) {
1485
- type = typeList [ typeIndex ] ;
1486
- break ;
1487
- }
1483
+ // looking for multi type
1484
+ type = null ;
1485
+ typeList = state . typeMap . multi [ state . kind || 'fallback' ] ;
1486
+
1487
+ for ( typeIndex = 0 , typeQuantity = typeList . length ; typeIndex < typeQuantity ; typeIndex += 1 ) {
1488
+ if ( state . tag . slice ( 0 , typeList [ typeIndex ] . tag . length ) === typeList [ typeIndex ] . tag ) {
1489
+ type = typeList [ typeIndex ] ;
1490
+ break ;
1488
1491
}
1489
1492
}
1493
+ }
1490
1494
1491
- if ( ! type ) {
1492
- throwError ( state , 'unknown tag !<' + state . tag + '>' ) ;
1493
- }
1495
+ if ( ! type ) {
1496
+ throwError ( state , 'unknown tag !<' + state . tag + '>' ) ;
1497
+ }
1494
1498
1495
- if ( state . result !== null && type . kind !== state . kind ) {
1496
- throwError ( state , 'unacceptable node kind for !<' + state . tag + '> tag; it should be "' + type . kind + '", not "' + state . kind + '"' ) ;
1497
- }
1499
+ if ( state . result !== null && type . kind !== state . kind ) {
1500
+ throwError ( state , 'unacceptable node kind for !<' + state . tag + '> tag; it should be "' + type . kind + '", not "' + state . kind + '"' ) ;
1501
+ }
1498
1502
1499
- if ( ! type . resolve ( state . result , state . tag ) ) { // `state.result` updated in resolver if matched
1500
- throwError ( state , 'cannot resolve a node with !<' + state . tag + '> explicit tag' ) ;
1501
- } else {
1502
- state . result = type . construct ( state . result , state . tag ) ;
1503
- if ( state . anchor !== null ) {
1504
- state . anchorMap [ state . anchor ] = state . result ;
1505
- }
1503
+ if ( ! type . resolve ( state . result , state . tag ) ) { // `state.result` updated in resolver if matched
1504
+ throwError ( state , 'cannot resolve a node with !<' + state . tag + '> explicit tag' ) ;
1505
+ } else {
1506
+ state . result = type . construct ( state . result , state . tag ) ;
1507
+ if ( state . anchor !== null ) {
1508
+ state . anchorMap [ state . anchor ] = state . result ;
1506
1509
}
1507
1510
}
1508
1511
}
0 commit comments