Merge pull request #17354 from weswigham/fix-parameter-parsing-infinite-loop

Fix parameter parsing infinite loop
This commit is contained in:
Ron Buckton
2017-07-24 18:21:10 -07:00
committed by GitHub
10 changed files with 71 additions and 8 deletions

View File

@@ -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));
}

View File

@@ -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.

View File

@@ -0,0 +1,7 @@
//// [parseCommaSeperatedNewlineNew.ts]
(a,
new)
//// [parseCommaSeperatedNewlineNew.js]
(a,
new );

View File

@@ -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)

View File

@@ -0,0 +1,7 @@
//// [parseCommaSeperatedNewlineNumber.ts]
(a,
1)
//// [parseCommaSeperatedNewlineNumber.js]
(a,
1);

View File

@@ -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.
'')

View File

@@ -0,0 +1,7 @@
//// [parseCommaSeperatedNewlineString.ts]
(a,
'')
//// [parseCommaSeperatedNewlineString.js]
(a,
'');

View File

@@ -0,0 +1,2 @@
(a,
new)

View File

@@ -0,0 +1,2 @@
(a,
1)

View File

@@ -0,0 +1,2 @@
(a,
'')