Skip to content

Commit

Permalink
Pragma improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Dec 15, 2023
1 parent d06a77f commit d1aec77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
}

let compilerState = null;
let evalCode = async (code) => {
let evalCode = async (code) => {
try {
let importSource = url.searchParams.get('jsx.import-source') || 'react';
let opts = { repl: repl, 'elide-exports': repl, context: repl ? 'return' : 'statement', "jsx-runtime": {"import-source": importSource, development: true} };
Expand Down Expand Up @@ -289,7 +289,7 @@
var compileStringEx = squint.compileStringEx;
window.compile = () => {
let code = editor.state.doc.toString();
code = '' + boilerplateSrc + '\n\n' + code;
code = (boilerplateSrc || '') + '\n\n' + code;
evalCode(code);
};
window.share = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/squint/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
core-alias cc/*core-package*))
(format "import * as %s from '%s';\n"
core-alias cc/*core-package*)))
pragmas (atom "")]
pragmas (atom {:js ""})]
(binding [*imported-vars* imported-vars
*public-vars* public-vars
*aliases* aliases
Expand All @@ -480,7 +480,7 @@
(if jsx-dev
"/jsx-dev-runtime"
"/jsx-runtime")))))
pragmas @pragmas
pragmas (:js @pragmas)
imports (when-not elide-imports @imports)
exports (when-not elide-exports
(str
Expand Down
22 changes: 14 additions & 8 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,20 @@
*async* (wrap-await return?))))

(defn save-pragma [env next-t]
(if (and (:top-level env)
(re-find #"^(/\*|//|\"|\')" (str next-t)))
(let [js (str next-t "\n")]
(if-let [p (:pragmas env)]
(do (swap! p str js)
nil)
js))
(statement next-t)))
(let [p (:pragmas env)
past (and p (:past @p))]
(if (and (:top-level env)
(re-find #"^(/\*|//|\"|\')" (str next-t)))
(let [js (str next-t "\n")]
(if (and p (not past))
(do (swap! p update :js str js)
nil)
js))
(let [js (statement next-t)]
(if (or (not p) past) js
(do
(swap! p assoc :past true)
js))))))

(defn emit-do [env exprs]
(let [bl (butlast exprs)
Expand Down

0 comments on commit d1aec77

Please sign in to comment.