Skip to content

Commit 094f97e

Browse files
author
Andy Hanson
committed
Respond to PR comments
1 parent 3b19825 commit 094f97e

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

src/compiler/binder.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,9 @@ namespace ts {
11811181
lastContainer = next;
11821182
}
11831183

1184-
function declareSymbolAndAddToSymbolTable(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): void {
1184+
function declareSymbolAndAddToSymbolTable(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
11851185
// Just call this directly so that the return type of this function stays "void".
1186-
declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
1186+
return declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
11871187
}
11881188

11891189
function declareSymbolAndAddToSymbolTableWorker(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
@@ -1298,14 +1298,10 @@ namespace ts {
12981298
}
12991299
}
13001300

1301+
const symbol = declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
1302+
13011303
if (pattern) {
1302-
// TODO: don't really need such a symbol in container.locals...
1303-
const symbol = declareSymbol(container.locals, undefined, node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
1304-
file.patternAmbientModules = file.patternAmbientModules || [];
1305-
file.patternAmbientModules.push({ pattern, symbol });
1306-
}
1307-
else {
1308-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
1304+
(file.patternAmbientModules || (file.patternAmbientModules = [])).push({ pattern, symbol });
13091305
}
13101306
}
13111307
}
@@ -2084,10 +2080,10 @@ namespace ts {
20842080
checkStrictModeFunctionName(<FunctionDeclaration>node);
20852081
if (inStrictMode) {
20862082
checkStrictModeFunctionDeclaration(node);
2087-
return bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
2083+
bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
20882084
}
20892085
else {
2090-
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
2086+
declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
20912087
}
20922088
}
20932089

src/compiler/checker.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,9 +1292,11 @@ namespace ts {
12921292
return undefined;
12931293
}
12941294

1295-
const patternModuleSymbol = getPatternAmbientModule(moduleName);
1296-
if (patternModuleSymbol) {
1297-
return getMergedSymbol(patternModuleSymbol);
1295+
if (patternAmbientModules) {
1296+
const pattern = findBestPatternMatch(patternAmbientModules, _ => _.pattern, moduleName);
1297+
if (pattern) {
1298+
return getMergedSymbol(pattern.symbol);
1299+
}
12981300
}
12991301

13001302
if (moduleNotFoundError) {
@@ -1304,16 +1306,6 @@ namespace ts {
13041306
return undefined;
13051307
}
13061308

1307-
/** Get an ambient module with a wildcard ("*") in it. */
1308-
function getPatternAmbientModule(name: string): Symbol | undefined {
1309-
if (patternAmbientModules) {
1310-
const pattern = findBestPatternMatch(patternAmbientModules, _ => _.pattern, name);
1311-
if (pattern) {
1312-
return pattern.symbol;
1313-
}
1314-
}
1315-
}
1316-
13171309
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
13181310
// and an external module with no 'export =' declaration resolves to the module itself.
13191311
function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol {

src/compiler/program.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ namespace ts {
9595
return compilerOptions.traceResolution && host.trace !== undefined;
9696
}
9797

98+
/* @internal */
9899
export function hasZeroOrOneAsteriskCharacter(str: string): boolean {
99100
let seenAsterisk = false;
100101
for (let i = 0; i < str.length; i++) {
@@ -502,7 +503,7 @@ namespace ts {
502503
if (state.traceEnabled) {
503504
trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName);
504505
}
505-
matchedPattern = matchPatternOrExact(Object.keys(state.compilerOptions.paths), moduleName);
506+
matchedPattern = matchPatternOrExact(getKeys(state.compilerOptions.paths), moduleName);
506507
}
507508

508509
if (matchedPattern) {
@@ -570,6 +571,7 @@ namespace ts {
570571
}
571572

572573
/** Return the object corresponding to the best pattern to match `candidate`. */
574+
/* @internal */
573575
export function findBestPatternMatch<T>(values: T[], getPattern: (value: T) => Pattern, candidate: string): T | undefined {
574576
let matchedValue: T | undefined = undefined;
575577
// use length of prefix as betterness criteria
@@ -592,6 +594,7 @@ namespace ts {
592594
endsWith(candidate, suffix);
593595
}
594596

597+
/* @internal */
595598
export function tryParsePattern(pattern: string): Pattern | undefined {
596599
// This should be verified outside of here and a proper error thrown.
597600
Debug.assert(hasZeroOrOneAsteriskCharacter(pattern));

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,12 +2137,14 @@ namespace ts {
21372137
}
21382138

21392139
/** Represents a "prefix*suffix" pattern. */
2140+
/* @internal */
21402141
export interface Pattern {
21412142
prefix: string;
21422143
suffix: string;
21432144
}
2144-
2145+
21452146
/** Used to track a `declare module "foo*"`-like declaration. */
2147+
/* @internal */
21462148
export interface PatternAmbientModule {
21472149
pattern: Pattern;
21482150
symbol: Symbol;

0 commit comments

Comments
 (0)