8889841cREADME.md000066600000000600150515241250006023 0ustar00# @babel/plugin-transform-new-target > Transforms new.target meta property See our website [@babel/plugin-transform-new-target](https://babeljs.io/docs/en/babel-plugin-transform-new-target) for more information. ## Install Using npm: ```sh npm install --save-dev @babel/plugin-transform-new-target ``` or using yarn: ```sh yarn add @babel/plugin-transform-new-target --dev ``` lib/index.js000066600000004432150515241250006766 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _helperPluginUtils = require("@babel/helper-plugin-utils"); var _core = require("@babel/core"); var _default = (0, _helperPluginUtils.declare)(api => { api.assertVersion(7); return { name: "transform-new-target", visitor: { MetaProperty(path) { const meta = path.get("meta"); const property = path.get("property"); const { scope } = path; if (meta.isIdentifier({ name: "new" }) && property.isIdentifier({ name: "target" })) { const func = path.findParent(path => { if (path.isClass()) return true; if (path.isFunction() && !path.isArrowFunctionExpression()) { if (path.isClassMethod({ kind: "constructor" })) { return false; } return true; } return false; }); if (!func) { throw path.buildCodeFrameError("new.target must be under a (non-arrow) function or a class."); } const { node } = func; if (_core.types.isMethod(node)) { path.replaceWith(scope.buildUndefinedNode()); return; } const constructor = _core.types.memberExpression(_core.types.thisExpression(), _core.types.identifier("constructor")); if (func.isClass()) { path.replaceWith(constructor); return; } if (!node.id) { node.id = scope.generateUidIdentifier("target"); } else { let scope = path.scope; const name = node.id.name; while (scope !== func.parentPath.scope) { if (scope.hasOwnBinding(name) && !scope.bindingIdentifierEquals(name, node.id)) { scope.rename(name); } scope = scope.parent; } } path.replaceWith(_core.types.conditionalExpression(_core.types.binaryExpression("instanceof", _core.types.thisExpression(), _core.types.cloneNode(node.id)), constructor, scope.buildUndefinedNode())); } } } }; }); exports.default = _default;LICENSE000066600000002122150515241250005552 0ustar00MIT License Copyright (c) 2014-present Sebastian McKenzie and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package.json000066600000001714150515241250007041 0ustar00{ "name": "@babel/plugin-transform-new-target", "version": "7.18.6", "description": "Transforms new.target meta property", "repository": { "type": "git", "url": "https://github.com/babel/babel.git", "directory": "packages/babel-plugin-transform-new-target" }, "homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-new-target", "license": "MIT", "publishConfig": { "access": "public" }, "main": "./lib/index.js", "keywords": [ "babel-plugin" ], "dependencies": { "@babel/helper-plugin-utils": "^7.18.6" }, "peerDependencies": { "@babel/core": "^7.0.0-0" }, "devDependencies": { "@babel/core": "^7.18.6", "@babel/helper-plugin-test-runner": "^7.18.6", "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-transform-arrow-functions": "^7.18.6" }, "engines": { "node": ">=6.9.0" }, "author": "The Babel Team (https://babel.dev/team)", "type": "commonjs" }