Skip to content

Commit 2c7c62d

Browse files
committed
Merge branch 'master' into fix-incremental-jsx-crash
2 parents dc7d997 + 266d8de commit 2c7c62d

Some content is hidden

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

44 files changed

+614
-475
lines changed

.github/pr_owners.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ RyanCavanaugh
66
sheetalkamat
77
orta
88
rbuckton
9+
ahejlsberg
10+
amcasey
11+
jessetrinity
12+
minestarks
13+
uniqueiniquity

package-lock.json

Lines changed: 38 additions & 20 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ namespace ts {
28002800
const resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias);
28012801
const name = node.propertyName || node.name;
28022802
if (commonJSPropertyAccess && resolved && isIdentifier(name)) {
2803-
return getPropertyOfType(getTypeOfSymbol(resolved), name.escapedText);
2803+
return resolveSymbol(getPropertyOfType(getTypeOfSymbol(resolved), name.escapedText), dontResolveAlias);
28042804
}
28052805
markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false);
28062806
return resolved;

src/compiler/moduleSpecifiers.ts

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Used by importFixes, getEditsForFileRename, and declaration emit to synthesize import module specifiers.
22
/* @internal */
33
namespace ts.moduleSpecifiers {
4-
const enum RelativePreference { Relative, NonRelative, Auto }
4+
const enum RelativePreference { Relative, NonRelative, Shortest, ExternalNonRelative }
55
// See UserPreferences#importPathEnding
66
const enum Ending { Minimal, Index, JsExtension }
77

@@ -13,7 +13,11 @@ namespace ts.moduleSpecifiers {
1313

1414
function getPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }: UserPreferences, compilerOptions: CompilerOptions, importingSourceFile: SourceFile): Preferences {
1515
return {
16-
relativePreference: importModuleSpecifierPreference === "relative" ? RelativePreference.Relative : importModuleSpecifierPreference === "non-relative" ? RelativePreference.NonRelative : RelativePreference.Auto,
16+
relativePreference:
17+
importModuleSpecifierPreference === "relative" ? RelativePreference.Relative :
18+
importModuleSpecifierPreference === "non-relative" ? RelativePreference.NonRelative :
19+
importModuleSpecifierPreference === "project-relative" ? RelativePreference.ExternalNonRelative :
20+
RelativePreference.Shortest,
1721
ending: getEnding(),
1822
};
1923
function getEnding(): Ending {
@@ -147,17 +151,19 @@ namespace ts.moduleSpecifiers {
147151

148152
interface Info {
149153
readonly getCanonicalFileName: GetCanonicalFileName;
154+
readonly importingSourceFileName: Path
150155
readonly sourceDirectory: Path;
151156
}
152157
// importingSourceFileName is separate because getEditsForFileRename may need to specify an updated path
153158
function getInfo(importingSourceFileName: Path, host: ModuleSpecifierResolutionHost): Info {
154159
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : true);
155160
const sourceDirectory = getDirectoryPath(importingSourceFileName);
156-
return { getCanonicalFileName, sourceDirectory };
161+
return { getCanonicalFileName, importingSourceFileName, sourceDirectory };
157162
}
158163

159-
function getLocalModuleSpecifier(moduleFileName: string, { getCanonicalFileName, sourceDirectory }: Info, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, { ending, relativePreference }: Preferences): string {
164+
function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, { ending, relativePreference }: Preferences): string {
160165
const { baseUrl, paths, rootDirs, bundledPackageName } = compilerOptions;
166+
const { sourceDirectory, getCanonicalFileName } = info;
161167

162168
const relativePath = rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName, ending, compilerOptions) ||
163169
removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), ending, compilerOptions);
@@ -183,7 +189,42 @@ namespace ts.moduleSpecifiers {
183189
return nonRelative;
184190
}
185191

