Open
Description
Describe the bug
The input code is commonjs. If SWC triggers any helpers in transpiling or other processes, which will inject import ... from '@swc/...'
statements, the commonjs visitor will detect these import statements and mark it with __esModule: true
. But the original module is actually a commonjs module.
Input code
const a = require('./foo')
const foo = async () => {}
Config
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"externalHelpers": true,
"transform": {
"react": {
"refresh": {}
}
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"isModule": true
}
Playground link
Expected behavior
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var a = require('./foo');
var foo = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function foo() {
return _ref.apply(this, arguments);
};
}();
Actual behavior
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default;
var _tsGenerator = require("@swc/helpers/lib/_ts_generator.js").default;
var a = require("./foo");
var foo = function() {
var _ref = _asyncToGenerator(function() {
return _tsGenerator(this, function(_state) {
return [
2
];
});
});
return function foo() {
return _ref.apply(this, arguments);
};
}();
Version
1.3.19
Additional context
No response