mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
[Babel 8] Remove plugin-transform-react-{compat,source,self} (#17620)
remove
This commit is contained in:
Vendored
+15
@@ -1,5 +1,20 @@
|
||||
/* This file is automatically generated by scripts/generators/archived-libs-typings.js */
|
||||
|
||||
declare module "@babel/plugin-transform-react-jsx-compat" {
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
let exports: {default: ReturnType<typeof declare>};
|
||||
export = exports;
|
||||
}
|
||||
declare module "@babel/plugin-transform-react-jsx-self" {
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
let exports: {default: ReturnType<typeof declare>};
|
||||
export = exports;
|
||||
}
|
||||
declare module "@babel/plugin-transform-react-jsx-source" {
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
let exports: {default: ReturnType<typeof declare>};
|
||||
export = exports;
|
||||
}
|
||||
declare module "@babel/plugin-proposal-record-and-tuple" {
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
let exports: {default: ReturnType<typeof declare>};
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
tsconfig.json
|
||||
tsconfig.tsbuildinfo
|
||||
@@ -1,19 +0,0 @@
|
||||
# @babel/plugin-transform-react-jsx-compat
|
||||
|
||||
> Turn JSX into React Pre-0.12 function calls
|
||||
|
||||
See our website [@babel/plugin-transform-react-jsx-compat](https://babeljs.io/docs/babel-plugin-transform-react-jsx-compat) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-react-jsx-compat
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/plugin-transform-react-jsx-compat --dev
|
||||
```
|
||||
@@ -1,42 +0,0 @@
|
||||
{
|
||||
"name": "@babel/plugin-transform-react-jsx-compat",
|
||||
"version": "7.27.1",
|
||||
"description": "Turn JSX into React Pre-0.12 function calls",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-transform-react-jsx-compat"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-react-jsx-compat",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-builder-react-jsx": "workspace:^",
|
||||
"@babel/helper-plugin-utils": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "workspace:^",
|
||||
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import helper from "@babel/helper-builder-react-jsx";
|
||||
import { types as t } from "@babel/core";
|
||||
|
||||
export default declare(api => {
|
||||
api.assertVersion(REQUIRED_VERSION(7));
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx-compat",
|
||||
|
||||
manipulateOptions(_, parserOpts) {
|
||||
parserOpts.plugins.push("jsx");
|
||||
},
|
||||
|
||||
visitor: helper({
|
||||
pre(state) {
|
||||
state.callee = state.tagExpr;
|
||||
},
|
||||
|
||||
post(state) {
|
||||
if (t.react.isCompatTag(state.tagName)) {
|
||||
state.call = t.callExpression(
|
||||
t.memberExpression(
|
||||
t.memberExpression(t.identifier("React"), t.identifier("DOM")),
|
||||
state.tagExpr,
|
||||
t.isLiteral(state.tagExpr),
|
||||
),
|
||||
state.args,
|
||||
);
|
||||
}
|
||||
},
|
||||
compat: true,
|
||||
}),
|
||||
};
|
||||
});
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
var x = <Component foo="bar">
|
||||
<Namespace.Component />
|
||||
</Component>
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
var x = Component({
|
||||
foo: "bar"
|
||||
}, Namespace.Component(null));
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
var x = <div foo="bar"><font-face></font-face></div>;
|
||||
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
var x = React.DOM.div({
|
||||
foo: "bar"
|
||||
}, React.DOM["font-face"](null));
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["syntax-jsx", "transform-react-jsx-compat"]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(import.meta.url);
|
||||
@@ -1,24 +0,0 @@
|
||||
/* This file is automatically generated by scripts/generators/tsconfig.js */
|
||||
{
|
||||
"extends": [
|
||||
"../../tsconfig.base.json",
|
||||
"../../tsconfig.paths.json"
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*.ts",
|
||||
"./src/**/*.cts",
|
||||
"../../lib/globals.d.ts",
|
||||
"../../scripts/repo-utils/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/babel-helper-builder-react-jsx"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-helper-plugin-utils"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-core"
|
||||
}
|
||||
]
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
var x = (
|
||||
<>
|
||||
<div>
|
||||
<div key="1" />
|
||||
<div key="2" meow="wolf" />
|
||||
<div key="3" />
|
||||
<div {...props} key="4" />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
["transform-react-jsx-development", { "runtime": "classic" }],
|
||||
"transform-react-jsx-source",
|
||||
"transform-react-jsx-self"
|
||||
],
|
||||
"throws": "Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config."
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
var x = <div __self={self}></div>;
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"throws": "Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config.",
|
||||
"plugins": ["transform-react-jsx-development"]
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
var x = <div __source={source}></div>;
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"throws": "Duplicate __source prop found. You are most likely using the deprecated transform-react-jsx-source Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config.",
|
||||
"plugins": ["transform-react-jsx-development"]
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
var x = (
|
||||
<>
|
||||
<div>
|
||||
<div key="1" />
|
||||
<div key="2" meow="wolf" />
|
||||
<div key="3" />
|
||||
<div {...props} key="4" />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-react-jsx-development",
|
||||
"transform-react-jsx-source",
|
||||
"transform-react-jsx-self"
|
||||
],
|
||||
"sourceType": "module",
|
||||
"throws": "Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config."
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
tsconfig.json
|
||||
tsconfig.tsbuildinfo
|
||||
@@ -1,19 +0,0 @@
|
||||
# @babel/plugin-transform-react-jsx-self
|
||||
|
||||
> Add a __self prop to all JSX Elements
|
||||
|
||||
See our website [@babel/plugin-transform-react-jsx-self](https://babeljs.io/docs/babel-plugin-transform-react-jsx-self) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-react-jsx-self
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/plugin-transform-react-jsx-self --dev
|
||||
```
|
||||
@@ -1,42 +0,0 @@
|
||||
{
|
||||
"name": "@babel/plugin-transform-react-jsx-self",
|
||||
"version": "7.27.1",
|
||||
"description": "Add a __self prop to all JSX Elements",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-transform-react-jsx-self"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-react-jsx-self",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "workspace:^",
|
||||
"@babel/helper-plugin-test-runner": "workspace:^",
|
||||
"@babel/plugin-syntax-jsx": "workspace:^"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* This adds a __self={this} JSX attribute to all JSX elements, which React will use
|
||||
* to generate some runtime warnings. However, if the JSX element appears within a
|
||||
* constructor of a derived class, `__self={this}` will not be inserted in order to
|
||||
* prevent runtime errors.
|
||||
*
|
||||
* == JSX Literals ==
|
||||
*
|
||||
* <sometag />
|
||||
*
|
||||
* becomes:
|
||||
*
|
||||
* <sometag __self={this} />
|
||||
*/
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import { types as t } from "@babel/core";
|
||||
import type { Visitor, NodePath } from "@babel/core";
|
||||
|
||||
const TRACE_ID = "__self";
|
||||
|
||||
/**
|
||||
* Finds the closest parent function that provides `this`. Specifically, this looks for
|
||||
* the first parent function that isn't an arrow function.
|
||||
*
|
||||
* Derived from `Scope#getFunctionParent`
|
||||
*/
|
||||
function getThisFunctionParent(
|
||||
path: NodePath<t.JSXOpeningElement>,
|
||||
): NodePath<Exclude<t.FunctionParent, t.ArrowFunctionExpression>> | null {
|
||||
let scope = path.scope;
|
||||
do {
|
||||
const { path } = scope;
|
||||
if (path.isFunctionParent() && !path.isArrowFunctionExpression()) {
|
||||
return path;
|
||||
}
|
||||
} while ((scope = scope.parent));
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the class has specified a superclass.
|
||||
*/
|
||||
function isDerivedClass(classPath: NodePath<t.Class>) {
|
||||
return classPath.node.superClass !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether `this` is allowed at given path.
|
||||
*/
|
||||
function isThisAllowed(path: NodePath<t.JSXOpeningElement>) {
|
||||
// This specifically skips arrow functions as they do not rewrite `this`.
|
||||
const parentMethodOrFunction = getThisFunctionParent(path);
|
||||
if (parentMethodOrFunction === null) {
|
||||
// We are not in a method or function. It is fine to use `this`.
|
||||
return true;
|
||||
}
|
||||
if (!parentMethodOrFunction.isMethod()) {
|
||||
// If the closest parent is a regular function, `this` will be rebound, therefore it is fine to use `this`.
|
||||
return true;
|
||||
}
|
||||
// Current node is within a method, so we need to check if the method is a constructor.
|
||||
if (parentMethodOrFunction.node.kind !== "constructor") {
|
||||
// We are not in a constructor, therefore it is always fine to use `this`.
|
||||
return true;
|
||||
}
|
||||
// Now we are in a constructor. If it is a derived class, we do not reference `this`.
|
||||
return !isDerivedClass(
|
||||
parentMethodOrFunction.parentPath.parentPath as NodePath<t.Class>,
|
||||
);
|
||||
}
|
||||
|
||||
export default declare(api => {
|
||||
api.assertVersion(REQUIRED_VERSION(7));
|
||||
|
||||
const visitor: Visitor = {
|
||||
JSXOpeningElement(path) {
|
||||
if (!isThisAllowed(path)) {
|
||||
return;
|
||||
}
|
||||
const node = path.node;
|
||||
const id = t.jsxIdentifier(TRACE_ID);
|
||||
const trace = t.thisExpression();
|
||||
|
||||
node.attributes.push(t.jsxAttribute(id, t.jsxExpressionContainer(trace)));
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx-self",
|
||||
visitor: {
|
||||
Program(path) {
|
||||
path.traverse(visitor);
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
<div />;
|
||||
() => <div />;
|
||||
|
||||
function fn() {
|
||||
<div />;
|
||||
() => <div />;
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["syntax-jsx", "transform-react-jsx-self", "transform-arrow-functions"]
|
||||
}
|
||||
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
var _this = this;
|
||||
<div __self={this} />;
|
||||
(function () {
|
||||
return <div __self={_this} />;
|
||||
});
|
||||
function fn() {
|
||||
var _this2 = this;
|
||||
<div __self={this} />;
|
||||
(function () {
|
||||
return <div __self={_this2} />;
|
||||
});
|
||||
}
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
var x = <sometag />
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
var x = <sometag __self={this} />;
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
class A { }
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
<sometag1 />;
|
||||
super(<sometag2 />);
|
||||
<sometag3 />;
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
constructor() {
|
||||
<sometag4 />;
|
||||
class D extends A {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
const E = class extends A {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class E extends A {
|
||||
constructor() {
|
||||
this.x = () => <sometag5 />;
|
||||
this.y = function () {
|
||||
return <sometag6 />;
|
||||
};
|
||||
function z() {
|
||||
return <sometag7 />;
|
||||
}
|
||||
{ <sometag8 /> }
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
class F {
|
||||
constructor() {
|
||||
<sometag9 />
|
||||
}
|
||||
}
|
||||
|
||||
class G extends A {
|
||||
constructor() {
|
||||
return <sometag10 />;
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
class A {}
|
||||
class B extends A {
|
||||
constructor() {
|
||||
<sometag1 />;
|
||||
super(<sometag2 />);
|
||||
<sometag3 />;
|
||||
}
|
||||
}
|
||||
class C {
|
||||
constructor() {
|
||||
<sometag4 __self={this} />;
|
||||
class D extends A {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
const E = class extends A {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
class E extends A {
|
||||
constructor() {
|
||||
this.x = () => <sometag5 />;
|
||||
this.y = function () {
|
||||
return <sometag6 __self={this} />;
|
||||
};
|
||||
function z() {
|
||||
return <sometag7 __self={this} />;
|
||||
}
|
||||
{
|
||||
<sometag8 />;
|
||||
}
|
||||
super();
|
||||
}
|
||||
}
|
||||
class F {
|
||||
constructor() {
|
||||
<sometag9 __self={this} />;
|
||||
}
|
||||
}
|
||||
class G extends A {
|
||||
constructor() {
|
||||
return <sometag10 />;
|
||||
}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"plugins": ["syntax-jsx", "transform-react-jsx-self"],
|
||||
"sourceType": "script"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(import.meta.url);
|
||||
@@ -1,21 +0,0 @@
|
||||
/* This file is automatically generated by scripts/generators/tsconfig.js */
|
||||
{
|
||||
"extends": [
|
||||
"../../tsconfig.base.json",
|
||||
"../../tsconfig.paths.json"
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*.ts",
|
||||
"./src/**/*.cts",
|
||||
"../../lib/globals.d.ts",
|
||||
"../../scripts/repo-utils/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/babel-helper-plugin-utils"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-core"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
tsconfig.json
|
||||
tsconfig.tsbuildinfo
|
||||
@@ -1,19 +0,0 @@
|
||||
# @babel/plugin-transform-react-jsx-source
|
||||
|
||||
> Add a __source prop to all JSX Elements
|
||||
|
||||
See our website [@babel/plugin-transform-react-jsx-source](https://babeljs.io/docs/babel-plugin-transform-react-jsx-source) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-react-jsx-source
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/plugin-transform-react-jsx-source --dev
|
||||
```
|
||||
@@ -1,42 +0,0 @@
|
||||
{
|
||||
"name": "@babel/plugin-transform-react-jsx-source",
|
||||
"version": "7.27.1",
|
||||
"description": "Add a __source prop to all JSX Elements",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-transform-react-jsx-source"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-react-jsx-source",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "workspace:^",
|
||||
"@babel/helper-plugin-test-runner": "workspace:^",
|
||||
"@babel/plugin-syntax-jsx": "workspace:^"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* This adds {fileName, lineNumber, columnNumber} annotations to JSX tags.
|
||||
*
|
||||
* NOTE: lineNumber and columnNumber are both 1-based.
|
||||
*
|
||||
* == JSX Literals ==
|
||||
*
|
||||
* <sometag />
|
||||
*
|
||||
* becomes:
|
||||
*
|
||||
* var __jsxFileName = 'this/file.js';
|
||||
* <sometag __source={{fileName: __jsxFileName, lineNumber: 10, columnNumber: 1}}/>
|
||||
*/
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import { types as t, template } from "@babel/core";
|
||||
|
||||
const TRACE_ID = "__source";
|
||||
const FILE_NAME_VAR = "_jsxFileName";
|
||||
|
||||
const createNodeFromNullish = <T, N extends t.Node>(
|
||||
val: T | null,
|
||||
fn: (val: T) => N,
|
||||
): N | t.NullLiteral => (val == null ? t.nullLiteral() : fn(val));
|
||||
|
||||
type State = {
|
||||
fileNameIdentifier: t.Identifier;
|
||||
};
|
||||
export default declare<State>(api => {
|
||||
api.assertVersion(REQUIRED_VERSION(7));
|
||||
|
||||
function makeTrace(
|
||||
fileNameIdentifier: t.Identifier,
|
||||
{ line, column }: { line: number; column: number },
|
||||
) {
|
||||
const fileLineLiteral = createNodeFromNullish(line, t.numericLiteral);
|
||||
const fileColumnLiteral = createNodeFromNullish(column, c =>
|
||||
// c + 1 to make it 1-based instead of 0-based.
|
||||
t.numericLiteral(c + 1),
|
||||
);
|
||||
|
||||
return template.expression.ast`{
|
||||
fileName: ${fileNameIdentifier},
|
||||
lineNumber: ${fileLineLiteral},
|
||||
columnNumber: ${fileColumnLiteral},
|
||||
}`;
|
||||
}
|
||||
|
||||
const isSourceAttr = (attr: t.Node) =>
|
||||
t.isJSXAttribute(attr) && attr.name.name === TRACE_ID;
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx-source",
|
||||
visitor: {
|
||||
JSXOpeningElement(path, state) {
|
||||
const { node } = path;
|
||||
if (
|
||||
// the element was generated and doesn't have location information
|
||||
!node.loc ||
|
||||
// Already has __source
|
||||
path.node.attributes.some(isSourceAttr)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!state.fileNameIdentifier) {
|
||||
const fileNameId = path.scope.generateUidIdentifier(FILE_NAME_VAR);
|
||||
state.fileNameIdentifier = fileNameId;
|
||||
|
||||
path.scope.getProgramParent().push({
|
||||
id: fileNameId,
|
||||
init: t.stringLiteral(state.filename || ""),
|
||||
});
|
||||
}
|
||||
|
||||
node.attributes.push(
|
||||
t.jsxAttribute(
|
||||
t.jsxIdentifier(TRACE_ID),
|
||||
t.jsxExpressionContainer(
|
||||
makeTrace(t.cloneNode(state.fileNameIdentifier), node.loc.start),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
Vendored
-17
@@ -1,17 +0,0 @@
|
||||
var actualP = transformAsync(
|
||||
'var x = <sometag />',
|
||||
Object.assign({}, opts, { filename: '/fake/path/mock.js' })
|
||||
)
|
||||
|
||||
var expected = `
|
||||
var _jsxFileName = "/fake/path/mock.js";
|
||||
var x = <sometag __source={{
|
||||
fileName: _jsxFileName,
|
||||
lineNumber: 1,
|
||||
columnNumber: 9
|
||||
}} />;
|
||||
`.trim();
|
||||
|
||||
return actualP.then(actual => {
|
||||
expect(actual.code).toBe(expected);
|
||||
});
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"os": ["linux", "darwin"],
|
||||
"parserOpts": { "allowReturnOutsideFunction": true }
|
||||
}
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
var x = 42;
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
var x = 42;
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["syntax-jsx", "transform-react-jsx-source"]
|
||||
}
|
||||
Vendored
-10
@@ -1,10 +0,0 @@
|
||||
var actualP = transformAsync(
|
||||
'var x = <sometag __source="custom" />;',
|
||||
Object.assign({}, opts, { filename: '/fake/path/mock.js' })
|
||||
)
|
||||
|
||||
var expected = 'var x = <sometag __source="custom" />;';
|
||||
|
||||
return actualP.then(actual => {
|
||||
expect(actual.code).toBe(expected);
|
||||
});
|
||||
packages/babel-plugin-transform-react-jsx-source/test/fixtures/react-source/with-source/options.json
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"os": ["linux", "darwin"],
|
||||
"parserOpts": { "allowReturnOutsideFunction": true }
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(import.meta.url);
|
||||
@@ -1,21 +0,0 @@
|
||||
/* This file is automatically generated by scripts/generators/tsconfig.js */
|
||||
{
|
||||
"extends": [
|
||||
"../../tsconfig.base.json",
|
||||
"../../tsconfig.paths.json"
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*.ts",
|
||||
"./src/**/*.cts",
|
||||
"../../lib/globals.d.ts",
|
||||
"../../scripts/repo-utils/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/babel-helper-plugin-utils"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-core"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -95,10 +95,10 @@
|
||||
"@babel/plugin-transform-react-display-name": "workspace:^",
|
||||
"@babel/plugin-transform-react-inline-elements": "workspace:^",
|
||||
"@babel/plugin-transform-react-jsx": "workspace:^",
|
||||
"@babel/plugin-transform-react-jsx-compat": "workspace:^",
|
||||
"@babel/plugin-transform-react-jsx-compat": "^7.27.1",
|
||||
"@babel/plugin-transform-react-jsx-development": "workspace:^",
|
||||
"@babel/plugin-transform-react-jsx-self": "workspace:^",
|
||||
"@babel/plugin-transform-react-jsx-source": "workspace:^",
|
||||
"@babel/plugin-transform-react-jsx-self": "^7.27.1",
|
||||
"@babel/plugin-transform-react-jsx-source": "^7.27.1",
|
||||
"@babel/plugin-transform-regenerator": "workspace:^",
|
||||
"@babel/plugin-transform-regexp-modifiers": "workspace:^",
|
||||
"@babel/plugin-transform-reserved-words": "workspace:^",
|
||||
|
||||
@@ -100,10 +100,7 @@
|
||||
"transform-react-display-name",
|
||||
"transform-react-inline-elements",
|
||||
"transform-react-jsx",
|
||||
"transform-react-jsx-compat",
|
||||
"transform-react-jsx-development",
|
||||
"transform-react-jsx-self",
|
||||
"transform-react-jsx-source",
|
||||
"transform-regenerator",
|
||||
"transform-reserved-words",
|
||||
"transform-runtime",
|
||||
|
||||
@@ -84,10 +84,7 @@ import transformReactConstantElements from "@babel/plugin-transform-react-consta
|
||||
import transformReactDisplayName from "@babel/plugin-transform-react-display-name";
|
||||
import transformReactInlineElements from "@babel/plugin-transform-react-inline-elements";
|
||||
import transformReactJsx from "@babel/plugin-transform-react-jsx";
|
||||
import transformReactJsxCompat from "@babel/plugin-transform-react-jsx-compat";
|
||||
import transformReactJsxDevelopment from "@babel/plugin-transform-react-jsx-development";
|
||||
import transformReactJsxSelf from "@babel/plugin-transform-react-jsx-self";
|
||||
import transformReactJsxSource from "@babel/plugin-transform-react-jsx-source";
|
||||
import transformRegenerator from "@babel/plugin-transform-regenerator";
|
||||
import transformReservedWords from "@babel/plugin-transform-reserved-words";
|
||||
import transformRuntime from "@babel/plugin-transform-runtime";
|
||||
@@ -191,10 +188,7 @@ export {
|
||||
transformReactDisplayName,
|
||||
transformReactInlineElements,
|
||||
transformReactJsx,
|
||||
transformReactJsxCompat,
|
||||
transformReactJsxDevelopment,
|
||||
transformReactJsxSelf,
|
||||
transformReactJsxSource,
|
||||
transformRegenerator,
|
||||
transformReservedWords,
|
||||
transformRuntime,
|
||||
@@ -301,10 +295,7 @@ export const all: Record<string, any> = {
|
||||
"transform-react-display-name": transformReactDisplayName,
|
||||
"transform-react-inline-elements": transformReactInlineElements,
|
||||
"transform-react-jsx": transformReactJsx,
|
||||
"transform-react-jsx-compat": transformReactJsxCompat,
|
||||
"transform-react-jsx-development": transformReactJsxDevelopment,
|
||||
"transform-react-jsx-self": transformReactJsxSelf,
|
||||
"transform-react-jsx-source": transformReactJsxSource,
|
||||
"transform-regenerator": transformRegenerator,
|
||||
"transform-reserved-words": transformReservedWords,
|
||||
"transform-runtime": transformRuntime,
|
||||
|
||||
@@ -255,18 +255,9 @@
|
||||
{
|
||||
"path": "../../packages/babel-plugin-transform-react-jsx"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-plugin-transform-react-jsx-compat"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-plugin-transform-react-jsx-development"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-plugin-transform-react-jsx-self"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-plugin-transform-react-jsx-source"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/babel-plugin-transform-regenerator"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
[
|
||||
"@babel/plugin-transform-react-jsx-compat",
|
||||
"@babel/plugin-transform-react-jsx-self",
|
||||
"@babel/plugin-transform-react-jsx-source",
|
||||
"@babel/plugin-proposal-record-and-tuple",
|
||||
"@babel/plugin-syntax-async-functions",
|
||||
"@babel/plugin-syntax-async-generators",
|
||||
|
||||
@@ -395,18 +395,9 @@
|
||||
{
|
||||
"path": "./packages/babel-plugin-transform-react-jsx"
|
||||
},
|
||||
{
|
||||
"path": "./packages/babel-plugin-transform-react-jsx-compat"
|
||||
},
|
||||
{
|
||||
"path": "./packages/babel-plugin-transform-react-jsx-development"
|
||||
},
|
||||
{
|
||||
"path": "./packages/babel-plugin-transform-react-jsx-self"
|
||||
},
|
||||
{
|
||||
"path": "./packages/babel-plugin-transform-react-jsx-source"
|
||||
},
|
||||
{
|
||||
"path": "./packages/babel-plugin-transform-react-pure-annotations"
|
||||
},
|
||||
|
||||
+9
-9
@@ -383,18 +383,9 @@
|
||||
"@babel/plugin-transform-react-jsx/lib/development": [
|
||||
"./packages/babel-plugin-transform-react-jsx/src/development.ts"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-compat": [
|
||||
"./packages/babel-plugin-transform-react-jsx-compat/src"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-development": [
|
||||
"./packages/babel-plugin-transform-react-jsx-development/src"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-self": [
|
||||
"./packages/babel-plugin-transform-react-jsx-self/src"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-source": [
|
||||
"./packages/babel-plugin-transform-react-jsx-source/src"
|
||||
],
|
||||
"@babel/plugin-transform-react-pure-annotations": [
|
||||
"./packages/babel-plugin-transform-react-pure-annotations/src"
|
||||
],
|
||||
@@ -482,6 +473,15 @@
|
||||
"@babel/plugin-codemod-optional-catch-binding": [
|
||||
"./codemods/babel-plugin-codemod-optional-catch-binding/src"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-compat": [
|
||||
"./lib/archived-libs.d.ts"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-self": [
|
||||
"./lib/archived-libs.d.ts"
|
||||
],
|
||||
"@babel/plugin-transform-react-jsx-source": [
|
||||
"./lib/archived-libs.d.ts"
|
||||
],
|
||||
"@babel/plugin-proposal-record-and-tuple": [
|
||||
"./lib/archived-libs.d.ts"
|
||||
],
|
||||
|
||||
@@ -622,6 +622,15 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-annotate-as-pure@npm:^7.27.1":
|
||||
version: 7.27.3
|
||||
resolution: "@babel/helper-annotate-as-pure@npm:7.27.3"
|
||||
dependencies:
|
||||
"@babel/types": "npm:^7.27.3"
|
||||
checksum: 10/63863a5c936ef82b546ca289c9d1b18fabfc24da5c4ee382830b124e2e79b68d626207febc8d4bffc720f50b2ee65691d7d12cc0308679dee2cd6bdc926b7190
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-annotate-as-pure@npm:^8.0.0-beta.3":
|
||||
version: 8.0.0-beta.3
|
||||
resolution: "@babel/helper-annotate-as-pure@npm:8.0.0-beta.3"
|
||||
@@ -640,6 +649,16 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-builder-react-jsx@npm:^7.27.1":
|
||||
version: 7.27.1
|
||||
resolution: "@babel/helper-builder-react-jsx@npm:7.27.1"
|
||||
dependencies:
|
||||
"@babel/helper-annotate-as-pure": "npm:^7.27.1"
|
||||
"@babel/types": "npm:^7.27.1"
|
||||
checksum: 10/b84452533af521970d1969f887d82066283831f8d96657148e628215223627b224d9ac2ea456eae7ca713f507c9bb6bf72a0afa625db8c01dc61cb0ac1da2d25
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-builder-react-jsx@workspace:^, @babel/helper-builder-react-jsx@workspace:packages/babel-helper-builder-react-jsx":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-builder-react-jsx@workspace:packages/babel-helper-builder-react-jsx"
|
||||
@@ -3290,18 +3309,17 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/plugin-transform-react-jsx-compat@workspace:^, @babel/plugin-transform-react-jsx-compat@workspace:packages/babel-plugin-transform-react-jsx-compat":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/plugin-transform-react-jsx-compat@workspace:packages/babel-plugin-transform-react-jsx-compat"
|
||||
"@babel/plugin-transform-react-jsx-compat@npm:^7.27.1":
|
||||
version: 7.27.1
|
||||
resolution: "@babel/plugin-transform-react-jsx-compat@npm:7.27.1"
|
||||
dependencies:
|
||||
"@babel/core": "workspace:^"
|
||||
"@babel/helper-builder-react-jsx": "workspace:^"
|
||||
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||
"@babel/helper-plugin-utils": "workspace:^"
|
||||
"@babel/helper-builder-react-jsx": "npm:^7.27.1"
|
||||
"@babel/helper-plugin-utils": "npm:^7.27.1"
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
checksum: 10/40ed4825ecff830190545ce3fbfadeac37583e1fa3b15557553df794c9c614dcbeb5d212e7c682c69bf1f46d0b2978e770fdf0b714cf46f4f4f6f30699fb4351
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-transform-react-jsx-development@workspace:^, @babel/plugin-transform-react-jsx-development@workspace:packages/babel-plugin-transform-react-jsx-development":
|
||||
version: 0.0.0-use.local
|
||||
@@ -3315,31 +3333,27 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/plugin-transform-react-jsx-self@workspace:^, @babel/plugin-transform-react-jsx-self@workspace:packages/babel-plugin-transform-react-jsx-self":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/plugin-transform-react-jsx-self@workspace:packages/babel-plugin-transform-react-jsx-self"
|
||||
"@babel/plugin-transform-react-jsx-self@npm:^7.27.1":
|
||||
version: 7.27.1
|
||||
resolution: "@babel/plugin-transform-react-jsx-self@npm:7.27.1"
|
||||
dependencies:
|
||||
"@babel/core": "workspace:^"
|
||||
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||
"@babel/helper-plugin-utils": "workspace:^"
|
||||
"@babel/plugin-syntax-jsx": "workspace:^"
|
||||
"@babel/helper-plugin-utils": "npm:^7.27.1"
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
checksum: 10/72cbae66a58c6c36f7e12e8ed79f292192d858dd4bb00e9e89d8b695e4c5cb6ef48eec84bffff421a5db93fd10412c581f1cccdb00264065df76f121995bdb68
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-transform-react-jsx-source@workspace:^, @babel/plugin-transform-react-jsx-source@workspace:packages/babel-plugin-transform-react-jsx-source":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/plugin-transform-react-jsx-source@workspace:packages/babel-plugin-transform-react-jsx-source"
|
||||
"@babel/plugin-transform-react-jsx-source@npm:^7.27.1":
|
||||
version: 7.27.1
|
||||
resolution: "@babel/plugin-transform-react-jsx-source@npm:7.27.1"
|
||||
dependencies:
|
||||
"@babel/core": "workspace:^"
|
||||
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||
"@babel/helper-plugin-utils": "workspace:^"
|
||||
"@babel/plugin-syntax-jsx": "workspace:^"
|
||||
"@babel/helper-plugin-utils": "npm:^7.27.1"
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
checksum: 10/e2843362adb53692be5ee9fa07a386d2d8883daad2063a3575b3c373fc14cdf4ea7978c67a183cb631b4c9c8d77b2f48c24c088f8e65cc3600cb8e97d72a7161
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-transform-react-jsx@workspace:^, @babel/plugin-transform-react-jsx@workspace:packages/babel-plugin-transform-react-jsx":
|
||||
version: 0.0.0-use.local
|
||||
@@ -4111,10 +4125,10 @@ __metadata:
|
||||
"@babel/plugin-transform-react-display-name": "workspace:^"
|
||||
"@babel/plugin-transform-react-inline-elements": "workspace:^"
|
||||
"@babel/plugin-transform-react-jsx": "workspace:^"
|
||||
"@babel/plugin-transform-react-jsx-compat": "workspace:^"
|
||||
"@babel/plugin-transform-react-jsx-compat": "npm:^7.27.1"
|
||||
"@babel/plugin-transform-react-jsx-development": "workspace:^"
|
||||
"@babel/plugin-transform-react-jsx-self": "workspace:^"
|
||||
"@babel/plugin-transform-react-jsx-source": "workspace:^"
|
||||
"@babel/plugin-transform-react-jsx-self": "npm:^7.27.1"
|
||||
"@babel/plugin-transform-react-jsx-source": "npm:^7.27.1"
|
||||
"@babel/plugin-transform-regenerator": "workspace:^"
|
||||
"@babel/plugin-transform-regexp-modifiers": "workspace:^"
|
||||
"@babel/plugin-transform-reserved-words": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user