mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
Merge pull request #17354 from weswigham/fix-parameter-parsing-infinite-loop
Fix parameter parsing infinite loop
This commit is contained in:
@@ -2214,6 +2214,7 @@ namespace ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
const startPos = scanner.getStartPos();
|
||||
node.decorators = parseDecorators();
|
||||
node.modifiers = parseModifiers();
|
||||
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
@@ -2237,14 +2238,13 @@ namespace ts {
|
||||
node.type = parseParameterType();
|
||||
node.initializer = parseBindingElementInitializer(/*inParameter*/ true);
|
||||
|
||||
// Do not check for initializers in an ambient context for parameters. This is not
|
||||
// a grammar error because the grammar allows arbitrary call signatures in
|
||||
// an ambient context.
|
||||
// It is actually not necessary for this to be an error at all. The reason is that
|
||||
// function/constructor implementations are syntactically disallowed in ambient
|
||||
// contexts. In addition, parameter initializers are semantically disallowed in
|
||||
// overload signatures. So parameter initializers are transitively disallowed in
|
||||
// ambient contexts.
|
||||
if (startPos === scanner.getStartPos()) {
|
||||
// What we're parsing isn't actually remotely recognizable as a parameter and we've consumed no tokens whatsoever
|
||||
// Consume a token to advance the parser in some way and avoid an infinite loop in `parseDelimitedList`
|
||||
// This can happen when we're speculatively parsing parenthesized expressions which we think may be arrow functions,
|
||||
// or when a modifier keyword which is disallowed as a parameter name (ie, `static` in strict mode) is supplied
|
||||
nextToken();
|
||||
}
|
||||
|
||||
return addJSDocComment(finishNode(node));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineNew.ts(1,2): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineNew.ts(1,2): error TS2695: Left side of comma operator is unused and has no side effects.
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineNew.ts(2,4): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/parseCommaSeperatedNewlineNew.ts (3 errors) ====
|
||||
(a,
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2695: Left side of comma operator is unused and has no side effects.
|
||||
new)
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [parseCommaSeperatedNewlineNew.ts]
|
||||
(a,
|
||||
new)
|
||||
|
||||
//// [parseCommaSeperatedNewlineNew.js]
|
||||
(a,
|
||||
new );
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineNumber.ts(1,2): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineNumber.ts(1,2): error TS2695: Left side of comma operator is unused and has no side effects.
|
||||
|
||||
|
||||
==== tests/cases/compiler/parseCommaSeperatedNewlineNumber.ts (2 errors) ====
|
||||
(a,
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2695: Left side of comma operator is unused and has no side effects.
|
||||
1)
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [parseCommaSeperatedNewlineNumber.ts]
|
||||
(a,
|
||||
1)
|
||||
|
||||
//// [parseCommaSeperatedNewlineNumber.js]
|
||||
(a,
|
||||
1);
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineString.ts(1,2): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/parseCommaSeperatedNewlineString.ts(1,2): error TS2695: Left side of comma operator is unused and has no side effects.
|
||||
|
||||
|
||||
==== tests/cases/compiler/parseCommaSeperatedNewlineString.ts (2 errors) ====
|
||||
(a,
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2695: Left side of comma operator is unused and has no side effects.
|
||||
'')
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [parseCommaSeperatedNewlineString.ts]
|
||||
(a,
|
||||
'')
|
||||
|
||||
//// [parseCommaSeperatedNewlineString.js]
|
||||
(a,
|
||||
'');
|
||||
2
tests/cases/compiler/parseCommaSeperatedNewlineNew.ts
Normal file
2
tests/cases/compiler/parseCommaSeperatedNewlineNew.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
(a,
|
||||
new)
|
||||
2
tests/cases/compiler/parseCommaSeperatedNewlineNumber.ts
Normal file
2
tests/cases/compiler/parseCommaSeperatedNewlineNumber.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
(a,
|
||||
1)
|
||||
2
tests/cases/compiler/parseCommaSeperatedNewlineString.ts
Normal file
2
tests/cases/compiler/parseCommaSeperatedNewlineString.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
(a,
|
||||
'')
|
||||
Reference in New Issue
Block a user