Skip to content

Commit 6b29060

Browse files
committed
Merge branch 'master' into fix32434
2 parents 623a172 + 70b7bd5 commit 6b29060

File tree

58 files changed

+498
-985
lines changed

Some content is hidden

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

58 files changed

+498
-985
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9890,28 +9890,28 @@ namespace ts {
98909890
return links.resolvedType;
98919891
}
98929892

9893-
function addTypeToIntersection(typeSet: Type[], includes: TypeFlags, type: Type) {
9893+
function addTypeToIntersection(typeSet: Map<Type>, includes: TypeFlags, type: Type) {
98949894
const flags = type.flags;
98959895
if (flags & TypeFlags.Intersection) {
98969896
return addTypesToIntersection(typeSet, includes, (<IntersectionType>type).types);
98979897
}
98989898
if (isEmptyAnonymousObjectType(type)) {
98999899
if (!(includes & TypeFlags.IncludesEmptyObject)) {
99009900
includes |= TypeFlags.IncludesEmptyObject;
9901-
typeSet.push(type);
9901+
typeSet.set(type.id.toString(), type);
99029902
}
99039903
}
99049904
else {
99059905
if (flags & TypeFlags.AnyOrUnknown) {
99069906
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard;
99079907
}
9908-
else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains(typeSet, type)) {
9908+
else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !typeSet.has(type.id.toString())) {
99099909
if (type.flags & TypeFlags.Unit && includes & TypeFlags.Unit) {
99109910
// We have seen two distinct unit types which means we should reduce to an
99119911
// empty intersection. Adding TypeFlags.NonPrimitive causes that to happen.
99129912
includes |= TypeFlags.NonPrimitive;
99139913
}
9914-
typeSet.push(type);
9914+
typeSet.set(type.id.toString(), type);
99159915
}
99169916
includes |= flags & TypeFlags.IncludesMask;
99179917
}
@@ -9920,7 +9920,7 @@ namespace ts {
99209920

99219921
// Add the given types to the given type set. Order is preserved, freshness is removed from literal
99229922
// types, duplicates are removed, and nested types of the given kind are flattened into the set.
9923-
function addTypesToIntersection(typeSet: Type[], includes: TypeFlags, types: ReadonlyArray<Type>) {
9923+
function addTypesToIntersection(typeSet: Map<Type>, includes: TypeFlags, types: ReadonlyArray<Type>) {
99249924
for (const type of types) {
99259925
includes = addTypeToIntersection(typeSet, includes, getRegularTypeOfLiteralType(type));
99269926
}
@@ -10027,8 +10027,9 @@ namespace ts {
1002710027
// Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
1002810028
// for intersections of types with signatures can be deterministic.
1002910029
function getIntersectionType(types: ReadonlyArray<Type>, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray<Type>): Type {
10030-
const typeSet: Type[] = [];
10031-
const includes = addTypesToIntersection(typeSet, 0, types);
10030+
const typeMembershipMap: Map<Type> = createMap();
10031+
const includes = addTypesToIntersection(typeMembershipMap, 0, types);
10032+
const typeSet: Type[] = arrayFrom(typeMembershipMap.values());
1003210033
// An intersection type is considered empty if it contains
1003310034
// the type never, or
1003410035
// more than one unit type or,
@@ -24809,6 +24810,12 @@ namespace ts {
2480924810
|| anyType;
2481024811
}
2481124812

24813+
const contextualReturnType = getContextualReturnType(func);
24814+
if (contextualReturnType) {
24815+
return getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Next, contextualReturnType, isAsync)
24816+
|| anyType;
24817+
}
24818+
2481224819
return anyType;
2481324820
}
2481424821

src/compiler/emitter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ namespace ts {
411411
}
412412
);
413413
if (emitOnlyDtsFiles && declarationTransform.transformed[0].kind === SyntaxKind.SourceFile) {
414-
const sourceFile = declarationTransform.transformed[0] as SourceFile;
414+
// Improved narrowing in master/3.6 makes this cast unnecessary, triggering a lint rule.
415+
// But at the same time, the LKG (3.5) necessitates it because it doesn’t narrow.
416+
// Once the LKG is updated to 3.6, this comment, the cast to `SourceFile`, and the
417+
// tslint directive can be all be removed.
418+
const sourceFile = declarationTransform.transformed[0] as SourceFile; // tslint:disable-line
415419
exportedModulesFromDeclarationEmit = sourceFile.exportedModulesFromDeclarationEmit;
416420
}
417421
}

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4760,7 +4760,7 @@ namespace ts {
47604760
UMD = 3,
47614761
System = 4,
47624762
ES2015 = 5,
4763-
ESNext = 6
4763+
ESNext = 99
47644764
}
47654765

47664766
export const enum JsxEmit {
@@ -4808,7 +4808,7 @@ namespace ts {
48084808
ES2018 = 5,
48094809
ES2019 = 6,
48104810
ES2020 = 7,
4811-
ESNext = 8,
4811+
ESNext = 99,
48124812
JSON = 100,
48134813
Latest = ESNext,
48144814
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7485,7 +7485,7 @@ namespace ts {
74857485
export function getDirectoryPath(path: Path): Path;
74867486
/**
74877487
* Returns the path except for its basename. Semantics align with NodeJS's `path.dirname`
7488-
* except that we support URLs as well.
7488+
* except that we support URL's as well.
74897489
*
74907490
* ```ts
74917491
* getDirectoryPath("/path/to/file.ext") === "/path/to"

src/harness/fourslash.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -797,16 +797,16 @@ namespace FourSlash {
797797
for (const include of toArray(options.includes)) {
798798
const name = typeof include === "string" ? include : include.name;
799799
const found = nameToEntries.get(name);
800-
if (!found) throw this.raiseError(`No completion ${name} found`);
801-
assert(found.length === 1, `Must use 'exact' for multiple completions with same name: '${name}'`);
800+
if (!found) throw this.raiseError(`Includes: completion '${name}' not found.`);
801+
assert(found.length === 1); // Must use 'exact' for multiple completions with same name
802802
this.verifyCompletionEntry(ts.first(found), include);
803803
}
804804
}
805805
if (options.excludes) {
806806
for (const exclude of toArray(options.excludes)) {
807807
assert(typeof exclude === "string");
808808
if (nameToEntries.has(exclude)) {
809-
this.raiseError(`Did not expect to get a completion named ${exclude}`);
809+
this.raiseError(`Excludes: unexpected completion '${exclude}' found.`);
810810
}
811811
}
812812
}
@@ -4827,40 +4827,23 @@ namespace FourSlashInterface {
48274827
"interface",
48284828
"let",
48294829
"package",
4830-
"private",
4831-
"protected",
4832-
"public",
4833-
"static",
48344830
"yield",
4835-
"abstract",
4836-
"as",
48374831
"any",
48384832
"async",
48394833
"await",
48404834
"boolean",
4841-
"constructor",
48424835
"declare",
4843-
"get",
4844-
"infer",
4845-
"is",
48464836
"keyof",
48474837
"module",
4848-
"namespace",
48494838
"never",
48504839
"readonly",
4851-
"require",
48524840
"number",
48534841
"object",
4854-
"set",
48554842
"string",
48564843
"symbol",
4857-
"type",
48584844
"unique",
48594845
"unknown",
4860-
"from",
4861-
"global",
48624846
"bigint",
4863-
"of",
48644847
].map(keywordEntry);
48654848

48664849
export const statementKeywords: ReadonlyArray<ExpectedCompletionEntryObject> = statementKeywordsWithTypes.filter(k => {
@@ -5041,40 +5024,23 @@ namespace FourSlashInterface {
50415024
"interface",
50425025
"let",
50435026
"package",
5044-
"private",
5045-
"protected",
5046-
"public",
5047-
"static",
50485027
"yield",
5049-
"abstract",
5050-
"as",
50515028
"any",
50525029
"async",
50535030
"await",
50545031
"boolean",
5055-
"constructor",
50565032
"declare",
5057-
"get",
5058-
"infer",
5059-
"is",
50605033
"keyof",
50615034
"module",
5062-
"namespace",
50635035
"never",
50645036
"readonly",
5065-
"require",
50665037
"number",
50675038
"object",
5068-
"set",
50695039
"string",
50705040
"symbol",
5071-
"type",
50725041
"unique",
50735042
"unknown",
5074-
"from",
5075-
"global",
50765043
"bigint",
5077-
"of",
50785044
].map(keywordEntry);
50795045

50805046
export const globalInJsKeywords = getInJsKeywords(globalKeywords);
@@ -5127,11 +5093,6 @@ namespace FourSlashInterface {
51275093

51285094
export const insideMethodInJsKeywords = getInJsKeywords(insideMethodKeywords);
51295095

5130-
export const globalKeywordsPlusUndefined: ReadonlyArray<ExpectedCompletionEntryObject> = (() => {
5131-
const i = ts.findIndex(globalKeywords, x => x.name === "unique");
5132-
return [...globalKeywords.slice(0, i), keywordEntry("undefined"), ...globalKeywords.slice(i)];
5133-
})();
5134-
51355096
export const globals: ReadonlyArray<ExpectedCompletionEntryObject> = [
51365097
globalThisEntry,
51375098
...globalsVars,

src/jsTyping/jsTyping.ts

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,8 @@ namespace ts.JsTyping {
289289

290290
}
291291

292-
export const enum PackageNameValidationResult {
292+
export const enum NameValidationResult {
293293
Ok,
294-
ScopedPackagesNotSupported,
295294
EmptyName,
296295
NameTooLong,
297296
NameStartsWithDot,
@@ -301,49 +300,77 @@ namespace ts.JsTyping {
301300

302301
const maxPackageNameLength = 214;
303302

303+
export interface ScopedPackageNameValidationResult {
304+
name: string;
305+
isScopeName: boolean;
306+
result: NameValidationResult;
307+
}
308+
export type PackageNameValidationResult = NameValidationResult | ScopedPackageNameValidationResult;
309+
304310
/**
305311
* Validates package name using rules defined at https://docs.npmjs.com/files/package.json
306312
*/
307313
export function validatePackageName(packageName: string): PackageNameValidationResult {
314+
return validatePackageNameWorker(packageName, /*supportScopedPackage*/ true);
315+
}
316+
317+
function validatePackageNameWorker(packageName: string, supportScopedPackage: false): NameValidationResult;
318+
function validatePackageNameWorker(packageName: string, supportScopedPackage: true): PackageNameValidationResult;
319+
function validatePackageNameWorker(packageName: string, supportScopedPackage: boolean): PackageNameValidationResult {
308320
if (!packageName) {
309-
return PackageNameValidationResult.EmptyName;
321+
return NameValidationResult.EmptyName;
310322
}
311323
if (packageName.length > maxPackageNameLength) {
312-
return PackageNameValidationResult.NameTooLong;
324+
return NameValidationResult.NameTooLong;
313325
}
314326
if (packageName.charCodeAt(0) === CharacterCodes.dot) {
315-
return PackageNameValidationResult.NameStartsWithDot;
327+
return NameValidationResult.NameStartsWithDot;
316328
}
317329
if (packageName.charCodeAt(0) === CharacterCodes._) {
318-
return PackageNameValidationResult.NameStartsWithUnderscore;
330+
return NameValidationResult.NameStartsWithUnderscore;
319331
}
320332
// check if name is scope package like: starts with @ and has one '/' in the middle
321333
// scoped packages are not currently supported
322-
// TODO: when support will be added we'll need to split and check both scope and package name
323-
if (/^@[^/]+\/[^/]+$/.test(packageName)) {
324-
return PackageNameValidationResult.ScopedPackagesNotSupported;
334+
if (supportScopedPackage) {
335+
const matches = /^@([^/]+)\/([^/]+)$/.exec(packageName);
336+
if (matches) {
337+
const scopeResult = validatePackageNameWorker(matches[1], /*supportScopedPackage*/ false);
338+
if (scopeResult !== NameValidationResult.Ok) {
339+
return { name: matches[1], isScopeName: true, result: scopeResult };
340+
}
341+
const packageResult = validatePackageNameWorker(matches[2], /*supportScopedPackage*/ false);
342+
if (packageResult !== NameValidationResult.Ok) {
343+
return { name: matches[2], isScopeName: false, result: packageResult };
344+
}
345+
return NameValidationResult.Ok;
346+
}
325347
}
326348
if (encodeURIComponent(packageName) !== packageName) {
327-
return PackageNameValidationResult.NameContainsNonURISafeCharacters;
349+
return NameValidationResult.NameContainsNonURISafeCharacters;
328350
}
329-
return PackageNameValidationResult.Ok;
351+
return NameValidationResult.Ok;
330352
}
331353

332354
export function renderPackageNameValidationFailure(result: PackageNameValidationResult, typing: string): string {
355+
return typeof result === "object" ?
356+
renderPackageNameValidationFailureWorker(typing, result.result, result.name, result.isScopeName) :
357+
renderPackageNameValidationFailureWorker(typing, result, typing, /*isScopeName*/ false);
358+
}
359+
360+
function renderPackageNameValidationFailureWorker(typing: string, result: NameValidationResult, name: string, isScopeName: boolean): string {
361+
const kind = isScopeName ? "Scope" : "Package";
333362
switch (result) {
334-
case PackageNameValidationResult.EmptyName:
335-
return `Package name '${typing}' cannot be empty`;
336-
case PackageNameValidationResult.NameTooLong:
337-
return `Package name '${typing}' should be less than ${maxPackageNameLength} characters`;
338-
case PackageNameValidationResult.NameStartsWithDot:
339-
return `Package name '${typing}' cannot start with '.'`;
340-
case PackageNameValidationResult.NameStartsWithUnderscore:
341-
return `Package name '${typing}' cannot start with '_'`;
342-
case PackageNameValidationResult.ScopedPackagesNotSupported:
343-
return `Package '${typing}' is scoped and currently is not supported`;
344-
case PackageNameValidationResult.NameContainsNonURISafeCharacters:
345-
return `Package name '${typing}' contains non URI safe characters`;
346-
case PackageNameValidationResult.Ok:
363+
case NameValidationResult.EmptyName:
364+
return `'${typing}':: ${kind} name '${name}' cannot be empty`;
365+
case NameValidationResult.NameTooLong:
366+
return `'${typing}':: ${kind} name '${name}' should be less than ${maxPackageNameLength} characters`;
367+
case NameValidationResult.NameStartsWithDot:
368+
return `'${typing}':: ${kind} name '${name}' cannot start with '.'`;
369+
case NameValidationResult.NameStartsWithUnderscore:
370+
return `'${typing}':: ${kind} name '${name}' cannot start with '_'`;
371+
case NameValidationResult.NameContainsNonURISafeCharacters:
372+
return `'${typing}':: ${kind} name '${name}' contains non URI safe characters`;
373+
case NameValidationResult.Ok:
347374
return Debug.fail(); // Shouldn't have called this.
348375
default:
349376
throw Debug.assertNever(result);

src/lib/es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare var Infinity: number;
1212
declare function eval(x: string): any;
1313

1414
/**
15-
* Converts A string to an integer.
15+
* Converts a string to an integer.
1616
* @param s A string to convert into a number.
1717
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
1818
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.

src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<LCX SchemaVersion="6.0" Name="f:\ddSetup\sources\typescript\localization\compiler2.resx" PsrId="306" FileType="1" SrcCul="en-US" TgtCul="it-IT" xmlns="http://schemas.microsoft.com/locstudio/2006/6/lcx">
33
<Props>
44
<Str Name="CustomName1" Val="Custom 1" />
@@ -3301,7 +3301,7 @@
33013301
<Str Cat="Text">
33023302
<Val><![CDATA[Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set.]]></Val>
33033303
<Tgt Cat="Text" Stat="Loc" Orig="New">
3304-
<Val><![CDATA[Crea l'origine unitamente alle mappe di origine all'interno di un unico file. Richiede l'impostazione di '--inlineSourceMap' o '--sourceMap'.]]></Val>
3304+
<Val><![CDATA[Crea l'origine unitamente ai mapping di origine all'interno di un unico file. Richiede l'impostazione di '--inlineSourceMap' o '--sourceMap'.]]></Val>
33053305
</Tgt>
33063306
</Str>
33073307
<Disp Icon="Str" />
@@ -4123,7 +4123,7 @@
41234123
<Str Cat="Text">
41244124
<Val><![CDATA[Generates a sourcemap for each corresponding '.d.ts' file.]]></Val>
41254125
<Tgt Cat="Text" Stat="Loc" Orig="New">
4126-
<Val><![CDATA[Genera un sourcemap per ogni file '.d.ts' corrispondente.]]></Val>
4126+
<Val><![CDATA[Genera un mapping di origine per ogni file '.d.ts' corrispondente.]]></Val>
41274127
</Tgt>
41284128
</Str>
41294129
<Disp Icon="Str" />

src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<LCX SchemaVersion="6.0" Name="f:\ddSetup\sources\typescript\localization\compiler2.resx" PsrId="306" FileType="1" SrcCul="en-US" TgtCul="ru-RU" xmlns="http://schemas.microsoft.com/locstudio/2006/6/lcx">
33
<Props>
44
<Str Name="CustomName1" Val="Custom 1" />
@@ -3300,7 +3300,7 @@
33003300
<Str Cat="Text">
33013301
<Val><![CDATA[Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set.]]></Val>
33023302
<Tgt Cat="Text" Stat="Loc" Orig="New">
3303-
<Val><![CDATA[Порождать источник вместе с sourcemap в одном файле (нужно задать параметр --inlineSourceMap или --sourceMap).]]></Val>
3303+
<Val><![CDATA[Порождать источник вместе с сопоставителями с исходным кодом в одном файле (нужно задать параметр --inlineSourceMap или --sourceMap).]]></Val>
33043304
</Tgt>
33053305
</Str>
33063306
<Disp Icon="Str" />
@@ -4122,7 +4122,7 @@
41224122
<Str Cat="Text">
41234123
<Val><![CDATA[Generates a sourcemap for each corresponding '.d.ts' file.]]></Val>
41244124
<Tgt Cat="Text" Stat="Loc" Orig="New">
4125-
<Val><![CDATA[Создает sourcemap для каждого соответствующего файла ".d.ts".]]></Val>
4125+
<Val><![CDATA[Создает сопоставитель с исходным кодом для каждого соответствующего файла ".d.ts".]]></Val>
41264126
</Tgt>
41274127
</Str>
41284128
<Disp Icon="Str" />

0 commit comments

Comments
 (0)