Skip to content

Commit 06beee1

Browse files
committed
Much simpler fix, rolls in really old fix, removed unused comment
1 parent 7040df2 commit 06beee1

1 file changed

Lines changed: 9 additions & 29 deletions

File tree

src/compiler/parser.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,11 +1881,6 @@ namespace ts {
18811881
if (considerSemicolonAsDelimiter && token() === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) {
18821882
nextToken();
18831883
}
1884-
else if (isJSDocParameterStart() && parsingContext & (1 << ParsingContext.Parameters)) {
1885-
// If the token was a jsdoc parameter start and we're parsing parameter lists,
1886-
// we need to consume the (mostly erroneous) parameter token
1887-
nextToken();
1888-
}
18891884
continue;
18901885
}
18911886

@@ -2207,11 +2202,7 @@ namespace ts {
22072202
return token() === SyntaxKind.DotDotDotToken ||
22082203
isIdentifierOrPattern() ||
22092204
isModifierKind(token()) ||
2210-
token() === SyntaxKind.AtToken || token() === SyntaxKind.ThisKeyword || isJSDocParameterStart();
2211-
}
2212-
2213-
function isJSDocParameterStart(): boolean {
2214-
return token() === SyntaxKind.NewKeyword ||
2205+
token() === SyntaxKind.AtToken || token() === SyntaxKind.ThisKeyword || token() === SyntaxKind.NewKeyword ||
22152206
token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral;
22162207
}
22172208

@@ -2230,30 +2221,19 @@ namespace ts {
22302221
// FormalParameter [Yield,Await]:
22312222
// BindingElement[?Yield,?Await]
22322223
node.name = parseIdentifierOrPattern();
2233-
if (getFullWidth(node.name) === 0 && !hasModifiers(node) && isModifierKind(token())) {
2234-
// in cases like
2235-
// 'use strict'
2236-
// function foo(static)
2237-
// isParameter('static') === true, because of isModifier('static')
2238-
// however 'static' is not a legal identifier in a strict mode.
2239-
// so result of this function will be ParameterDeclaration (flags = 0, name = missing, type = undefined, initializer = undefined)
2240-
// and current token will not change => parsing of the enclosing parameter list will last till the end of time (or OOM)
2241-
// to avoid this we'll advance cursor to the next token.
2242-
nextToken();
2243-
}
22442224

22452225
node.questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
22462226
node.type = parseParameterType();
22472227
node.initializer = parseBindingElementInitializer(/*inParameter*/ true);
22482228

2249-
// Do not check for initializers in an ambient context for parameters. This is not
2250-
// a grammar error because the grammar allows arbitrary call signatures in
2251-
// an ambient context.
2252-
// It is actually not necessary for this to be an error at all. The reason is that
2253-
// function/constructor implementations are syntactically disallowed in ambient
2254-
// contexts. In addition, parameter initializers are semantically disallowed in
2255-
// overload signatures. So parameter initializers are transitively disallowed in
2256-
// ambient contexts.
2229+
const zeroLengthName = getFullWidth(node.name) === 0;
2230+
if (zeroLengthName && !node.type && !node.initializer && !node.decorators && !node.modifiers && !node.dotDotDotToken && !node.questionToken) {
2231+
// What we're parsing isn't actually remotely recognizable as a parameter and we've consumed no tokens whatsoever
2232+
// Consume a token to advance the parser in some way and avoid an infinite loop in `parseDelimitedList`
2233+
// This can happen when we're speculatively parsing parenthesized expressions which we think may be arrow functions,
2234+
// or when a modifier keyword which is disallowed as a parameter name (ie, `static` in strict mode) is supplied
2235+
nextToken();
2236+
}
22572237

22582238
return addJSDocComment(finishNode(node));
22592239
}

0 commit comments

Comments
 (0)