Skip to content

Commit 34e4209

Browse files
authored
Allow use before declaration for export= assignments (#17967) (#17972)
* Allow use before declaration for export= assignments (#17967) * Add release-2.5 to covered branches
1 parent f5698fc commit 34e4209

File tree

5 files changed

+7
-59
lines changed

5 files changed

+7
-59
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ matrix:
1616
branches:
1717
only:
1818
- master
19+
- release-2.5
1920

2021
install:
2122
- npm uninstall typescript --no-save

src/compiler/checker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,17 @@ namespace ts {
791791
// 2. inside a function
792792
// 3. inside an instance property initializer, a reference to a non-instance property
793793
// 4. inside a static property initializer, a reference to a static method in the same class
794+
// 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ)
794795
// or if usage is in a type context:
795796
// 1. inside a type query (typeof in type position)
796-
if (usage.parent.kind === SyntaxKind.ExportSpecifier) {
797+
if (usage.parent.kind === SyntaxKind.ExportSpecifier || (usage.parent.kind === SyntaxKind.ExportAssignment && (usage.parent as ExportAssignment).isExportEquals)) {
797798
// export specifiers do not use the variable, they only make it available for use
798799
return true;
799800
}
801+
// When resolving symbols for exports, the `usage` location passed in can be the export site directly
802+
if (usage.kind === SyntaxKind.ExportAssignment && (usage as ExportAssignment).isExportEquals) {
803+
return true;
804+
}
800805

801806
const container = getEnclosingBlockScopeContainer(declaration);
802807
return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);

tests/baselines/reference/exportAssignmentOfGenericType1.errors.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/baselines/reference/exportImport.errors.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/baselines/reference/privacyCheckExternalModuleExportAssignmentOfGenericClass.errors.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)