Skip to content

Commit 89f5d10

Browse files
committed
Merge branch 'main' into fix55630
# Conflicts: # src/compiler/diagnosticMessages.json
2 parents 806ffbb + 55d8bed commit 89f5d10

File tree

208 files changed

+9264
-3270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+9264
-3270
lines changed

package-lock.json

+32-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/builderState.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,15 @@ export namespace BuilderState {
238238
}
239239

240240
// Handle type reference directives
241-
const resolvedTypeReferenceDirectiveNames = program.resolvedTypeReferenceDirectiveNames?.get(sourceFile.path);
242-
if (resolvedTypeReferenceDirectiveNames) {
243-
resolvedTypeReferenceDirectiveNames.forEach(({ resolvedTypeReferenceDirective }) => {
244-
if (!resolvedTypeReferenceDirective) {
245-
return;
246-
}
241+
program.forEachResolvedTypeReferenceDirective(({ resolvedTypeReferenceDirective }) => {
242+
if (!resolvedTypeReferenceDirective) {
243+
return;
244+
}
247245

248-
const fileName = resolvedTypeReferenceDirective.resolvedFileName!; // TODO: GH#18217
249-
const typeFilePath = getReferencedFileFromFileName(program, fileName, sourceFileDirectory, getCanonicalFileName);
250-
addReferencedFile(typeFilePath);
251-
});
252-
}
246+
const fileName = resolvedTypeReferenceDirective.resolvedFileName!; // TODO: GH#18217
247+
const typeFilePath = getReferencedFileFromFileName(program, fileName, sourceFileDirectory, getCanonicalFileName);
248+
addReferencedFile(typeFilePath);
249+
}, sourceFile);
253250

254251
// Add module augmentation as references
255252
if (sourceFile.moduleAugmentations.length) {

src/compiler/checker.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ import {
477477
isClassDeclaration,
478478
isClassElement,
479479
isClassExpression,
480+
isClassFieldAndNotAutoAccessor,
480481
isClassLike,
481482
isClassStaticBlockDeclaration,
482483
isCommaSequence,
@@ -4959,7 +4960,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
49594960
(isLiteralImportTypeNode(location) ? location : undefined)?.argument.literal;
49604961
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
49614962
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
4962-
const resolvedModule = host.resolvedModules?.get(currentSourceFile.path)?.get(moduleReference, mode)?.resolvedModule;
4963+
const resolvedModule = host.getResolvedModule(currentSourceFile, moduleReference, mode)?.resolvedModule;
49634964
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile);
49644965
const sourceFile = resolvedModule
49654966
&& (!resolutionDiagnostic || resolutionDiagnostic === Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set)
@@ -31843,6 +31844,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3184331844
}
3184431845
return false;
3184531846
}
31847+
// A class field cannot be accessed via super.* from a derived class.
31848+
// This is true for both [[Set]] (old) and [[Define]] (ES spec) semantics.
31849+
if (!(flags & ModifierFlags.Static) && prop.declarations?.some(isClassFieldAndNotAutoAccessor)) {
31850+
if (errorNode) {
31851+
error(errorNode, Diagnostics.Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super, symbolToString(prop));
31852+
}
31853+
return false;
31854+
}
3184631855
}
3184731856

3184831857
// Referencing abstract properties within their own constructors is not allowed
@@ -32329,9 +32338,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3232932338
if (file) {
3233032339
if (compilerOptions.checkJs === undefined && file.checkJsDirective === undefined && (file.scriptKind === ScriptKind.JS || file.scriptKind === ScriptKind.JSX)) {
3233132340
const declarationFile = forEach(suggestion?.declarations, getSourceFileOfNode);
32341+
const suggestionHasNoExtendsOrDecorators = !suggestion?.valueDeclaration
32342+
|| !isClassLike(suggestion.valueDeclaration)
32343+
|| suggestion.valueDeclaration.heritageClauses?.length
32344+
|| classOrConstructorParameterIsDecorated(/*useLegacyDecorators*/ false, suggestion.valueDeclaration);
3233232345
return !(file !== declarationFile && !!declarationFile && isGlobalSourceFile(declarationFile))
32333-
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class)
32334-
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword);
32346+
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class && suggestionHasNoExtendsOrDecorators)
32347+
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword && suggestionHasNoExtendsOrDecorators);
3233532348
}
3233632349
}
3233732350
return false;

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3663,10 +3663,14 @@
36633663
"category": "Error",
36643664
"code": 2854
36653665
},
3666-
"Excessive complexity comparing types '{0}' and '{1}'.": {
3666+
"Class field '{0}' defined by the parent class is not accessible in the child class via super.": {
36673667
"category": "Error",
36683668
"code": 2855
36693669
},
3670+
"Excessive complexity comparing types '{0}' and '{1}'.": {
3671+
"category": "Error",
3672+
"code": 2856
3673+
},
36703674

36713675
"Import declaration '{0}' is using private name '{1}'.": {
36723676
"category": "Error",

src/compiler/emitter.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
927927
inlineSourceMap: compilerOptions.inlineSourceMap,
928928
extendedDiagnostics: compilerOptions.extendedDiagnostics,
929929
onlyPrintJsDocStyle: true,
930+
omitBraceSourceMapPositions: true,
930931
writeBundleFileInfo: !!bundleBuildInfo,
931932
recordInternalSection: !!bundleBuildInfo,
932933
relativeToBuildInfo,
@@ -1391,6 +1392,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
13911392
} = handlers;
13921393

13931394
var extendedDiagnostics = !!printerOptions.extendedDiagnostics;
1395+
var omitBraceSourcePositions = !!printerOptions.omitBraceSourceMapPositions;
13941396
var newLine = getNewLineCharacter(printerOptions);
13951397
var moduleKind = getEmitModuleKind(printerOptions);
13961398
var bundledHelpers = new Map<string, boolean>();
@@ -3578,7 +3580,18 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
35783580
decreaseIndent();
35793581
}
35803582
}
3581-
pos = writeTokenText(token, writer, pos);
3583+
3584+
// We don't emit source positions for most tokens as it tends to be quite noisy, however
3585+
// we need to emit source positions for open and close braces so that tools like istanbul
3586+
// can map branches for code coverage. However, we still omit brace source positions when
3587+
// the output is a declaration file.
3588+
if (!omitBraceSourcePositions && (token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken)) {
3589+
pos = writeToken(token, pos, writer, contextNode);
3590+
}
3591+
else {
3592+
pos = writeTokenText(token, writer, pos);
3593+
}
3594+
35823595
if (isSimilarNode && contextNode.end !== pos) {
35833596
const isJsxExprContext = contextNode.kind === SyntaxKind.JsxExpression;
35843597
emitTrailingCommentsOfPosition(pos, /*prefixSpace*/ !isJsxExprContext, /*forceNoNewline*/ isJsxExprContext);

0 commit comments

Comments
 (0)