186-
if (relativePreference !== RelativePreference.Auto) Debug.assertNever(relativePreference);
192+
if (relativePreference === RelativePreference.ExternalNonRelative) {
193+
const projectDirectory = host.getCurrentDirectory();
194+
const modulePath = toPath(moduleFileName, projectDirectory, getCanonicalFileName);
195+
const sourceIsInternal = startsWith(sourceDirectory, projectDirectory);
196+
const targetIsInternal = startsWith(modulePath, projectDirectory);
197+
if (sourceIsInternal && !targetIsInternal || !sourceIsInternal && targetIsInternal) {
198+
// 1. The import path crosses the boundary of the tsconfig.json-containing directory.
199+
//
200+
// src/
201+
// tsconfig.json
202+
// index.ts -------
203+
// lib/ | (path crosses tsconfig.json)
204+
// imported.ts <---
205+
//
206+
return nonRelative;
207+
}
208+
209+
const nearestTargetPackageJson = getNearestAncestorDirectoryWithPackageJson(host, getDirectoryPath(modulePath));
210+
const nearestSourcePackageJson = getNearestAncestorDirectoryWithPackageJson(host, sourceDirectory);
211+
if (nearestSourcePackageJson !== nearestTargetPackageJson) {
212+
// 2. The importing and imported files are part of different packages.
213+
//
214+
// packages/a/
215+
// package.json
216+
// index.ts --------
217+
// packages/b/ | (path crosses package.json)
218+
// package.json |
219+
// component.ts <---
220+
//
221+
return nonRelative;
222+
}
223+
224+
return relativePath;
225+
}
226+
227+
if (relativePreference !== RelativePreference.Shortest) Debug.assertNever(relativePreference);
187228

188229
// Prefer a relative import over a baseUrl import if it has fewer components.
189230
return isPathRelativeToParent(nonRelative) || countPathComponents(relativePath) < countPathComponents(nonRelative) ? relativePath : nonRelative;
@@ -213,6 +254,15 @@ namespace ts.moduleSpecifiers {
213254
);
214255
}
215256

