Skip to content

Commit

Permalink
improve parser by allowing custom elements that self close, but throw…
Browse files Browse the repository at this point in the history
… if there is no slash to indicate it
  • Loading branch information
kbrsh committed May 2, 2017
1 parent 8c2b323 commit a645d40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
20 changes: 11 additions & 9 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,20 +1290,20 @@
var previousToken = state.tokens[state.current - 1];
var nextToken = state.tokens[state.current + 1];

var increment = function (num) {
var move = function (num) {
state.current += num === undefined ? 1 : num;
token = state.tokens[state.current];
previousToken = state.tokens[state.current - 1];
nextToken = state.tokens[state.current + 1];
};

if (token.type === "text") {
increment();
move();
return previousToken.value;
}

if (token.type === "comment") {
increment();
move();
return null;
}

Expand All @@ -1314,18 +1314,18 @@
var closeEnd = token.closeEnd;

var isSVGElement = SVG_ELEMENTS.indexOf(tagType) !== -1;
var isVoidElement = VOID_ELEMENTS.indexOf(tagType) !== -1;
var isVoidElement = VOID_ELEMENTS.indexOf(tagType) !== -1 || closeEnd === true;

var node = createParseNode(tagType, token.attributes, []);

increment();
move();

// If it is an svg element, let code generator know
if (isSVGElement) {
node.isSVG = true;
}

if (isVoidElement) {
if (isVoidElement === true) {
// Self closing, don't process further
return node;
} else if (closeStart === true) {
Expand All @@ -1339,7 +1339,9 @@
if (parsedChildState !== null) {
node.children.push(parsedChildState);
}
increment(0);

move(0);

if (token === undefined) {
// No token means a tag was most likely left unclosed
if ("development" !== "production") {
Expand All @@ -1349,13 +1351,13 @@
}
}

increment();
move();
}

return node;
}

increment();
move();
return;
};

Expand Down
Loading

0 comments on commit a645d40

Please sign in to comment.