Skip to content

Commit

Permalink
Merge pull request #1553 from DanielXMoore/repl-ref
Browse files Browse the repository at this point in the history
Fix REPL support for `ref`s created by Civet
  • Loading branch information
edemaine authored Oct 31, 2024
2 parents b64b231 + b1d7c89 commit 922ceba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions civet.dev/.vitepress/components/PlaygroundFull.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ function runInBrowser() {
}
} catch (err) {
console.error(err);
if (err instanceof SyntaxError) {
console.log('Attempted to eval:', code)
}
evalOutput.value += `[THROWN] ${err.toString()}\n`
}
evalComplete.value = true
Expand Down
1 change: 1 addition & 0 deletions source/parser/lib.civet
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ function processRepl(root: BlockStatement, rootIIFE: ASTNode): void
i .= 0
// Hoist top-level declarations and all var declarations
for each decl of gatherRecursiveWithinFunction topBlock, .type is "Declaration"
continue unless decl.names?# // skip 'let ref'
if decl.parent is topBlock or decl.decl is "var"
decl.children.shift() // remove const/let/var
root.expressions.splice i++, 0, ["", `var ${decl.names.join ','};`]
Expand Down
11 changes: 10 additions & 1 deletion test/iife.civet
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe "repl directive", ->
"""

testCase """
inner classesj
inner classes
---
"civet repl"
if true
Expand All @@ -176,3 +176,12 @@ describe "repl directive", ->
return new C
}})()
"""

testCase """
skip let ref
---
"civet repl"
primes := [...smallPrimes] ||> .# = n
---
var primes;(()=>{let ref;primes =( (ref = [...smallPrimes]).length = n,ref);return primes})()
"""

0 comments on commit 922ceba

Please sign in to comment.