@@ -1324,7 +1324,10 @@ function setExternalModuleIndicator(sourceFile: SourceFile) {
1324
1324
sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile);
1325
1325
}
1326
1326
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 {
1328
1331
tracing?.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
1329
1332
performance.mark("beforeParse");
1330
1333
let result: SourceFile;
@@ -1336,14 +1339,14 @@ export function createSourceFile(fileName: string, sourceText: string, languageV
1336
1339
impliedNodeFormat: format,
1337
1340
} = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : ({ languageVersion: languageVersionOrOptions } as CreateSourceFileOptions);
1338
1341
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 );
1340
1343
}
1341
1344
else {
1342
1345
const setIndicator = format === undefined ? overrideSetExternalModuleIndicator : (file: SourceFile) => {
1343
1346
file.impliedNodeFormat = format;
1344
1347
return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file);
1345
1348
};
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 );
1347
1350
}
1348
1351
perfLogger?.logStopParseSourceFile();
1349
1352
@@ -1575,7 +1578,16 @@ namespace Parser {
1575
1578
var parseErrorBeforeNextFinishedNode = false;
1576
1579
/* eslint-enable no-var */
1577
1580
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 {
1579
1591
scriptKind = ensureScriptKind(fileName, scriptKind);
1580
1592
if (scriptKind === ScriptKind.JSON) {
1581
1593
const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes);
@@ -1589,9 +1601,10 @@ namespace Parser {
1589
1601
return result;
1590
1602
}
1591
1603
1592
- initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind);
1604
+ skipNonSemanticJSDoc = !!skipNonSemanticJSDoc && scriptKind !== ScriptKind.JS && scriptKind !== ScriptKind.JSX;
1605
+ initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind, skipNonSemanticJSDoc);
1593
1606
1594
- const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator);
1607
+ const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator, skipNonSemanticJSDoc );
1595
1608
1596
1609
clearState();
1597
1610
@@ -1600,7 +1613,7 @@ namespace Parser {
1600
1613
1601
1614
export function parseIsolatedEntityName(content: string, languageVersion: ScriptTarget): EntityName | undefined {
1602
1615
// Choice of `isDeclarationFile` should be arbitrary
1603
- initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS);
1616
+ initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS, /*skipNonSemanticJSDoc*/ false );
1604
1617
// Prime the scanner.
1605
1618
nextToken();
1606
1619
const entityName = parseEntityName(/*allowReservedWords*/ true);
@@ -1610,7 +1623,7 @@ namespace Parser {
1610
1623
}
1611
1624
1612
1625
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 );
1614
1627
sourceFlags = contextFlags;
1615
1628
1616
1629
// Prime the scanner.
@@ -1698,7 +1711,7 @@ namespace Parser {
1698
1711
return result;
1699
1712
}
1700
1713
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 ) {
1702
1715
NodeConstructor = objectAllocator.getNodeConstructor();
1703
1716
TokenConstructor = objectAllocator.getTokenConstructor();
1704
1717
IdentifierConstructor = objectAllocator.getIdentifierConstructor();
@@ -1739,13 +1752,15 @@ namespace Parser {
1739
1752
scanner.setOnError(scanError);
1740
1753
scanner.setScriptTarget(languageVersion);
1741
1754
scanner.setLanguageVariant(languageVariant);
1755
+ scanner.setSkipNonSemanticJSDoc(_skipNonSemanticJSDoc);
1742
1756
}
1743
1757
1744
1758
function clearState() {
1745
1759
// Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily.
1746
1760
scanner.clearCommentDirectives();
1747
1761
scanner.setText("");
1748
1762
scanner.setOnError(undefined);
1763
+ scanner.setSkipNonSemanticJSDoc(false);
1749
1764
1750
1765
// Clear any data. We don't want to accidentally hold onto it for too long.
1751
1766
sourceText = undefined!;
@@ -1762,7 +1777,7 @@ namespace Parser {
1762
1777
topLevel = true;
1763
1778
}
1764
1779
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 {
1766
1781
const isDeclarationFile = isDeclarationFileName(fileName);
1767
1782
if (isDeclarationFile) {
1768
1783
contextFlags |= NodeFlags.Ambient;
@@ -1789,6 +1804,7 @@ namespace Parser {
1789
1804
sourceFile.identifierCount = identifierCount;
1790
1805
sourceFile.identifiers = identifiers;
1791
1806
sourceFile.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile);
1807
+ sourceFile.skipNonSemanticJSDoc = skipNonSemanticJSDoc;
1792
1808
if (jsDocDiagnostics) {
1793
1809
sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile);
1794
1810
}
@@ -8670,7 +8686,7 @@ namespace Parser {
8670
8686
8671
8687
export namespace JSDocParser {
8672
8688
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 );
8674
8690
scanner.setText(content, start, length);
8675
8691
currentToken = scanner.scan();
8676
8692
const jsDocTypeExpression = parseJSDocTypeExpression();
@@ -8720,7 +8736,7 @@ namespace Parser {
8720
8736
}
8721
8737
8722
8738
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 );
8724
8740
const jsDoc = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
8725
8741
8726
8742
const sourceFile = { languageVariant: LanguageVariant.Standard, text: content } as SourceFile;
@@ -9788,7 +9804,7 @@ namespace IncrementalParser {
9788
9804
if (sourceFile.statements.length === 0) {
9789
9805
// If we don't have any statements in the current source file, then there's no real
9790
9806
// 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 );
9792
9808
}
9793
9809
9794
9810
// Make sure we're not trying to incrementally update a source file more than once. Once
@@ -9851,7 +9867,7 @@ namespace IncrementalParser {
9851
9867
// inconsistent tree. Setting the parents on the new tree should be very fast. We
9852
9868
// will immediately bail out of walking any subtrees when we can see that their parents
9853
9869
// 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 );
9855
9871
result.commentDirectives = getNewCommentDirectives(
9856
9872
sourceFile.commentDirectives,
9857
9873
result.commentDirectives,
0 commit comments