Skip to content

Commit

Permalink
test in development and production
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 4, 2019
1 parent 3de8daf commit 4a3ac07
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
29 changes: 8 additions & 21 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,6 @@
return tokens;
}

function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}

function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];

return arr2;
}
}

function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}

/**
* Stores an error message, a slice of tokens associated with the error, and a
* related error for later reporting.
Expand Down Expand Up @@ -313,7 +293,14 @@
var elements = parseElements(elementEnd, end, tokens);

if (!(elements instanceof ParseError)) {
return [element].concat(_toConsumableArray(elements));
// Combine the first element with the rest of the elements.
var elementsAll = [element];

for (var i = 0; i < elements.length; i++) {
elementsAll.push(elements[i]);
}

return elementsAll;
}
}
}
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.

9 changes: 8 additions & 1 deletion packages/moon/src/compiler/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ function parseElements(start, end, tokens) {
const elements = parseElements(elementEnd, end, tokens);

if (!(elements instanceof ParseError)) {
return [element, ...elements];
// Combine the first element with the rest of the elements.
let elementsAll = [element];

for (let i = 0; i < elements.length; i++) {
elementsAll.push(elements[i]);
}

return elementsAll;
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions packages/moon/test/compiler/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test("parse nested elements", () => {
});

test("parse error from invalid view", () => {
process.env.MOON_ENV = "development";
console.error = jest.fn();

expect(parseTest(`
Expand All @@ -98,11 +99,29 @@ test("parse error from invalid view", () => {
</div>
`).constructor.name).toBe("ParseError");
expect(console.error).toBeCalled();

process.env.MOON_ENV = "production";
console.error = jest.fn();

expect(parseTest(`
<div>
<p>text?
</h1></input>
</div>
`).constructor.name).toBe("ParseError");
expect(console.error).not.toBeCalled();
});

test("parse error from empty element", () => {
process.env.MOON_ENV = "development";
console.error = jest.fn();

expect(parseTest("").constructor.name).toBe("ParseError");
expect(console.error).toBeCalled();

process.env.MOON_ENV = "production";
console.error = jest.fn();

expect(parseTest("").constructor.name).toBe("ParseError");
expect(console.error).not.toBeCalled();
});

0 comments on commit 4a3ac07

Please sign in to comment.