Skip to content

Commit

Permalink
remove errors from production build
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 4, 2019
1 parent fe8149e commit 3de8daf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 30 deletions.
22 changes: 8 additions & 14 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
}(this, function() {
"use strict";

var config = {
silent: "development" === "production" || typeof console === "undefined"
};

/**
* Does nothing.
*/

function noop() {}
/**
* Returns a value if it is defined, or else returns a default value.
Expand Down Expand Up @@ -49,7 +44,7 @@
*/

function error(message) {
if (config.silent === false) {
if ("development" === "development") {
console.error("[Moon] ERROR: " + message);
}
}
Expand Down Expand Up @@ -323,7 +318,7 @@
}
}

return new ParseError("Parser expected valid elements but encountered an error.", start, end, error);
return new ParseError("development" === "development" ? "Parser expected valid elements but encountered an error." : "", start, end, error);
}
}
/**
Expand All @@ -348,7 +343,7 @@

if (length === 0) {
// Return an error because this parser does not accept empty inputs.
return new ParseError("Parser expected an element but received nothing.", start, end);
return new ParseError("development" === "development" ? "Parser expected an element but received nothing." : "", start, end);
} else if (length === 1) {
// The next alternate only matches on inputs with one token.
if (firstToken.type === "tagOpen" && firstToken.closed === true) {
Expand All @@ -360,7 +355,7 @@
children: []
};
} else {
return new ParseError("Parser expected a self-closing tag or text but received \"\".", start, end);
return new ParseError("development" === "development" ? "Parser expected a self-closing tag or text but received \"\"." : "", start, end);
}
} else {
// If the input size is greater than one, it must be a full element with
Expand All @@ -371,7 +366,7 @@
var children = parseElements(start + 1, end - 1, tokens);

if (children instanceof ParseError) {
return new ParseError("Parser expected valid child elements but encountered an error.", start, end, children);
return new ParseError("development" === "development" ? "Parser expected valid child elements but encountered an error." : "", start, end, children);
} else {
return {
type: firstToken.value,
Expand All @@ -380,7 +375,7 @@
};
}
} else {
return new ParseError("Parser expected an element with matching opening and closing tags.", start, end);
return new ParseError("development" === "development" ? "Parser expected an element with matching opening and closing tags." : "", start, end);
}
}
}
Expand Down Expand Up @@ -421,7 +416,7 @@
function parse(tokens) {
var tree = parseElement(0, tokens.length, tokens);

if (tree instanceof ParseError) {
if ("development" === "development" && tree instanceof ParseError) {
// Append error messages and print all of them with their corresponding
// locations in the source.
var parseErrors = "";
Expand Down Expand Up @@ -751,7 +746,7 @@

var view = data.view;

if (view === undefined) {
if ("development" === "development" && view === undefined) {
error("The ".concat(data.name, " component requires a \"view\" property."));
}

Expand Down Expand Up @@ -786,7 +781,6 @@
Moon.parse = parse;
Moon.generate = generate;
Moon.compile = compile;
Moon.config = config;

return Moon;
}));
2 changes: 1 addition & 1 deletion packages/moon/dist/moon.min.js

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

22 changes: 16 additions & 6 deletions packages/moon/src/compiler/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function parseElements(start, end, tokens) {
}

return new ParseError(
`Parser expected valid elements but encountered an error.`,
process.env.MOON_ENV === "development" ?
`Parser expected valid elements but encountered an error.` :
"",
start,
end,
error
Expand Down Expand Up @@ -83,7 +85,9 @@ function parseElement(start, end, tokens) {
if (length === 0) {
// Return an error because this parser does not accept empty inputs.
return new ParseError(
`Parser expected an element but received nothing.`,
process.env.MOON_ENV === "development" ?
`Parser expected an element but received nothing.` :
"",
start,
end
);
Expand All @@ -102,7 +106,9 @@ function parseElement(start, end, tokens) {
};
} else {
return new ParseError(
`Parser expected a self-closing tag or text but received "".`,
process.env.MOON_ENV === "development" ?
`Parser expected a self-closing tag or text but received "".` :
"",
start,
end
);
Expand All @@ -121,7 +127,9 @@ function parseElement(start, end, tokens) {

if (children instanceof ParseError) {
return new ParseError(
`Parser expected valid child elements but encountered an error.`,
process.env.MOON_ENV === "development" ?
`Parser expected valid child elements but encountered an error.` :
"",
start,
end,
children
Expand All @@ -135,7 +143,9 @@ function parseElement(start, end, tokens) {
}
} else {
return new ParseError(
`Parser expected an element with matching opening and closing tags.`,
process.env.MOON_ENV === "development" ?
`Parser expected an element with matching opening and closing tags.` :
"",
start,
end
);
Expand Down Expand Up @@ -178,7 +188,7 @@ function parseElement(start, end, tokens) {
export function parse(tokens) {
const tree = parseElement(0, tokens.length, tokens);

if (tree instanceof ParseError) {
if (process.env.MOON_ENV === "development" && tree instanceof ParseError) {
// Append error messages and print all of them with their corresponding
// locations in the source.
let parseErrors = "";
Expand Down
4 changes: 1 addition & 3 deletions packages/moon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { generate } from "./compiler/generator/generator";
import { compile } from "./compiler/compiler";
import { components } from "./component/components";
import { defaultValue, error, noop } from "./util/util";
import { config } from "./util/config";

/**
* Moon
Expand Down Expand Up @@ -55,7 +54,7 @@ export default function Moon(data) {
// Ensure the view is defined, and compile it if needed.
let view = data.view;

if (view === undefined) {
if (process.env.MOON_ENV === "development" && view === undefined) {
error(`The ${data.name} component requires a "view" property.`);
}

Expand Down Expand Up @@ -94,4 +93,3 @@ Moon.lex = lex;
Moon.parse = parse;
Moon.generate = generate;
Moon.compile = compile;
Moon.config = config;
3 changes: 0 additions & 3 deletions packages/moon/src/util/config.js

This file was deleted.

Loading

0 comments on commit 3de8daf

Please sign in to comment.