swc/packages/helpers/esm/_create_super.js
Jiwon Choi 69719c2acb
refactor(es/helpers): Remove unnecessary exports (#9225)
**Description:**

Helper methods were exporting twice, `_` and it's own function name.
We can map the build script to export `_` as it's own name (filename).
Therefore we export only once as `_`, and map the name on the build
script.

```js
// helpers/_foo.js

function _foo() {
  // ...
}

export { _foo as _ }
```
```js
// index.js

// We know the func name will be `_foo` based on the filename.
export { _ as _foo } from '_foo.js'
```

Closes #9203

---------

Co-authored-by: magic-akari <akari.ccino@gmail.com>
2024-07-13 17:13:25 +09:00

22 lines
798 B
JavaScript

import { _ as _get_prototype_of } from "./_get_prototype_of.js";
import { _ as _is_native_reflect_construct } from "./_is_native_reflect_construct.js";
import { _ as _possible_constructor_return } from "./_possible_constructor_return.js";
function _create_super(Derived) {
var hasNativeReflectConstruct = _is_native_reflect_construct();
return function _createSuperInternal() {
var Super = _get_prototype_of(Derived), result;
if (hasNativeReflectConstruct) {
var NewTarget = _get_prototype_of(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possible_constructor_return(this, result);
};
}
export { _create_super as _ };