From 75807b1ee9fe37af2788d9a18960e3a71b312db3 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 22 Aug 2017 13:47:53 -0700 Subject: [PATCH 1/2] Allow use before declaration for export= assignments (#17967) --- src/compiler/checker.ts | 7 ++++++- .../exportAssignmentOfGenericType1.errors.txt | 17 --------------- .../reference/exportImport.errors.txt | 21 ------------------- ...eExportAssignmentOfGenericClass.errors.txt | 20 ------------------ 4 files changed, 6 insertions(+), 59 deletions(-) delete mode 100644 tests/baselines/reference/exportAssignmentOfGenericType1.errors.txt delete mode 100644 tests/baselines/reference/exportImport.errors.txt delete mode 100644 tests/baselines/reference/privacyCheckExternalModuleExportAssignmentOfGenericClass.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 15fd97ca5ba8d..89e718e48cc59 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -791,12 +791,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); diff --git a/tests/baselines/reference/exportAssignmentOfGenericType1.errors.txt b/tests/baselines/reference/exportAssignmentOfGenericType1.errors.txt deleted file mode 100644 index e484d4096bb78..0000000000000 --- a/tests/baselines/reference/exportAssignmentOfGenericType1.errors.txt +++ /dev/null @@ -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) ==== - /// - import q = require("exportAssignmentOfGenericType1_0"); - - class M extends q { } - 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 { foo: X; } - \ No newline at end of file diff --git a/tests/baselines/reference/exportImport.errors.txt b/tests/baselines/reference/exportImport.errors.txt deleted file mode 100644 index 4f397d54a557d..0000000000000 --- a/tests/baselines/reference/exportImport.errors.txt +++ /dev/null @@ -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'); - \ No newline at end of file diff --git a/tests/baselines/reference/privacyCheckExternalModuleExportAssignmentOfGenericClass.errors.txt b/tests/baselines/reference/privacyCheckExternalModuleExportAssignmentOfGenericClass.errors.txt deleted file mode 100644 index 2945950068a42..0000000000000 --- a/tests/baselines/reference/privacyCheckExternalModuleExportAssignmentOfGenericClass.errors.txt +++ /dev/null @@ -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; - } -==== 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 { - constructor(public a: A) { } - } - \ No newline at end of file From 4fe7fe72ae58d79bde006cc059088109a40900b0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 18 Aug 2017 15:58:21 -0700 Subject: [PATCH 2/2] Add release-2.5 to covered branches --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4a99aaf2237fd..27b14739d8b10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ matrix: branches: only: - master + - release-2.5 install: - npm uninstall typescript --no-save