Skip to content

Commit 08f08e3

Browse files
committed
Merge branch 'main' into lib-replacement
2 parents c792dba + f28c518 commit 08f08e3

File tree

279 files changed

+7264
-841
lines changed

Some content is hidden

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

279 files changed

+7264
-841
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,16 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
15361536
function bindForStatement(node: ForStatement): void {
15371537
const preLoopLabel = setContinueTarget(node, createLoopLabel());
15381538
const preBodyLabel = createBranchLabel();
1539+
const preIncrementorLabel = createBranchLabel();
15391540
const postLoopLabel = createBranchLabel();
15401541
bind(node.initializer);
15411542
addAntecedent(preLoopLabel, currentFlow);
15421543
currentFlow = preLoopLabel;
15431544
bindCondition(node.condition, preBodyLabel, postLoopLabel);
15441545
currentFlow = finishFlowLabel(preBodyLabel);
1545-
bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
1546+
bindIterativeStatement(node.statement, postLoopLabel, preIncrementorLabel);
1547+
addAntecedent(preIncrementorLabel, currentFlow);
1548+
currentFlow = finishFlowLabel(preIncrementorLabel);
15461549
bind(node.incrementor);
15471550
addAntecedent(preLoopLabel, currentFlow);
15481551
currentFlow = finishFlowLabel(postLoopLabel);

src/compiler/checker.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,8 +1931,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
19311931
isTypeParameterPossiblyReferenced,
19321932
typeHasCallOrConstructSignatures,
19331933
getSymbolFlags,
1934+
getTypeArgumentsForResolvedSignature,
19341935
};
19351936

1937+
function getTypeArgumentsForResolvedSignature(signature: Signature) {
1938+
if (signature.mapper === undefined) return undefined;
1939+
return instantiateTypes((signature.target || signature).typeParameters, signature.mapper);
1940+
}
1941+
19361942
function getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: Node) {
19371943
const candidatesSet = new Set<Signature>();
19381944
const candidates: Signature[] = [];
@@ -4715,7 +4721,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
47154721
if (errorNode && resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) {
47164722
errorOnImplicitAnyModule(/*isError*/ false, errorNode, currentSourceFile, mode, resolvedModule, moduleReference);
47174723
}
4718-
if (errorNode && (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext)) {
4724+
if (errorNode && (moduleKind === ModuleKind.Node16 || moduleKind === ModuleKind.Node18)) {
47194725
const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration);
47204726
const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l) || isJSDocImportTag(l));
47214727
// An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of
@@ -16684,6 +16690,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1668416690
case "Number":
1668516691
checkNoTypeArguments(node);
1668616692
return numberType;
16693+
case "BigInt":
16694+
checkNoTypeArguments(node);
16695+
return bigintType;
1668716696
case "Boolean":
1668816697
checkNoTypeArguments(node);
1668916698
return booleanType;
@@ -27182,7 +27191,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2718227191
return target.kind === SyntaxKind.SuperKeyword;
2718327192
case SyntaxKind.NonNullExpression:
2718427193
case SyntaxKind.ParenthesizedExpression:
27185-
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
27194+
case SyntaxKind.SatisfiesExpression:
27195+
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression | SatisfiesExpression).expression, target);
2718627196
case SyntaxKind.PropertyAccessExpression:
2718727197
case SyntaxKind.ElementAccessExpression:
2718827198
const sourcePropertyName = getAccessedPropertyName(source as AccessExpression);
@@ -29534,7 +29544,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2953429544
return narrowTypeByCallExpression(type, expr as CallExpression, assumeTrue);
2953529545
case SyntaxKind.ParenthesizedExpression:
2953629546
case SyntaxKind.NonNullExpression:
29537-
return narrowType(type, (expr as ParenthesizedExpression | NonNullExpression).expression, assumeTrue);
29547+
case SyntaxKind.SatisfiesExpression:
29548+
return narrowType(type, (expr as ParenthesizedExpression | NonNullExpression | SatisfiesExpression).expression, assumeTrue);
2953829549
case SyntaxKind.BinaryExpression:
2953929550
return narrowTypeByBinaryExpression(type, expr as BinaryExpression, assumeTrue);
2954029551
case SyntaxKind.PrefixUnaryExpression:
@@ -33467,6 +33478,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3346733478
}
3346833479

