Skip to content

Commit

Permalink
Merge pull request #9046 from mwijngaard/master
Browse files Browse the repository at this point in the history
Allow top-level return in script parsing. Fixes issue 8509 in master,…
  • Loading branch information
sokra committed Apr 20, 2019
2 parents 42db81a + dc6dd51 commit 81cf088
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/Parser.js
Expand Up @@ -2238,6 +2238,8 @@ class Parser extends Tapable {

if (type === "auto") {
parserOptions.sourceType = "module";
} else if (parserOptions.sourceType === "script") {
parserOptions.allowReturnOutsideFunction = true;
}

let ast;
Expand All @@ -2252,6 +2254,7 @@ class Parser extends Tapable {

if (threw && type === "auto") {
parserOptions.sourceType = "script";
parserOptions.allowReturnOutsideFunction = true;
if (Array.isArray(parserOptions.onComment)) {
parserOptions.onComment.length = 0;
}
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/b.js
@@ -1,3 +1,6 @@
module.exports = function b() {
return "This is b";
};
};

// Test CJS top-level return
return;

0 comments on commit 81cf088

Please sign in to comment.