Skip to content

Commit b159bb9

Browse files
committed
Avoid code duplication for attribute reading.
1 parent 2ece567 commit b159bb9

File tree

1 file changed

+13
-78
lines changed

1 file changed

+13
-78
lines changed

lib/tokenizer/index.js

Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,56 +1333,32 @@ _[BEFORE_ATTRIBUTE_NAME_STATE] = function beforeAttributeNameState(cp) {
13331333
if (isWhitespace(cp))
13341334
return;
13351335

1336-
if (cp === $.SOLIDUS)
1337-
this.state = SELF_CLOSING_START_TAG_STATE;
1336+
if (cp === $.SOLIDUS || cp === $.GREATER_THAN_SIGN || cp === $.EOF)
1337+
this._reconsumeInState(AFTER_ATTRIBUTE_NAME_STATE);
13381338

1339-
else if (cp === $.GREATER_THAN_SIGN) {
1340-
this.state = DATA_STATE;
1341-
this._emitCurrentToken();
1342-
}
1343-
1344-
else if (isAsciiUpper(cp)) {
1345-
this._createAttr(toAsciiLowerChar(cp));
1339+
else if (cp === $.EQUALS_SIGN) {
1340+
this._createAttr('=');
13461341
this.state = ATTRIBUTE_NAME_STATE;
13471342
}
13481343

1349-
else if (cp === $.NULL) {
1350-
this._createAttr(UNICODE.REPLACEMENT_CHARACTER);
1351-
this.state = ATTRIBUTE_NAME_STATE;
1352-
}
1353-
1354-
else if (cp === $.QUOTATION_MARK || cp === $.APOSTROPHE || cp === $.LESS_THAN_SIGN || cp === $.EQUALS_SIGN) {
1355-
this._createAttr(toChar(cp));
1356-
this.state = ATTRIBUTE_NAME_STATE;
1357-
}
1358-
1359-
else if (cp === $.EOF)
1360-
this._reconsumeInState(DATA_STATE);
1361-
13621344
else {
1363-
this._createAttr(toChar(cp));
1364-
this.state = ATTRIBUTE_NAME_STATE;
1345+
this._createAttr('');
1346+
this._reconsumeInState(ATTRIBUTE_NAME_STATE);
13651347
}
13661348
};
13671349

13681350

13691351
//12.2.4.35 Attribute name state
13701352
//------------------------------------------------------------------
13711353
_[ATTRIBUTE_NAME_STATE] = function attributeNameState(cp) {
1372-
if (isWhitespace(cp))
1354+
if (isWhitespace(cp) || cp === $.SOLIDUS || cp === $.GREATER_THAN_SIGN || cp === $.EOF) {
13731355
this._leaveAttrName(AFTER_ATTRIBUTE_NAME_STATE);
1374-
1375-
else if (cp === $.SOLIDUS)
1376-
this._leaveAttrName(SELF_CLOSING_START_TAG_STATE);
1356+
this._unconsume();
1357+
}
13771358

13781359
else if (cp === $.EQUALS_SIGN)
13791360
this._leaveAttrName(BEFORE_ATTRIBUTE_VALUE_STATE);
13801361

1381-
else if (cp === $.GREATER_THAN_SIGN) {
1382-
this._leaveAttrName(DATA_STATE);
1383-
this._emitCurrentToken();
1384-
}
1385-
13861362
else if (isAsciiUpper(cp))
13871363
this.currentAttr.name += toAsciiLowerChar(cp);
13881364

@@ -1392,9 +1368,6 @@ _[ATTRIBUTE_NAME_STATE] = function attributeNameState(cp) {
13921368
else if (cp === $.NULL)
13931369
this.currentAttr.name += UNICODE.REPLACEMENT_CHARACTER;
13941370

1395-
else if (cp === $.EOF)
1396-
this._reconsumeInState(DATA_STATE);
1397-
13981371
else
13991372
this.currentAttr.name += toChar(cp);
14001373
};
@@ -1417,27 +1390,12 @@ _[AFTER_ATTRIBUTE_NAME_STATE] = function afterAttributeNameState(cp) {
14171390
this._emitCurrentToken();
14181391
}
14191392

1420-
else if (isAsciiUpper(cp)) {
1421-
this._createAttr(toAsciiLowerChar(cp));
1422-
this.state = ATTRIBUTE_NAME_STATE;
1423-
}
1424-
1425-
else if (cp === $.NULL) {
1426-
this._createAttr(UNICODE.REPLACEMENT_CHARACTER);
1427-
this.state = ATTRIBUTE_NAME_STATE;
1428-
}
1429-
1430-
else if (cp === $.QUOTATION_MARK || cp === $.APOSTROPHE || cp === $.LESS_THAN_SIGN) {
1431-
this._createAttr(toChar(cp));
1432-
this.state = ATTRIBUTE_NAME_STATE;
1433-
}
1434-
14351393
else if (cp === $.EOF)
14361394
this._reconsumeInState(DATA_STATE);
14371395

14381396
else {
1439-
this._createAttr(toChar(cp));
1440-
this.state = ATTRIBUTE_NAME_STATE;
1397+
this._createAttr('');
1398+
this._reconsumeInState(ATTRIBUTE_NAME_STATE);
14411399
}
14421400
};
14431401

@@ -1451,34 +1409,11 @@ _[BEFORE_ATTRIBUTE_VALUE_STATE] = function beforeAttributeValueState(cp) {
14511409
if (cp === $.QUOTATION_MARK)
14521410
this.state = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
14531411

1454-
else if (cp === $.AMPERSAND)
1455-
this._reconsumeInState(ATTRIBUTE_VALUE_UNQUOTED_STATE);
1456-
14571412
else if (cp === $.APOSTROPHE)
14581413
this.state = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
14591414

1460-
else if (cp === $.NULL) {
1461-
this.currentAttr.value += UNICODE.REPLACEMENT_CHARACTER;
1462-
this.state = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1463-
}
1464-
1465-
else if (cp === $.GREATER_THAN_SIGN) {
1466-
this.state = DATA_STATE;
1467-
this._emitCurrentToken();
1468-
}
1469-
1470-
else if (cp === $.LESS_THAN_SIGN || cp === $.EQUALS_SIGN || cp === $.GRAVE_ACCENT) {
1471-
this.currentAttr.value += toChar(cp);
1472-
this.state = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1473-
}
1474-
1475-
else if (cp === $.EOF)
1476-
this._reconsumeInState(DATA_STATE);
1477-
1478-
else {
1479-
this.currentAttr.value += toChar(cp);
1480-
this.state = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1481-
}
1415+
else
1416+
this._reconsumeInState(ATTRIBUTE_VALUE_UNQUOTED_STATE);
14821417
};
14831418

14841419

0 commit comments

Comments
 (0)