@@ -308,12 +308,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) {
308
308
else Blk (stmts.map {
309
309
case t : Term =>
310
310
desugarQuote(t)(blkScope, isQuoted, freeVars)
311
- case nd @ NuFunDef (isLetRec, nme, symbol, tparams, rhs) => // * TODO: other cases in addition to let?
312
- NuFunDef (isLetRec, nme, symbol, tparams, rhs match {
313
- case L (t) => L (desugarQuote(t)(blkScope, isQuoted, freeVars))
314
- case R (t) => R (t)
315
- })(nd.declareLoc, nd.virtualLoc, nd.mutLoc, nd.signature, nd.outer, nd.genField, nd.annotations)
316
- case s => throw CodeGenError (s " statement $s is not supported in quasiquotes " )
311
+ case s => desugarStatementForQuote(s)(blkScope, isQuoted, freeVars)
317
312
})
318
313
case Tup (eles) =>
319
314
def toVar (b : Bool ) = if (b) Var (" true" ) else Var (" false" )
@@ -354,6 +349,25 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) {
354
349
throw CodeGenError (" this quote syntax is not supported yet." )
355
350
}
356
351
352
+ private def desugarStatementForQuote (s : Statement )(implicit scope : Scope , isQuoted : Bool , freeVars : FreeVars ): Statement = s match {
353
+ case nd @ NuFunDef (isLetRec, nme, symbol, tparams, rhs) =>
354
+ NuFunDef (isLetRec, nme, symbol, tparams, rhs match {
355
+ case L (t) => L (desugarQuote(t))
356
+ case R (t) => R (t)
357
+ })(nd.declareLoc, nd.virtualLoc, nd.mutLoc, nd.signature, nd.outer, nd.genField)
358
+ case nt @ NuTypeDef (kind, nme, tparams, params, ctor, sig, parents, superAnnot, thisAnnot, TypingUnit (body)) =>
359
+ NuTypeDef (kind, nme, tparams, params, ctor.map(c => desugarStatementForQuote(c) match {
360
+ case c : Constructor => c
361
+ case _ => die
362
+ }), sig, parents.map(p => desugarQuote(p)), superAnnot, thisAnnot, TypingUnit (body.map(s => desugarStatementForQuote(s))))(nt.declareLoc, nt.abstractLoc)
363
+ case Constructor (ps, body) => Constructor (ps, desugarQuote(body) match {
364
+ case b : Blk => b
365
+ case _ => die
366
+ })
367
+ case t : Term => desugarQuote(t)
368
+ case _ : LetS | _ : DataDefn | _ : DatatypeDefn | _ : TypeDef | _ : Def => die // * Impossible. newDef is true
369
+ }
370
+
357
371
/**
358
372
* Translate MLscript terms into JavaScript expressions.
359
373
*/
0 commit comments