Skip to content

Commit

Permalink
feat(compiler): require passing custom translator directly
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed May 26, 2020
1 parent 3cd6b47 commit b9d4c46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
17 changes: 5 additions & 12 deletions packages/compiler/src/babel-plugin/index.js
Expand Up @@ -9,21 +9,14 @@ import { buildLookup } from "../taglib";
export default (api, options) => {
api.assertVersion(7);
options.output = options.output || "html";
options.translator = options.translator || "default";

const isProduction = api.env("production");
let translator;
const translator = options.translator;

if (typeof window === "undefined") {
translator = require(`@marko/translator-${options.translator}`);
} else {
if (translator !== "default") {
throw new Error(
"@marko/compiler: only the default translator can be used in the browser."
);
}

translator = require("@marko/translator-default");
if (!translator || !translator.visitor) {
throw new Error(
"@marko/compiler: translator must provide a visitor object"
);
}

return {
Expand Down
9 changes: 8 additions & 1 deletion packages/compiler/src/config.js
@@ -1,3 +1,5 @@
import * as translator from "@marko/translator-default";

let config;
const globalThis = typeof window === "undefined" ? global : window;
const MARKO_CONFIG_KEY = Symbol("Default Marko Compiler Config");
Expand Down Expand Up @@ -34,7 +36,12 @@ if (globalThis[MARKO_CONFIG_KEY]) {
* You can also access this metadata via `compile(...).meta`.
* This API is sticking around for compatibility purposes.
*/
meta: false
meta: false,

/**
* Allows configuring Marko to compile to different runtimes.
*/
translator
};

if (process.env.MARKO_CONFIG) {
Expand Down

0 comments on commit b9d4c46

Please sign in to comment.