Skip to content

Commit

Permalink
Merge branch 'main' into lib-replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jan 24, 2025
2 parents c792dba + f28c518 commit 08f08e3
Show file tree
Hide file tree
Showing 279 changed files with 7,264 additions and 841 deletions.
5 changes: 4 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,13 +1536,16 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
function bindForStatement(node: ForStatement): void {
const preLoopLabel = setContinueTarget(node, createLoopLabel());
const preBodyLabel = createBranchLabel();
const preIncrementorLabel = createBranchLabel();
const postLoopLabel = createBranchLabel();
bind(node.initializer);
addAntecedent(preLoopLabel, currentFlow);
currentFlow = preLoopLabel;
bindCondition(node.condition, preBodyLabel, postLoopLabel);
currentFlow = finishFlowLabel(preBodyLabel);
bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
bindIterativeStatement(node.statement, postLoopLabel, preIncrementorLabel);
addAntecedent(preIncrementorLabel, currentFlow);
currentFlow = finishFlowLabel(preIncrementorLabel);
bind(node.incrementor);
addAntecedent(preLoopLabel, currentFlow);
currentFlow = finishFlowLabel(postLoopLabel);
Expand Down
42 changes: 38 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1931,8 +1931,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
isTypeParameterPossiblyReferenced,
typeHasCallOrConstructSignatures,
getSymbolFlags,
getTypeArgumentsForResolvedSignature,
};

function getTypeArgumentsForResolvedSignature(signature: Signature) {
if (signature.mapper === undefined) return undefined;
return instantiateTypes((signature.target || signature).typeParameters, signature.mapper);
}

function getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: Node) {
const candidatesSet = new Set<Signature>();
const candidates: Signature[] = [];
Expand Down Expand Up @@ -4715,7 +4721,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (errorNode && resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) {
errorOnImplicitAnyModule(/*isError*/ false, errorNode, currentSourceFile, mode, resolvedModule, moduleReference);
}
if (errorNode && (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext)) {
if (errorNode && (moduleKind === ModuleKind.Node16 || moduleKind === ModuleKind.Node18)) {
const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration);
const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l) || isJSDocImportTag(l));
// An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of
Expand Down Expand Up @@ -16684,6 +16690,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case "Number":
checkNoTypeArguments(node);
return numberType;
case "BigInt":
checkNoTypeArguments(node);
return bigintType;
case "Boolean":
checkNoTypeArguments(node);
return booleanType;
Expand Down Expand Up @@ -27182,7 +27191,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return target.kind === SyntaxKind.SuperKeyword;
case SyntaxKind.NonNullExpression:
case SyntaxKind.ParenthesizedExpression:
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
case SyntaxKind.SatisfiesExpression:
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression | SatisfiesExpression).expression, target);
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ElementAccessExpression:
const sourcePropertyName = getAccessedPropertyName(source as AccessExpression);
Expand Down Expand Up @@ -29534,7 +29544,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return narrowTypeByCallExpression(type, expr as CallExpression, assumeTrue);
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.NonNullExpression:
return narrowType(type, (expr as ParenthesizedExpression | NonNullExpression).expression, assumeTrue);
case SyntaxKind.SatisfiesExpression:
return narrowType(type, (expr as ParenthesizedExpression | NonNullExpression | SatisfiesExpression).expression, assumeTrue);
case SyntaxKind.BinaryExpression:
return narrowTypeByBinaryExpression(type, expr as BinaryExpression, assumeTrue);
case SyntaxKind.PrefixUnaryExpression:
Expand Down Expand Up @@ -33467,6 +33478,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

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

Expand Down Expand Up @@ -41290,6 +41305,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
checkVariableLikeDeclaration(node);
const func = getContainingFunction(node)!;
if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) {
if (compilerOptions.erasableSyntaxOnly) {
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
}
if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
}
Expand Down Expand Up @@ -47504,6 +47522,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
checkExportsOnMergedDeclarations(node);
node.members.forEach(checkEnumMember);

if (compilerOptions.erasableSyntaxOnly && !(node.flags & NodeFlags.Ambient)) {
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
}

computeEnumMemberValues(node);