257+
function getNearestAncestorDirectoryWithPackageJson(host: ModuleSpecifierResolutionHost, fileName: string) {
258+
if (host.getNearestAncestorDirectoryWithPackageJson) {
259+
return host.getNearestAncestorDirectoryWithPackageJson(fileName);
260+
}
261+
return !!forEachAncestorDirectory(fileName, directory => {
262+
return host.fileExists(combinePaths(directory, "package.json")) ? true : undefined;
263+
});
264+
}
265+
216266
export function forEachFileNameOfModule<T>(
217267
importingFileName: string,
218268
importedFileName: string,

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7858,6 +7858,7 @@ namespace ts {
78587858
realpath?(path: string): string;
78597859
getSymlinkCache?(): SymlinkCache;
78607860
getGlobalTypingsCacheLocation?(): string | undefined;
7861+
getNearestAncestorDirectoryWithPackageJson?(fileName: string, rootDir?: string): string | undefined;
78617862

78627863
getSourceFiles(): readonly SourceFile[];
78637864
readonly redirectTargetsMap: RedirectTargetsMap;
@@ -8159,7 +8160,7 @@ namespace ts {
81598160
readonly includeCompletionsForModuleExports?: boolean;
81608161
readonly includeAutomaticOptionalChainCompletions?: boolean;
81618162
readonly includeCompletionsWithInsertText?: boolean;
8162-
readonly importModuleSpecifierPreference?: "auto" | "relative" | "non-relative";
8163+
readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative";
81638164
/** Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" */
81648165
readonly importModuleSpecifierEnding?: "auto" | "minimal" | "index" | "js";
81658166
readonly allowTextChangesInNewFiles?: boolean;

src/harness/fourslashImpl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,10 @@ namespace FourSlash {
29372937
}
29382938
const range = ts.firstOrUndefined(ranges);
29392939

2940+
if (preferences) {
2941+
this.configure(preferences);
2942+
}
2943+
29402944
const codeFixes = this.getCodeFixes(fileName, errorCode, preferences).filter(f => f.fixName === ts.codefix.importFixName);
29412945

29422946
if (codeFixes.length === 0) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,9 @@
41014101
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
41024102
<Str Cat="Text">
41034103
<Val><![CDATA[Delete all unused imports]]></Val>
4104+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4105+
<Val><![CDATA[删除所有未使用的导入]]></Val>
4106+
</Tgt>
41044107
</Str>
41054108
<Disp Icon="Str" />
41064109
</Item>
@@ -6177,6 +6180,9 @@
61776180
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61786181
<Str Cat="Text">
61796182
<Val><![CDATA[Infer function return type]]></Val>
6183+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6184+
<Val><![CDATA[推断函数返回类型]]></Val>
6185+
</Tgt>
61806186
</Str>
61816187
<Disp Icon="Str" />
61826188
</Item>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,9 @@
41014101
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
41024102
<Str Cat="Text">
41034103
<Val><![CDATA[Delete all unused imports]]></Val>
4104+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4105+
<Val><![CDATA[刪除所有未使用的匯入]]></Val>
4106+
</Tgt>
41044107
</Str>
41054108
<Disp Icon="Str" />
41064109
</Item>
@@ -6177,6 +6180,9 @@
61776180
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61786181
<Str Cat="Text">
61796182
<Val><![CDATA[Infer function return type]]></Val>
6183+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6184+
<Val><![CDATA[推斷函式傳回型別]]></Val>
6185+
</Tgt>
61806186
</Str>
61816187
<Disp Icon="Str" />
61826188
</Item>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,6 +4110,9 @@
41104110
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
41114111
<Str Cat="Text">
41124112
<Val><![CDATA[Delete all unused imports]]></Val>
4113+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4114+
<Val><![CDATA[Odstranit všechny nepoužívané importy]]></Val>
4115+
</Tgt>
41134116
</Str>
41144117
<Disp Icon="Str" />
41154118
</Item>
@@ -6186,6 +6189,9 @@
61866189
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61876190
<Str Cat="Text">
61886191
<Val><![CDATA[Infer function return type]]></Val>
6192+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6193+
<Val><![CDATA[Odvodit návratový typ funkce]]></Val>
6194+
</Tgt>
61896195
</Str>
61906196
<Disp Icon="Str" />
61916197
</Item>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,9 @@
40984098
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
40994099
<Str Cat="Text">
41004100
<Val><![CDATA[Delete all unused imports]]></Val>
4101+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4102+
<Val><![CDATA[Alle nicht verwendeten Importe löschen]]></Val>
4103+
</Tgt>
41014104
</Str>
41024105
<Disp Icon="Str" />
41034106
</Item>
@@ -6174,6 +6177,9 @@
61746177
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61756178
<Str Cat="Text">
61766179
<Val><![CDATA[Infer function return type]]></Val>
6180+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6181+
<Val><![CDATA[Funktionsrückgabetyp ableiten]]></Val>
6182+
</Tgt>
61776183
</Str>
61786184
<Disp Icon="Str" />
61796185
</Item>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,9 @@
41134113
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
41144114
<Str Cat="Text">
41154115
<Val><![CDATA[Delete all unused imports]]></Val>
4116+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4117+
<Val><![CDATA[Eliminar todas las importaciones sin usar]]></Val>
4118+
</Tgt>
41164119
</Str>
41174120
<Disp Icon="Str" />
41184121
</Item>
@@ -6189,6 +6192,9 @@
61896192
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61906193
<Str Cat="Text">
61916194
<Val><![CDATA[Infer function return type]]></Val>
6195+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6196+
<Val><![CDATA[Deducir el tipo de valor devuelto de función]]></Val>
6197+
</Tgt>
61926198
</Str>
61936199
<Disp Icon="Str" />
61946200
</Item>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,9 @@
41134113
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
41144114
<Str Cat="Text">
41154115
<Val><![CDATA[Delete all unused imports]]></Val>
4116+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4117+
<Val><![CDATA[Supprimer toutes les importations inutilisées]]></Val>
4118+
</Tgt>
41164119
</Str>
41174120
<Disp Icon="Str" />
41184121
</Item>
@@ -6189,6 +6192,9 @@
61896192
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61906193
<Str Cat="Text">
61916194
<Val><![CDATA[Infer function return type]]></Val>
6195+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6196+
<Val><![CDATA[Déduire le type de retour de la fonction]]></Val>
6197+
</Tgt>
61926198
</Str>
61936199
<Disp Icon="Str" />
61946200
</Item>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,9 @@
41014101
<Item ItemId=";Delete_all_unused_imports_95147" ItemType="0" PsrId="306" Leaf="true">
41024102
<Str Cat="Text">
41034103
<Val><![CDATA[Delete all unused imports]]></Val>
4104+
<Tgt Cat="Text" Stat="Loc" Orig="New">
4105+
<Val><![CDATA[Eliminare tutte le direttive import non usate]]></Val>
4106+
</Tgt>
41044107
</Str>
41054108
<Disp Icon="Str" />
41064109
</Item>
@@ -6177,6 +6180,9 @@
61776180
<Item ItemId=";Infer_function_return_type_95148" ItemType="0" PsrId="306" Leaf="true">
61786181
<Str Cat="Text">
61796182
<Val><![CDATA[Infer function return type]]></Val>
6183+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6184+
<Val><![CDATA[Dedurre il tipo restituito della funzione]]></Val>
6185+
</Tgt>
61806186
</Str>
61816187
<Disp Icon="Str" />
61826188
</Item>

0 commit comments

Comments
 (0)