@@ -1324,7 +1324,10 @@ function setExternalModuleIndicator(sourceFile: SourceFile) {
13241324 sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile);
13251325}
13261326
1327- export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes = false, scriptKind?: ScriptKind): SourceFile {
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 {
13281331 tracing?.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
13291332 performance.mark("beforeParse");
13301333 let result: SourceFile;
@@ -1336,14 +1339,14 @@ export function createSourceFile(fileName: string, sourceText: string, languageV
13361339 impliedNodeFormat: format,
13371340 } = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : ({ languageVersion: languageVersionOrOptions } as CreateSourceFileOptions);
13381341 if (languageVersion === ScriptTarget.JSON) {
1339- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON, noop);
1342+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON, noop, skipNonSemanticJSDoc );
13401343 }
13411344 else {
13421345 const setIndicator = format === undefined ? overrideSetExternalModuleIndicator : (file: SourceFile) => {
13431346 file.impliedNodeFormat = format;
13441347 return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file);
13451348 };
1346- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator);
1349+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator, skipNonSemanticJSDoc );
13471350 }
13481351 perfLogger?.logStopParseSourceFile();
13491352
@@ -1575,7 +1578,16 @@ namespace Parser {
15751578 var parseErrorBeforeNextFinishedNode = false;
15761579 /* eslint-enable no-var */
15771580
1578- export function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: IncrementalParser.SyntaxCursor | undefined, setParentNodes = false, scriptKind?: ScriptKind, setExternalModuleIndicatorOverride?: (file: SourceFile) => void): SourceFile {
1581+ export function parseSourceFile(
1582+ fileName: string,
1583+ sourceText: string,
1584+ languageVersion: ScriptTarget,
1585+ syntaxCursor: IncrementalParser.SyntaxCursor | undefined,
1586+ setParentNodes = false,
1587+ scriptKind?: ScriptKind,
1588+ setExternalModuleIndicatorOverride?: (file: SourceFile) => void,
1589+ skipNonSemanticJSDoc?: boolean,
1590+ ): SourceFile {
15791591 scriptKind = ensureScriptKind(fileName, scriptKind);
15801592 if (scriptKind === ScriptKind.JSON) {
15811593 const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes);
@@ -1589,9 +1601,10 @@ namespace Parser {
15891601 return result;
15901602 }
15911603
1592- initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind);
1604+ skipNonSemanticJSDoc = !!skipNonSemanticJSDoc && scriptKind !== ScriptKind.JS && scriptKind !== ScriptKind.JSX;
1605+ initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind, skipNonSemanticJSDoc);
15931606
1594- const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator);
1607+ const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator, skipNonSemanticJSDoc );
15951608
15961609 clearState();
15971610
@@ -1600,7 +1613,7 @@ namespace Parser {
16001613
16011614 export function parseIsolatedEntityName(content: string, languageVersion: ScriptTarget): EntityName | undefined {
16021615 // Choice of `isDeclarationFile` should be arbitrary
1603- initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS);
1616+ initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
16041617 // Prime the scanner.
16051618 nextToken();
16061619 const entityName = parseEntityName(/*allowReservedWords*/ true);
@@ -1610,7 +1623,7 @@ namespace Parser {
16101623 }
16111624
16121625 export function parseJsonText(fileName: string, sourceText: string, languageVersion: ScriptTarget = ScriptTarget.ES2015, syntaxCursor?: IncrementalParser.SyntaxCursor, setParentNodes = false): JsonSourceFile {
1613- initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON);
1626+ initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON, /*skipNonSemanticJSDoc*/ false );
16141627 sourceFlags = contextFlags;
16151628
16161629 // Prime the scanner.
@@ -1698,7 +1711,7 @@ namespace Parser {
16981711 return result;
16991712 }
17001713
1701- function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind) {
1714+ function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind, _skipNonSemanticJSDoc: boolean ) {
17021715 NodeConstructor = objectAllocator.getNodeConstructor();
17031716 TokenConstructor = objectAllocator.getTokenConstructor();
17041717 IdentifierConstructor = objectAllocator.getIdentifierConstructor();
@@ -1739,13 +1752,15 @@ namespace Parser {
17391752 scanner.setOnError(scanError);
17401753 scanner.setScriptTarget(languageVersion);
17411754 scanner.setLanguageVariant(languageVariant);
1755+ scanner.setSkipNonSemanticJSDoc(_skipNonSemanticJSDoc);
17421756 }
17431757
17441758 function clearState() {
17451759 // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily.
17461760 scanner.clearCommentDirectives();
17471761 scanner.setText("");
17481762 scanner.setOnError(undefined);
1763+ scanner.setSkipNonSemanticJSDoc(false);
17491764
17501765 // Clear any data. We don't want to accidentally hold onto it for too long.
17511766 sourceText = undefined!;
@@ -1762,7 +1777,7 @@ namespace Parser {
17621777 topLevel = true;
17631778 }
17641779
1765- function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void): SourceFile {
1780+ function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void, skipNonSemanticJSDoc: boolean ): SourceFile {
17661781 const isDeclarationFile = isDeclarationFileName(fileName);
17671782 if (isDeclarationFile) {
17681783 contextFlags |= NodeFlags.Ambient;
@@ -1789,6 +1804,7 @@ namespace Parser {
17891804 sourceFile.identifierCount = identifierCount;
17901805 sourceFile.identifiers = identifiers;
17911806 sourceFile.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile);
1807+ sourceFile.skipNonSemanticJSDoc = skipNonSemanticJSDoc;
17921808 if (jsDocDiagnostics) {
17931809 sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile);
17941810 }
@@ -8670,7 +8686,7 @@ namespace Parser {
86708686
86718687 export namespace JSDocParser {
86728688 export function parseJSDocTypeExpressionForTests(content: string, start: number | undefined, length: number | undefined): { jsDocTypeExpression: JSDocTypeExpression; diagnostics: Diagnostic[]; } | undefined {
8673- initializeState("file.js", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS);
8689+ initializeState("file.js", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
86748690 scanner.setText(content, start, length);
86758691 currentToken = scanner.scan();
86768692 const jsDocTypeExpression = parseJSDocTypeExpression();
@@ -8720,7 +8736,7 @@ namespace Parser {
87208736 }
87218737
87228738 export function parseIsolatedJSDocComment(content: string, start: number | undefined, length: number | undefined): { jsDoc: JSDoc; diagnostics: Diagnostic[]; } | undefined {
8723- initializeState("", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS);
8739+ initializeState("", content, ScriptTarget.Latest, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
87248740 const jsDoc = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
87258741
87268742 const sourceFile = { languageVariant: LanguageVariant.Standard, text: content } as SourceFile;
@@ -9788,7 +9804,7 @@ namespace IncrementalParser {
97889804 if (sourceFile.statements.length === 0) {
97899805 // If we don't have any statements in the current source file, then there's no real
97909806 // way to incrementally parse. So just do a full parse instead.
9791- return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
9807+ return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.skipNonSemanticJSDoc );
97929808 }
97939809
97949810 // Make sure we're not trying to incrementally update a source file more than once. Once
@@ -9851,7 +9867,7 @@ namespace IncrementalParser {
98519867 // inconsistent tree. Setting the parents on the new tree should be very fast. We
98529868 // will immediately bail out of walking any subtrees when we can see that their parents
98539869 // are already correct.
9854- const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
9870+ const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.skipNonSemanticJSDoc );
98559871 result.commentDirectives = getNewCommentDirectives(
98569872 sourceFile.commentDirectives,
98579873 result.commentDirectives,
0 commit comments