Find imported external modules that start with double underscores.
This commit is contained in:
parent
a6a7e81de2
commit
ec17f369a2
3 changed files with 47 additions and 28 deletions
|
@ -545,14 +545,18 @@ module ts {
|
||||||
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
|
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveExternalModuleName(location: Node, moduleExpression: Expression): Symbol {
|
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol {
|
||||||
if (moduleExpression.kind !== SyntaxKind.StringLiteral) {
|
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var moduleLiteral = <LiteralExpression>moduleExpression;
|
var moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
|
||||||
var searchPath = getDirectoryPath(getSourceFile(location).filename);
|
var searchPath = getDirectoryPath(getSourceFile(location).filename);
|
||||||
var moduleName = moduleLiteral.text;
|
|
||||||
|
// Module names are escaped in our symbol table. However, string literal values aren't.
|
||||||
|
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
|
||||||
|
var moduleName = escapeIdentifier(moduleReferenceLiteral.text);
|
||||||
|
|
||||||
if (!moduleName) return;
|
if (!moduleName) return;
|
||||||
var isRelative = isExternalModuleNameRelative(moduleName);
|
var isRelative = isExternalModuleNameRelative(moduleName);
|
||||||
if (!isRelative) {
|
if (!isRelative) {
|
||||||
|
@ -573,10 +577,10 @@ module ts {
|
||||||
if (sourceFile.symbol) {
|
if (sourceFile.symbol) {
|
||||||
return getResolvedExportSymbol(sourceFile.symbol);
|
return getResolvedExportSymbol(sourceFile.symbol);
|
||||||
}
|
}
|
||||||
error(moduleLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
|
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error(moduleLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
|
error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResolvedExportSymbol(moduleSymbol: Symbol): Symbol {
|
function getResolvedExportSymbol(moduleSymbol: Symbol): Symbol {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
tests/cases/compiler/externalModuleReferenceDoubleUnderscore1.ts(2,29): error TS2307: Cannot find external module '__timezonecomplete/basics'.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/externalModuleReferenceDoubleUnderscore1.ts (1 errors) ====
|
|
||||||
declare module 'timezonecomplete' {
|
|
||||||
import basics = require("__timezonecomplete/basics");
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
!!! error TS2307: Cannot find external module '__timezonecomplete/basics'.
|
|
||||||
export import TimeUnit = basics.TimeUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '__timezonecomplete/basics' {
|
|
||||||
export enum TimeUnit {
|
|
||||||
Second = 0,
|
|
||||||
Minute = 1,
|
|
||||||
Hour = 2,
|
|
||||||
Day = 3,
|
|
||||||
Week = 4,
|
|
||||||
Month = 5,
|
|
||||||
Year = 6,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
=== tests/cases/compiler/externalModuleReferenceDoubleUnderscore1.ts ===
|
||||||
|
declare module 'timezonecomplete' {
|
||||||
|
import basics = require("__timezonecomplete/basics");
|
||||||
|
>basics : typeof basics
|
||||||
|
|
||||||
|
export import TimeUnit = basics.TimeUnit;
|
||||||
|
>TimeUnit : typeof basics.TimeUnit
|
||||||
|
>basics : typeof basics
|
||||||
|
>TimeUnit : basics.TimeUnit
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '__timezonecomplete/basics' {
|
||||||
|
export enum TimeUnit {
|
||||||
|
>TimeUnit : TimeUnit
|
||||||
|
|
||||||
|
Second = 0,
|
||||||
|
>Second : TimeUnit
|
||||||
|
|
||||||
|
Minute = 1,
|
||||||
|
>Minute : TimeUnit
|
||||||
|
|
||||||
|
Hour = 2,
|
||||||
|
>Hour : TimeUnit
|
||||||
|
|
||||||
|
Day = 3,
|
||||||
|
>Day : TimeUnit
|
||||||
|
|
||||||
|
Week = 4,
|
||||||
|
>Week : TimeUnit
|
||||||
|
|
||||||
|
Month = 5,
|
||||||
|
>Month : TimeUnit
|
||||||
|
|
||||||
|
Year = 6,
|
||||||
|
>Year : TimeUnit
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue