@@ -187,6 +187,7 @@ import {
187
187
JSDocOverloadTag,
188
188
JSDocOverrideTag,
189
189
JSDocParameterTag,
190
+ JSDocParsingMode,
190
191
JSDocPrivateTag,
191
192
JSDocPropertyLikeTag,
192
193
JSDocPropertyTag,
@@ -1318,16 +1319,14 @@ export interface CreateSourceFileOptions {
1318
1319
setExternalModuleIndicator?: (file: SourceFile) => void;
1319
1320
/** @internal */ packageJsonLocations?: readonly string[];
1320
1321
/** @internal */ packageJsonScope?: PackageJsonInfo;
1322
+ jsDocParsingMode?: JSDocParsingMode;
1321
1323
}
1322
1324
1323
1325
function setExternalModuleIndicator(sourceFile: SourceFile) {
1324
1326
sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile);
1325
1327
}
1326
1328
1327
- export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile;
1328
- /** @internal */
1329
- export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind, skipNonSemanticJSDoc?: boolean): SourceFile;
1330
- export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes = false, scriptKind?: ScriptKind, skipNonSemanticJSDoc?: boolean): SourceFile {
1329
+ export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes = false, scriptKind?: ScriptKind): SourceFile {
1331
1330
tracing?.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
1332
1331
performance.mark("beforeParse");
1333
1332
let result: SourceFile;
@@ -1337,16 +1336,17 @@ export function createSourceFile(fileName: string, sourceText: string, languageV
1337
1336
languageVersion,
1338
1337
setExternalModuleIndicator: overrideSetExternalModuleIndicator,
1339
1338
impliedNodeFormat: format,
1339
+ jsDocParsingMode,
1340
1340
} = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : ({ languageVersion: languageVersionOrOptions } as CreateSourceFileOptions);
1341
1341
if (languageVersion === ScriptTarget.JSON) {
1342
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON, noop, skipNonSemanticJSDoc );
1342
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON, noop, jsDocParsingMode );
1343
1343
}
1344
1344
else {
1345
1345
const setIndicator = format === undefined ? overrideSetExternalModuleIndicator : (file: SourceFile) => {
1346
1346
file.impliedNodeFormat = format;
1347
1347
return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file);
1348
1348
};
1349
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator, skipNonSemanticJSDoc );
1349
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator, jsDocParsingMode );
1350
1350
}
1351
1351
perfLogger?.logStopParseSourceFile();
1352
1352
@@ -1586,7 +1586,7 @@ namespace Parser {
1586
1586
setParentNodes = false,
1587
1587
scriptKind?: ScriptKind,
1588
1588
setExternalModuleIndicatorOverride?: (file: SourceFile) => void,
1589
- skipNonSemanticJSDoc?: boolean ,
1589
+ jsDocParsingMode = JSDocParsingMode.ParseAll ,
1590
1590
): SourceFile {
1591
1591
scriptKind = ensureScriptKind(fileName, scriptKind);
1592
1592
if (scriptKind === ScriptKind.JSON) {
@@ -1601,10 +1601,9 @@ namespace Parser {
1601
1601
return result;
1602
1602
}
1603
1603
1604
- skipNonSemanticJSDoc = !!skipNonSemanticJSDoc && scriptKind !== ScriptKind.JS && scriptKind !== ScriptKind.JSX;
1605
- initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind, skipNonSemanticJSDoc);
1604
+ initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind, jsDocParsingMode);
1606
1605
1607
- const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator, skipNonSemanticJSDoc );
1606
+ const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator, jsDocParsingMode );
1608
1607
1609
1608
clearState();
1610
1609
@@ -1613,7 +1612,7 @@ namespace Parser {
1613
1612
1614
1613
export function parseIsolatedEntityName(content: string, languageVersion: ScriptTarget): EntityName | undefined {
1615
1614
// Choice of `isDeclarationFile` should be arbitrary
1616
- initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
1615
+ initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS, JSDocParsingMode.ParseAll );
1617
1616
// Prime the scanner.
1618
1617
nextToken();
1619
1618
const entityName = parseEntityName(/*allowReservedWords*/ true);
@@ -1623,7 +1622,7 @@ namespace Parser {
1623
1622
}
1624
1623
1625
1624
export function parseJsonText(fileName: string, sourceText: string, languageVersion: ScriptTarget = ScriptTarget.ES2015, syntaxCursor?: IncrementalParser.SyntaxCursor, setParentNodes = false): JsonSourceFile {
1626
- initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON, /*skipNonSemanticJSDoc*/ false );
1625
+ initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON, JSDocParsingMode.ParseAll );
1627
1626
sourceFlags = contextFlags;
1628
1627
1629
1628
// Prime the scanner.
@@ -1711,7 +1710,7 @@ namespace Parser {
1711
1710
return result;
1712
1711
}
1713
1712
1714
- function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind, _skipNonSemanticJSDoc: boolean ) {
1713
+ function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind, _jsDocParsingMode: JSDocParsingMode ) {
1715
1714
NodeConstructor = objectAllocator.getNodeConstructor();
1716
1715
TokenConstructor = objectAllocator.getTokenConstructor();
1717
1716
IdentifierConstructor = objectAllocator.getIdentifierConstructor();
@@ -1752,15 +1751,17 @@ namespace Parser {
1752
1751
scanner.setOnError(scanError);
1753
1752
scanner.setScriptTarget(languageVersion);
1754
1753
scanner.setLanguageVariant(languageVariant);
1755
- scanner.setSkipNonSemanticJSDoc(_skipNonSemanticJSDoc);
1754
+ scanner.setScriptKind(scriptKind);
1755
+ scanner.setJSDocParsingMode(_jsDocParsingMode);
1756
1756
}
1757
1757
1758
1758
function clearState() {
1759
1759
// Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily.
1760
1760
scanner.clearCommentDirectives();
1761
1761
scanner.setText("");
1762
1762
scanner.setOnError(undefined);
1763
- scanner.setSkipNonSemanticJSDoc(false);
1763
+ scanner.setScriptKind(ScriptKind.Unknown);
1764
+ scanner.setJSDocParsingMode(JSDocParsingMode.ParseAll);
1764
1765
1765
1766
// Clear any data. We don't want to accidentally hold onto it for too long.
1766
1767
sourceText = undefined!;
@@ -1777,7 +1778,7 @@ namespace Parser {
1777
1778
topLevel = true;
1778
1779
}
1779
1780
1780
- function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void, skipNonSemanticJSDoc: boolean ): SourceFile {
1781
+ function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void, jsDocParsingMode: JSDocParsingMode ): SourceFile {
1781
1782
const isDeclarationFile = isDeclarationFileName(fileName);
1782
1783
if (isDeclarationFile) {
1783
1784
contextFlags |= NodeFlags.Ambient;
@@ -1804,7 +1805,7 @@ namespace Parser {
1804
1805
sourceFile.identifierCount = identifierCount;
1805
1806
sourceFile.identifiers = identifiers;
1806
1807
sourceFile.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile);
1807
- sourceFile.skipNonSemanticJSDoc = skipNonSemanticJSDoc ;
1808
+ sourceFile.jsDocParsingMode = jsDocParsingMode ;
1808
1809
if (jsDocDiagnostics) {
1809
1810
sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile);
1810
1811
}
@@ -8686,7 +8687,7 @@ namespace Parser {
8686
8687
8687
8688
export namespace JSDocParser {
8688
8689
export function parseJSDocTypeExpressionForTests(content: string, start: number | undefined, length: number | undefined): { jsDocTypeExpression: JSDocTypeExpression; diagnostics: Diagnostic[]; } | undefined {
8689
- initializeState("file.js", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
8690
+ initializeState("file.js", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS, JSDocParsingMode.ParseAll );
8690
8691
scanner.setText(content, start, length);
8691
8692
currentToken = scanner.scan();
8692
8693
const jsDocTypeExpression = parseJSDocTypeExpression();
@@ -8736,7 +8737,7 @@ namespace Parser {
8736
8737
}
8737
8738
8738
8739
export function parseIsolatedJSDocComment(content: string, start: number | undefined, length: number | undefined): { jsDoc: JSDoc; diagnostics: Diagnostic[]; } | undefined {
8739
- initializeState("", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
8740
+ initializeState("", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS, JSDocParsingMode.ParseAll );
8740
8741
const jsDoc = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
8741
8742
8742
8743
const sourceFile = { languageVariant: LanguageVariant.Standard, text: content } as SourceFile;
@@ -9804,7 +9805,7 @@ namespace IncrementalParser {
9804
9805
if (sourceFile.statements.length === 0) {
9805
9806
// If we don't have any statements in the current source file, then there's no real
9806
9807
// way to incrementally parse. So just do a full parse instead.
9807
- return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.skipNonSemanticJSDoc );
9808
+ return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.jsDocParsingMode );
9808
9809
}
9809
9810
9810
9811
// Make sure we're not trying to incrementally update a source file more than once. Once
@@ -9867,7 +9868,7 @@ namespace IncrementalParser {
9867
9868
// inconsistent tree. Setting the parents on the new tree should be very fast. We
9868
9869
// will immediately bail out of walking any subtrees when we can see that their parents
9869
9870
// are already correct.
9870
- const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.skipNonSemanticJSDoc );
9871
+ const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.jsDocParsingMode );
9871
9872
result.commentDirectives = getNewCommentDirectives(
9872
9873
sourceFile.commentDirectives,
9873
9874
result.commentDirectives,
0 commit comments