Allow use before declaration for export= assignments (#17967)

This commit is contained in:
Wesley Wigham
2017-08-22 13:47:53 -07:00
committed by GitHub
parent b217d96cc1
commit bdc2aa8afb
4 changed files with 6 additions and 59 deletions

View File

@@ -794,12 +794,17 @@ namespace ts {
// 2. inside a function
// 3. inside an instance property initializer, a reference to a non-instance property
// 4. inside a static property initializer, a reference to a static method in the same class
// 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ)
// or if usage is in a type context:
// 1. inside a type query (typeof in type position)
if (usage.parent.kind === SyntaxKind.ExportSpecifier) {
if (usage.parent.kind === SyntaxKind.ExportSpecifier || (usage.parent.kind === SyntaxKind.ExportAssignment && (usage.parent as ExportAssignment).isExportEquals)) {
// export specifiers do not use the variable, they only make it available for use
return true;
}
// When resolving symbols for exports, the `usage` location passed in can be the export site directly
if (usage.kind === SyntaxKind.ExportAssignment && (usage as ExportAssignment).isExportEquals) {
return true;
}
const container = getEnclosingBlockScopeContainer(declaration);
return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);

View File

@@ -1,17 +0,0 @@
tests/cases/compiler/exportAssignmentOfGenericType1_0.ts(1,10): error TS2449: Class 'T' used before its declaration.
==== tests/cases/compiler/exportAssignmentOfGenericType1_1.ts (0 errors) ====
///<reference path='exportAssignmentOfGenericType1_0.ts'/>
import q = require("exportAssignmentOfGenericType1_0");
class M extends q<string> { }
var m: M;
var r: string = m.foo;
==== tests/cases/compiler/exportAssignmentOfGenericType1_0.ts (1 errors) ====
export = T;
~
!!! error TS2449: Class 'T' used before its declaration.
class T<X> { foo: X; }

View File

@@ -1,21 +0,0 @@
tests/cases/compiler/w1.ts(1,1): error TS2449: Class 'Widget1' used before its declaration.
tests/cases/compiler/w1.ts(1,10): error TS2449: Class 'Widget1' used before its declaration.
==== tests/cases/compiler/consumer.ts (0 errors) ====
import e = require('./exporter');
export function w(): e.w { // Should be OK
return new e.w();
}
==== tests/cases/compiler/w1.ts (2 errors) ====
export = Widget1
~~~~~~~~~~~~~~~~
!!! error TS2449: Class 'Widget1' used before its declaration.
~~~~~~~
!!! error TS2449: Class 'Widget1' used before its declaration.
class Widget1 { name = 'one'; }
==== tests/cases/compiler/exporter.ts (0 errors) ====
export import w = require('./w1');

View File

@@ -1,20 +0,0 @@
tests/cases/compiler/privacyCheckExternalModuleExportAssignmentOfGenericClass_0.ts(1,1): error TS2449: Class 'Foo' used before its declaration.
tests/cases/compiler/privacyCheckExternalModuleExportAssignmentOfGenericClass_0.ts(1,10): error TS2449: Class 'Foo' used before its declaration.
==== tests/cases/compiler/privacyCheckExternalModuleExportAssignmentOfGenericClass_1.ts (0 errors) ====
import Foo = require("./privacyCheckExternalModuleExportAssignmentOfGenericClass_0");
export = Bar;
interface Bar {
foo: Foo<number>;
}
==== tests/cases/compiler/privacyCheckExternalModuleExportAssignmentOfGenericClass_0.ts (2 errors) ====
export = Foo;
~~~~~~~~~~~~~
!!! error TS2449: Class 'Foo' used before its declaration.
~~~
!!! error TS2449: Class 'Foo' used before its declaration.
class Foo<A> {
constructor(public a: A) { }
}