@@ -202,7 +202,7 @@ void Scanner<EncodingPolicy>::SetText(EncodedCharPtr pszSrc, size_t offset, size
202202 m_startLine = lineNumber;
203203 m_pchStartLine = m_currentCharacter;
204204 m_ptoken->tk = tkNone;
205- m_fHtmlComments = (grfscr & fscrHtmlComments ) != 0 ;
205+ m_fIsModuleCode = (grfscr & fscrIsModuleCode ) != 0 ;
206206 m_fHadEol = FALSE ;
207207 m_fSyntaxColor = (grfscr & fscrSyntaxColor) != 0 ;
208208 m_DeferredParseFlags = ScanFlagNone;
@@ -1614,6 +1614,8 @@ tokens Scanner<EncodingPolicy>::SkipComment(EncodedCharPtr *pp, /* out */ bool*
16141614 return tkNone;
16151615 }
16161616 break ;
1617+
1618+ // ES 2015 11.3 Line Terminators
16171619 case kchLS: // 0x2028, classifies as new line
16181620 case kchPS: // 0x2029, classifies as new line
16191621LEcmaLineBreak:
@@ -1756,6 +1758,7 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
17561758 m_fHadEol = FALSE ;
17571759 CharTypes chType;
17581760 charcount_t commentStartLine;
1761+ bool seenDelimitedCommentEnd = false ;
17591762
17601763 if (m_scanState && *p != 0 )
17611764 {
@@ -1934,16 +1937,19 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
19341937 }
19351938 case ' (' : Assert (chType == _C_LPR); token = tkLParen; break ;
19361939 case ' )' : Assert (chType == _C_RPR); token = tkRParen; break ;
1937- case ' ,' : Assert (chType == _C_CMA); token = tkComma; break ;
1940+ case ' ,' : Assert (chType == _C_CMA); token = tkComma; break ;
19381941 case ' ;' : Assert (chType == _C_SMC); token = tkSColon; break ;
19391942 case ' [' : Assert (chType == _C_LBR); token = tkLBrack; break ;
19401943 case ' ]' : Assert (chType == _C_RBR); token = tkRBrack; break ;
1941- case ' ~' : Assert (chType == _C_TIL); token = tkTilde; break ;
1942- case ' ?' : Assert (chType == _C_QUE); token = tkQMark; break ;
1943- case ' {' : Assert (chType == _C_LC); token = tkLCurly; break ;
1944+ case ' ~' : Assert (chType == _C_TIL); token = tkTilde; break ;
1945+ case ' ?' : Assert (chType == _C_QUE); token = tkQMark; break ;
1946+ case ' {' : Assert (chType == _C_LC); token = tkLCurly; break ;
19441947
1948+ // ES 2015 11.3 Line Terminators
19451949 case ' \r ' :
19461950 case ' \n ' :
1951+ // kchLS:
1952+ // kchPS:
19471953LNewLine:
19481954 m_currentCharacter = p;
19491955 ScanNewLine (ch);
@@ -2087,36 +2093,11 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
20872093 case ' -' :
20882094 p++;
20892095 token = tkDec;
2090- if (m_fHtmlComments )
2096+ if (!m_fIsModuleCode )
20912097 {
2092- int i = 0 ;
2093- while (' -' == PeekFirst (p + i, last)) // Have already seen --, skip any further - characters
2094- i++;
2095- if (' >' == PeekFirst (p + i++, last)) // This means we've got a --------------------------->.
2098+ if (' >' == PeekFirst (p, last) && (m_fHadEol || seenDelimitedCommentEnd)) // --> HTMLCloseComment
20962099 {
2097- // If that precedes an EOF or }NWL (disregarding whitespace), then it is a comment.
2098- OLECHAR nextChar;
2099- nextChar = NextNonWhiteChar (&p[i], last);
2100- if (nextChar == 0 )
2101- {
2102- // Treat the -----------------------------> EOF as if it were EOF
2103- token = tkEOF;
2104- ++p;
2105- }
2106- else if (nextChar == ' }' )
2107- {
2108- CharTypes nextNextCharType = this ->charClassifier ->GetCharType (NextNonWhiteCharPlusOne (&p[i], last));
2109- if (nextNextCharType == _C_NWL
2110- // Corner case: If we have reached the end of the source, either we are at the end of the file or the end of
2111- // a deferred function. We treat this case as NWL.
2112- // TODO(tcare): Update to ES6 spec. Tracked in Bug 1164686
2113- || (last == m_pchLast && nextNextCharType == _C_NUL))
2114- {
2115- // Treat the -----------------------------> }NWL as if it were }NWL
2116- p += i;
2117- continue ;
2118- }
2119- }
2100+ goto LSkipLineComment;
21202101 }
21212102 }
21222103 break ;
@@ -2155,7 +2136,7 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
21552136 case ' /' :
21562137 if (p >= last)
21572138 {
2158- AssertMsg (m_fHtmlComments , " Do we have other line comment cases scanning pass last?" );
2139+ AssertMsg (!m_fIsModuleCode , " Do we have other line comment cases scanning pass last?" );
21592140
21602141 // Effective source length may have excluded HTMLCommentSuffix "//... -->". If we are scanning
21612142 // those, we have passed "last" already. Move back and return EOF.
@@ -2251,6 +2232,7 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
22512232 // of deciding whether to defer AST and byte code generation.
22522233 m_parser->ReduceDeferredScriptLength ((ULONG)(pchT - m_pchMinTok));
22532234 p = pchT;
2235+ seenDelimitedCommentEnd = true ;
22542236 goto LLoop;
22552237 }
22562238 p = pchT;
@@ -2286,7 +2268,8 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
22862268 }
22872269 break ;
22882270 case ' !' :
2289- if (m_fHtmlComments && PeekFirst (p + 1 , last) == ' -' && PeekFirst (p + 2 , last) == ' -' )
2271+ // ES 2015 B.1.3 - HTML comments are only allowed when parsing non-module code.
2272+ if (!m_fIsModuleCode && PeekFirst (p + 1 , last) == ' -' && PeekFirst (p + 2 , last) == ' -' )
22902273 {
22912274 // This is a "<!--" comment - treat as //
22922275 if (p >= last)
0 commit comments