Skip to content

Commit 597bb0e

Browse files
committed
Merge branch 'master' into strictParameter
2 parents f1c5fa5 + cff04e6 commit 597bb0e

File tree

70 files changed

+12842
-11280
lines changed

Some content is hidden

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

70 files changed

+12842
-11280
lines changed

src/compiler/checker.ts

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ namespace ts {
3131
}
3232

3333
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+
3446
// Cancellation that controls whether or not we can cancel in the middle of type checking.
3547
// In general cancelling is *not* safe for the type checker. We might be in the middle of
3648
// computing something, and we will leave our internals in an inconsistent state. Callers
@@ -358,7 +370,9 @@ namespace ts {
358370
finally {
359371
cancellationToken = undefined;
360372
}
361-
}
373+
},
374+
375+
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
362376
};
363377

364378
function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, isForSignatureHelp: boolean): Signature | undefined {
@@ -1196,17 +1210,23 @@ namespace ts {
11961210
// local types not visible outside the function body
11971211
: false;
11981212
}
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 =
12051224
lastLocation.kind === SyntaxKind.Parameter ||
12061225
(
12071226
lastLocation === (<FunctionLikeDeclaration>location).type &&
12081227
!!findAncestor(result.valueDeclaration, isParameter)
12091228
);
1229+
}
12101230
}
12111231
}
12121232
else if (location.kind === SyntaxKind.ConditionalType) {
@@ -2265,12 +2285,9 @@ namespace ts {
22652285
resolvedFileName));
22662286
}
22672287
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));
22702289
}
22712290

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.
22742291
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol;
22752292
function resolveExternalModuleSymbol(moduleSymbol: Symbol | undefined, dontResolveAlias?: boolean): Symbol | undefined;
22762293
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
@@ -3909,13 +3926,22 @@ namespace ts {
39093926
const links = getSymbolLinks(symbol);
39103927
let specifier = links.specifierCache && links.specifierCache.get(contextFile.path);
39113928
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(
39133937
symbol,
3914-
compilerOptions,
3938+
specifierCompilerOptions,
39153939
contextFile,
3916-
context.tracker.moduleResolverHost,
3940+
moduleResolverHost,
3941+
host.getSourceFiles(),
3942+
{ importModuleSpecifierPreference: isBundle ? "non-relative" : "relative" },
39173943
host.redirectTargetsMap,
3918-
);
3944+
)));
39193945
links.specifierCache = links.specifierCache || createMap();
39203946
links.specifierCache.set(contextFile.path, specifier);
39213947
}

src/compiler/commandLineParser.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,11 @@ namespace ts {
815815
}
816816

817817
function getOptionNameMap(): OptionNameMap {
818-
if (optionNameMapCache) {
819-
return optionNameMapCache;
820-
}
818+
return optionNameMapCache || (optionNameMapCache = createOptionNameMap(optionDeclarations));
819+
}
821820

821+
/*@internal*/
822+
export function createOptionNameMap(optionDeclarations: ReadonlyArray<CommandLineOption>): OptionNameMap {
822823
const optionNameMap = createMap<CommandLineOption>();
823824
const shortOptionNames = createMap<string>();
824825
forEach(optionDeclarations, option => {
@@ -828,8 +829,7 @@ namespace ts {
828829
}
829830
});
830831

831-
optionNameMapCache = { optionNameMap, shortOptionNames };
832-
return optionNameMapCache;
832+
return { optionNameMap, shortOptionNames };
833833
}
834834

835835
/* @internal */
@@ -979,7 +979,12 @@ namespace ts {
979979
}
980980

981981
/** @internal */
982-
export function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
982+
export function getOptionFromName(optionName: string, allowShort?: boolean): CommandLineOption | undefined {
983+
return getOptionDeclarationFromName(getOptionNameMap, optionName, allowShort);
984+
}
985+
986+
/*@internal*/
987+
export function getOptionDeclarationFromName(getOptionNameMap: () => OptionNameMap, optionName: string, allowShort = false): CommandLineOption | undefined {
983988
optionName = optionName.toLowerCase();
984989
const { optionNameMap, shortOptionNames } = getOptionNameMap();
985990
// Try to translate short option names to their full equivalents.

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,6 +2912,11 @@
29122912
"category": "Error",
29132913
"code": 5071
29142914
},
2915+
"Unknown build option '{0}'.": {
2916+
"category": "Error",
2917+
"code": 5072
2918+
},
2919+
29152920

29162921
"Generates a sourcemap for each corresponding '.d.ts' file.": {
29172922
"category": "Message",

0 commit comments

Comments
 (0)