Feature: Fix snippet dependency resolution for JS output#1158
Open
maptoan wants to merge 1 commit intosource-academy:masterfrom
Open
Feature: Fix snippet dependency resolution for JS output#1158maptoan wants to merge 1 commit intosource-academy:masterfrom
maptoan wants to merge 1 commit intosource-academy:masterfrom
Conversation
The `processSnippetJs` function currently does not correctly use the `snippetStore` to prepend the code of required snippets. This prevents programs that rely on previously defined sets from running. Affected files: processSnippetJs.js Signed-off-by: toanmap <174589430+maptoan@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the requirement and example processing logic in processSnippetJs.js to use a unified Set for dependency collection. However, the changes introduce a SyntaxError because the examples constant is declared twice. Feedback also includes suggestions to adopt idiomatic for...of loops for better readability and to restore the trailing newline at the end of the file for consistency with standard practices.
| for (let i = 0; requirements[i]; i++) { | ||
| recursiveGetRequires(requirements[i].firstChild.nodeValue, reqSet); | ||
| } | ||
| const examples = node.getElementsByTagName("EXAMPLE"); |
There was a problem hiding this comment.
Comment on lines
+95
to
103
| const requirements = node.getElementsByTagName("REQUIRES"); | ||
| for (let i = 0; requirements[i]; i++) { | ||
| recursiveGetRequires(requirements[i].firstChild.nodeValue, reqSet); | ||
| } | ||
| const examples = node.getElementsByTagName("EXAMPLE"); | ||
| for (let i = 0; examples[i]; i++) { | ||
| const exampleName = examples[i].firstChild.nodeValue; | ||
| recursiveGetRequires(exampleName, reqSet); | ||
| } |
There was a problem hiding this comment.
These C-style loops can be simplified by using for...of loops, which are more idiomatic in modern JavaScript and improve readability.
const requirements = node.getElementsByTagName("REQUIRES");
for (const requirement of requirements) {
recursiveGetRequires(requirement.firstChild.nodeValue, reqSet);
}
const examples = node.getElementsByTagName("EXAMPLE");
for (const example of examples) {
recursiveGetRequires(example.firstChild.nodeValue, reqSet);
}| }; | ||
|
|
||
| export default processSnippetJs; | ||
| export default processSnippetJs; No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
processSnippetJsfunction currently does not correctly use thesnippetStoreto prepend the code of required snippets. This prevents programs that rely on previously defined sets from running.Severity:
mediumFile:
javascript/processingFunctions/processSnippetJs.jsSolution
Update
processSnippetJsto userecursiveGetRequiresto collect all required code strings from thesnippetStoreand prepend them to the main snippet code.Changes
javascript/processingFunctions/processSnippetJs.js(modified)Testing
Closes #840