From 0672a0e547447cf80346bf9de853cc170d444a05 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 12 May 2020 08:20:01 +0100 Subject: [PATCH] refactor(ngcc): rename `ReexportStatement` to `WildcardReexportStatement` (#36989) The term `ReexportStatement` is too general for this particular concept. Here the re-export actually refers to a wildcard where all the module exports are being re-exported. When we introduce other re-export statement types later this will be confusing. PR Close #36989 --- .../ngcc/src/dependencies/commonjs_dependency_host.ts | 4 ++-- packages/compiler-cli/ngcc/src/host/commonjs_host.ts | 10 +++++----- .../compiler-cli/ngcc/src/host/commonjs_umd_utils.ts | 4 ++-- packages/compiler-cli/ngcc/src/host/umd_host.ts | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/dependencies/commonjs_dependency_host.ts b/packages/compiler-cli/ngcc/src/dependencies/commonjs_dependency_host.ts index ef783179ca..009fd5f958 100644 --- a/packages/compiler-cli/ngcc/src/dependencies/commonjs_dependency_host.ts +++ b/packages/compiler-cli/ngcc/src/dependencies/commonjs_dependency_host.ts @@ -8,7 +8,7 @@ import * as ts from 'typescript'; import {AbsoluteFsPath} from '../../../src/ngtsc/file_system'; -import {isReexportStatement, isRequireCall, RequireCall} from '../host/commonjs_umd_utils'; +import {isRequireCall, isWildcardReexportStatement, RequireCall} from '../host/commonjs_umd_utils'; import {DependencyHostBase} from './dependency_host'; import {ResolvedDeepImport, ResolvedRelativeModule} from './module_resolver'; @@ -59,7 +59,7 @@ export class CommonJsDependencyHost extends DependencyHostBase { // Import for the side-effects only: // `require('...')` requireCalls.push(stmt.expression); - } else if (isReexportStatement(stmt)) { + } else if (isWildcardReexportStatement(stmt)) { // Re-export in one of the following formats: // - `__export(require('...'))` // - `__export()` diff --git a/packages/compiler-cli/ngcc/src/host/commonjs_host.ts b/packages/compiler-cli/ngcc/src/host/commonjs_host.ts index 0ba357416b..4ca4fdcbc1 100644 --- a/packages/compiler-cli/ngcc/src/host/commonjs_host.ts +++ b/packages/compiler-cli/ngcc/src/host/commonjs_host.ts @@ -14,7 +14,7 @@ import {Logger} from '../logging/logger'; import {BundleProgram} from '../packages/bundle_program'; import {FactoryMap, getTsHelperFnFromIdentifier, isDefined, stripExtension} from '../utils'; -import {ExportDeclaration, ExportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isReexportStatement, isRequireCall, ReexportStatement, RequireCall} from './commonjs_umd_utils'; +import {ExportDeclaration, ExportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isRequireCall, isWildcardReexportStatement, RequireCall, WildcardReexportStatement} from './commonjs_umd_utils'; import {Esm5ReflectionHost} from './esm5_host'; import {NgccClassSymbol} from './ngcc_host'; @@ -101,8 +101,8 @@ export class CommonJsReflectionHost extends Esm5ReflectionHost { if (isExportStatement(statement)) { const exportDeclaration = this.extractCommonJsExportDeclaration(statement); moduleMap.set(exportDeclaration.name, exportDeclaration.declaration); - } else if (isReexportStatement(statement)) { - const reexports = this.extractCommonJsReexports(statement, sourceFile); + } else if (isWildcardReexportStatement(statement)) { + const reexports = this.extractCommonJsWildcardReexports(statement, sourceFile); for (const reexport of reexports) { moduleMap.set(reexport.name, reexport.declaration); } @@ -130,8 +130,8 @@ export class CommonJsReflectionHost extends Esm5ReflectionHost { } } - private extractCommonJsReexports(statement: ReexportStatement, containingFile: ts.SourceFile): - ExportDeclaration[] { + private extractCommonJsWildcardReexports( + statement: WildcardReexportStatement, containingFile: ts.SourceFile): ExportDeclaration[] { const reexportArg = statement.expression.arguments[0]; const requireCall = isRequireCall(reexportArg) ? diff --git a/packages/compiler-cli/ngcc/src/host/commonjs_umd_utils.ts b/packages/compiler-cli/ngcc/src/host/commonjs_umd_utils.ts index e871034f99..276bbbbce6 100644 --- a/packages/compiler-cli/ngcc/src/host/commonjs_umd_utils.ts +++ b/packages/compiler-cli/ngcc/src/host/commonjs_umd_utils.ts @@ -39,7 +39,7 @@ export interface ExportStatement extends ts.ExpressionStatement { * expression and can be either a `require('...')` call or an identifier (initialized via a * `require('...')` call). */ -export interface ReexportStatement extends ts.ExpressionStatement { +export interface WildcardReexportStatement extends ts.ExpressionStatement { expression: ts.CallExpression; } @@ -94,7 +94,7 @@ export function isExportStatement(stmt: ts.Statement): stmt is ExportStatement { * - `tslib.__export(, exports)` * - `tslib.__exportStar(, exports)` */ -export function isReexportStatement(stmt: ts.Statement): stmt is ReexportStatement { +export function isWildcardReexportStatement(stmt: ts.Statement): stmt is WildcardReexportStatement { // Ensure it is a call expression statement. if (!ts.isExpressionStatement(stmt) || !ts.isCallExpression(stmt.expression)) { return false; diff --git a/packages/compiler-cli/ngcc/src/host/umd_host.ts b/packages/compiler-cli/ngcc/src/host/umd_host.ts index 09298082fc..234d220e88 100644 --- a/packages/compiler-cli/ngcc/src/host/umd_host.ts +++ b/packages/compiler-cli/ngcc/src/host/umd_host.ts @@ -14,7 +14,7 @@ import {Logger} from '../logging/logger'; import {BundleProgram} from '../packages/bundle_program'; import {FactoryMap, getTsHelperFnFromIdentifier, stripExtension} from '../utils'; -import {ExportDeclaration, ExportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isReexportStatement, isRequireCall, ReexportStatement} from './commonjs_umd_utils'; +import {ExportDeclaration, ExportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isRequireCall, isWildcardReexportStatement, WildcardReexportStatement} from './commonjs_umd_utils'; import {Esm5ReflectionHost} from './esm5_host'; import {stripParentheses} from './utils'; @@ -92,8 +92,8 @@ export class UmdReflectionHost extends Esm5ReflectionHost { if (isExportStatement(statement)) { const exportDeclaration = this.extractUmdExportDeclaration(statement); moduleMap.set(exportDeclaration.name, exportDeclaration.declaration); - } else if (isReexportStatement(statement)) { - const reexports = this.extractUmdReexports(statement, sourceFile); + } else if (isWildcardReexportStatement(statement)) { + const reexports = this.extractUmdWildcardReexports(statement, sourceFile); for (const reexport of reexports) { moduleMap.set(reexport.name, reexport.declaration); } @@ -145,8 +145,8 @@ export class UmdReflectionHost extends Esm5ReflectionHost { } } - private extractUmdReexports(statement: ReexportStatement, containingFile: ts.SourceFile): - ExportDeclaration[] { + private extractUmdWildcardReexports( + statement: WildcardReexportStatement, containingFile: ts.SourceFile): ExportDeclaration[] { const reexportArg = statement.expression.arguments[0]; const requireCall = isRequireCall(reexportArg) ?