Skip to content

Commit f30195a

Browse files
committed
Add Comment start state errors.
1 parent 7a3442f commit f30195a

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

lib/common/error_codes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ module.exports = {
1515
cdataInHtmlContent: 'cdata-in-html-content',
1616
malformedComment: 'malformed-comment',
1717
eofInScriptHtmlComment: 'eof-in-script-html-comment',
18-
nestedComment: 'nested-comment'
18+
nestedComment: 'nested-comment',
19+
abruptComment: 'abrupt-comment'
1920
};

lib/tokenizer/index.js

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,25 +1577,14 @@ _[COMMENT_START_STATE] = function commentStartState(cp) {
15771577
if (cp === $.HYPHEN_MINUS)
15781578
this.state = COMMENT_START_DASH_STATE;
15791579

1580-
else if (cp === $.NULL) {
1581-
this.currentToken.data += UNICODE.REPLACEMENT_CHARACTER;
1582-
this.state = COMMENT_STATE;
1583-
}
1584-
15851580
else if (cp === $.GREATER_THAN_SIGN) {
1581+
this._err(ERR.abruptComment);
15861582
this.state = DATA_STATE;
15871583
this._emitCurrentToken();
15881584
}
15891585

1590-
else if (cp === $.EOF) {
1591-
this._emitCurrentToken();
1592-
this._emitEOFToken();
1593-
}
1594-
1595-
else {
1596-
this.currentToken.data += toChar(cp);
1597-
this.state = COMMENT_STATE;
1598-
}
1586+
else
1587+
this._reconsumeInState(COMMENT_STATE);
15991588
};
16001589

16011590

@@ -1605,12 +1594,6 @@ _[COMMENT_START_DASH_STATE] = function commentStartDashState(cp) {
16051594
if (cp === $.HYPHEN_MINUS)
16061595
this.state = COMMENT_END_STATE;
16071596

1608-
else if (cp === $.NULL) {
1609-
this.currentToken.data += '-';
1610-
this.currentToken.data += UNICODE.REPLACEMENT_CHARACTER;
1611-
this.state = COMMENT_STATE;
1612-
}
1613-
16141597
else if (cp === $.GREATER_THAN_SIGN) {
16151598
this.state = DATA_STATE;
16161599
this._emitCurrentToken();
@@ -1623,8 +1606,7 @@ _[COMMENT_START_DASH_STATE] = function commentStartDashState(cp) {
16231606

16241607
else {
16251608
this.currentToken.data += '-';
1626-
this.currentToken.data += toChar(cp);
1627-
this.state = COMMENT_STATE;
1609+
this._reconsumeInState(COMMENT_STATE);
16281610
}
16291611
};
16301612

@@ -1707,21 +1689,14 @@ _[COMMENT_END_DASH_STATE] = function commentEndDashState(cp) {
17071689
if (cp === $.HYPHEN_MINUS)
17081690
this.state = COMMENT_END_STATE;
17091691

1710-
else if (cp === $.NULL) {
1711-
this.currentToken.data += '-';
1712-
this.currentToken.data += UNICODE.REPLACEMENT_CHARACTER;
1713-
this.state = COMMENT_STATE;
1714-
}
1715-
17161692
else if (cp === $.EOF) {
17171693
this._emitCurrentToken();
17181694
this._emitEOFToken();
17191695
}
17201696

17211697
else {
17221698
this.currentToken.data += '-';
1723-
this.currentToken.data += toChar(cp);
1724-
this.state = COMMENT_STATE;
1699+
this._reconsumeInState(COMMENT_STATE);
17251700
}
17261701
};
17271702

@@ -1740,21 +1715,14 @@ _[COMMENT_END_STATE] = function commentEndState(cp) {
17401715
else if (cp === $.HYPHEN_MINUS)
17411716
this.currentToken.data += '-';
17421717

1743-
else if (cp === $.NULL) {
1744-
this.currentToken.data += '--';
1745-
this.currentToken.data += UNICODE.REPLACEMENT_CHARACTER;
1746-
this.state = COMMENT_STATE;
1747-
}
1748-
17491718
else if (cp === $.EOF) {
17501719
this._emitCurrentToken();
17511720
this._emitEOFToken();
17521721
}
17531722

17541723
else {
17551724
this.currentToken.data += '--';
1756-
this.currentToken.data += toChar(cp);
1757-
this.state = COMMENT_STATE;
1725+
this._reconsumeInState(COMMENT_STATE);
17581726
}
17591727
};
17601728

@@ -1772,21 +1740,14 @@ _[COMMENT_END_BANG_STATE] = function commentEndBangState(cp) {
17721740
this._emitCurrentToken();
17731741
}
17741742

1775-
else if (cp === $.NULL) {
1776-
this.currentToken.data += '--!';
1777-
this.currentToken.data += UNICODE.REPLACEMENT_CHARACTER;
1778-
this.state = COMMENT_STATE;
1779-
}
1780-
17811743
else if (cp === $.EOF) {
17821744
this._emitCurrentToken();
17831745
this._emitEOFToken();
17841746
}
17851747

17861748
else {
17871749
this.currentToken.data += '--!';
1788-
this.currentToken.data += toChar(cp);
1789-
this.state = COMMENT_STATE;
1750+
this._reconsumeInState(COMMENT_STATE);
17901751
}
17911752
};
17921753

0 commit comments

Comments
 (0)