@@ -31,6 +31,18 @@ namespace ts {
31
31
}
32
32
33
33
export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
34
+ const getPackagesSet: () => Map<true> = memoize(() => {
35
+ const set = createMap<true>();
36
+ host.getSourceFiles().forEach(sf => {
37
+ if (!sf.resolvedModules) return;
38
+
39
+ forEachEntry(sf.resolvedModules, r => {
40
+ if (r && r.packageId) set.set(r.packageId.name, true);
41
+ });
42
+ });
43
+ return set;
44
+ });
45
+
34
46
// Cancellation that controls whether or not we can cancel in the middle of type checking.
35
47
// In general cancelling is *not* safe for the type checker. We might be in the middle of
36
48
// computing something, and we will leave our internals in an inconsistent state. Callers
@@ -358,7 +370,9 @@ namespace ts {
358
370
finally {
359
371
cancellationToken = undefined;
360
372
}
361
- }
373
+ },
374
+
375
+ getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
362
376
};
363
377
364
378
function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, isForSignatureHelp: boolean): Signature | undefined {
@@ -1196,17 +1210,23 @@ namespace ts {
1196
1210
// local types not visible outside the function body
1197
1211
: false;
1198
1212
}
1199
- if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.FunctionScopedVariable) {
1200
- // parameters are visible only inside function body, parameter list and return type
1201
- // technically for parameter list case here we might mix parameters and variables declared in function,
1202
- // however it is detected separately when checking initializers of parameters
1203
- // to make sure that they reference no variables declared after them.
1204
- useResult =
1213
+ if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
1214
+ // parameter initializer will lookup as normal variable scope when targeting es2015+
1215
+ if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && result.valueDeclaration !== lastLocation) {
1216
+ useResult = false;
1217
+ }
1218
+ else if (result.flags & SymbolFlags.FunctionScopedVariable) {
1219
+ // parameters are visible only inside function body, parameter list and return type
1220
+ // technically for parameter list case here we might mix parameters and variables declared in function,
1221
+ // however it is detected separately when checking initializers of parameters
1222
+ // to make sure that they reference no variables declared after them.
1223
+ useResult =
1205
1224
lastLocation.kind === SyntaxKind.Parameter ||
1206
1225
(
1207
1226
lastLocation === (<FunctionLikeDeclaration>location).type &&
1208
1227
!!findAncestor(result.valueDeclaration, isParameter)
1209
1228
);
1229
+ }
1210
1230
}
1211
1231
}
1212
1232
else if (location.kind === SyntaxKind.ConditionalType) {
@@ -2265,12 +2285,9 @@ namespace ts {
2265
2285
resolvedFileName));
2266
2286
}
2267
2287
function typesPackageExists(packageName: string): boolean {
2268
- return host.getSourceFiles().some(sf => !!sf.resolvedModules && !!forEachEntry(sf.resolvedModules, r =>
2269
- r && r.packageId && r.packageId.name === getTypesPackageName(packageName)));
2288
+ return getPackagesSet().has(getTypesPackageName(packageName));
2270
2289
}
2271
2290
2272
- // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
2273
- // and an external module with no 'export =' declaration resolves to the module itself.
2274
2291
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol;
2275
2292
function resolveExternalModuleSymbol(moduleSymbol: Symbol | undefined, dontResolveAlias?: boolean): Symbol | undefined;
2276
2293
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
@@ -3909,13 +3926,22 @@ namespace ts {
3909
3926
const links = getSymbolLinks(symbol);
3910
3927
let specifier = links.specifierCache && links.specifierCache.get(contextFile.path);
3911
3928
if (!specifier) {
3912
- specifier = moduleSpecifiers.getModuleSpecifierForDeclarationFile(
3929
+ const isBundle = (compilerOptions.out || compilerOptions.outFile);
3930
+ // For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
3931
+ // just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
3932
+ // using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
3933
+ // specifier preference
3934
+ const { moduleResolverHost } = context.tracker;
3935
+ const specifierCompilerOptions = isBundle ? { ...compilerOptions, baseUrl: moduleResolverHost.getCommonSourceDirectory() } : compilerOptions;
3936
+ specifier = first(first(moduleSpecifiers.getModuleSpecifiers(
3913
3937
symbol,
3914
- compilerOptions ,
3938
+ specifierCompilerOptions ,
3915
3939
contextFile,
3916
- context.tracker.moduleResolverHost,
3940
+ moduleResolverHost,
3941
+ host.getSourceFiles(),
3942
+ { importModuleSpecifierPreference: isBundle ? "non-relative" : "relative" },
3917
3943
host.redirectTargetsMap,
3918
- );
3944
+ ))) ;
3919
3945
links.specifierCache = links.specifierCache || createMap();
3920
3946
links.specifierCache.set(contextFile.path, specifier);
3921
3947
}
0 commit comments