Skip to content

Commit

Permalink
JSON: Fix code snippet in 1.3.2 p6 (source-academy#574)
Browse files Browse the repository at this point in the history
* Remove redundant else statement

* Code quality improvements

* Fix whitespace 1.3.2 p6
  • Loading branch information
samuelfangjw authored Jul 17, 2021
1 parent 82d993d commit 1331747
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
13 changes: 4 additions & 9 deletions javascript/parseXmlJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,10 @@ const processTextFunctions = {
}

const writeTo = [];
if (ancestorHasTag(node, "NAME")) {
recursiveProcessPureText(node.firstChild, writeTo, {
removeNewline: "all"
});
} else {
recursiveProcessPureText(node.firstChild, writeTo, {
removeNewline: "all"
});
}
recursiveProcessPureText(node.firstChild, writeTo, {
removeNewline: "all"
});

addArrayToObj(obj, node, writeTo);
obj["tag"] = "JAVASCRIPTINLINE";
},
Expand Down
12 changes: 8 additions & 4 deletions javascript/processingFunctions/processSnippetJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,20 @@ export const processSnippetJson = (node, snippet) => {
}

const codeArr = [];
if (jsSnippet) recursiveProcessPureText(jsSnippet.firstChild, codeArr);
const codeStr = codeArr.join("").trim();
recursiveProcessPureText(jsSnippet.firstChild, codeArr);
let codeStr = codeArr.join("");
// Remove newline from beginning and end
codeStr = codeStr.replace(/^[\r\n]+/g, "");
codeStr = codeStr.replace(/[\r\n\s]+$/g, "");

const codeArr_run = [];
if (jsRunSnippet)
if (jsRunSnippet) {
recursiveProcessPureText(jsRunSnippet.firstChild, codeArr_run);
}
const codeStr_run = codeArr_run.join("").trim();

if (node.getAttribute("EVAL") === "no") {
addToSnippet("body", codeStr.trim(), snippet);
addToSnippet("body", codeStr, snippet);
} else {
addToSnippet("eval", true, snippet);
let reqStr = "";
Expand Down

0 comments on commit 1331747

Please sign in to comment.