Skip to content

Commit 92ec29e

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/errors-from-requests-with-blocked-inference
# Conflicts: # src/compiler/checker.ts
2 parents dbd8664 + 1513649 commit 92ec29e

File tree

102 files changed

+5436
-522
lines changed

Some content is hidden

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

102 files changed

+5436
-522
lines changed

package-lock.json

Lines changed: 282 additions & 282 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
generateDjb2Hash,
4646
getDirectoryPath,
4747
getEmitDeclarations,
48+
getIsolatedModules,
4849
getNormalizedAbsolutePath,
4950
getOptionsNameMap,
5051
getOwnKeys,
@@ -763,7 +764,7 @@ function handleDtsMayChangeOfReferencingExportOfAffectedFile(
763764

764765
// Since isolated modules dont change js files, files affected by change in signature is itself
765766
// But we need to cleanup semantic diagnostics and queue dts emit for affected files
766-
if (state.compilerOptions.isolatedModules) {
767+
if (getIsolatedModules(state.compilerOptions)) {
767768
const seenFileNamesMap = new Map<Path, true>();
768769
seenFileNamesMap.set(affectedFile.resolvedPath, true);
769770
const queue = BuilderState.getReferencedByPaths(state, affectedFile.resolvedPath);

src/compiler/builderState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ExportedModulesFromDeclarationEmit,
1010
GetCanonicalFileName,
1111
getDirectoryPath,
12+
getIsolatedModules,
1213
getSourceFileOfNode,
1314
HostForComputeHash,
1415
isDeclarationFileName,
@@ -635,7 +636,7 @@ export namespace BuilderState {
635636
}
636637

637638
const compilerOptions = programOfThisState.getCompilerOptions();
638-
if (compilerOptions && (compilerOptions.isolatedModules || outFile(compilerOptions))) {
639+
if (compilerOptions && (getIsolatedModules(compilerOptions) || outFile(compilerOptions))) {
639640
return [sourceFileWithUpdatedShape];
640641
}
641642

src/compiler/checker.ts

Lines changed: 150 additions & 75 deletions
Large diffs are not rendered by default.

src/compiler/parser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,6 @@ namespace Parser {
26842684
return canFollowExportModifier();
26852685
case SyntaxKind.DefaultKeyword:
26862686
return nextTokenCanFollowDefaultKeyword();
2687-
case SyntaxKind.AccessorKeyword:
26882687
case SyntaxKind.StaticKeyword:
26892688
case SyntaxKind.GetKeyword:
26902689
case SyntaxKind.SetKeyword:

src/compiler/program.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import {
118118
getEmitScriptTarget,
119119
getErrorSpanForNode,
120120
getExternalModuleName,
121+
getIsolatedModules,
121122
getJSXImplicitImportBase,
122123
getJSXRuntimeImport,
123124
getLineAndCharacterOfPosition,
@@ -3186,7 +3187,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
31863187

31873188
// If we are importing helpers, we need to add a synthetic reference to resolve the
31883189
// helpers library.
3189-
if ((options.isolatedModules || isExternalModuleFile)
3190+
if ((getIsolatedModules(options) || isExternalModuleFile)
31903191
&& !file.isDeclarationFile) {
31913192
if (options.importHelpers) {
31923193
// synthesize 'import "tslib"' declaration
@@ -3992,13 +3993,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
39923993
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "exactOptionalPropertyTypes", "strictNullChecks");
39933994
}
39943995

3995-
if (options.isolatedModules) {
3996+
if (options.isolatedModules || options.verbatimModuleSyntax) {
39963997
if (options.out) {
3997-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules");
3998+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", options.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules");
39983999
}
39994000

40004001
if (options.outFile) {
4001-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules");
4002+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", options.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules");
40024003
}
40034004
}
40044005

src/compiler/transformers/module/esnextAnd2015.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getEmitModuleKind,
1717
getEmitScriptTarget,
1818
getExternalModuleNameLiteral,
19+
getIsolatedModules,
1920
hasSyntacticModifier,
2021
Identifier,
2122
idText,
@@ -76,7 +77,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S
7677
return node;
7778
}
7879

79-
if (isExternalModule(node) || compilerOptions.isolatedModules) {
80+
if (isExternalModule(node) || getIsolatedModules(compilerOptions)) {
8081
currentSourceFile = node;
8182
importRequireStatements = undefined;
8283
let result = updateExternalModule(node);
@@ -286,7 +287,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S
286287
*/
287288
function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void {
288289
if (isSourceFile(node)) {
289-
if ((isExternalModule(node) || compilerOptions.isolatedModules) && compilerOptions.importHelpers) {
290+
if ((isExternalModule(node) || getIsolatedModules(compilerOptions)) && compilerOptions.importHelpers) {
290291
helperNameSubstitutions = new Map<string, Identifier>();
291292
}
292293
previousOnEmitNode(hint, node, emitCallback);

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
getEmitScriptTarget,
5555
getFirstConstructorWithBody,
5656
getInitializedVariables,
57+
getIsolatedModules,
5758
getOriginalNode,
5859
getParseTreeNode,
5960
getProperties,
@@ -2706,7 +2707,7 @@ export function transformTypeScript(context: TransformationContext) {
27062707
}
27072708

27082709
function tryGetConstEnumValue(node: Node): string | number | undefined {
2709-
if (compilerOptions.isolatedModules) {
2710+
if (getIsolatedModules(compilerOptions)) {
27102711
return undefined;
27112712
}
27122713

src/compiler/types.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5997,6 +5997,7 @@ export interface NodeLinks {
59975997
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
59985998
serializedTypes?: Map<string, SerializedTypeEntry>; // Collection of types serialized at this location
59995999
decoratorSignature?: Signature; // Signature for decorator as if invoked by the runtime.
6000+
parameterInitializerContainsUndefined?: boolean; // True if this is a parameter declaration whose type annotation contains "undefined".
60006001
}
60016002

60026003
/** @internal */
@@ -6042,7 +6043,8 @@ export const enum TypeFlags {
60426043
/** @internal */
60436044
Nullable = Undefined | Null,
60446045
Literal = StringLiteral | NumberLiteral | BigIntLiteral | BooleanLiteral,
6045-
Unit = Literal | UniqueESSymbol | Nullable,
6046+
Unit = Enum | Literal | UniqueESSymbol | Nullable,
6047+
Freshable = Enum | Literal,
60466048
StringOrNumberLiteral = StringLiteral | NumberLiteral,
60476049
/** @internal */
60486050
StringOrNumberLiteralOrUnique = StringLiteral | NumberLiteral | UniqueESSymbol,
@@ -6052,7 +6054,7 @@ export const enum TypeFlags {
60526054
/** @internal */
60536055
Intrinsic = Any | Unknown | String | Number | BigInt | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
60546056
/** @internal */
6055-
Primitive = String | Number | BigInt | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol,
6057+
Primitive = String | Number | BigInt | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol | TemplateLiteral,
60566058
StringLike = String | StringLiteral | TemplateLiteral | StringMapping,
60576059
NumberLike = Number | NumberLiteral | Enum,
60586060
BigIntLike = BigInt | BigIntLiteral,
@@ -6136,22 +6138,20 @@ export interface NullableType extends IntrinsicType {
61366138
objectFlags: ObjectFlags;
61376139
}
61386140

6139-
/** @internal */
6140-
export interface FreshableIntrinsicType extends IntrinsicType {
6141-
freshType: IntrinsicType; // Fresh version of type
6142-
regularType: IntrinsicType; // Regular version of type
6141+
export interface FreshableType extends Type {
6142+
freshType: FreshableType; // Fresh version of type
6143+
regularType: FreshableType; // Regular version of type
61436144
}
61446145

61456146
/** @internal */
6146-
export type FreshableType = LiteralType | FreshableIntrinsicType;
6147+
export interface FreshableIntrinsicType extends FreshableType, IntrinsicType {
6148+
}
61476149

61486150
// String literal types (TypeFlags.StringLiteral)
61496151
// Numeric literal types (TypeFlags.NumberLiteral)
61506152
// BigInt literal types (TypeFlags.BigIntLiteral)
6151-
export interface LiteralType extends Type {
6153+
export interface LiteralType extends FreshableType {
61526154
value: string | number | PseudoBigInt; // Value of literal
6153-
freshType: LiteralType; // Fresh version of type
6154-
regularType: LiteralType; // Regular version of type
61556155
}
61566156

61576157
// Unique symbol types (TypeFlags.UniqueESSymbol)
@@ -6173,7 +6173,7 @@ export interface BigIntLiteralType extends LiteralType {
61736173
}
61746174

61756175
// Enum types (TypeFlags.Enum)
6176-
export interface EnumType extends Type {
6176+
export interface EnumType extends FreshableType {
61776177
}
61786178

61796179
// Types included in TypeFlags.ObjectFlagsType have an objectFlags property. Some ObjectFlags

src/compiler/utilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ function isCommonJSContainingModuleKind(kind: ModuleKind) {
17811781

17821782
/** @internal */
17831783
export function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions) {
1784-
return isExternalModule(node) || compilerOptions.isolatedModules || (isCommonJSContainingModuleKind(getEmitModuleKind(compilerOptions)) && !!node.commonJsModuleIndicator);
1784+
return isExternalModule(node) || getIsolatedModules(compilerOptions) || (isCommonJSContainingModuleKind(getEmitModuleKind(compilerOptions)) && !!node.commonJsModuleIndicator);
17851785
}
17861786

17871787
/**
@@ -1812,7 +1812,7 @@ export function isEffectiveStrictModeSourceFile(node: SourceFile, compilerOption
18121812
if (startsWithUseStrict(node.statements)) {
18131813
return true;
18141814
}
1815-
if (isExternalModule(node) || compilerOptions.isolatedModules) {
1815+
if (isExternalModule(node) || getIsolatedModules(compilerOptions)) {
18161816
// ECMAScript Modules are always strict.
18171817
if (getEmitModuleKind(compilerOptions) >= ModuleKind.ES2015) {
18181818
return true;
@@ -8443,7 +8443,7 @@ export function getEmitDeclarations(compilerOptions: CompilerOptions): boolean {
84438443

84448444
/** @internal */
84458445
export function shouldPreserveConstEnums(compilerOptions: CompilerOptions): boolean {
8446-
return !!(compilerOptions.preserveConstEnums || compilerOptions.isolatedModules);
8446+
return !!(compilerOptions.preserveConstEnums || getIsolatedModules(compilerOptions));
84478447
}
84488448

84498449
/** @internal */

src/services/codefixes/fixImportNonExportedMember.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
findAncestor,
1010
findLast,
1111
firstOrUndefined,
12+
getIsolatedModules,
1213
getResolvedModule,
1314
getTokenAtPosition,
1415
Identifier,
@@ -173,7 +174,7 @@ function tryGetExportDeclaration(sourceFile: SourceFile, isTypeOnly: boolean) {
173174

174175
function updateExport(changes: textChanges.ChangeTracker, program: Program, sourceFile: SourceFile, node: ExportDeclaration, names: ExportName[]) {
175176
const namedExports = node.exportClause && isNamedExports(node.exportClause) ? node.exportClause.elements : factory.createNodeArray([]);
176-
const allowTypeModifier = !node.isTypeOnly && !!(program.getCompilerOptions().isolatedModules || find(namedExports, e => e.isTypeOnly));
177+
const allowTypeModifier = !node.isTypeOnly && !!(getIsolatedModules(program.getCompilerOptions()) || find(namedExports, e => e.isTypeOnly));
177178
changes.replaceNode(sourceFile, node,
178179
factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly,
179180
factory.createNamedExports(
@@ -183,7 +184,7 @@ function updateExport(changes: textChanges.ChangeTracker, program: Program, sour
183184
function createExport(changes: textChanges.ChangeTracker, program: Program, sourceFile: SourceFile, names: ExportName[]) {
184185
changes.insertNodeAtEndOfScope(sourceFile, sourceFile,
185186
factory.createExportDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false,
186-
factory.createNamedExports(createExportSpecifiers(names, /*allowTypeModifier*/ !!program.getCompilerOptions().isolatedModules)), /*moduleSpecifier*/ undefined, /*assertClause*/ undefined));
187+
factory.createNamedExports(createExportSpecifiers(names, /*allowTypeModifier*/ getIsolatedModules(program.getCompilerOptions()))), /*moduleSpecifier*/ undefined, /*assertClause*/ undefined));
187188
}
188189

189190
function createExportSpecifiers(names: ExportName[], allowTypeModifier: boolean) {

src/services/codefixes/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ function createMethodImplementingSignatures(
751751
function getReturnTypeFromSignatures(signatures: readonly Signature[], checker: TypeChecker, context: TypeConstructionContext, enclosingDeclaration: ClassLikeDeclaration): TypeNode | undefined {
752752
if (length(signatures)) {
753753
const type = checker.getUnionType(map(signatures, checker.getReturnTypeOfSignature));
754-
return checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context));
754+
return checker.typeToTypeNode(type, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context));
755755
}
756756
}
757757

src/services/codefixes/importFixes.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
ImportEqualsDeclaration,
5858
importFromModuleSpecifier,
5959
ImportKind,
60+
importNameElisionDisabled,
6061
ImportsNotUsedAsValues,
6162
insertImports,
6263
InternalSymbolName,
@@ -371,7 +372,8 @@ function createImportAdderWorker(sourceFile: SourceFile, program: Program, useAu
371372
quotePreference,
372373
defaultImport,
373374
namedImports && arrayFrom(namedImports.entries(), ([name, addAsTypeOnly]) => ({ addAsTypeOnly, name })),
374-
namespaceLikeImport);
375+
namespaceLikeImport,
376+
compilerOptions);
375377
newDeclarations = combine(newDeclarations, declarations);
376378
});
377379
if (newDeclarations) {
@@ -676,7 +678,7 @@ function getAddAsTypeOnly(
676678
// Not writing a (top-level) type-only import here would create an error because the runtime dependency is unnecessary
677679
return AddAsTypeOnly.Required;
678680
}
679-
if ((compilerOptions.isolatedModules && compilerOptions.preserveValueImports || compilerOptions.verbatimModuleSyntax) &&
681+
if (importNameElisionDisabled(compilerOptions) &&
680682
(!(targetFlags & SymbolFlags.Value) || !!checker.getTypeOnlyAliasDeclaration(symbol))
681683
) {
682684
// A type-only import is required for this symbol if under these settings if the symbol will
@@ -1248,7 +1250,13 @@ function codeActionForFixWorker(changes: textChanges.ChangeTracker, sourceFile:
12481250
const namespaceLikeImport = importKind === ImportKind.Namespace || importKind === ImportKind.CommonJS
12491251
? { importKind, name: qualification?.namespacePrefix || symbolName, addAsTypeOnly }
12501252
: undefined;
1251-
insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true, preferences);
1253+
insertImports(changes, sourceFile, getDeclarations(
1254+
moduleSpecifier,
1255+
quotePreference,
1256+
defaultImport,
1257+
namedImports,
1258+
namespaceLikeImport,
1259+
compilerOptions), /*blankLineBetween*/ true, preferences);
12521260
if (qualification) {
12531261
addNamespaceQualifier(changes, sourceFile, qualification);
12541262
}
@@ -1276,7 +1284,7 @@ function getModuleSpecifierText(promotedDeclaration: ImportClause | ImportEquals
12761284

12771285
function promoteFromTypeOnly(changes: textChanges.ChangeTracker, aliasDeclaration: TypeOnlyAliasDeclaration, compilerOptions: CompilerOptions, sourceFile: SourceFile, preferences: UserPreferences) {
12781286
// See comment in `doAddExistingFix` on constant with the same name.
1279-
const convertExistingToTypeOnly = compilerOptions.preserveValueImports && compilerOptions.isolatedModules || compilerOptions.verbatimModuleSyntax;
1287+
const convertExistingToTypeOnly = importNameElisionDisabled(compilerOptions);
12801288
switch (aliasDeclaration.kind) {
12811289
case SyntaxKind.ImportSpecifier:
12821290
if (aliasDeclaration.isTypeOnly) {
@@ -1362,8 +1370,7 @@ function doAddExistingFix(
13621370
// never used in an emitting position). These are allowed to be imported without being type-only,
13631371
// but the user has clearly already signified that they don't need them to be present at runtime
13641372
// by placing them in a type-only import. So, just mark each specifier as type-only.
1365-
const convertExistingToTypeOnly = promoteFromTypeOnly
1366-
&& (compilerOptions.preserveValueImports && compilerOptions.isolatedModules || compilerOptions.verbatimModuleSyntax);
1373+
const convertExistingToTypeOnly = promoteFromTypeOnly && importNameElisionDisabled(compilerOptions);
13671374

13681375
if (defaultImport) {
13691376
Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
@@ -1489,12 +1496,18 @@ function getNewImports(
14891496
quotePreference: QuotePreference,
14901497
defaultImport: Import | undefined,
14911498
namedImports: readonly Import[] | undefined,
1492-
namespaceLikeImport: Import & { importKind: ImportKind.CommonJS | ImportKind.Namespace } | undefined
1499+
namespaceLikeImport: Import & { importKind: ImportKind.CommonJS | ImportKind.Namespace } | undefined,
1500+
compilerOptions: CompilerOptions,
14931501
): AnyImportSyntax | readonly AnyImportSyntax[] {
14941502
const quotedModuleSpecifier = makeStringLiteral(moduleSpecifier, quotePreference);
14951503
let statements: AnyImportSyntax | readonly AnyImportSyntax[] | undefined;
14961504
if (defaultImport !== undefined || namedImports?.length) {
1497-
const topLevelTypeOnly = (!defaultImport || needsTypeOnly(defaultImport)) && every(namedImports, needsTypeOnly);
1505+
// `verbatimModuleSyntax` should prefer top-level `import type` -
1506+
// even though it's not an error, it would add unnecessary runtime emit.
1507+
const topLevelTypeOnly = (!defaultImport || needsTypeOnly(defaultImport)) && every(namedImports, needsTypeOnly) ||
1508+
compilerOptions.verbatimModuleSyntax &&
1509+
defaultImport?.addAsTypeOnly !== AddAsTypeOnly.NotAllowed &&
1510+
!some(namedImports, i => i.addAsTypeOnly === AddAsTypeOnly.NotAllowed);
14981511
statements = combine(statements, makeImport(
14991512
defaultImport && factory.createIdentifier(defaultImport.name),
15001513
namedImports?.map(({ addAsTypeOnly, name }) => factory.createImportSpecifier(

src/services/completions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import {
117117
isAbstractConstructorSymbol,
118118
isArrowFunction,
119119
isAssertionExpression,
120+
isAwaitExpression,
120121
isBigIntLiteral,
121122
isBinaryExpression,
122123
isBindingElement,
@@ -1319,7 +1320,9 @@ function createCompletionEntry(
13191320

13201321
awaitText += `(await ${propertyAccessToConvert.expression.getText()})`;
13211322
insertText = needsConvertPropertyAccess ? `${awaitText}${insertText}` : `${awaitText}${insertQuestionDot ? "?." : "."}${insertText}`;
1322-
replacementSpan = createTextSpanFromBounds(propertyAccessToConvert.getStart(sourceFile), propertyAccessToConvert.end);
1323+
const isInAwaitExpression = tryCast(propertyAccessToConvert.parent, isAwaitExpression);
1324+
const wrapNode = isInAwaitExpression ? propertyAccessToConvert.parent : propertyAccessToConvert.expression;
1325+
replacementSpan = createTextSpanFromBounds(wrapNode.getStart(sourceFile), propertyAccessToConvert.end);
13231326
}
13241327

13251328
if (originIsResolvedExport(origin)) {

src/services/jsDoc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const jsDocTagNames = [
145145
"module",
146146
"name",
147147
"namespace",
148+
"overload",
148149
"override",
149150
"package",
150151
"param",

0 commit comments

Comments
 (0)