@@ -1446,6 +1446,8 @@ namespace Parser {
1446
1446
let identifiers: Map<string, string>;
1447
1447
let identifierCount: number;
1448
1448
1449
+ // TODO(jakebailey): This type is a lie; this value actually contains the result
1450
+ // of ORing a bunch of `1 << ParsingContext.XYZ`.
1449
1451
let parsingContext: ParsingContext;
1450
1452
1451
1453
let notParenthesizedArrow: Set<number> | undefined;
@@ -2824,9 +2826,13 @@ namespace Parser {
2824
2826
return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.OpenBraceToken;
2825
2827
case ParsingContext.JsxChildren:
2826
2828
return true;
2829
+ case ParsingContext.StandaloneJSDoc:
2830
+ return true;
2831
+ case ParsingContext.Count:
2832
+ return Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
2833
+ default:
2834
+ Debug.assertNever(parsingContext, "Non-exhaustive case in 'isListElement'.");
2827
2835
}
2828
-
2829
- return Debug.fail("Non-exhaustive case in 'isListElement'.");
2830
2836
}
2831
2837
2832
2838
function isValidHeritageClauseObjectLiteral() {
@@ -2962,6 +2968,9 @@ namespace Parser {
2962
2968
2963
2969
// True if positioned at element or terminator of the current list or any enclosing list
2964
2970
function isInSomeParsingContext(): boolean {
2971
+ // We should be in at least one parsing context, be it SourceElements while parsing
2972
+ // a SourceFile, or StandaloneJSDoc when lazily parsing JSDoc.
2973
+ Debug.assert(parsingContext, "Missing parsing context");
2965
2974
for (let kind = 0; kind < ParsingContext.Count; kind++) {
2966
2975
if (parsingContext & (1 << kind)) {
2967
2976
if (isListElement(kind, /*inErrorRecovery*/ true) || isListTerminator(kind)) {
@@ -3078,6 +3087,7 @@ namespace Parser {
3078
3087
case ParsingContext.VariableDeclarations:
3079
3088
case ParsingContext.JSDocParameters:
3080
3089
case ParsingContext.Parameters:
3090
+ case ParsingContext.StandaloneJSDoc: // TODO(jakebailey): is it?
3081
3091
return true;
3082
3092
}
3083
3093
return false;
@@ -3337,6 +3347,7 @@ namespace Parser {
3337
3347
case ParsingContext.JsxAttributes: return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
3338
3348
case ParsingContext.JsxChildren: return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
3339
3349
case ParsingContext.AssertEntries: return parseErrorAtCurrentToken(Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
3350
+ case ParsingContext.StandaloneJSDoc: return; // TODO(jakebailey): any error here?
3340
3351
case ParsingContext.Count: return Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
3341
3352
default: Debug.assertNever(context);
3342
3353
}
@@ -7210,6 +7221,8 @@ namespace Parser {
7210
7221
7211
7222
function tryReuseAmbientDeclaration(pos: number): Statement | undefined {
7212
7223
return doInsideOfContext(NodeFlags.Ambient, () => {
7224
+ // TODO(jakebailey): this is totally wrong; `parsingContext` is the result of ORing a bunch of `1 << ParsingContext.XYZ`.
7225
+ // The enum should really be a bunch of flags.
7213
7226
const node = currentNode(parsingContext, pos);
7214
7227
if (node) {
7215
7228
return consumeNode(node) as Statement;
@@ -8397,7 +8410,8 @@ namespace Parser {
8397
8410
TupleElementTypes, // Element types in tuple element type list
8398
8411
HeritageClauses, // Heritage clauses for a class or interface declaration.
8399
8412
ImportOrExportSpecifiers, // Named import clause's import specifier list,
8400
- AssertEntries, // Import entries list.
8413
+ AssertEntries, // Import entries list.
8414
+ StandaloneJSDoc, // TODO(jakebailey): describe
8401
8415
Count // Number of parsing contexts
8402
8416
}
8403
8417
@@ -8503,6 +8517,15 @@ namespace Parser {
8503
8517
}
8504
8518
8505
8519
function parseJSDocCommentWorker(start = 0, length: number | undefined): JSDoc | undefined {
8520
+ const saveParsingContext = parsingContext;
8521
+ parsingContext |= 1 << ParsingContext.StandaloneJSDoc;
8522
+ const jsdoc = parseJSDocCommentWorkerWorker(start, length);
8523
+ parsingContext = saveParsingContext;
8524
+ return jsdoc;
8525
+ }
8526
+
8527
+ // TODO(jakebailey): name
8528
+ function parseJSDocCommentWorkerWorker(start: number, length: number | undefined): JSDoc | undefined {
8506
8529
const content = sourceText;
8507
8530
const end = length === undefined ? content.length : start + length;
8508
8531
length = end - start;
0 commit comments