Skip to content

Commit

Permalink
refactor: add implementation details about parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Sep 13, 2017
1 parent a902ea2 commit 71ee4fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,19 @@
for(var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if(token.type === "Text") {
// Push text to currently pending element
elements[lastIndex].children.push(token.value);
} else if(token.type === "Tag") {
// Tag found
if(token.closeStart === true) {
if("development" !== "production" && token.value !== elements[lastIndex].type) {
error(("The element \"" + (elements[lastIndex].type) + "\" was left unclosed"));
}
// Closing tag found, close current element
elements.pop();
lastIndex--;
} else {
// Opening tag found, create element
var type = token.value;
var node = {
type: type,
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ const parse = function(tokens) {
for(let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if(token.type === "Text") {
// Push text to currently pending element
elements[lastIndex].children.push(token.value);
} else if(token.type === "Tag") {
// Tag found
if(token.closeStart === true) {
if("__ENV__" !== "production" && token.value !== elements[lastIndex].type) {
error(`The element "${elements[lastIndex].type}" was left unclosed`);
}
// Closing tag found, close current element
elements.pop();
lastIndex--;
} else {
// Opening tag found, create element
const type = token.value;
let node = {
type: type,
Expand Down

0 comments on commit 71ee4fb

Please sign in to comment.