         ({mname, mLabels, mNames, bodyExprs}) =>
           mname.warn "named modules not supported; name is being ignored" if mname
 
-          requires = for [iport, param] in underscore.zip(mLabels, mNames)
-            "import #{param.name.compile o} = require(#{iport.compile o})"
-          bodyExprs.unshift new Literal requires.join ";\n"
-
-          # assuming no weirder control flow, and last line is what's exported
-          eport = bodyExprs.pop()
-          bodyExprs.push new Literal "export = #{eport.compile o}"
+          # imports
+          prelude.push @makeCode("\n")
+          for [iport, param] in underscore.zip(mLabels, mNames)
+            prelude = prelude.concat [
+              @makeCode("import "), param.compileToFragments(o),
+              @makeCode(" = require("), iport.compileNode(o), @makeCode(");\n")
+            ]
+          prelude.push @makeCode("\n")
+          prelude = flatten prelude
+
+          # exports
+          bodyExprs.push bodyExprs.pop().match [
+            M("eport", Value), ({eport}) =>
+              o.scope.parameter "export"  # suppress `var export`
+              new Assign(mkVanillaID("export"), eport)
+
+            M("klass", Class), ({klass}) =>
+              o.scope.parameter "export"  # suppress `var export`
+              [
+                klass
+                new Assign(mkVanillaID("export"), klass.variable)
+              ]
+          ]
 
           @expressions[node_i] = bodyExprs
       ]

    # this is just Palantir specific
    prelude.push @makeCode '/// <reference path="../../libraries/libraries.d.ts" />\n\n'

    # assuming AMD define
    for node, node_i in @expressions
      node.match [
        new Call(mkVanillaID("define"), [new Value(new Arr(M("mLabels"))),

# Pattern matching utilities
matchNode = (pattern, node, match) ->
  if pattern instanceof MatchCapture
    match[pattern.name] = node
    matchNode(pattern.subpattern, node, match) if pattern.subpattern

  else if pattern instanceof AnyMatch
    return yes

  else if pattern instanceof Base
    throw "match failed" unless node instanceof pattern.constructor
