Skip to content

Commit

Permalink
remove development checks in production
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 5, 2019
1 parent d73333f commit 64a02fe
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 43 deletions.
22 changes: 5 additions & 17 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
const fs = require("fs");

const overrides = [];
const packages = fs.readdirSync("./packages");

for (let i = 0; i < packages.length; i++) {
const package = packages[i];

if (fs.lstatSync(`./packages/${package}`).isDirectory()) {
overrides.push({
test: `./packages/${package}/dist/${package}.js`,
presets: require(`./packages/${package}/config.js`).babel
});
}
}

module.exports = {
presets: ["@babel/preset-env"],
overrides: overrides
plugins: [
["@babel/plugin-transform-template-literals", {
loose: true
}]
]
};
8 changes: 0 additions & 8 deletions packages/moon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@ module.exports = {
name: "Moon",
exportName: "Moon",
format: "iife",
uglify: {
compress: {
pure_funcs: ["error", "lexError"]
},
mangle: {
reserved: ["concat", "error", "lexError"]
}
},
transform: (output) => fs.readFileSync("./packages/moon/src/wrapper.js").toString().replace("INSERT", output.split("\n").slice(1, -3).join("\n")).replace("'use strict'", "\"use strict\"")
};
12 changes: 6 additions & 6 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
if (_char === "<") {
var charNext = input[i + 1];

if (charNext === undefined) {
if ("development" === "development" && charNext === undefined) {
lexError("Lexer expected a character after \"<\".", input, i);
}

Expand All @@ -156,7 +156,7 @@

var _type = input.slice(i + 2, closeIndex);

if (closeIndex === -1) {
if ("development" === "development" && closeIndex === -1) {
lexError("Lexer expected a closing \">\" after \"</\".", input, i);
}

Expand All @@ -170,11 +170,11 @@
// Ignore input if a sequence of characters begins with "<!--".
var _closeIndex = input.indexOf("-->", i + 4);

if (_closeIndex === -1) {
if ("development" === "development" && _closeIndex === -1) {
lexError("Lexer expected a closing \"-->\" after \"<!--\".", input, i);
}

i = input.indexOf("-->", i + 4) + 3;
i = _closeIndex + 3;
continue;
} // Set the last searched index of the tag type regular expression to
// the index of the character currently being processed. Since it is
Expand Down Expand Up @@ -384,7 +384,7 @@
children: []
};
} else {
return new ParseError("development" === "development" ? "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." : "", start, end);
}
} else {
// If the input size is greater than one, it must be a full element with
Expand Down Expand Up @@ -773,7 +773,7 @@

var view = data.view;

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

Expand Down
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.

8 changes: 4 additions & 4 deletions packages/moon/src/compiler/lexer/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function lex(input) {
if (char === "<") {
const charNext = input[i + 1];

if (charNext === undefined) {
if (process.env.MOON_ENV === "development" && charNext === undefined) {
lexError(`Lexer expected a character after "<".`, input, i);
}

Expand All @@ -113,7 +113,7 @@ export function lex(input) {
const closeIndex = input.indexOf(">", i + 2);
const type = input.slice(i + 2, closeIndex);

if (closeIndex === -1) {
if (process.env.MOON_ENV === "development" && closeIndex === -1) {
lexError(`Lexer expected a closing ">" after "</".`, input, i);
}

Expand All @@ -132,11 +132,11 @@ export function lex(input) {
// Ignore input if a sequence of characters begins with "<!--".
const closeIndex = input.indexOf("-->", i + 4);

if (closeIndex === -1) {
if (process.env.MOON_ENV === "development" && closeIndex === -1) {
lexError(`Lexer expected a closing "-->" after "<!--".`, input, i);
}

i = input.indexOf("-->", i + 4) + 3;
i = closeIndex + 3;
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/moon/src/compiler/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function parseElements(start, end, tokens) {
}

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

if (children instanceof ParseError) {
return new ParseError(
parseErrorMessage(`Parser expected valid child elements but encountered an error.`),
parseErrorMessage("Parser expected valid child elements but encountered an error."),
start,
end,
children
Expand All @@ -154,7 +154,7 @@ function parseElement(start, end, tokens) {
}
} else {
return new ParseError(
parseErrorMessage(`Parser expected an element with matching opening and closing tags.`),
parseErrorMessage("Parser expected an element with matching opening and closing tags."),
start,
end
);
Expand Down
2 changes: 1 addition & 1 deletion packages/moon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,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
2 changes: 1 addition & 1 deletion packages/moon/src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export function isQuote(char) {
* @param {string} message
*/
export function error(message) {
console.error("[Moon] ERROR: " + message);
console.error(`[Moon] ERROR: ${message}`);
}

0 comments on commit 64a02fe

Please sign in to comment.