3346933480
function getJsxElementChildrenPropertyName(jsxNamespace: Symbol): __String | undefined {
33481+
if (compilerOptions.jsx === JsxEmit.ReactJSX || compilerOptions.jsx === JsxEmit.ReactJSXDev) {
33482+
// In these JsxEmit modes the children property is fixed to 'children'
33483+
return "children" as __String;
33484+
}
3347033485
return getNameFromJsxElementAttributesContainer(JsxNames.ElementChildrenAttributeNameContainer, jsxNamespace);
3347133486
}
3347233487

@@ -41290,6 +41305,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4129041305
checkVariableLikeDeclaration(node);
4129141306
const func = getContainingFunction(node)!;
4129241307
if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) {
41308+
if (compilerOptions.erasableSyntaxOnly) {
41309+
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
41310+
}
4129341311
if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
4129441312
error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
4129541313
}
@@ -47504,6 +47522,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4750447522
checkExportsOnMergedDeclarations(node);
4750547523
node.members.forEach(checkEnumMember);
4750647524

47525+
if (compilerOptions.erasableSyntaxOnly && !(node.flags & NodeFlags.Ambient)) {
47526+
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
47527+
}
47528+
4750747529
computeEnumMemberValues(node);
4750847530

4750947531
// Spec 2014 - Section 9.3:
@@ -47643,6 +47665,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4764347665
&& !inAmbientContext
4764447666
&& isInstantiatedModule(node, shouldPreserveConstEnums(compilerOptions))
4764547667
) {
47668+
if (compilerOptions.erasableSyntaxOnly) {
47669+
error(node.name, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
47670+
}
47671+
4764647672
if (getIsolatedModules(compilerOptions) && !getSourceFileOfNode(node).externalModuleIndicator) {
4764747673
// This could be loosened a little if needed. The only problem we are trying to avoid is unqualified
4764847674
// references to namespace members declared in other files. But use of namespaces is discouraged anyway,
@@ -48077,6 +48103,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4807748103
);
4807848104
}
4807948105

48106+
if (moduleKind === ModuleKind.NodeNext && !isImportAttributes) {
48107+
return grammarErrorOnFirstToken(node, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_asserts);
48108+
}
48109+
4808048110
if (declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier) === ModuleKind.CommonJS) {
4808148111
return grammarErrorOnNode(
4808248112
node,
@@ -48155,7 +48185,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4815548185
}
4815648186

4815748187
checkGrammarModifiers(node);
48158-
if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
48188+
const isImportEquals = isInternalModuleImportEqualsDeclaration(node);
48189+
if (compilerOptions.erasableSyntaxOnly && isImportEquals && !(node.flags & NodeFlags.Ambient)) {
48190+
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
48191+
}
48192+
if (isImportEquals || checkExternalImportOrExportDeclaration(node)) {
4815948193
checkImportBinding(node);
4816048194
markLinkedReferences(node, ReferenceHint.ExportImportEquals);
4816148195
if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) {

src/compiler/commandLineParser.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
856856
affectsBuildInfo: true,
857857
affectsSemanticDiagnostics: true,
858858
},
859+
{
860+
name: "erasableSyntaxOnly",
861+
type: "boolean",
862+
category: Diagnostics.Interop_Constraints,
863+
description: Diagnostics.Do_not_allow_runtime_constructs_that_are_not_part_of_ECMAScript,
864+
defaultValueDescription: false,
865+
affectsBuildInfo: true,
866+
affectsSemanticDiagnostics: true,
867+
},
859868
{
860869
name: "libReplacement",
861870
type: "boolean",

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,10 @@
971971
"category": "Error",
972972
"code": 1293
973973
},
974-
974+
"This syntax is not allowed when 'erasableSyntaxOnly' is enabled.": {
975+
"category": "Error",
976+
"code": 1294
977+
},
975978
"'with' statements are not allowed in an async function block.": {
976979
"category": "Error",
977980
"code": 1300
@@ -3980,6 +3983,10 @@
39803983
"category": "Error",
39813984
"code": 2879
39823985
},
3986+
"Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.": {
3987+
"category": "Error",
3988+
"code": 2880
3989+
},
39833990

39843991
"Import declaration '{0}' is using private name '{1}'.": {
39853992
"category": "Error",
@@ -6467,11 +6474,14 @@
64676474
"category": "Message",
64686475
"code": 6719
64696476
},
6470-
64716477
"Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'.": {
64726478
"category": "Message",
64736479
"code": 6720
64746480
},
6481+
"Do not allow runtime constructs that are not part of ECMAScript.": {
6482+
"category": "Message",
6483+
"code": 6721
6484+
},
64756485
"Default catch clause variables as 'unknown' instead of 'any'.": {
64766486
"category": "Message",
64776487
"code": 6803

src/compiler/moduleNameResolver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,11 @@ function getLoadModuleFromTargetExportOrImport(extensions: Extensions, state: Mo
27562756
traceIfEnabled(state, Diagnostics.Using_0_subpath_1_with_target_2, "imports", key, combinedLookup);
27572757
traceIfEnabled(state, Diagnostics.Resolving_module_0_from_1, combinedLookup, scope.packageDirectory + "/");
27582758
const result = nodeModuleNameResolverWorker(state.features, combinedLookup, scope.packageDirectory + "/", state.compilerOptions, state.host, cache, extensions, /*isConfigLookup*/ false, redirectedReference, state.conditions);
2759+
// Note: we cannot safely reassign `state.failedLookupLocations` during a request;
2760+
// `nodeModuleNameResolverWorker` relies on the `state` property remaining reference-equal
2761+
// to the one it initializes.
2762+
state.failedLookupLocations?.push(...result.failedLookupLocations ?? emptyArray);
2763+
state.affectingLocations?.push(...result.affectingLocations ?? emptyArray);
27592764
return toSearchResult(
27602765
result.resolvedModule ? {
27612766
path: result.resolvedModule.resolvedFileName,

src/compiler/program.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,14 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
15111511
* @returns A 'Program' object.
15121512
*/
15131513
export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
1514-
export function createProgram(rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
1515-
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
1516-
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion } = createProgramOptions;
1517-
let { oldProgram } = createProgramOptions;
1514+
export function createProgram(_rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
1515+
let _createProgramOptions = isArray(_rootNamesOrOptions) ? createCreateProgramOptions(_rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : _rootNamesOrOptions; // TODO: GH#18217
1516+
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion, host: createProgramOptionsHost } = _createProgramOptions;
1517+
let { oldProgram } = _createProgramOptions;
1518+
// Stop referencing these objects to ensure GC collects them.
1519+
_createProgramOptions = undefined!;
1520+
_rootNamesOrOptions = undefined!;
1521+
15181522
for (const option of commandLineOptionOfCustomType) {
15191523
if (hasProperty(options, option.name)) {
15201524
if (typeof options[option.name] === "string") {
@@ -1569,7 +1573,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
15691573
tracing?.push(tracing.Phase.Program, "createProgram", { configFilePath: options.configFilePath, rootDir: options.rootDir }, /*separateBeginAndEnd*/ true);
15701574
performance.mark("beforeProgram");
15711575

1572-
const host = createProgramOptions.host || createCompilerHost(options);
1576+
const host = createProgramOptionsHost || createCompilerHost(options);
15731577
const configParsingHost = parseConfigHostFromCompilerHostLike(host);
15741578

15751579
let skipDefaultLib = options.noLib;

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5439,6 +5439,8 @@ export interface TypeChecker {
54395439
/** @internal */ typeHasCallOrConstructSignatures(type: Type): boolean;
54405440
/** @internal */ getSymbolFlags(symbol: Symbol): SymbolFlags;
54415441
/** @internal */ fillMissingTypeArguments(typeArguments: readonly Type[], typeParameters: readonly TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[];
5442+
5443+
getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined;
54425444
}
54435445

54445446
/** @internal */
@@ -7503,6 +7505,7 @@ export interface CompilerOptions {
75037505
/** Paths used to compute primary types search locations */
75047506
typeRoots?: string[];
75057507
verbatimModuleSyntax?: boolean;
7508+
erasableSyntaxOnly?: boolean;
75067509
/** @internal */ version?: boolean;
75077510
/** @internal */ watch?: boolean;
75087511
esModuleInterop?: boolean;

0 commit comments

Comments
 (0)