Skip to content

Commit

Permalink
Fix top level return (#43)
Browse files Browse the repository at this point in the history
* more integration tests

* fix top level return
  • Loading branch information
rauchg authored Nov 23, 2018
1 parent 0a4c789 commit aa19c86
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ const resolve = require("resolve");
const fs = require("fs");
const webpack = require("webpack");
const MemoryFS = require("memory-fs");
const WebpackParser = require('webpack/lib/Parser');
const webpackParse = WebpackParser.parse

// overload the webpack parser so that we can make
// acorn work with the node.js / commonjs semantics
// of being able to `return` in the top level of a
// requireable module
// https://github.com/zeit/ncc/issues/40
WebpackParser.parse = function (source, opts = {}) {
return webpackParse.call(this, source, {
...opts,
allowReturnOutsideFunction: true
});
}

const SUPPORTED_EXTENSIONS = [".mjs", ".js", ".json"];

Expand Down Expand Up @@ -113,4 +127,4 @@ function getFlatFiles (mfsData, output, curBase = '') {
else
output[curPath] = mfsData[path];
}
}
}

0 comments on commit aa19c86

Please sign in to comment.