Skip to content

Commit a3a2db2

Browse files
committed
Merge branch 'master' into consistentTemplateLiteralInference
# Conflicts: # tests/baselines/reference/templateLiteralTypes1.errors.txt # tests/baselines/reference/templateLiteralTypes1.symbols
2 parents 0ab5513 + c9422e6 commit a3a2db2

File tree

366 files changed

+6379
-835
lines changed

Some content is hidden

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

366 files changed

+6379
-835
lines changed

package-lock.json

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

src/compiler/checker.ts

Lines changed: 90 additions & 34 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ namespace ts {
22
/* @internal */
33
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };
44

5+
const jsxOptionMap = new Map(getEntries({
6+
"preserve": JsxEmit.Preserve,
7+
"react-native": JsxEmit.ReactNative,
8+
"react": JsxEmit.React,
9+
"react-jsx": JsxEmit.ReactJSX,
10+
"react-jsxdev": JsxEmit.ReactJSXDev,
11+
}));
12+
13+
/* @internal */
14+
export const inverseJsxOptionMap = new Map(arrayFrom(mapIterator(jsxOptionMap.entries(), ([key, value]: [string, JsxEmit]) => ["" + value, key] as const)));
15+
516
// NOTE: The order here is important to default lib ordering as entries will have the same
617
// order in the generated program (see `getDefaultLibPriority` in program.ts). This
718
// order also affects overload resolution when a type declared in one lib is
@@ -23,6 +34,7 @@ namespace ts {
2334
["dom.iterable", "lib.dom.iterable.d.ts"],
2435
["webworker", "lib.webworker.d.ts"],
2536
["webworker.importscripts", "lib.webworker.importscripts.d.ts"],
37+
["webworker.iterable", "lib.webworker.iterable.d.ts"],
2638
["scripthost", "lib.scripthost.d.ts"],
2739
// ES2015 Or ESNext By-feature options
2840
["es2015.core", "lib.es2015.core.d.ts"],
@@ -51,6 +63,7 @@ namespace ts {
5163
["es2019.symbol", "lib.es2019.symbol.d.ts"],
5264
["es2020.bigint", "lib.es2020.bigint.d.ts"],
5365
["es2020.promise", "lib.es2020.promise.d.ts"],
66+
["es2020.sharedmemory", "lib.es2020.sharedmemory.d.ts"],
5467
["es2020.string", "lib.es2020.string.d.ts"],
5568
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
5669
["es2020.intl", "lib.es2020.intl.d.ts"],
@@ -365,11 +378,7 @@ namespace ts {
365378
},
366379
{
367380
name: "jsx",
368-
type: new Map(getEntries({
369-
"preserve": JsxEmit.Preserve,
370-
"react-native": JsxEmit.ReactNative,
371-
"react": JsxEmit.React
372-
})),
381+
type: jsxOptionMap,
373382
affectsSourceFile: true,
374383
paramType: Diagnostics.KIND,
375384
showInSimplifiedHelpView: true,
@@ -615,6 +624,14 @@ namespace ts {
615624
category: Diagnostics.Additional_Checks,
616625
description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement
617626
},
627+
{
628+
name: "noUncheckedIndexedAccess",
629+
type: "boolean",
630+
affectsSemanticDiagnostics: true,
631+
showInSimplifiedHelpView: false,
632+
category: Diagnostics.Additional_Checks,
633+
description: Diagnostics.Include_undefined_in_index_signature_results
634+
},
618635

619636
// Module Resolution
620637
{
@@ -780,6 +797,12 @@ namespace ts {
780797
category: Diagnostics.Advanced_Options,
781798
description: Diagnostics.Specify_the_JSX_fragment_factory_function_to_use_when_targeting_react_JSX_emit_with_jsxFactory_compiler_option_is_specified_e_g_Fragment
782799
},
800+
{
801+
name: "jsxImportSource",
802+
type: "string",
803+
category: Diagnostics.Advanced_Options,
804+
description: Diagnostics.Specify_the_module_specifier_to_be_used_to_import_the_jsx_and_jsxs_factory_functions_from_eg_react
805+
},
783806
{
784807
name: "resolveJsonModule",
785808
type: "boolean",
@@ -1002,6 +1025,14 @@ namespace ts {
10021025
category: Diagnostics.Advanced_Options,
10031026
description: Diagnostics.Emit_class_fields_with_Define_instead_of_Set,
10041027
},
1028+
{
1029+
name: "bundledPackageName",
1030+
type: "string",
1031+
affectsEmit: true,
1032+
category: Diagnostics.Advanced_Options,
1033+
description: Diagnostics.Provides_a_root_package_name_when_using_outFile_with_declarations,
1034+
},
1035+
10051036
{
10061037
name: "keyofStringsOnly",
10071038
type: "boolean",
@@ -2486,6 +2517,13 @@ namespace ts {
24862517
parseOwnConfigOfJson(json, host, basePath, configFileName, errors) :
24872518
parseOwnConfigOfJsonSourceFile(sourceFile!, host, basePath, configFileName, errors);
24882519

2520+
if (ownConfig.options?.paths) {
2521+
// If we end up needing to resolve relative paths from 'paths' relative to
2522+
// the config file location, we'll need to know where that config file was.
2523+
// Since 'paths' can be inherited from an extended config in another directory,
2524+
// we wouldn't know which directory to use unless we store it here.
2525+
ownConfig.options.pathsBasePath = basePath;
2526+
}
24892527
if (ownConfig.extendedConfigPath) {
24902528
// copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios.
24912529
resolutionStack = resolutionStack.concat([resolvedPath]);

src/compiler/core.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,18 +2250,26 @@ namespace ts {
22502250
}
22512251
}
22522252

2253-
export function padLeft(s: string, length: number) {
2254-
while (s.length < length) {
2255-
s = " " + s;
2256-
}
2257-
return s;
2258-
}
22592253

2260-
export function padRight(s: string, length: number) {
2261-
while (s.length < length) {
2262-
s = s + " ";
2263-
}
2254+
/**
2255+
* Returns string left-padded with spaces or zeros until it reaches the given length.
2256+
*
2257+
* @param s String to pad.
2258+
* @param length Final padded length. If less than or equal to 's.length', returns 's' unchanged.
2259+
* @param padString Character to use as padding (default " ").
2260+
*/
2261+
export function padLeft(s: string, length: number, padString: " " | "0" = " ") {
2262+
return length <= s.length ? s : padString.repeat(length - s.length) + s;
2263+
}
22642264

2265-
return s;
2265+
/**
2266+
* Returns string right-padded with spaces until it reaches the given length.
2267+
*
2268+
* @param s String to pad.
2269+
* @param length Final padded length. If less than or equal to 's.length', returns 's' unchanged.
2270+
* @param padString Character to use as padding (default " ").
2271+
*/
2272+
export function padRight(s: string, length: number, padString: " " = " ") {
2273+
return length <= s.length ? s : s + padString.repeat(length - s.length);
22662274
}
22672275
}

src/compiler/diagnosticMessages.json

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,14 @@
11841184
"category": "Error",
11851185
"code": 1389
11861186
},
1187-
1187+
"Provides a root package name when using outFile with declarations.": {
1188+
"category": "Message",
1189+
"code": 1390
1190+
},
1191+
"The `bundledPackageName` option must be provided when using outFile and node module resolution with declaration emit.": {
1192+
"category": "Error",
1193+
"code": 1391
1194+
},
11881195
"The types of '{0}' are incompatible between these types.": {
11891196
"category": "Error",
11901197
"code": 2200
@@ -3486,10 +3493,6 @@
34863493
"category": "Error",
34873494
"code": 5059
34883495
},
3489-
"Option 'paths' cannot be used without specifying '--baseUrl' option.": {
3490-
"category": "Error",
3491-
"code": 5060
3492-
},
34933496
"Pattern '{0}' can have at most one '*' character.": {
34943497
"category": "Error",
34953498
"code": 5061
@@ -3602,6 +3605,14 @@
36023605
"category": "Error",
36033606
"code": 5088
36043607
},
3608+
"Option '{0}' cannot be specified when option 'jsx' is '{1}'.": {
3609+
"category": "Error",
3610+
"code": 5089
3611+
},
3612+
"Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?": {
3613+
"category": "Error",
3614+
"code": 5090
3615+
},
36053616

36063617
"Generates a sourcemap for each corresponding '.d.ts' file.": {
36073618
"category": "Message",
@@ -4501,6 +4512,10 @@
45014512
"category": "Message",
45024513
"code": 6237
45034514
},
4515+
"Specify the module specifier to be used to import the `jsx` and `jsxs` factory functions from. eg, react": {
4516+
"category": "Error",
4517+
"code": 6238
4518+
},
45044519

45054520
"Projects to reference": {
45064521
"category": "Message",
@@ -4706,6 +4721,11 @@
47064721
"code": 6504
47074722
},
47084723

4724+
"Include 'undefined' in index signature results": {
4725+
"category": "Message",
4726+
"code": 6800
4727+
},
4728+
47094729
"Variable '{0}' implicitly has an '{1}' type.": {
47104730
"category": "Error",
47114731
"code": 7005

src/compiler/moduleNameResolver.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,16 @@ namespace ts {
788788
}
789789

790790
function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState) {
791-
const { baseUrl, paths } = state.compilerOptions;
792-
if (baseUrl && paths && !pathIsRelative(moduleName)) {
791+
const { baseUrl, paths, pathsBasePath } = state.compilerOptions;
792+
if (paths && !pathIsRelative(moduleName)) {
793793
if (state.traceEnabled) {
794-
trace(state.host, Diagnostics.baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1, baseUrl, moduleName);
794+
if (baseUrl) {
795+
trace(state.host, Diagnostics.baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1, baseUrl, moduleName);
796+
}
795797
trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName);
796798
}
797-
return tryLoadModuleUsingPaths(extensions, moduleName, baseUrl, paths, loader, /*onlyRecordFailures*/ false, state);
799+
const baseDirectory = baseUrl ?? Debug.checkDefined(pathsBasePath || state.host.getCurrentDirectory?.(), "Encountered 'paths' without a 'baseUrl', config file, or host 'getCurrentDirectory'.");
800+
return tryLoadModuleUsingPaths(extensions, moduleName, baseDirectory, paths, loader, /*onlyRecordFailures*/ false, state);
798801
}
799802
}
800803

@@ -1368,6 +1371,7 @@ namespace ts {
13681371
}
13691372
const resolved = forEach(paths[matchedPatternText], subst => {
13701373
const path = matchedStar ? subst.replace("*", matchedStar) : subst;
1374+
// When baseUrl is not specified, the command line parser resolves relative paths to the config file location.
13711375
const candidate = normalizePath(combinePaths(baseDirectory, path));
13721376
if (state.traceEnabled) {
13731377
trace(state.host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path);

src/compiler/moduleSpecifiers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace ts.moduleSpecifiers {
157157
}
158158

159159
function getLocalModuleSpecifier(moduleFileName: string, { getCanonicalFileName, sourceDirectory }: Info, compilerOptions: CompilerOptions, { ending, relativePreference }: Preferences): string {
160-
const { baseUrl, paths, rootDirs } = compilerOptions;
160+
const { baseUrl, paths, rootDirs, bundledPackageName } = compilerOptions;
161161

162162
const relativePath = rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName, ending, compilerOptions) ||
163163
removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), ending, compilerOptions);
@@ -170,8 +170,9 @@ namespace ts.moduleSpecifiers {
170170
return relativePath;
171171
}
172172

173-
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
174-
const fromPaths = paths && tryGetModuleNameFromPaths(removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
173+
const bundledPkgReference = bundledPackageName ? combinePaths(bundledPackageName, relativeToBaseUrl) : relativeToBaseUrl;
174+
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix(bundledPkgReference, ending, compilerOptions);
175+
const fromPaths = paths && tryGetModuleNameFromPaths(removeFileExtension(bundledPkgReference), importRelativeToBaseUrl, paths);
175176
const nonRelative = fromPaths === undefined ? importRelativeToBaseUrl : fromPaths;
176177

177178
if (relativePreference === RelativePreference.NonRelative) {
@@ -278,7 +279,7 @@ namespace ts.moduleSpecifiers {
278279
const isInNodeModules = pathContainsNodeModules(path);
279280
allFileNames.set(path, { path: getCanonicalFileName(path), isRedirect, isInNodeModules });
280281
importedFileFromNodeModules = importedFileFromNodeModules || isInNodeModules;
281-
// dont return value, so we collect everything
282+
// don't return value, so we collect everything
282283
}
283284
);
284285

src/compiler/parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8879,6 +8879,8 @@ namespace ts {
88798879
}
88808880
case "jsx":
88818881
case "jsxfrag":
8882+
case "jsximportsource":
8883+
case "jsxruntime":
88828884
return; // Accessed directly
88838885
default: Debug.fail("Unhandled pragma kind"); // Can this be made into an assertNever in the future?
88848886
}

src/compiler/program.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,10 +2994,6 @@ namespace ts {
29942994
}
29952995
}
29962996

2997-
if (options.paths && options.baseUrl === undefined) {
2998-
createDiagnosticForOptionName(Diagnostics.Option_paths_cannot_be_used_without_specifying_baseUrl_option, "paths");
2999-
}
3000-
30012997
if (options.composite) {
30022998
if (options.declaration === false) {
30032999
createDiagnosticForOptionName(Diagnostics.Composite_projects_may_not_disable_declaration_emit, "declaration");
@@ -3056,6 +3052,9 @@ namespace ts {
30563052
if (!hasZeroOrOneAsteriskCharacter(subst)) {
30573053
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Substitution_0_in_pattern_1_can_have_at_most_one_Asterisk_character, subst, key);
30583054
}
3055+
if (!options.baseUrl && !pathIsRelative(subst) && !pathIsAbsolute(subst)) {
3056+
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Non_relative_paths_are_not_allowed_when_baseUrl_is_not_set_Did_you_forget_a_leading_Slash);
3057+
}
30593058
}
30603059
else {
30613060
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2, subst, key, typeOfSubst);
@@ -3139,6 +3138,11 @@ namespace ts {
31393138
}
31403139
}
31413140

3141+
// Without a package name, for multiple files being bundled into a .d.ts file you basically get a file which doesn't wrk
3142+
if (outputFile && getEmitDeclarations(options) && getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeJs && !options.bundledPackageName) {
3143+
createDiagnosticForOptionName(Diagnostics.The_bundledPackageName_option_must_be_provided_when_using_outFile_and_node_module_resolution_with_declaration_emit, options.out ? "out" : "outFile");
3144+
}
3145+
31423146
if (options.resolveJsonModule) {
31433147
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs) {
31443148
createDiagnosticForOptionName(Diagnostics.Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy, "resolveJsonModule");
@@ -3191,6 +3195,9 @@ namespace ts {
31913195
if (options.reactNamespace) {
31923196
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory");
31933197
}
3198+
if (options.jsx === JsxEmit.ReactJSX || options.jsx === JsxEmit.ReactJSXDev) {
3199+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_jsx_is_1, "jsxFactory", inverseJsxOptionMap.get("" + options.jsx));
3200+
}
31943201
if (!parseIsolatedEntityName(options.jsxFactory, languageVersion)) {
31953202
createOptionValueDiagnostic("jsxFactory", Diagnostics.Invalid_value_for_jsxFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFactory);
31963203
}
@@ -3203,11 +3210,26 @@ namespace ts {
32033210
if (!options.jsxFactory) {
32043211
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "jsxFragmentFactory", "jsxFactory");
32053212
}
3213+
if (options.jsx === JsxEmit.ReactJSX || options.jsx === JsxEmit.ReactJSXDev) {
3214+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_jsx_is_1, "jsxFragmentFactory", inverseJsxOptionMap.get("" + options.jsx));
3215+
}
32063216
if (!parseIsolatedEntityName(options.jsxFragmentFactory, languageVersion)) {
32073217
createOptionValueDiagnostic("jsxFragmentFactory", Diagnostics.Invalid_value_for_jsxFragmentFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFragmentFactory);
32083218
}
32093219
}
32103220

3221+
if (options.reactNamespace) {
3222+
if (options.jsx === JsxEmit.ReactJSX || options.jsx === JsxEmit.ReactJSXDev) {
3223+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_jsx_is_1, "reactNamespace", inverseJsxOptionMap.get("" + options.jsx));
3224+
}
3225+
}
3226+
3227+
if (options.jsxImportSource) {
3228+
if (options.jsx === JsxEmit.React) {
3229+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_jsx_is_1, "jsxImportSource", inverseJsxOptionMap.get("" + options.jsx));
3230+
}
3231+
}
3232+
32113233
// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
32123234
if (!options.noEmit && !options.suppressOutputPathCheck) {
32133235
const emitHost = getEmitHost();
@@ -3316,7 +3338,7 @@ namespace ts {
33163338
});
33173339
}
33183340

3319-
function createDiagnosticForOptionPathKeyValue(key: string, valueIndex: number, message: DiagnosticMessage, arg0: string | number, arg1: string | number, arg2?: string | number) {
3341+
function createDiagnosticForOptionPathKeyValue(key: string, valueIndex: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number) {
33203342
let needCompilerDiagnostic = true;
33213343
const pathsSyntax = getOptionPathsSyntax();
33223344
for (const pathProp of pathsSyntax) {

0 commit comments

Comments
 (0)