Skip to content

Commit

Permalink
Rename "transform" to "name"
Browse files Browse the repository at this point in the history
  • Loading branch information
ark120202 committed May 5, 2019
1 parent 1d72e24 commit 90b1ccc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/CompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type KnownKeys<T> = {

type OmitIndexSignature<T extends Record<any, any>> = Pick<T, KnownKeys<T>>;

export interface TransformerConfig {
transform: string;
export interface TransformerImport {
name: string;
when?: keyof ts.CustomTransformers;
[option: string]: any;
}
Expand All @@ -20,8 +20,8 @@ export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
luaLibImport?: LuaLibImportKind;
noHoisting?: boolean;
sourceMapTraceback?: boolean;
tsTransformers?: TransformerConfig[];
[option: string]: ts.CompilerOptions[string] | TransformerConfig[];
tsTransformers?: TransformerImport[];
[option: string]: ts.CompilerOptions[string] | TransformerImport[];
};

export enum LuaLibImportKind {
Expand Down
15 changes: 6 additions & 9 deletions src/Transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ function loadTransformersFromOptions(

const extensions = [".ts", ".tsx", ".js"];
for (const transformer of options.tsTransformers) {
const { transform, when = "before", ...transformerOptions } = transformer;
const { name, when = "before", ...transformerOptions } = transformer;

let resolved: string;
try {
resolved = resolve.sync(transform, { extensions, basedir });
resolved = resolve.sync(name, { extensions, basedir });
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;
diagnostics.push(
diagnosticFactories.couldNotResolveTransformerFrom(transform, basedir)
);
diagnostics.push(diagnosticFactories.couldNotResolveTransformerFrom(name, basedir));

continue;
}
Expand All @@ -48,9 +47,7 @@ function loadTransformersFromOptions(
tsNode.register({ transpileOnly: true });
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;
diagnostics.push(
diagnosticFactories.toLoadTransformerItShouldBeTranspiled(transform)
);
diagnostics.push(diagnosticFactories.toLoadTransformerItShouldBeTranspiled(name));

continue;
}
Expand All @@ -60,7 +57,7 @@ function loadTransformersFromOptions(
if (result !== undefined) {
customTransformers[when].push(result(program, transformerOptions));
} else {
diagnostics.push(diagnosticFactories.transformerShouldHaveADefaultExport(transform));
diagnostics.push(diagnosticFactories.transformerShouldHaveADefaultExport(name));
}
}

Expand Down
16 changes: 8 additions & 8 deletions test/unit/transformers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as path from "path";
import * as tstl from "../../src";
import * as util from "../util";

const testTransform = (transform: string) => {
const options: tstl.CompilerOptions = { tsTransformers: [{ transform }] };
const testTransform = (name: string) => {
const options: tstl.CompilerOptions = { tsTransformers: [{ name }] };
expect(util.transpileAndExecute("return", options)).toBe(true);
};

Expand All @@ -21,23 +21,23 @@ test("should load ts transformers", () => {
});

test("should pass program to transformers", () => {
const transform = path.join(__dirname, "transformers/program.ts");
const options: tstl.CompilerOptions = { tsTransformers: [{ transform }] };
const name = path.join(__dirname, "transformers/program.ts");
const options: tstl.CompilerOptions = { tsTransformers: [{ name }] };

expect(util.transpileAndExecute("return false", options)).toBe(true);
});

test("should pass extra options to transformers", () => {
const transform = path.join(__dirname, "transformers/options.ts");
const name = path.join(__dirname, "transformers/options.ts");
const value = "foo";
const options: tstl.CompilerOptions = { tsTransformers: [{ transform, value }] };
const options: tstl.CompilerOptions = { tsTransformers: [{ name, value }] };

expect(util.transpileAndExecute("return", options)).toBe(value);
});

test("should error if transformer could not be resolved", () => {
const transform = path.join(__dirname, "transformers/error.ts");
const options: tstl.CompilerOptions = { tsTransformers: [{ transform }] };
const name = path.join(__dirname, "transformers/error.ts");
const options: tstl.CompilerOptions = { tsTransformers: [{ name }] };
const { diagnostics } = util.transpileStringResult("", options);
expect(diagnostics).toHaveDiagnostics();
});

0 comments on commit 90b1ccc

Please sign in to comment.