babel: Bug: @babel/transform-modules-commonjs: loose does not work
As per the spec, import and export are only allowed to be used at the top level. When in loose mode these are allowed to be used anywhere.
However, not with babel 6 or babel 7 will it work.
Input Code
function test() {
import 'which'
}
Babel/Babylon Configuration (.babelrc, package.json, cli command)
{
"presets": ["@babel/es2015"],
"plugins": [
["@babel/transform-modules-commonjs", { "loose": true }],
"@babel/syntax-object-rest-spread"
]
}
Expected Behavior
It should compile.
Current Behavior
SyntaxError: ‘import’ and ‘export’ may only appear at the top level
Your Environment
software | version(s) |
---|---|
Babel | 7.0.0-beta.33 |
node | 8.6.0 |
Operating System | linux |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23 (17 by maintainers)
Commits related to this issue
- fixes #6954 documentation change for 'loose' option in 'babel-plugin-transform-modules-commonjs' [skip ci] — committed to perinikhil/babel by deleted user 7 years ago
- Fixes #6954 accurately describe behavior of 'loose' option in 'babel-plugin-transform-modules-commonjs' [skip-ci] — committed to abianco3/babel by abianco3 7 years ago
@perinikhil PR is in. Thanks again!
On Sat, Dec 16, 2017 at 10:49 AM, Peri Nikhil notifications@github.com wrote:
– Software Engineer linkedin https://www.linkedin.com/in/abianco3/ github https://www.github.com/abianco3
From what I understand the line that reads “As per the spec, import and export are only allowed to be used at the top level. When in loose mode these are allowed to be used anywhere.” needs to be simply removed from the docs. I’ve been working my way through the source code to make sure I’m not missing some functionality that should replace this line.