Skip to content

Commit

Permalink
Remove deriveFromInputSource lifecycle (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferbaxter authored Nov 1, 2018
1 parent 75a918f commit 3b861ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 45 deletions.
16 changes: 7 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from 'rollup';
import compiler from './compiler';
import options from './options';
import { preCompilation, createTransforms, deriveFromInputSource } from './transforms';
import { preCompilation, createTransforms } from './transforms';
import { Transform } from './types';

const readFile = promisify(fs.readFile);
Expand Down Expand Up @@ -85,7 +85,6 @@ export default function closureCompiler(requestedCompileOptions: CompileOptions
},
renderChunk: async (code: string, chunk: RenderedChunk, outputOptions: OutputOptions) => {
const transforms = createTransforms(context, inputOptions);
await deriveFromInputSource(code, chunk, transforms);
return await renderChunk(transforms, requestedCompileOptions, code, outputOptions);
},
};
Expand Down
16 changes: 5 additions & 11 deletions src/transformers/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
Node,
ClassDeclaration,
} from 'estree';
import { TransformSourceDescription, RenderedChunk } from 'rollup';
import { TransformSourceDescription } from 'rollup';
import { NamedDeclaration, DefaultDeclaration } from './parsing-utilities';
import { isESMFormat } from '../options';
import {
Expand All @@ -45,13 +45,7 @@ import { parse, walk } from '../acorn';
export default class ExportTransform extends Transform implements TransformInterface {
private originalExports: ExportNameToClosureMapping = {};

/**
* Before Closure Compiler is given a chance to look at the code, we need to
* find and store all export statements with their correct type
* @param code source to parse
* @param chunk Rollup chunk reference to the source
*/
public async deriveFromInputSource(code: string, chunk: RenderedChunk): Promise<void> {
private async deriveExports(code: string): Promise<ExportNameToClosureMapping> {
const context = this.context;
let originalExports: ExportNameToClosureMapping = {};
const program = parse(code);
Expand Down Expand Up @@ -79,9 +73,7 @@ export default class ExportTransform extends Transform implements TransformInter
},
});

this.originalExports = originalExports;

return void 0;
return originalExports;
}

/**
Expand All @@ -99,6 +91,8 @@ export default class ExportTransform extends Transform implements TransformInter
);
} else if (isESMFormat(this.outputOptions.format)) {
const source = new MagicString(code);
this.originalExports = await this.deriveExports(code);

Object.keys(this.originalExports).forEach(key => {
// Remove export statements before Closure Compiler sees the code
// This prevents CC from transpiling `export` statements when the language_out is set to a value
Expand Down
18 changes: 1 addition & 17 deletions src/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { OutputOptions, PluginContext, InputOptions, RenderedChunk } from 'rollup';
import { OutputOptions, PluginContext, InputOptions } from 'rollup';
import { Transform } from './types';
import IifeTransform from './transformers/iife';
import LiteralComputedKeys from './transformers/literal-computed-keys';
Expand Down Expand Up @@ -89,19 +89,3 @@ export async function postCompilation(code: string, transforms: Array<Transform>
logSource('after postCompilation handlers', code);
return code;
}

/**
* Run each transform's `deriveFromInputSource` phase in parallel.
* @param code source code to derive information from, pre Closure Compiler minification.
* @param id Rollup identifier for this input source.
* @param transforms Transforms to execute.
*/
export async function deriveFromInputSource(
code: string,
chunk: RenderedChunk,
transforms: Array<Transform>,
): Promise<void> {
await Promise.all(transforms.map(transform => transform.deriveFromInputSource(code, chunk))).then(
_ => void 0,
);
}
6 changes: 0 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
PluginContext,
InputOptions,
InputOption,
RenderedChunk,
} from 'rollup';
const dynamicImport = require('acorn-dynamic-import');

Expand Down Expand Up @@ -66,7 +65,6 @@ export interface ExportNameToClosureMapping {
export type TransformMethod = (code: string) => Promise<TransformSourceDescription>;
export interface TransformInterface {
extern: (options: OutputOptions) => string;
deriveFromInputSource: (code: string, chunk: RenderedChunk) => Promise<void>;
preCompilation: TransformMethod;
postCompilation: TransformMethod;
}
Expand All @@ -84,10 +82,6 @@ export class Transform implements TransformInterface {
return '';
}

public async deriveFromInputSource(code: string, chunk: RenderedChunk): Promise<void> {
return void 0;
}

public async preCompilation(code: string): Promise<TransformSourceDescription> {
return {
code,
Expand Down

0 comments on commit 3b861ac

Please sign in to comment.