Skip to content

Commit c0ef9da

Browse files
committed
Support export *
1 parent c769f65 commit c0ef9da

26 files changed

+570
-227
lines changed

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ under the licensing terms detailed in LICENSE:
88
* Igor Sbitnev <[email protected]>
99
* Norton Wang <[email protected]>
1010
* Alan Pierce <[email protected]>
11+
* Andy Hanson <[email protected]>
1112

1213
Portions of this software are derived from third-party works licensed under
1314
the following terms:

src/ast.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,9 +1972,24 @@ export function mangleInternalName(declaration: DeclarationStatement, asGlobal:
19721972
return mangleInternalName(<DeclarationStatement>parent, asGlobal) +
19731973
STATIC_DELIMITER + name;
19741974
}
1975-
return asGlobal
1976-
? name
1977-
: declaration.range.source.internalPath + PATH_DELIMITER + name;
1975+
return asGlobal ? name : getSourceLevelName(declaration.range.source, name);
1976+
}
1977+
1978+
export function getSourceLevelName({ internalPath }: Source, simpleName: string): string {
1979+
return getSourceLevelNameFromInternalPath(internalPath, simpleName);
1980+
}
1981+
1982+
export function getSourceLevelNameFromInternalPath(internalPath: string, simpleName: string): string {
1983+
return stripIndex(internalPath) + PATH_DELIMITER + simpleName;
1984+
}
1985+
1986+
// "foo/index" -> "foo"
1987+
// "foo/bar" -> itself
1988+
export function stripIndex(internalPath: string): string {
1989+
const indexPart = PATH_DELIMITER + "index";
1990+
return internalPath.endsWith(indexPart)
1991+
? internalPath.substring(0, internalPath.length - indexPart.length)
1992+
: internalPath;
19781993
}
19791994

19801995
/** Mangles an external to an internal path. */

src/compiler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ import {
144144

145145
nodeIsConstantValue,
146146
isLastStatement,
147-
findDecorator
147+
findDecorator,
148+
getSourceLevelName
148149
} from "./ast";
149150

150151
import {
@@ -1266,9 +1267,7 @@ export class Compiler extends DiagnosticEmitter {
12661267
if (!members) return; // filespace
12671268
for (let i = 0, k = members.length; i < k; ++i) {
12681269
let member = members[i];
1269-
let element = fileLevelExports.get(
1270-
statement.range.source.internalPath + PATH_DELIMITER + member.externalName.text
1271-
);
1270+
let element = fileLevelExports.get(getSourceLevelName(statement.range.source, member.externalName.text));
12721271
if (!element) continue; // reported in Program#initialize
12731272
switch (element.kind) {
12741273
case ElementKind.CLASS_PROTOTYPE: {

src/diagnosticMessages.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export enum DiagnosticCode {
8383
A_class_may_only_extend_another_class = 1311,
8484
A_parameter_property_cannot_be_declared_using_a_rest_parameter = 1317,
8585
Duplicate_identifier_0 = 2300,
86+
Identifier_0_is_re_exported_from_modules_1_and_2 = 2301,
8687
Cannot_find_name_0 = 2304,
8788
Module_0_has_no_exported_member_1 = 2305,
8889
Generic_type_0_requires_1_type_argument_s = 2314,
@@ -202,6 +203,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
202203
case 1311: return "A class may only extend another class.";
203204
case 1317: return "A parameter property cannot be declared using a rest parameter.";
204205
case 2300: return "Duplicate identifier '{0}'.";
206+
case 2301: return "Identifier '{0}' is re-exported from modules '{1}' and '{2}'.";
205207
case 2304: return "Cannot find name '{0}'.";
206208
case 2305: return "Module '{0}' has no exported member '{1}'.";
207209
case 2314: return "Generic type '{0}' requires {1} type argument(s).";

src/diagnosticMessages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"A parameter property cannot be declared using a rest parameter.": 1317,
7878

7979
"Duplicate identifier '{0}'.": 2300,
80+
"Identifier '{0}' is re-exported from modules '{1}' and '{2}'.": 2301,
8081
"Cannot find name '{0}'.": 2304,
8182
"Module '{0}' has no exported member '{1}'.": 2305,
8283
"Generic type '{0}' requires {1} type argument(s).": 2314,

0 commit comments

Comments
 (0)