refactor(compiler-cli): ngcc - remove unnecessary `sourcePath` parameters (#29643)

The `Transformer` and `Renderer` classes do not
actually need a `sourcePath` value as by the time
they are doing their work we are only working directly
with full absolute paths.

PR Close #29643
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:47:56 +01:00 committed by Andrew Kushnir
parent 1195dabb84
commit 78b5bd5174
8 changed files with 12 additions and 18 deletions

View File

@ -73,7 +73,7 @@ export function mainNgcc({basePath, targetEntryPointPath,
propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
compileAllFormats = true, createNewEntryPointFormats = false, compileAllFormats = true, createNewEntryPointFormats = false,
logger = new ConsoleLogger(LogLevel.info)}: NgccOptions): void { logger = new ConsoleLogger(LogLevel.info)}: NgccOptions): void {
const transformer = new Transformer(logger, basePath); const transformer = new Transformer(logger);
const host = new DependencyHost(); const host = new DependencyHost();
const resolver = new DependencyResolver(logger, host); const resolver = new DependencyResolver(logger, host);
const finder = new EntryPointFinder(logger, resolver); const finder = new EntryPointFinder(logger, resolver);

View File

@ -46,7 +46,7 @@ import {EntryPointBundle} from './entry_point_bundle';
* - Some formats may contain multiple "modules" in a single file. * - Some formats may contain multiple "modules" in a single file.
*/ */
export class Transformer { export class Transformer {
constructor(private logger: Logger, private sourcePath: string) {} constructor(private logger: Logger) {}
/** /**
* Transform the source (and typings) files of a bundle. * Transform the source (and typings) files of a bundle.
@ -85,9 +85,9 @@ export class Transformer {
getRenderer(host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle): Renderer { getRenderer(host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle): Renderer {
switch (bundle.format) { switch (bundle.format) {
case 'esm2015': case 'esm2015':
return new EsmRenderer(this.logger, host, isCore, bundle, this.sourcePath); return new EsmRenderer(this.logger, host, isCore, bundle);
case 'esm5': case 'esm5':
return new Esm5Renderer(this.logger, host, isCore, bundle, this.sourcePath); return new Esm5Renderer(this.logger, host, isCore, bundle);
default: default:
throw new Error(`Renderer for "${bundle.format}" not yet implemented.`); throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
} }

View File

@ -15,10 +15,8 @@ import {EntryPointBundle} from '../packages/entry_point_bundle';
import {Logger} from '../logging/logger'; import {Logger} from '../logging/logger';
export class Esm5Renderer extends EsmRenderer { export class Esm5Renderer extends EsmRenderer {
constructor( constructor(logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, super(logger, host, isCore, bundle);
sourcePath: string) {
super(logger, host, isCore, bundle, sourcePath);
} }
/** /**

View File

@ -17,10 +17,8 @@ import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
import {Logger} from '../logging/logger'; import {Logger} from '../logging/logger';
export class EsmRenderer extends Renderer { export class EsmRenderer extends Renderer {
constructor( constructor(logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, super(logger, host, isCore, bundle);
sourcePath: string) {
super(logger, host, isCore, bundle, sourcePath);
} }
/** /**

View File

@ -82,7 +82,7 @@ export const RedundantDecoratorMap = Map;
export abstract class Renderer { export abstract class Renderer {
constructor( constructor(
protected logger: Logger, protected host: NgccReflectionHost, protected isCore: boolean, protected logger: Logger, protected host: NgccReflectionHost, protected isCore: boolean,
protected bundle: EntryPointBundle, protected sourcePath: string) {} protected bundle: EntryPointBundle) {}
renderProgram( renderProgram(
decorationAnalyses: DecorationAnalyses, switchMarkerAnalyses: SwitchMarkerAnalyses, decorationAnalyses: DecorationAnalyses, switchMarkerAnalyses: SwitchMarkerAnalyses,

View File

@ -19,7 +19,6 @@ import {MockLogger} from '../helpers/mock_logger';
function setup(file: {name: string, contents: string}) { function setup(file: {name: string, contents: string}) {
const logger = new MockLogger(); const logger = new MockLogger();
const dir = dirname(file.name);
const bundle = makeTestEntryPointBundle('es2015', 'esm2015', false, [file]) !; const bundle = makeTestEntryPointBundle('es2015', 'esm2015', false, [file]) !;
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm2015ReflectionHost(logger, false, typeChecker); const host = new Esm2015ReflectionHost(logger, false, typeChecker);
@ -30,7 +29,7 @@ function setup(file: {name: string, contents: string}) {
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false) referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
.analyzeProgram(); .analyzeProgram();
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program); const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
const renderer = new EsmRenderer(logger, host, false, bundle, dir); const renderer = new EsmRenderer(logger, host, false, bundle);
return { return {
host, host,
program: bundle.src.program, program: bundle.src.program,

View File

@ -19,7 +19,6 @@ import {MockLogger} from '../helpers/mock_logger';
function setup(file: {name: string, contents: string}) { function setup(file: {name: string, contents: string}) {
const logger = new MockLogger(); const logger = new MockLogger();
const dir = dirname(file.name);
const bundle = makeTestEntryPointBundle('module', 'esm5', false, [file]); const bundle = makeTestEntryPointBundle('module', 'esm5', false, [file]);
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm5ReflectionHost(logger, false, typeChecker); const host = new Esm5ReflectionHost(logger, false, typeChecker);
@ -30,7 +29,7 @@ function setup(file: {name: string, contents: string}) {
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false) referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
.analyzeProgram(); .analyzeProgram();
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program); const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
const renderer = new Esm5Renderer(logger, host, false, bundle, dir); const renderer = new Esm5Renderer(logger, host, false, bundle);
return { return {
host, host,
program: bundle.src.program, program: bundle.src.program,

View File

@ -24,7 +24,7 @@ import {MockLogger} from '../helpers/mock_logger';
class TestRenderer extends Renderer { class TestRenderer extends Renderer {
constructor( constructor(
logger: Logger, host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) { logger: Logger, host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
super(logger, host, isCore, bundle, '/src'); super(logger, host, isCore, bundle);
} }
addImports( addImports(
output: MagicString, imports: {specifier: string, qualifier: string}[], sf: ts.SourceFile) { output: MagicString, imports: {specifier: string, qualifier: string}[], sf: ts.SourceFile) {