// Spec 2014 - Section 9.3:
Expand Down Expand Up @@ -47643,6 +47665,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
&& !inAmbientContext
&& isInstantiatedModule(node, shouldPreserveConstEnums(compilerOptions))
) {
if (compilerOptions.erasableSyntaxOnly) {
error(node.name, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
}

if (getIsolatedModules(compilerOptions) && !getSourceFileOfNode(node).externalModuleIndicator) {
// This could be loosened a little if needed. The only problem we are trying to avoid is unqualified
// references to namespace members declared in other files. But use of namespaces is discouraged anyway,
Expand Down Expand Up @@ -48077,6 +48103,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}

if (moduleKind === ModuleKind.NodeNext && !isImportAttributes) {
return grammarErrorOnFirstToken(node, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_asserts);
}

if (declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier) === ModuleKind.CommonJS) {
return grammarErrorOnNode(
node,
Expand Down Expand Up @@ -48155,7 +48185,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

checkGrammarModifiers(node);
if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
const isImportEquals = isInternalModuleImportEqualsDeclaration(node);
if (compilerOptions.erasableSyntaxOnly && isImportEquals && !(node.flags & NodeFlags.Ambient)) {
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
}
if (isImportEquals || checkExternalImportOrExportDeclaration(node)) {
checkImportBinding(node);
markLinkedReferences(node, ReferenceHint.ExportImportEquals);
if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) {
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
affectsBuildInfo: true,
affectsSemanticDiagnostics: true,
},
{
name: "erasableSyntaxOnly",
type: "boolean",
category: Diagnostics.Interop_Constraints,
description: Diagnostics.Do_not_allow_runtime_constructs_that_are_not_part_of_ECMAScript,
defaultValueDescription: false,
affectsBuildInfo: true,
affectsSemanticDiagnostics: true,
},
{
name: "libReplacement",
type: "boolean",
Expand Down
14 changes: 12 additions & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,10 @@
"category": "Error",
"code": 1293
},

"This syntax is not allowed when 'erasableSyntaxOnly' is enabled.": {
"category": "Error",
"code": 1294
},
"'with' statements are not allowed in an async function block.": {
"category": "Error",
"code": 1300
Expand Down Expand Up @@ -3980,6 +3983,10 @@
"category": "Error",
"code": 2879
},
"Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.": {
"category": "Error",
"code": 2880
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down Expand Up @@ -6467,11 +6474,14 @@
"category": "Message",
"code": 6719
},

"Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'.": {
"category": "Message",
"code": 6720
},
"Do not allow runtime constructs that are not part of ECMAScript.": {
"category": "Message",
"code": 6721
},
"Default catch clause variables as 'unknown' instead of 'any'.": {
"category": "Message",
"code": 6803
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,11 @@ function getLoadModuleFromTargetExportOrImport(extensions: Extensions, state: Mo
traceIfEnabled(state, Diagnostics.Using_0_subpath_1_with_target_2, "imports", key, combinedLookup);
traceIfEnabled(state, Diagnostics.Resolving_module_0_from_1, combinedLookup, scope.packageDirectory + "/");
const result = nodeModuleNameResolverWorker(state.features, combinedLookup, scope.packageDirectory + "/", state.compilerOptions, state.host, cache, extensions, /*isConfigLookup*/ false, redirectedReference, state.conditions);
// Note: we cannot safely reassign `state.failedLookupLocations` during a request;
// `nodeModuleNameResolverWorker` relies on the `state` property remaining reference-equal
// to the one it initializes.
state.failedLookupLocations?.push(...result.failedLookupLocations ?? emptyArray);
state.affectingLocations?.push(...result.affectingLocations ?? emptyArray);
return toSearchResult(
result.resolvedModule ? {
path: result.resolvedModule.resolvedFileName,
Expand Down
14 changes: 9 additions & 5 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1511,10 +1511,14 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
* @returns A 'Program' object.
*/
export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
export function createProgram(rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion } = createProgramOptions;
let { oldProgram } = createProgramOptions;
export function createProgram(_rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
let _createProgramOptions = isArray(_rootNamesOrOptions) ? createCreateProgramOptions(_rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : _rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion, host: createProgramOptionsHost } = _createProgramOptions;
let { oldProgram } = _createProgramOptions;
// Stop referencing these objects to ensure GC collects them.
_createProgramOptions = undefined!;
_rootNamesOrOptions = undefined!;

for (const option of commandLineOptionOfCustomType) {
if (hasProperty(options, option.name)) {
if (typeof options[option.name] === "string") {
Expand Down Expand Up @@ -1569,7 +1573,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
tracing?.push(tracing.Phase.Program, "createProgram", { configFilePath: options.configFilePath, rootDir: options.rootDir }, /*separateBeginAndEnd*/ true);
performance.mark("beforeProgram");

const host = createProgramOptions.host || createCompilerHost(options);
const host = createProgramOptionsHost || createCompilerHost(options);
const configParsingHost = parseConfigHostFromCompilerHostLike(host);

let skipDefaultLib = options.noLib;
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5439,6 +5439,8 @@ export interface TypeChecker {
/** @internal */ typeHasCallOrConstructSignatures(type: Type): boolean;
/** @internal */ getSymbolFlags(symbol: Symbol): SymbolFlags;
/** @internal */ fillMissingTypeArguments(typeArguments: readonly Type[], typeParameters: readonly TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[];

getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined;
}

/** @internal */
Expand Down Expand Up @@ -7503,6 +7505,7 @@ export interface CompilerOptions {
/** Paths used to compute primary types search locations */
typeRoots?: string[];
verbatimModuleSyntax?: boolean;
erasableSyntaxOnly?: boolean;
/** @internal */ version?: boolean;
/** @internal */ watch?: boolean;
esModuleInterop?: boolean;
Expand Down
Loading

0 comments on commit 08f08e3

Please sign in to comment.