source: imaps-frontend/node_modules/@babel/plugin-transform-classes/lib/inline-callSuper-helpers.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.3 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = addCallSuperHelper;
7var _core = require("@babel/core");
8const helper = _core.template.statement`
9 function CALL_SUPER(
10 _this,
11 derived,
12 args,
13 ) {
14 function isNativeReflectConstruct() {
15 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
16
17 // core-js@3
18 if (Reflect.construct.sham) return false;
19
20 // Proxy can't be polyfilled. Every browser implemented
21 // proxies before or at the same time as Reflect.construct,
22 // so if they support Proxy they also support Reflect.construct.
23 if (typeof Proxy === "function") return true;
24
25 // Since Reflect.construct can't be properly polyfilled, some
26 // implementations (e.g. core-js@2) don't set the correct internal slots.
27 // Those polyfills don't allow us to subclass built-ins, so we need to
28 // use our fallback implementation.
29 try {
30 // If the internal slots aren't set, this throws an error similar to
31 // TypeError: this is not a Boolean object.
32 return !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}),);
33 } catch (e) {
34 return false;
35 }
36 }
37
38 // Super
39 derived = GET_PROTOTYPE_OF(derived);
40 return POSSIBLE_CONSTRUCTOR_RETURN(
41 _this,
42 isNativeReflectConstruct()
43 ? // NOTE: This doesn't work if this.__proto__.constructor has been modified.
44 Reflect.construct(
45 derived,
46 args || [],
47 GET_PROTOTYPE_OF(_this).constructor,
48 )
49 : derived.apply(_this, args),
50 );
51 }
52`;
53const helperIDs = new WeakMap();
54function addCallSuperHelper(file) {
55 if (helperIDs.has(file)) {
56 return (_core.types.cloneNode || _core.types.clone)(helperIDs.get(file));
57 }
58 try {
59 return file.addHelper("callSuper");
60 } catch (_unused) {}
61 const id = file.scope.generateUidIdentifier("callSuper");
62 helperIDs.set(file, id);
63 const fn = helper({
64 CALL_SUPER: id,
65 GET_PROTOTYPE_OF: file.addHelper("getPrototypeOf"),
66 POSSIBLE_CONSTRUCTOR_RETURN: file.addHelper("possibleConstructorReturn")
67 });
68 file.path.unshiftContainer("body", [fn]);
69 file.scope.registerDeclaration(file.path.get("body.0"));
70 return _core.types.cloneNode(id);
71}
72
73//# sourceMappingURL=inline-callSuper-helpers.js.map
Note: See TracBrowser for help on using the repository browser.