Skip to content

Commit

Permalink
fix if clause condition duplicate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed May 19, 2019
1 parent 9b4d608 commit af9c57d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
} else {
// Return a dynamic match if there is a dynamic name or a local.
isStatic = false;
return name[0] === "$" ? match : "data." + name;
return name[0] === "$" ? name : "data." + name;
}
});
return {
Expand Down Expand Up @@ -635,12 +635,11 @@

function generateNodeIf(element, parent, index, staticNodes) {
var variable = "m" + generateVariable;
var attributes = element.attributes;
var prelude = "";
var emptyElseClause = true;
setGenerateVariable(generateVariable + 1); // Generate the initial `if` clause.

prelude += "var " + variable + ";if(" + attributes[""].value + "){" + generateClause(variable, element, staticNodes) + "}"; // Search for `else-if` and `else` clauses if there are siblings.
prelude += "var " + variable + ";if(" + element.attributes[""].value + "){" + generateClause(variable, element, staticNodes) + "}"; // Search for `else-if` and `else` clauses if there are siblings.

if (parent !== null) {
var siblings = parent.children;
Expand All @@ -650,7 +649,7 @@

if (sibling.name === "else-if") {
// Generate the `else-if` clause.
prelude += "else if(" + attributes[""].value + "){" + generateClause(variable, sibling, staticNodes) + "}"; // Remove the `else-if` clause so that it isn't generated
prelude += "else if(" + sibling.attributes[""].value + "){" + generateClause(variable, sibling, staticNodes) + "}"; // Remove the `else-if` clause so that it isn't generated
// individually by the parent.

siblings.splice(i, 1);
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.

5 changes: 2 additions & 3 deletions packages/moon/src/compiler/generator/components/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ function generateClause(variable, element, staticNodes) {
*/
export function generateNodeIf(element, parent, index, staticNodes) {
const variable = "m" + generateVariable;
const attributes = element.attributes;
let prelude = "";
let emptyElseClause = true;

setGenerateVariable(generateVariable + 1);

// Generate the initial `if` clause.
prelude += `var ${variable};if(${attributes[""].value}){${generateClause(variable, element, staticNodes)}}`;
prelude += `var ${variable};if(${element.attributes[""].value}){${generateClause(variable, element, staticNodes)}}`;

// Search for `else-if` and `else` clauses if there are siblings.
if (parent !== null) {
Expand All @@ -56,7 +55,7 @@ export function generateNodeIf(element, parent, index, staticNodes) {

if (sibling.name === "else-if") {
// Generate the `else-if` clause.
prelude += `else if(${attributes[""].value}){${generateClause(variable, sibling, staticNodes)}}`;
prelude += `else if(${sibling.attributes[""].value}){${generateClause(variable, sibling, staticNodes)}}`;

// Remove the `else-if` clause so that it isn't generated
// individually by the parent.
Expand Down
2 changes: 1 addition & 1 deletion packages/moon/src/compiler/lexer/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function scopeExpression(expression) {
} else {
// Return a dynamic match if there is a dynamic name or a local.
isStatic = false;
return name[0] === "$" ? match : "data." + name;
return name[0] === "$" ? name : "data." + name;
}
});

Expand Down

0 comments on commit af9c57d

Please sign in to comment.