source: imaps-frontend/node_modules/@babel/plugin-transform-new-target/lib/index.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks 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 = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _core = require("@babel/core");
9var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
10 api.assertVersion(7);
11 return {
12 name: "transform-new-target",
13 visitor: {
14 MetaProperty(path) {
15 const meta = path.get("meta");
16 const property = path.get("property");
17 const {
18 scope
19 } = path;
20 if (meta.isIdentifier({
21 name: "new"
22 }) && property.isIdentifier({
23 name: "target"
24 })) {
25 const func = path.findParent(path => {
26 if (path.isClass()) return true;
27 if (path.isFunction() && !path.isArrowFunctionExpression()) {
28 if (path.isClassMethod({
29 kind: "constructor"
30 })) {
31 return false;
32 }
33 return true;
34 }
35 return false;
36 });
37 if (!func) {
38 throw path.buildCodeFrameError("new.target must be under a (non-arrow) function or a class.");
39 }
40 const {
41 node
42 } = func;
43 if (_core.types.isMethod(node)) {
44 path.replaceWith(scope.buildUndefinedNode());
45 return;
46 }
47 const constructor = _core.types.memberExpression(_core.types.thisExpression(), _core.types.identifier("constructor"));
48 if (func.isClass()) {
49 path.replaceWith(constructor);
50 return;
51 }
52 if (!node.id) {
53 node.id = scope.generateUidIdentifier("target");
54 } else {
55 let scope = path.scope;
56 const name = node.id.name;
57 while (scope !== func.parentPath.scope) {
58 if (scope.hasOwnBinding(name) && !scope.bindingIdentifierEquals(name, node.id)) {
59 scope.rename(name);
60 }
61 scope = scope.parent;
62 }
63 }
64 path.replaceWith(_core.types.conditionalExpression(_core.types.binaryExpression("instanceof", _core.types.thisExpression(), _core.types.cloneNode(node.id)), constructor, scope.buildUndefinedNode()));
65 }
66 }
67 }
68 };
69});
70
71//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.