);
5 | }, [
6 | outsetArrows
7 | ]);
8 | }
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-assign-property-variable-export/actual.js:
--------------------------------------------------------------------------------
1 | export const propTypes = {
2 | foo: PropTypes.string
3 | };
4 |
5 | class Foo extends React.Component {
6 | render() {}
7 | }
8 |
9 | Foo.propTypes = propTypes;
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/basic/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | [
4 | "transform-react-constant-elements",
5 | { "allowMutablePropsOnTags": ["FormattedMessage"] }
6 | ],
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/function-closure/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | [
4 | "transform-react-constant-elements",
5 | { "allowMutablePropsOnTags": ["Counter"] }
6 | ],
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/compound-assignment/input.mjs:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Loader from 'loader';
3 |
4 | const errorComesHere = () =>
,
5 | thisWorksFine = () =>
;
6 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/deopt-mutable-complex/output.mjs:
--------------------------------------------------------------------------------
1 | let foo = 'hello';
2 | const mutate = ()=>{
3 | foo = 'goodbye';
4 | };
5 | export const Component = ()=>{
6 | if (Math.random() > 0.5) mutate();
7 | return
{foo};
8 | };
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/regression-14363/output.js:
--------------------------------------------------------------------------------
1 | function RoutesComponent() {
2 | return
3 | {(c)=>{
4 | {
5 | const Comp = c;
6 | return ;
7 | }
8 | }}
9 | ;
10 | }
11 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cSpell.words": [
3 | "androideabi",
4 | "cjsx",
5 | "eabi",
6 | "elems",
7 | "mjsx",
8 | "modernjs",
9 | "rustc_hash",
10 | "Stylesheet",
11 | "wasi"
12 | ],
13 | "rust-analyzer.procMacro.ignored": { "napi-derive": ["napi"] }
14 | }
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_import/fixtures/ignore-style-component/option.json:
--------------------------------------------------------------------------------
1 | {
2 | "extensions": {
3 | "pluginImport": [
4 | {
5 | "libraryName": "foo",
6 | "style": true,
7 | "ignoreStyleComponent": ["PascalCase"]
8 | }
9 | ]
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lock_corejs_version/fixtures/lock-corejs/esm/expected.js:
--------------------------------------------------------------------------------
1 | import { _ as _object_spread } from "@@swc/_/_object_spread";
2 | import "@@corejs/modules/es.object.to-string.js";
3 | import "@@corejs/modules/es.promise.js";
4 | import 'foo';
5 | console.log(_object_spread({}, Promise));
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/mixed-fixtures/lodash-esmodule/option.json:
--------------------------------------------------------------------------------
1 | {
2 | "swc": {},
3 | "extensions": {
4 | "lodash": {
5 | "cwd": "",
6 | "ids": ["lodash", "lodash-es"]
7 | }
8 | },
9 | "module": {
10 | "type": "esmodule"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/function-impure-body/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | [
4 | "transform-react-constant-elements",
5 | { "allowMutablePropsOnTags": ["Counter"] }
6 | ],
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/for-loop-2/output.js:
--------------------------------------------------------------------------------
1 | function render() {
2 | const nodes = [];
3 | for(let i = 0; i < 5; i++){
4 | const o = "foo";
5 | const n = i;
6 | nodes.push(
{n}
);
7 | }
8 | return nodes;
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/for-loop-5/output.js:
--------------------------------------------------------------------------------
1 | function render() {
2 | const nodes = [];
3 | for(let i = 0; i < 5; i++){
4 | const o = "foo";
5 | const n = i;
6 | nodes.push(
{o}
);
7 | }
8 | return nodes;
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/function-same-binding-name/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | [
4 | "transform-react-constant-elements",
5 | { "allowMutablePropsOnTags": ["Counter"] }
6 | ],
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/not-allowed-element/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | [
4 | "transform-react-constant-elements",
5 | { "allowMutablePropsOnTags": ["FormattedNumber"] }
6 | ],
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/dont-hoist-block-scoped-variables/input.js:
--------------------------------------------------------------------------------
1 | function render(flag) {
2 | if (flag) {
3 | let bar = "bar";
4 |
5 | [].map(() => bar);
6 |
7 | return
;
8 | }
9 |
10 | return null;
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-deopt/actual.js:
--------------------------------------------------------------------------------
1 | import BaseComponent from 'components/base';
2 |
3 | class Foo extends BaseComponent {
4 | static propTypes = {
5 | foo: PropTypes.string.isRequired,
6 | };
7 | render() {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/variable-comment-annotation/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { connect } from 'react-redux';
3 | import FooComponent from './FooComponent';
4 | const Foo = connect(()=>{}, ()=>{})(FooComponent);
5 | export default Foo;
6 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-arrays/actual.js:
--------------------------------------------------------------------------------
1 | import { cond, isNumber, isString, round, toUpper } from "lodash";
2 | import fp, { partial } from "lodash/fp";
3 |
4 | cond([
5 | [isNumber, round],
6 | [isString, toUpper]
7 | ])(1.8);
8 |
9 | partial(func)([fp, 2])(1);
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/for-loop-2/input.js:
--------------------------------------------------------------------------------
1 | function render() {
2 | const nodes = [];
3 |
4 | for (let i = 0; i < 5; i++) {
5 | const o = "foo";
6 | const n = i;
7 | nodes.push({n}
);
8 | }
9 |
10 | return nodes;
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/for-loop-5/input.js:
--------------------------------------------------------------------------------
1 | function render() {
2 | const nodes = [];
3 |
4 | for (let i = 0; i < 5; i++) {
5 | const o = "foo";
6 | const n = i;
7 | nodes.push({o}
);
8 | }
9 |
10 | return nodes;
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/html-element/output.js:
--------------------------------------------------------------------------------
1 | let _foo, _div;
2 | function render() {
3 | return _foo || (_foo = );
4 | }
5 | function render() {
6 | return _div || (_div = );
7 | }
8 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/issue-7610/input.mjs:
--------------------------------------------------------------------------------
1 | import Parent from './Parent';
2 | import Child from './Child';
3 |
4 | function MyComponent({closeFn}) {
5 | return (
6 | }/>
7 | );
8 | }
9 |
10 | export default Parent;
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/function-same-binding-name/output.js:
--------------------------------------------------------------------------------
1 | function Component({ value }) {
2 | let _Counter;
3 | return ()=>{
4 | return _Counter || (_Counter = {
5 | return value + 1;
6 | }}/>);
7 | };
8 | }
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/deopt-mutable-complex/input.mjs:
--------------------------------------------------------------------------------
1 | let foo = 'hello';
2 |
3 | const mutate = ()=>{
4 | foo = 'goodbye';
5 | }
6 |
7 | export const Component = ()=>{
8 | if (Math.random() > 0.5) mutate();
9 | return {foo};
10 | };
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/dont-hoist-block-scoped-variables/output.js:
--------------------------------------------------------------------------------
1 | function render(flag) {
2 | if (flag) {
3 | let bar = "bar";
4 | [].map(()=>{
5 | return bar;
6 | });
7 | return ;
8 | }
9 | return null;
10 | }
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/class-name-matchers/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import BaseComponent from 'components/base';
2 | class Foo extends BaseComponent {
3 | render() {}
4 | }
5 | Foo.propTypes = process.env.NODE_ENV !== "production" ? {
6 | bar: PropTypes.string
7 | } : {};
8 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/deep-constant-violation/output.js:
--------------------------------------------------------------------------------
1 | let _b, _span;
2 | function render() {
3 | var children = _b || (_b = );
4 | if (someCondition) {
5 | children = _span || (_span = );
6 | }
7 | return {children}
;
8 | }
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/parameter-destructure-rest/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "transform-destructuring",
4 | "transform-parameters",
5 | "transform-spread",
6 | "transform-react-constant-elements",
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/pure-expression/input.js:
--------------------------------------------------------------------------------
1 | var Foo = React.createClass({
2 | render: function () {
3 | return (
4 |
8 | );
9 | }
10 | });
11 |
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/regression-14363/input.js:
--------------------------------------------------------------------------------
1 | function RoutesComponent() {
2 | return (
3 |
4 | {(c) => {
5 | {
6 | const Comp = c;
7 | return ;
8 | }
9 | }}
10 |
11 | );
12 | }
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/remove-import-proptypes/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 |
3 | class Greeting extends Component {
4 | render() {
5 | return /*#__PURE__*/ React.createElement("h1", null, "Hello, ", this.props.name);
6 | }
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/parameter-destructure-spread-deopt/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "transform-destructuring",
4 | "transform-parameters",
5 | "transform-spread",
6 | "transform-react-constant-elements",
7 | "syntax-jsx"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/parameter-reference/input.js:
--------------------------------------------------------------------------------
1 | function render(text) {
2 | return function () {
3 | return {text}
;
4 | };
5 | }
6 |
7 | function render() {
8 | return function (text) {
9 | return {text}
;
10 | };
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/trouble/member-expression-this/output.js:
--------------------------------------------------------------------------------
1 | let _span;
2 | class Component extends React.Component {
3 | subComponent = ()=>{
4 | return _span || (_span = Sub Component);
5 | };
6 | render = ()=>{
7 | return <_this.subComponent/>
8 | };
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-assign-property-variable-export/expected-wrap.js:
--------------------------------------------------------------------------------
1 | export const propTypes = {
2 | foo: PropTypes.string
3 | };
4 | class Foo extends React.Component {
5 | render() {}
6 | }
7 | Foo.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
8 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/async-function/output.mjs:
--------------------------------------------------------------------------------
1 | export default {
2 | async function (name) {
3 | const uppercasedName = name.upperCase();
4 |
5 | // awaits depending on uppercasedName go here
6 |
7 | return ;
8 | }
9 | };
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-reimports/actual.js:
--------------------------------------------------------------------------------
1 | import { map as map2 } from "lodash";
2 | import { map as map3 } from "lodash";
3 | import _ from "lodash";
4 | import l from "lodash";
5 |
6 | var result1 = map2([]);
7 | var result2 = map3([]);
8 | var result3 = _.map([]);
9 | var result4 = l.map([]);
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/issue-10879/input.mjs:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const namespace = {
4 | MyComponent: (props) => props.name
5 | };
6 |
7 | const buildTest = (name) => {
8 | const { MyComponent } = namespace;
9 | return () => (
10 |
11 | );
12 | }
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/parameter-destructure-rest/output.js:
--------------------------------------------------------------------------------
1 | function render({ text, className, id, ...props }) {
2 | let _div;
3 |
4 | // intentionally ignoring props
5 | return ()=>{
6 | return _div || (_div = );
7 | };
8 | }
9 |
--------------------------------------------------------------------------------
/crates/swc_plugins_utils/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "swc_plugins_utils"
4 | version = "0.1.0"
5 |
6 | [dependencies]
7 | swc_core = { workspace = true, features = [
8 | "common",
9 | "ecma_ast",
10 | "ecma_visit",
11 | "ecma_transforms",
12 | "ecma_quote",
13 | ] }
14 | rustc-hash = { workspace = true }
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/async-function/input.mjs:
--------------------------------------------------------------------------------
1 | export default {
2 | async function(name) {
3 | const uppercasedName = name.upperCase();
4 |
5 | // awaits depending on uppercasedName go here
6 |
7 | return (
);
8 | }
9 | };
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/destructure/input.js:
--------------------------------------------------------------------------------
1 | class AnchorLink extends Component {
2 | render() {
3 | const { isExternal, children } = this.props;
4 | if (isExternal) {
5 | return (immutable);
6 | }
7 |
8 | return ({children});
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/bugfix-175/actual.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | const sharedPropType = PropTypes.number;
5 |
6 | export default class Foo extends React.Component {
7 | static propTypes = {
8 | bar: sharedPropType,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/issue-10879-babel-7/input.mjs:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const namespace = {
4 | MyComponent: (props) => props.name
5 | };
6 |
7 | const buildTest = (name) => {
8 | const { MyComponent } = namespace;
9 | return () => (
10 |
11 | );
12 | }
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/inline-elements/output.js:
--------------------------------------------------------------------------------
1 | let _foo;
2 | function render() {
3 | return _foo || (_foo = );
4 | }
5 | function render() {
6 | let _foo2;
7 | var text = getText();
8 | return function() {
9 | return _foo2 || (_foo2 = {text});
10 | };
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/parameter-reference/output.js:
--------------------------------------------------------------------------------
1 | function render(text) {
2 | let _div;
3 | return function() {
4 | return _div || (_div = {text}
);
5 | };
6 | }
7 | function render() {
8 | return function(text) {
9 | return {text}
;
10 | };
11 | }
12 |
--------------------------------------------------------------------------------
/.changeset/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
3 | "changelog": "@changesets/cli/changelog",
4 | "commit": false,
5 | "fixed": [],
6 | "linked": [["@modern-js/*"]],
7 | "access": "restricted",
8 | "baseBranch": "main",
9 | "updateInternalDependencies": "patch",
10 | "ignore": []
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/function-closure/output.js:
--------------------------------------------------------------------------------
1 | import Counter from 'foo';
2 | function Component({ increment }) {
3 | let _Counter;
4 | return ()=>{
5 | return _Counter || (_Counter = {
6 | return value + increment;
7 | }}/>);
8 | };
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/function-impure-body/output.js:
--------------------------------------------------------------------------------
1 | import Counter from 'foo';
2 | function Component() {
3 | let _Counter;
4 | return ()=>{
5 | return _Counter || (_Counter = {
6 | return value + prompt("Increment:");
7 | }}/>);
8 | };
9 | }
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/destructure/output.js:
--------------------------------------------------------------------------------
1 | let _a;
2 | class AnchorLink extends Component {
3 | render() {
4 | const { isExternal, children } = this.props;
5 | if (isExternal) {
6 | return _a || (_a = immutable);
7 | }
8 | return {children};
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/crates/plugin_config_routes/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "plugin_config_routes"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | [dependencies]
7 | swc_core = { workspace = true, features = [
8 | "common",
9 | "ecma_visit",
10 | "ecma_ast",
11 | "ecma_quote",
12 | ] }
13 | swc_plugins_utils = { path = "../swc_plugins_utils" }
14 | serde = { workspace = true}
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-specifier-alias/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
7 | (0, _map.default)([]);
8 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/function-parameter/input.js:
--------------------------------------------------------------------------------
1 | import Foo from 'Foo'
2 |
3 | function render(text) {
4 | return function () {
5 | return {text};
6 | };
7 | }
8 |
9 | function createComponent(text) {
10 | return function render() {
11 | return {text};
12 | };
13 | }
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/es-class-assign-property-variable/expected-remove.js:
--------------------------------------------------------------------------------
1 | "use strict"
2 | class Foo extends React.Component {
3 | render() {}
4 |
5 | }
6 |
7 | class Getter extends React.Component {
8 | get foo() {
9 | return {
10 | foo: PropTypes.string
11 | };
12 | }
13 |
14 | render() {}
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/mixed-fixtures/lodash-esmodule/expected.js:
--------------------------------------------------------------------------------
1 | import _lodash_map3 from "lodash-es/map";
2 | import _lodash_map2 from "lodash/map";
3 | import addEs from "lodash-es/add";
4 | import add from "lodash/add";
5 | add(1, 2);
6 | _lodash_map2([
7 | 1
8 | ], function() {});
9 | addEs(1, 2);
10 | _lodash_map3([
11 | 1
12 | ], function() {});
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-component/actual.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends Component {
2 | static propTypes = {
3 | foo1: PropTypes.string,
4 | };
5 |
6 | render() {}
7 | }
8 |
9 | class Foo2 extends Component {
10 | render() {}
11 | }
12 |
13 | Foo2.propTypes = {
14 | foo2: PropTypes.string,
15 | };
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-assign-property/actual.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends React.Component {
2 | render() {}
3 | }
4 |
5 | Foo1.propTypes = {
6 | bar1: PropTypes.string,
7 | };
8 |
9 | class Foo2 extends React.PureComponent {
10 | render() {}
11 | }
12 |
13 | Foo2.propTypes = {
14 | bar2: PropTypes.string,
15 | };
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-deopt/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | import BaseComponent from 'components/base';
3 | class Foo extends BaseComponent {
4 | render() {}
5 | }
6 | _define_property(Foo, "propTypes", {
7 | foo: PropTypes.string.isRequired
8 | });
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/remove-import-proptypes/actual.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | class Greeting extends Component {
5 | render() {
6 | return Hello, {this.props.name}
;
7 | }
8 | }
9 |
10 | Greeting.propTypes = {
11 | name: PropTypes.string
12 | };
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/stateless-arrow-return-function/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { PropTypes } from 'react';
2 | import map from 'lodash/map';
3 |
4 | var Message = ({ mapList }) => {
5 | return map(mapList, index => {
6 | return /*#__PURE__*/ React.createElement("div", null);
7 | });
8 | };
9 |
10 | export default Message;
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-assignment/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/noop"));
7 | var o = {};
8 | o.a = _noop.default;
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-property-assignment/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _bind = /*#__PURE__*/ _interop_require_default._(require("lodash/bind"));
7 | _bind.default.placeholder = {};
8 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/mixed-fixtures/lodash-and-fp/actual.js:
--------------------------------------------------------------------------------
1 | import _, { map, take } from "lodash";
2 | import fp, { map as fmap, take as ftake } from "lodash/fp";
3 |
4 | var mapper = fmap(fp.add(1));
5 | var result = mapper([]);
6 | ftake(1, fp.reject(Boolean, result));
7 |
8 | var result2 = map([], n => _.add(1, n));
9 | take(_.reject(result2), 1);
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/after-return-issue-6751/output.js:
--------------------------------------------------------------------------------
1 | function AComponent() {
2 | let _div, _CComponent;
3 | const CComponent = ()=>{
4 | return _div || (_div = );
5 | };
6 | return ;
7 | function BComponent() {
8 | return _CComponent || (_CComponent = );
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_ssr_loader_id/useMemo/actual.js:
--------------------------------------------------------------------------------
1 | import { useLoader } from '@modern-js/runtime';
2 | import { memo } from 'react';
3 |
4 | const Wrap = memo((props) => {
5 | useLoader(()=>{
6 | console.log('wrap');
7 | return Promise.resolve({});
8 | }, {});
9 |
10 | return wrap header{props.children}
;
11 | });
12 | export default Wrap;
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/dont-hoist-before-class/input.mjs:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const Parent = ({}) => (
4 |
5 |
6 |
7 | );
8 |
9 | export default Parent;
10 |
11 | let Child = () => (
12 |
13 | ChildTextContent
14 |
15 | );
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/dont-hoist-before-declaration/input.js:
--------------------------------------------------------------------------------
1 | function render() {
2 | const bar = "bar", renderFoo = () => ;
3 |
4 | return renderFoo();
5 | }
6 |
7 | function render() {
8 | const bar = "bar", renderFoo = () => , baz = "baz";
9 |
10 | return renderFoo();
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-global-base-component/actual.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends GlobalComponent {
2 | static propTypes = {
3 | foo1: PropTypes.string
4 | };
5 | render() {}
6 | }
7 |
8 | class Foo2 extends GlobalComponent {
9 | render() {}
10 | }
11 |
12 | Foo2.propTypes = {
13 | foo2: PropTypes.string
14 | };
15 |
--------------------------------------------------------------------------------
/crates/plugin_remove_es_module_mark/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "plugin_remove_es_module_mark"
4 | version = "0.1.0"
5 |
6 | [dependencies]
7 | swc_core = { workspace = true, features = [
8 | "common",
9 | "ecma_ast",
10 | "ecma_visit",
11 | "ecma_quote",
12 | ] }
13 | swc_plugins_utils = { path = "../swc_plugins_utils" }
14 | serde = { workspace = true }
15 |
--------------------------------------------------------------------------------
/crates/plugin_ssr_loader_id/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "plugin_ssr_loader_id"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | [dependencies]
7 | md5 = "0.7.0"
8 | swc_plugins_utils = { path = "../swc_plugins_utils" }
9 | serde = { workspace = true }
10 | swc_core = { workspace = true, features = [
11 | "common",
12 | "ecma_ast",
13 | "ecma_visit",
14 | "ecma_quote",
15 | ] }
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope/input.mjs:
--------------------------------------------------------------------------------
1 | export default class App extends React.Component {
2 | render() {
3 | return (
4 |
8 | );
9 | }
10 | }
11 |
12 | const AppItem = ()=>{
13 | return child
;
14 | };
15 |
--------------------------------------------------------------------------------
/crates/plugin_react_const_elements/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "plugin_react_const_elements"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | [dependencies]
7 | serde = { workspace = true }
8 | swc_core = { workspace = true, features = [
9 | "ecma_utils",
10 | "ecma_visit",
11 | "ecma_ast",
12 | "ecma_usage_analyzer",
13 | "common",
14 | ] }
15 | rustc-hash = { workspace = true }
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope-2/input.mjs:
--------------------------------------------------------------------------------
1 | const AppItem = ()=>{
2 | return child
;
3 | };
4 |
5 | export default class App extends React.Component {
6 | render() {
7 | return (
8 |
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/compound-assignment/output.mjs:
--------------------------------------------------------------------------------
1 | let _Loader, _Loader2;
2 | import React from 'react';
3 | import Loader from 'loader';
4 | const errorComesHere = ()=>{
5 | return _Loader || (_Loader = );
6 | }, thisWorksFine = ()=>{
7 | return _Loader2 || (_Loader2 = );
8 | };
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/class-comment-annotation/actual.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import PropTypes from 'prop-types'
3 | import ParentComponent from './Parent'
4 |
5 | export default class Foo extends ParentComponent {
6 | render () {}
7 | }
8 |
9 | Foo.propTypes /* remove-proptypes */ = {
10 | bar: PropTypes.string.isRequired,
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-deopt/expected-remove.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | import BaseComponent from 'components/base';
3 | class Foo extends BaseComponent {
4 | render() {}
5 |
6 | }
7 |
8 | _define_property(Foo, "propTypes", {
9 | foo: PropTypes.string.isRequired
10 | });
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-static-property/actual.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends React.Component {
2 | static propTypes = {
3 | bar1: PropTypes.string,
4 | };
5 |
6 | render() {}
7 | }
8 |
9 | export default class Foo2 extends React.Component {
10 | static propTypes = {
11 | bar2: PropTypes.string,
12 | };
13 |
14 | render() {}
15 | }
16 |
--------------------------------------------------------------------------------
/crates/swc_plugins_core/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![feature(let_chains)]
2 | mod minify;
3 | mod transform;
4 |
5 | pub use minify::{minify, minify_css, CssMinifyOptions};
6 | use swc_core::base::config::Options;
7 | use swc_plugins_utils::PluginContext;
8 | pub use transform::transform;
9 |
10 | pub type TransformFn<'a, E, P> =
11 | fn(extensions_config: &'a E, swc_config: &Options, plugin_context: &PluginContext) -> P;
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/stateless-arrow-return-function/actual.js:
--------------------------------------------------------------------------------
1 | import React, {PropTypes} from 'react';
2 | import map from 'lodash/map';
3 |
4 | var Message = ({mapList}) => {
5 | return map(mapList, (index) => {
6 | return
7 | });
8 | };
9 |
10 | Message.propTypes = {
11 | mapList: PropTypes.array.isRequired,
12 | };
13 |
14 | export default Message;
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/member-expression/output.js:
--------------------------------------------------------------------------------
1 | var _span, _els$subComponent;
2 | const els = {
3 | subComponent: () => _span || (_span = Sub Component)
4 | };
5 | class Component extends React.Component {
6 | constructor(...args) {
7 | super(...args);
8 | this.render = () => _els$subComponent || (_els$subComponent = );
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope-2/output.mjs:
--------------------------------------------------------------------------------
1 | let _div, _div2;
2 | const AppItem = ()=>{
3 | return _div || (_div = child
);
4 | };
5 | export default class App extends React.Component {
6 | render() {
7 | return _div2 || (_div2 = );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope/output.mjs:
--------------------------------------------------------------------------------
1 | let _div, _div2;
2 | export default class App extends React.Component {
3 | render() {
4 | return _div || (_div = );
8 | }
9 | }
10 | const AppItem = ()=>{
11 | return _div2 || (_div2 = child
);
12 | };
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/bugfix-175/expected-unsafe-wrap.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | const sharedPropType = process.env.NODE_ENV !== "production" ? PropTypes.number : {};
4 | export default class Foo extends React.Component {
5 | }
6 | process.env.NODE_ENV !== "production" ? Foo.propTypes = {
7 | bar: sharedPropType
8 | } : void 0;
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/dont-hoist-before-hoc/input.mjs:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const HOC = component => component;
4 |
5 | const Parent = ({}) => (
6 |
7 |
8 |
9 | );
10 |
11 | export default Parent;
12 |
13 | let Child = () => (
14 |
15 | ChildTextContent
16 |
17 | );
18 | Child = HOC(Child);
19 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope-3/input.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | class App extends React.Component {
3 | render() {
4 | return (
5 |
9 | );
10 | }
11 | }
12 |
13 | const AppItem = ()=>{
14 | return child
;
15 | };
16 | });
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope-4/input.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | const AppItem = ()=>{
3 | return child
;
4 | };
5 |
6 | class App extends React.Component {
7 | render() {
8 | return (
9 |
13 | );
14 | }
15 | }
16 | });
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/dont-hoist-before-class/output.mjs:
--------------------------------------------------------------------------------
1 | let _div, _div2;
2 | import React from "react";
3 | const Parent = ({})=>{
4 | return _div || (_div =
5 |
6 |
);
7 | };
8 | export default Parent;
9 | let Child = ()=>{
10 | return _div2 || (_div2 =
11 | ChildTextContent
12 |
);
13 | };
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/dont-hoist-before-hoc/output.mjs:
--------------------------------------------------------------------------------
1 | var _div, _div2;
2 | import React from "react";
3 | const HOC = component => component;
4 | const Parent = ({}) => _div || (_div =
5 |
6 |
);
7 | export default Parent;
8 | let Child = () => _div2 || (_div2 =
9 | ChildTextContent
10 |
);
11 | Child = HOC(Child);
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/function-parameter/output.js:
--------------------------------------------------------------------------------
1 | import Foo from 'Foo';
2 |
3 | function render(text) {
4 | let _foo;
5 | return function() {
6 | return _foo || (_foo = {text});
7 | };
8 | }
9 |
10 | function createComponent(text) {
11 | let _Foo;
12 | return function render() {
13 | return _Foo || (_Foo = {text});
14 | };
15 | }
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_ssr_loader_id/useLoader/expected.js:
--------------------------------------------------------------------------------
1 | import { useLoader } from "@modern-js/runtime";
2 | useLoader(function() {
3 | var innerLoader = foo;
4 | innerLoader.id = "6bfe2068e141072c511e31bf4c18c260_0";
5 | return innerLoader;
6 | }());
7 | useLoader(function() {
8 | var innerLoader = bar;
9 | innerLoader.id = "6bfe2068e141072c511e31bf4c18c260_1";
10 | return innerLoader;
11 | }());
12 |
--------------------------------------------------------------------------------
/crates/plugin_import/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "swc_plugin_import"
4 | version = "0.1.8"
5 | license = "MIT"
6 | description = "babel-plugin-import rewritten in Rust"
7 |
8 | [dependencies]
9 | handlebars = "4.3.3"
10 | regex = "1.6.0"
11 | serde = { workspace = true }
12 | rustc-hash = { workspace = true }
13 | swc_core = { workspace = true, features = ["common", "ecma_ast", "ecma_visit"] }
14 | heck = "0.4.1"
15 |
--------------------------------------------------------------------------------
/packages/plugin-import/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "swc_plugin_import"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | [lib]
7 | crate-type = ['cdylib']
8 |
9 | [dependencies]
10 | serde = { workspace = true }
11 | serde_json = { workspace = true }
12 | swc_core = { workspace = true, features = [
13 | "ecma_plugin_transform",
14 | "common",
15 | "ecma_ast",
16 | ] }
17 | swc_plugin_import = { path = "../../crates/plugin_import" }
18 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_import/fixtures/custom-name-fn/option.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "extensions": {
3 | "pluginImport": [
4 | {
5 | "libraryName": "foo",
6 | "customName": (name) => {
7 | if (name === 'PascalCase') {
8 | return undefined
9 | } else {
10 | return `foo/__custom_es__/${name}`
11 | }
12 | }
13 | }
14 | ]
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/variable-comment-annotation/actual.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import PropTypes from 'prop-types'
3 | import { connect } from 'react-redux'
4 | import FooComponent from './FooComponent'
5 |
6 | const Foo = connect(()=>{}, ()=>{})(FooComponent);
7 |
8 | Foo.propTypes /* remove-proptypes */ = {
9 | bar: PropTypes.string.isRequired,
10 | }
11 |
12 | export default Foo
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/issue-11686/output.mjs:
--------------------------------------------------------------------------------
1 | const A = Foo;
2 | const B = Foo;
3 | const C = Foo;
4 | function outer(arg) {
5 | let _A;
6 | const valueB = null;
7 | const valueA = {};
8 | function inner() {
9 | console.log(_A || (_A =
10 |
11 |
12 |
13 | ));
14 | }
15 | inner();
16 | }
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/bugfix-assignment/actual.js:
--------------------------------------------------------------------------------
1 | var App = {
2 | init: function(assets) {
3 | assets = assets || {};
4 | if (assets.templates) {
5 | TemplateStore.init(assets.templates);
6 | }
7 | },
8 | };
9 |
10 | const FormattedPlural = () => ;
11 |
12 | process.env.NODE_ENV !== 'production' ? FormattedPlural.propTypes = {
13 | value: PropTypes.any.isRequired,
14 | } : void 0;
15 |
--------------------------------------------------------------------------------
/packages/react-const-elements/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "swc_plugin_react_const_elements"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | [lib]
7 | crate-type = ['cdylib']
8 |
9 | [dependencies]
10 | serde_json = { workspace = true }
11 | swc_core = { workspace = true, features = [
12 | "ecma_plugin_transform",
13 | "common",
14 | "ecma_ast",
15 | ] }
16 | plugin_react_const_elements = { path = "../../crates/plugin_react_const_elements" }
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/imported-components-issue-12337/input.mjs:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import OtherComponent from "./components/other-component";
3 |
4 | export default function App() {
5 | return (
6 |
7 |
8 |
9 |
10 | );
11 | }
12 |
13 | const LazyComponent = React.lazy(() => import("./components/lazy-component"));
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-no-name/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | var _React_Component;
3 | class _class extends (_React_Component = React.Component) {
4 | render() {}
5 | }
6 | _define_property(_class, "propTypes", process.env.NODE_ENV !== "production" ? {
7 | foo: PropTypes.string
8 | } : {});
9 | export { _class as default };
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/bugfix-assignment/expected-remove.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var App = {
3 | init: function(assets) {
4 | assets = assets || {};
5 |
6 | if (assets.templates) {
7 | TemplateStore.init(assets.templates);
8 | }
9 | }
10 | };
11 |
12 | const FormattedPlural = () => /*#__PURE__*/ React.createElement("div", null);
13 |
14 | process.env.NODE_ENV !== 'production' ? void 0 : void 0;
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/es-class-assign-property-variable/actual.js:
--------------------------------------------------------------------------------
1 | const propTypes = {
2 | foo: PropTypes.string
3 | };
4 |
5 | class Foo extends React.Component {
6 | render() {}
7 | }
8 |
9 | Foo.propTypes = propTypes;
10 |
11 | class Getter extends React.Component {
12 | get foo() {
13 | return { foo: PropTypes.string };
14 | }
15 |
16 | render() {}
17 | }
18 |
19 | Getter.propTypes = Getter.foo;
20 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-nested-scope/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _merge = /*#__PURE__*/ _interop_require_default._(require("lodash/merge"));
7 | function foo(object) {
8 | return (0, _merge.default)(object, {
9 | "a": 1
10 | });
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope-3/output.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | let _div, _div2;
3 | class App extends React.Component {
4 | render() {
5 | return _div || (_div = );
9 | }
10 | }
11 | const AppItem = ()=>{
12 | return _div2 || (_div2 = child
);
13 | };
14 | });
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/append-to-end-when-declared-in-scope-4/output.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | let _div, _div2;
3 | const AppItem = ()=>{
4 | return _div || (_div = child
);
5 | };
6 | class App extends React.Component {
7 | render() {
8 | return _div2 || (_div2 = );
12 | }
13 | }
14 | });
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-assign-property/expected-wrap.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends React.Component {
2 | render() {}
3 | }
4 | Foo1.propTypes = process.env.NODE_ENV !== "production" ? {
5 | bar1: PropTypes.string
6 | } : {};
7 | class Foo2 extends React.PureComponent {
8 | render() {}
9 | }
10 | Foo2.propTypes = process.env.NODE_ENV !== "production" ? {
11 | bar2: PropTypes.string
12 | } : {};
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/flow/actual.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends Component {
2 | props: {
3 | bar1?: string,
4 | };
5 | render() {}
6 | }
7 |
8 | export type Props2 = {
9 | bar2?: string
10 | }
11 |
12 | class Foo2 extends Component {
13 | props: Props2;
14 | render() {}
15 | }
16 |
17 | type Props3 = {
18 | bar3?: string,
19 | }
20 |
21 | function Foo3(props: Props3) {
22 | return ;
23 | }
24 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/issue-11686/input.mjs:
--------------------------------------------------------------------------------
1 | const A = Foo;
2 | const B = Foo;
3 | const C = Foo;
4 |
5 | function outer(arg) {
6 | const valueB = null;
7 | const valueA = {};
8 |
9 | function inner() {
10 | console.log(
11 |
12 |
13 |
14 |
15 |
16 | );
17 | }
18 |
19 | inner();
20 | }
21 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/mixed-fixtures/react-bootstrap/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _jsxruntime = require("react/jsx-runtime");
7 | var _Alert = /*#__PURE__*/ _interop_require_default._(require("react-bootstrap/cjs/Alert"));
8 | /*#__PURE__*/ (0, _jsxruntime.jsx)(_Alert.default, {});
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/shared-prop-type-variable/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { omit } from 'underscore';
3 | import Bar from './bar';
4 | const { PropTypes } = React;
5 | const propTypes = {
6 | foo: PropTypes.any
7 | };
8 | export default function Foo(props) {
9 | const barProps = omit(props, Object.keys(propTypes));
10 | return /*#__PURE__*/ React.createElement(Bar, barProps);
11 | }
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/stateless-arrow-return-function/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import React, { PropTypes } from 'react';
2 | import map from 'lodash/map';
3 |
4 | var Message = ({
5 | mapList
6 | }) => {
7 | return map(mapList, index => {
8 | return ;
9 | });
10 | };
11 |
12 | Message.propTypes = process.env.NODE_ENV !== "production" ? {
13 | mapList: PropTypes.array.isRequired
14 | } : {};
15 | export default Message;
16 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_ssr_loader_id/useStaticLoader/expected.js:
--------------------------------------------------------------------------------
1 | import { useStaticLoader as staticLoader } from "@modern1-js/runtime";
2 | staticLoader(function() {
3 | var innerLoader = foo1;
4 | innerLoader.id = "ff48b900a2ce78b3163e1b3b3f6b8ebf_0";
5 | return innerLoader;
6 | }());
7 | staticLoader(function() {
8 | var innerLoader = bar1;
9 | innerLoader.id = "ff48b900a2ce78b3163e1b3b3f6b8ebf_1";
10 | return innerLoader;
11 | }());
12 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-arguments/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
7 | var _capitalize = /*#__PURE__*/ _interop_require_default._(require("lodash/capitalize"));
8 | (0, _map.default)([], _capitalize.default);
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/es-arguments/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash-es/map"));
7 | var _capitalize = /*#__PURE__*/ _interop_require_default._(require("lodash-es/capitalize"));
8 | (0, _map.default)([], _capitalize.default);
9 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/imported-components-issue-12337/output.mjs:
--------------------------------------------------------------------------------
1 | let _div;
2 | import React from "react";
3 | import OtherComponent from "./components/other-component";
4 | export default function App() {
5 | return _div || (_div =
6 |
7 |
8 |
);
9 | }
10 | const LazyComponent = React.lazy(()=>{
11 | return import("./components/lazy-component");
12 | });
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/mixed-fixtures/syntax-jsx/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _jsxruntime = require("react/jsx-runtime");
7 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/noop"));
8 | /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
9 | onClick: _noop.default
10 | });
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/shared-prop-type-variable/actual.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {omit} from 'underscore';
3 |
4 | import Bar from './bar';
5 |
6 | const {PropTypes} = React;
7 |
8 | const propTypes = {
9 | foo: PropTypes.any,
10 | };
11 |
12 | export default function Foo(props) {
13 | const barProps = omit(props, Object.keys(propTypes));
14 | return ;
15 | }
16 |
17 | Foo.propTypes = propTypes;
18 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/unsafe-wrap/actual.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends React.Component {
2 | render() {}
3 | }
4 |
5 | Foo1.propTypes = {
6 | bar1: PropTypes.string,
7 | };
8 |
9 | class Foo2 extends React.Component {
10 | static propTypes = {
11 | bar2: PropTypes.string,
12 | };
13 |
14 | render() {}
15 | }
16 |
17 | const Foo3 = () => (
18 |
19 | );
20 |
21 | Foo3.propTypes = {
22 | bar3: PropTypes.string
23 | };
24 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/dont-hoist-before-declaration/output.js:
--------------------------------------------------------------------------------
1 | function render() {
2 | let _foo;
3 | const bar = "bar", renderFoo = ()=>{
4 | return _foo || (_foo = );
5 | };
6 | return renderFoo();
7 | }
8 | function render() {
9 | let _foo2;
10 | const bar = "bar", renderFoo = ()=>{
11 | return _foo2 || (_foo2 = );
12 | }, baz = "baz";
13 | return renderFoo();
14 | }
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/variable-assignment-member-expressions/expected-remove.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | const ComponentA = () =>/*#__PURE__*/ React.createElement("div", null);
3 |
4 | const ComponentB = () =>/*#__PURE__*/ React.createElement("div", null);
5 |
6 | const ComponentC = () =>/*#__PURE__*/ React.createElement("div", null);
7 |
8 | const ComponentD = () =>/*#__PURE__*/ React.createElement("div", null);
9 |
10 | const foo = {
11 | bar: 'foo'
12 | };
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/tag-member-expression/output.mjs:
--------------------------------------------------------------------------------
1 | var _Intl$FormattedMessag;
2 | import Intl from 'react-intl';
3 | var Foo = React.createClass({
4 | render: function () {
5 | return _Intl$FormattedMessag || (_Intl$FormattedMessag = );
8 | }
9 | });
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/basic/output.js:
--------------------------------------------------------------------------------
1 | let _FormattedMessage;
2 | import FormattedMessage from 'foo';
3 | var Foo = React.createClass({
4 | render: function() {
5 | return _FormattedMessage || (_FormattedMessage = );
8 | }
9 | });
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-global-base-component/expected-remove.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | class Foo1 extends GlobalComponent {
3 | render() {}
4 |
5 | }
6 |
7 | _define_property(Foo1, "propTypes", {
8 | foo1: PropTypes.string
9 | });
10 |
11 | class Foo2 extends GlobalComponent {
12 | render() {}
13 |
14 | }
15 |
16 | Foo2.propTypes = {
17 | foo2: PropTypes.string
18 | };
19 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-reimports/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
7 | var result1 = (0, _map.default)([]);
8 | var result2 = (0, _map.default)([]);
9 | var result3 = (0, _map.default)([]);
10 | var result4 = (0, _map.default)([]);
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-repeat-use/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
7 | var result1 = (0, _map.default)([]);
8 | var result2 = (0, _map.default)([]);
9 | var result3 = (0, _map.default)([]);
10 | var result4 = (0, _map.default)([]);
11 |
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/plugin_emotion.rs:
--------------------------------------------------------------------------------
1 | use napi::Status;
2 | use swc_plugins_collection::plugin_emotion::EmotionOptions;
3 |
4 | use super::IntoRawConfig;
5 |
6 | pub type EmotionOptionsNapi = String;
7 |
8 | impl IntoRawConfig for EmotionOptionsNapi {
9 | fn into_raw_config(self, _env: napi::Env) -> napi::Result {
10 | serde_json::from_str(&self)
11 | .map_err(|_| napi::Error::new::(Status::InvalidArg, "invalid emotion options".into()))
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | cargo-features = ["strip"]
2 |
3 | [workspace]
4 | members = ["crates/*"]
5 | resolver = "2"
6 |
7 | [profile.release]
8 | strip = "symbols"
9 |
10 | # Enable following optimization on CI, based on env variable
11 | # lto = true
12 | # codegen-units = 1
13 |
14 | [workspace.dependencies]
15 | rustc-hash = { version = "1.1.0" }
16 | anyhow = { version = "1.0.69" }
17 | dashmap = { version = "6.0.1" }
18 | serde = "1.0.163"
19 | serde_json = "1.0.91"
20 | swc_core = { version = "0.103.1", default-features = false }
21 |
--------------------------------------------------------------------------------
/crates/plugin_react_utils/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "swc_plugin_react_utils"
4 | version = "0.1.0"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | swc_core = { workspace = true, features = [
10 | "cached",
11 | "common",
12 | "ecma_ast",
13 | "ecma_visit",
14 | "ecma_quote",
15 | ] }
16 | swc_plugins_utils = { path = "../swc_plugins_utils" }
17 | serde = { workspace = true }
18 | rustc-hash = { workspace = true }
19 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/not-allowed-element/output.js:
--------------------------------------------------------------------------------
1 | // This is the same as the basic test, but 'FormattedMessage' is *not* one of the
2 | // allowed tags so it should not be hoisted.
3 | var Foo = React.createClass({
4 | render: function() {
5 | return ;
8 | }
9 | });
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_ssr_loader_id/useCreateContainer/expected.js:
--------------------------------------------------------------------------------
1 | import { createContainer as useContainer } from "@modern123-js/runtime";
2 | useContainer({
3 | loader: function() {
4 | var innerLoader = foo2;
5 | innerLoader.id = "d7919ac9a4465387c91457f8c62ccb7d_0";
6 | return innerLoader;
7 | }(),
8 | staticLoader: function() {
9 | var innerLoader = bar2;
10 | innerLoader.id = "d7919ac9a4465387c91457f8c62ccb7d_1";
11 | return innerLoader;
12 | }()
13 | });
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/issue-10879-babel-7/output.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | import React from 'react';
4 |
5 | const namespace = {
6 | MyComponent: (props)=>{
7 | return props.name;
8 | }
9 | };
10 | const buildTest = function buildTest(name) {
11 | let _MyComponent;
12 | const { MyComponent } = namespace;
13 | return function () {
14 | return _MyComponent || (_MyComponent = /*#__PURE__*/_react["default"].createElement(MyComponent, {
15 | name: name
16 | }));
17 | };
18 | };
19 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/issue-10879/output.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | var _react = babelHelpers.interopRequireDefault(require("react"));
4 | var _jsxRuntime = require("react/jsx-runtime");
5 | const namespace = {
6 | MyComponent: props => props.name
7 | };
8 | const buildTest = name => {
9 | var _MyComponent;
10 | const {
11 | MyComponent
12 | } = namespace;
13 | return () => _MyComponent || (_MyComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(MyComponent, {
14 | name: name
15 | }));
16 | };
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-extend-component/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | class Foo1 extends Component {
3 | render() {}
4 | }
5 | _define_property(Foo1, "propTypes", process.env.NODE_ENV !== "production" ? {
6 | foo1: PropTypes.string
7 | } : {});
8 | class Foo2 extends Component {
9 | render() {}
10 | }
11 | Foo2.propTypes = process.env.NODE_ENV !== "production" ? {
12 | foo2: PropTypes.string
13 | } : {};
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/shared-prop-type-variable/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { omit } from 'underscore';
3 | import Bar from './bar';
4 | const { PropTypes } = React;
5 | const propTypes = {
6 | foo: PropTypes.any
7 | };
8 | export default function Foo(props) {
9 | const barProps = omit(props, Object.keys(propTypes));
10 | return /*#__PURE__*/ React.createElement(Bar, barProps);
11 | }
12 | Foo.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/scoped-module/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | Object.defineProperty(exports, "default", {
6 | enumerable: true,
7 | get: function() {
8 | return _default;
9 | }
10 | });
11 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12 | var _register = /*#__PURE__*/ _interop_require_default._(require("@storybook/addon-links/register"));
13 | var _default = _register.default;
14 |
--------------------------------------------------------------------------------
/npm/darwin-x64/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-darwin-x64",
3 | "version": "0.0.1",
4 | "os": [
5 | "darwin"
6 | ],
7 | "cpu": [
8 | "x64"
9 | ],
10 | "main": "swc-plugins.darwin-x64.node",
11 | "files": [
12 | "swc-plugins.darwin-x64.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/plugin_config_routes.rs:
--------------------------------------------------------------------------------
1 | use napi_derive::napi;
2 | use swc_plugins_collection::plugin_config_routes::ConfigRoutesConfig;
3 |
4 | use super::IntoRawConfig;
5 |
6 | #[derive(Default)]
7 | #[napi(object)]
8 | pub struct ConfigRoutesConfigNapi {
9 | pub lazy: Option,
10 | }
11 |
12 | impl IntoRawConfig for ConfigRoutesConfigNapi {
13 | fn into_raw_config(self, _: napi::Env) -> napi::Result {
14 | let Self { lazy } = self;
15 |
16 | Ok(ConfigRoutesConfig { lazy })
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-placeholders/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _partial = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/partial"));
7 | var _bind = /*#__PURE__*/ _interop_require_default._(require("lodash/bind"));
8 | (0, _bind.default)(func, _bind.default.placeholder, 1);
9 | (0, _partial.default)(func, _partial.default.placeholder, 1);
10 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_ssr_loader_id/useMemo/expected.js:
--------------------------------------------------------------------------------
1 | import { useLoader } from "@modern-js/runtime";
2 | import { memo } from "react";
3 | var Wrap = memo(function(props) {
4 | useLoader(function() {
5 | var innerLoader = function() {
6 | console.log("wrap");
7 | return Promise.resolve({});
8 | };
9 | innerLoader.id = "6a66e22043a0ad5e33bc19f7345c89db_0";
10 | return innerLoader;
11 | }(), {});
12 | return wrap header{props.children}
;
13 | });
14 | export default Wrap;
15 |
--------------------------------------------------------------------------------
/npm/darwin-arm64/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-darwin-arm64",
3 | "version": "0.0.2",
4 | "os": [
5 | "darwin"
6 | ],
7 | "cpu": [
8 | "arm64"
9 | ],
10 | "main": "swc-plugins.darwin-arm64.node",
11 | "files": [
12 | "swc-plugins.darwin-arm64.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/tag-member-expression/input.mjs:
--------------------------------------------------------------------------------
1 | import Intl from 'react-intl';
2 |
3 | var Foo = React.createClass({
4 | render: function () {
5 | return (
6 |
17 | );
18 | }
19 | });
20 |
21 |
--------------------------------------------------------------------------------
/npm/linux-x64-gnu/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-linux-x64-gnu",
3 | "version": "0.0.1",
4 | "os": [
5 | "linux"
6 | ],
7 | "cpu": [
8 | "x64"
9 | ],
10 | "main": "swc-plugins.linux-x64-gnu.node",
11 | "files": [
12 | "swc-plugins.linux-x64-gnu.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/npm/linux-x64-musl/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-linux-x64-musl",
3 | "version": "0.0.1",
4 | "os": [
5 | "linux"
6 | ],
7 | "cpu": [
8 | "x64"
9 | ],
10 | "main": "swc-plugins.linux-x64-musl.node",
11 | "files": [
12 | "swc-plugins.linux-x64-musl.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/npm/win32-x64-msvc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-win32-x64-msvc",
3 | "version": "0.0.1",
4 | "os": [
5 | "win32"
6 | ],
7 | "cpu": [
8 | "x64"
9 | ],
10 | "main": "swc-plugins.win32-x64-msvc.node",
11 | "files": [
12 | "swc-plugins.win32-x64-msvc.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/basic/input.js:
--------------------------------------------------------------------------------
1 | import FormattedMessage from 'foo'
2 | var Foo = React.createClass({
3 | render: function () {
4 | return (
5 |
16 | );
17 | }
18 | });
19 |
20 |
--------------------------------------------------------------------------------
/crates/swc_plugins_collection/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![feature(let_chains)]
2 |
3 | pub mod pass;
4 | pub mod types;
5 | pub use modularize_imports;
6 | pub use plugin_config_routes;
7 | pub use plugin_lock_corejs_version;
8 | pub use plugin_react_const_elements;
9 | pub use plugin_ssr_loader_id;
10 | pub use styled_components as plugin_styled_components;
11 | pub use styled_jsx as plugin_styled_jsx;
12 | pub use swc_emotion as plugin_emotion;
13 | pub use swc_plugin_import;
14 | pub use swc_plugin_loadable_components;
15 | pub use swc_plugin_lodash;
16 | pub use swc_plugin_react_utils;
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/src/utils.rs:
--------------------------------------------------------------------------------
1 | use colored::Colorize;
2 | use similar::ChangeTag;
3 |
4 | pub fn show_diff(expected: &str, res: &str) {
5 | let diff = similar::TextDiff::from_lines(expected.trim(), res.trim());
6 |
7 | for change in diff.iter_all_changes() {
8 | let sign = match change.tag() {
9 | ChangeTag::Delete => format!("-{}", change.value().red()),
10 | ChangeTag::Insert => format!("+{}", change.value().green()),
11 | ChangeTag::Equal => format!(" {}", change.value()),
12 | };
13 | print!("{sign}");
14 | }
15 | println!();
16 | }
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-inheritance/expected-remove.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | class PureRenderComponent extends Component {
3 |
4 | }
5 |
6 | class Foo1 extends PureRenderComponent {
7 | render() {}
8 |
9 | }
10 |
11 | class Foo2 extends PureRenderComponent {
12 | render() {}
13 |
14 | }
15 |
16 | // With no inheritance
17 | export class Foo3 {
18 | render() {}
19 |
20 | }
21 | _define_property(Foo3, "propTypes", {
22 | foo3: PropTypes.string
23 | });
24 |
--------------------------------------------------------------------------------
/crates/plugin_config_routes/tests/lazyEqualfalse/actual.js:
--------------------------------------------------------------------------------
1 | const a = {
2 | component: "a's name",
3 | };
4 |
5 | const b = {
6 | "component": "b's name",
7 | };
8 |
9 | export default [
10 | {
11 | path: '/',
12 | component: '@/home/Layout',
13 | title: 'home',
14 | routes: [
15 | {
16 | path: '/apple',
17 | component: '@/component/Apple',
18 | title: 'apple',
19 | exact: true,
20 | },
21 | ],
22 | },
23 | {
24 | path: '*',
25 | component: '@/component/404',
26 | title: '404',
27 | },
28 | ];
29 |
--------------------------------------------------------------------------------
/crates/plugin_config_routes/tests/lazyEqualtrue/actual.js:
--------------------------------------------------------------------------------
1 | const a = {
2 | component: "a's name",
3 | };
4 |
5 | const b = {
6 | "component": "b's name",
7 | };
8 |
9 | export default [
10 | {
11 | path: '/',
12 | component: '@/home/Layout',
13 | title: 'home',
14 | routes: [
15 | {
16 | path: '/apple',
17 | component: '@/component/Apple',
18 | title: 'apple',
19 | exact: true,
20 | },
21 | ],
22 | },
23 | {
24 | path: '*',
25 | component: '@/component/404',
26 | title: '404',
27 | },
28 | ];
29 |
--------------------------------------------------------------------------------
/npm/linux-arm64-gnu/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-linux-arm64-gnu",
3 | "version": "0.0.1",
4 | "os": [
5 | "linux"
6 | ],
7 | "cpu": [
8 | "arm64"
9 | ],
10 | "main": "swc-plugins.linux-arm64-gnu.node",
11 | "files": [
12 | "swc-plugins.linux-arm64-gnu.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/npm/linux-arm64-musl/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-linux-arm64-musl",
3 | "version": "0.0.1",
4 | "os": [
5 | "linux"
6 | ],
7 | "cpu": [
8 | "arm64"
9 | ],
10 | "main": "swc-plugins.linux-arm64-musl.node",
11 | "files": [
12 | "swc-plugins.linux-arm64-musl.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/npm/win32-arm64-msvc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-win32-arm64-msvc",
3 | "version": "0.0.1",
4 | "os": [
5 | "win32"
6 | ],
7 | "cpu": [
8 | "arm64"
9 | ],
10 | "main": "swc-plugins.win32-arm64-msvc.node",
11 | "files": [
12 | "swc-plugins.win32-arm64-msvc.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/crates/plugin_config_routes/tests/configEqualUndefined/actual.js:
--------------------------------------------------------------------------------
1 | const a = {
2 | component: "a's name",
3 | };
4 |
5 | const b = {
6 | "component": "b's name",
7 | };
8 |
9 | export default [
10 | {
11 | path: '/',
12 | component: '@/home/Layout',
13 | title: 'home',
14 | routes: [
15 | {
16 | path: '/apple',
17 | component: '@/component/Apple',
18 | title: 'apple',
19 | exact: true,
20 | },
21 | ],
22 | },
23 | {
24 | path: '*',
25 | component: '@/component/404',
26 | title: '404',
27 | },
28 | ];
29 |
--------------------------------------------------------------------------------
/crates/plugin_config_routes/tests/lazyEqualUndefined/actual.js:
--------------------------------------------------------------------------------
1 | const a = {
2 | component: "a's name",
3 | };
4 |
5 | const b = {
6 | "component": "b's name",
7 | };
8 |
9 | export default [
10 | {
11 | path: '/',
12 | component: '@/home/Layout',
13 | title: 'home',
14 | routes: [
15 | {
16 | path: '/apple',
17 | component: '@/component/Apple',
18 | title: 'apple',
19 | exact: true,
20 | },
21 | ],
22 | },
23 | {
24 | path: '*',
25 | component: '@/component/404',
26 | title: '404',
27 | },
28 | ];
29 |
--------------------------------------------------------------------------------
/npm/linux-arm-gnueabihf/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugins-linux-arm-gnueabihf",
3 | "version": "0.0.1",
4 | "os": [
5 | "linux"
6 | ],
7 | "cpu": [
8 | "arm"
9 | ],
10 | "main": "swc-plugins.linux-arm-gnueabihf.node",
11 | "files": [
12 | "swc-plugins.linux-arm-gnueabihf.node"
13 | ],
14 | "description": "",
15 | "keywords": [],
16 | "author": "",
17 | "license": "MIT",
18 | "engines": {
19 | "node": ">=14.12"
20 | },
21 | "publishConfig": {
22 | "registry": "https://registry.npmjs.org",
23 | "access": "public"
24 | }
25 | }
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/class-assign-unreferenced-param-deopt/input.mjs:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | // Regression test for https://github.com/babel/babel/issues/5552
4 | class BugReport extends React.Component {
5 | thisWontWork = ({ color }) => (data) => {
6 | return does not reference data
;
7 | };
8 |
9 | thisWorks = ({ color }) => (data) => {
10 | return { data }
;
11 | };
12 |
13 | render() {
14 | return
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/plugin_lock_corejs_version.rs:
--------------------------------------------------------------------------------
1 | use napi_derive::napi;
2 | use swc_plugins_collection::plugin_lock_corejs_version::LockCoreJsVersion;
3 |
4 | use super::IntoRawConfig;
5 |
6 | #[napi(object)]
7 | pub struct LockCoreJsVersionNapi {
8 | pub corejs: String,
9 | pub swc_helpers: String,
10 | }
11 |
12 | impl IntoRawConfig for LockCoreJsVersionNapi {
13 | fn into_raw_config(self, _env: napi::Env) -> napi::Result {
14 | Ok(LockCoreJsVersion {
15 | corejs: self.corejs,
16 | swc_helpers: self.swc_helpers,
17 | })
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/additional-libraries-regexp/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | class Greeting extends Component {
3 | render() {
4 | return /*#__PURE__*/ React.createElement("h1", null, "Welcome ", this.props.name, " and ", this.props.friends.join(', '), " to ", this.state.appName);
5 | }
6 | constructor(props, context){
7 | super(props, context);
8 | const appName = context.store.getState().appName;
9 | this.state = {
10 | appName: appName
11 | };
12 | }
13 | }
14 | export { Greeting as default };
--------------------------------------------------------------------------------
/crates/plugin_lodash/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "swc_plugin_lodash"
4 | version = "0.1.0"
5 |
6 | [dependencies]
7 | nodejs-resolver = "0.0.86"
8 | serde = { workspace = true }
9 | serde_json = { workspace = true }
10 | rustc-hash = { workspace = true }
11 | dashmap = { workspace = true }
12 | anyhow = { workspace = true }
13 | swc_core = { workspace = true, features = [
14 | "common",
15 | "ecma_ast",
16 | "ecma_visit",
17 | "ecma_quote",
18 | "ecma_utils",
19 | ] }
20 | swc_plugins_utils = { path = "../swc_plugins_utils" }
21 |
22 | [lib]
23 | crate-type = ["cdylib", "rlib"]
24 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-convert/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
7 | var _filter = /*#__PURE__*/ _interop_require_default._(require("lodash/filter"));
8 | var _convert = /*#__PURE__*/ _interop_require_default._(require("lodash-fp/convert"));
9 | var fp = (0, _convert.default)({
10 | filter: _filter.default,
11 | map: _map.default
12 | });
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/additional-libraries/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | class Greeting extends Component {
3 | render() {
4 | return /*#__PURE__*/ React.createElement("h1", null, "Welcome ", this.props.name, " and ", this.props.friends.join(', '), " to ", this.state.appName);
5 | }
6 |
7 | constructor(props, context){
8 | super(props, context);
9 | const appName = context.store.getState().appName;
10 | this.state = {
11 | appName: appName
12 | };
13 | }
14 | }
15 |
16 | export { Greeting as default };
--------------------------------------------------------------------------------
/.github/workflows/publish-crate.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request: null
8 |
9 | jobs:
10 | publish:
11 | if: "startsWith(github.event.head_commit.message, 'chore(release): publish-crate')"
12 | name: Publish
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v3
16 | - uses: actions-rs/toolchain@v1
17 | with:
18 | profile: default
19 | - name: publish
20 | env:
21 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
22 | run: cargo publish -p swc_plugin_import
23 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-inheritance/actual.js:
--------------------------------------------------------------------------------
1 | class PureRenderComponent extends Component {
2 | }
3 |
4 | class Foo1 extends PureRenderComponent {
5 | static propTypes = {
6 | foo1: PropTypes.string.isRequired,
7 | };
8 | render() {}
9 | }
10 |
11 | class Foo2 extends PureRenderComponent {
12 | render() {}
13 | }
14 |
15 | Foo2.propTypes = {
16 | foo2: PropTypes.string.isRequired,
17 | };
18 |
19 | // With no inheritance
20 | export class Foo3 {
21 | static propTypes = {
22 | foo3: PropTypes.string,
23 | };
24 |
25 | render() {}
26 | }
27 |
--------------------------------------------------------------------------------
/crates/integration_tests/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "integration_tests"
4 | version = "0.1.0"
5 |
6 | [dependencies]
7 | colored = "2.0.0"
8 | serde = { workspace = true }
9 | serde_json = { workspace = true }
10 | similar = "2.1.0"
11 | swc_core = { workspace = true, features = [
12 | "common",
13 | "ecma_ast",
14 | "ecma_visit",
15 | "ecma_transforms",
16 | "testing_transform",
17 | ] }
18 | swc_plugins_core = { path = "../swc_plugins_core", features = ["plugin"] }
19 | swc_plugins_collection = { path = "../swc_plugins_collection" }
20 | swc_plugins_utils = { path = "../swc_plugins_utils" }
21 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/es-class-assign-property-variable/expected-wrap.js:
--------------------------------------------------------------------------------
1 | const propTypes = process.env.NODE_ENV !== "production" ? {
2 | foo: PropTypes.string
3 | } : {};
4 |
5 | class Foo extends React.Component {
6 | render() {}
7 |
8 | }
9 |
10 | Foo.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
11 |
12 | class Getter extends React.Component {
13 | get foo() {
14 | return {
15 | foo: PropTypes.string
16 | };
17 | }
18 |
19 | render() {}
20 |
21 | }
22 |
23 | Getter.propTypes = process.env.NODE_ENV !== "production" ? Getter.foo : {};
24 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/unsafe-wrap/expected-unsafe-wrap.js:
--------------------------------------------------------------------------------
1 | class Foo1 extends React.Component {
2 | render() {}
3 | }
4 | process.env.NODE_ENV !== "production" ? Foo1.propTypes = {
5 | bar1: PropTypes.string
6 | } : void 0;
7 | class Foo2 extends React.Component {
8 | render() {}
9 | }
10 | process.env.NODE_ENV !== "production" ? Foo2.propTypes = {
11 | bar2: PropTypes.string
12 | } : void 0;
13 | const Foo3 = ()=>/*#__PURE__*/ React.createElement("div", null);
14 | process.env.NODE_ENV !== "production" ? Foo3.propTypes = {
15 | bar3: PropTypes.string
16 | } : void 0;
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-repeat-identifiers/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/noop"));
7 | var array = [
8 | void 0,
9 | void 0,
10 | _noop.default,
11 | _noop.default,
12 | _noop.default,
13 | _noop.default
14 | ];
15 | (0, _noop.default)(_noop.default.placeholder, _noop.default.placeholder, _noop.default, _noop.default, _noop.default, _noop.default);
16 |
--------------------------------------------------------------------------------
/crates/plugin_config_routes/tests/configEqualUndefined/expected.js:
--------------------------------------------------------------------------------
1 | var a = {
2 | component: "a's name"
3 | };
4 | var b = {
5 | "component": "b's name"
6 | };
7 | export default [
8 | {
9 | path: "/",
10 | component: "@/home/Layout",
11 | title: "home",
12 | routes: [
13 | {
14 | path: "/apple",
15 | component: "@/component/Apple",
16 | title: "apple",
17 | exact: true
18 | }
19 | ]
20 | },
21 | {
22 | path: "*",
23 | component: "@/component/404",
24 | title: "404"
25 | }
26 | ];
27 |
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/plugin_styled_components.rs:
--------------------------------------------------------------------------------
1 | use napi::Status;
2 |
3 | use super::IntoRawConfig;
4 |
5 | pub type StyledComponentsConfigNapi = String;
6 |
7 | impl IntoRawConfig
8 | for StyledComponentsConfigNapi
9 | {
10 | fn into_raw_config(
11 | self,
12 | _env: napi::Env,
13 | ) -> napi::Result {
14 | serde_json::from_str(&self).map_err(|_| {
15 | napi::Error::new::(
16 | Status::InvalidArg,
17 | "invalid styled components options".into(),
18 | )
19 | })
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/magical-bindings/output.js:
--------------------------------------------------------------------------------
1 | function thisExpr() {
2 | return {this.Foo}
;
3 | }
4 | function thisJSX() {
5 | return <_this.Foo/>;
6 | }
7 | class A extends B {
8 | superExpr() {
9 | return {super.Foo}
;
10 | }
11 | superJSX() {
12 | return <_super.Foo/>;
13 | }
14 | }
15 | function argumentsExpr() {
16 | return {arguments.Foo}
;
17 | }
18 | function argumentsJSX() {
19 | return ;
20 | }
21 | function newTargetExpr() {
22 | return {new.target.Foo}
;
23 | }
24 | function newTargetJSX() {
25 | return <_new.target.Foo/>;
26 | }
27 |
--------------------------------------------------------------------------------
/packages/react-const-elements/src/lib.rs:
--------------------------------------------------------------------------------
1 | use swc_core::{
2 | ecma::{ast::Program, visit::VisitMutWith},
3 | plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
4 | };
5 |
6 | #[plugin_transform]
7 | fn transform(mut program: Program, meta: TransformPluginProgramMetadata) -> Program {
8 | let config = meta.get_transform_plugin_config();
9 |
10 | let config = config
11 | .map(|raw| serde_json::from_str(&raw).expect("Failed to parse config of react-const-elements"))
12 | .unwrap_or_default();
13 |
14 | let mut v = plugin_react_const_elements::react_const_elements(config);
15 |
16 | program.visit_mut_with(&mut v);
17 |
18 | program
19 | }
20 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/allowMutablePropsOnTags/not-allowed-element/input.js:
--------------------------------------------------------------------------------
1 | // This is the same as the basic test, but 'FormattedMessage' is *not* one of the
2 | // allowed tags so it should not be hoisted.
3 | var Foo = React.createClass({
4 | render: function () {
5 | return (
6 |
17 | );
18 | }
19 | });
20 |
21 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/class-assign-unreferenced-param-deopt/output.mjs:
--------------------------------------------------------------------------------
1 | let _div;
2 | import React from 'react';
3 |
4 | // Regression test for https://github.com/babel/babel/issues/5552
5 | class BugReport extends React.Component {
6 | thisWontWork = ({ color })=>{
7 | let _div2;
8 | return (data)=>{
9 | return _div2 || (_div2 = does not reference data
);
10 | };
11 | };
12 | thisWorks = ({ color })=>{
13 | return (data)=>{
14 | return {data}
;
15 | };
16 | };
17 | render() {
18 | return _div || (_div = );
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/regression-14363-2/output.mjs:
--------------------------------------------------------------------------------
1 | import { Routes, Route } from "react-router";
2 | import { router } from "common/router";
3 | function RoutesComponent() {
4 | return
5 | {Object.keys(router).map((routerKey)=>{
6 | const route = router[routerKey];
7 | if (route && route.element) {
8 | const { path, element: Component } = route;
9 | // Component should not be hoisted
10 | return }/>;
11 | } else {
12 | return null;
13 | }
14 | }).filter(Boolean)}
15 | ;
16 | }
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/magical-bindings/input.js:
--------------------------------------------------------------------------------
1 | function thisExpr() {
2 | return {this.Foo}
;
3 | }
4 | function thisJSX() {
5 | return ;
6 | }
7 |
8 | class A extends B {
9 | superExpr() {
10 | return {super.Foo}
;
11 | }
12 | superJSX() {
13 | return ;
14 | }
15 | }
16 |
17 | function argumentsExpr() {
18 | return {arguments.Foo}
;
19 | }
20 | function argumentsJSX() {
21 | return ;
22 | }
23 |
24 | function newTargetExpr() {
25 | return {new.target.Foo}
;
26 | }
27 | function newTargetJSX() {
28 | return ;
29 | }
30 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/dont-remove-used-import/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | class Greeting extends Component {
5 | render() {
6 | return /*#__PURE__*/ React.createElement("h1", null, "Welcome ", this.props.name, " to ", this.state.appName);
7 | }
8 | constructor(props, context){
9 | super(props, context);
10 | const appName = context.store.getState().appName;
11 | this.state = {
12 | appName: appName
13 | };
14 | }
15 | }
16 |
17 | export { Greeting as default };
18 | Greeting.contextTypes = {
19 | store: PropTypes.object
20 | };
--------------------------------------------------------------------------------
/packages/plugin-import/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-plugin-import",
3 | "version": "0.6.11",
4 | "author": "jserfeng",
5 | "description": "swc port of babel-plugin-import",
6 | "license": "MIT",
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/web-infra-dev/swc-plugins",
10 | "directory": "packages/plugin-import"
11 | },
12 | "main": "./swc_plugin_import_wasm.wasm",
13 | "scripts": {
14 | "wasm": "cargo build --target wasm32-wasi --release && cp ../target/wasm32-wasi/release/swc_plugin_import.wasm ."
15 | },
16 | "publishConfig": {
17 | "access": "public"
18 | },
19 | "files": [
20 | "*.wasm"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-arguments/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/map"));
7 | var _head = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/head"));
8 | var _compose = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/compose"));
9 | var _capitalize = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/capitalize"));
10 | (0, _compose.default)((0, _map.default)(_capitalize.default), _head.default)([]);
11 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/dont-remove-used-import/actual.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import PropTypes from 'prop-types'
3 |
4 | export default class Greeting extends Component {
5 | constructor (props, context) {
6 | super(props, context)
7 | const appName = context.store.getState().appName
8 | this.state = {
9 | appName: appName
10 | }
11 | }
12 |
13 | render () {
14 | return Welcome {this.props.name} to {this.state.appName}
;
15 | }
16 | }
17 |
18 | Greeting.propTypes = {
19 | name: PropTypes.string.isRequired
20 | }
21 |
22 | Greeting.contextTypes = {
23 | store: PropTypes.object
24 | }
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-static-property/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | var _React_Component;
3 | class Foo1 extends (_React_Component = React.Component) {
4 | render() {}
5 | }
6 | _define_property(Foo1, "propTypes", process.env.NODE_ENV !== "production" ? {
7 | bar1: PropTypes.string
8 | } : {});
9 | var _React_Component1;
10 | class Foo2 extends (_React_Component1 = React.Component) {
11 | render() {}
12 | }
13 | _define_property(Foo2, "propTypes", process.env.NODE_ENV !== "production" ? {
14 | bar2: PropTypes.string
15 | } : {});
16 | export { Foo2 as default };
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-spread-operator/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _to_consumable_array = require("@swc/helpers/_/_to_consumable_array");
7 | var _merge = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/merge"));
8 | var _merge1 = /*#__PURE__*/ _interop_require_default._(require("lodash/merge"));
9 | _merge1.default.apply(void 0, [
10 | {}
11 | ].concat(_to_consumable_array._(args)));
12 | _merge.default.apply(void 0, [
13 | {}
14 | ].concat(_to_consumable_array._(args)));
15 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-expression-default/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/noop"));
7 | var _filter = /*#__PURE__*/ _interop_require_default._(require("lodash/filter"));
8 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
9 | var _identity = /*#__PURE__*/ _interop_require_default._(require("lodash/identity"));
10 | _identity.default || _noop.default;
11 | _noop.default ? _map.default : _filter.default;
12 | _noop.default;
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-expression-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/noop"));
7 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
8 | var _identity = /*#__PURE__*/ _interop_require_default._(require("lodash/identity"));
9 | var _filter = /*#__PURE__*/ _interop_require_default._(require("lodash/filter"));
10 | _identity.default || _noop.default;
11 | _noop.default ? _map.default : _filter.default;
12 | _noop.default;
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/es-expression-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash-es/noop"));
7 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash-es/map"));
8 | var _identity = /*#__PURE__*/ _interop_require_default._(require("lodash-es/identity"));
9 | var _filter = /*#__PURE__*/ _interop_require_default._(require("lodash-es/filter"));
10 | _identity.default || _noop.default;
11 | _noop.default ? _map.default : _filter.default;
12 | _noop.default;
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-expression-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/noop"));
7 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/map"));
8 | var _identity = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/identity"));
9 | var _filter = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/filter"));
10 | _identity.default || _noop.default;
11 | _noop.default ? _map.default : _filter.default;
12 | _noop.default;
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-expression-default/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _noop = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/noop"));
7 | var _filter = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/filter"));
8 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/map"));
9 | var _identity = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/identity"));
10 | _identity.default || _noop.default;
11 | _noop.default ? _map.default : _filter.default;
12 | _noop.default;
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/fixtures/constant-elements/regression-14363-2/input.mjs:
--------------------------------------------------------------------------------
1 | import { Routes, Route } from "react-router";
2 | import { router } from "common/router";
3 |
4 | function RoutesComponent() {
5 | return
6 | {Object.keys(router).map(routerKey => {
7 | const route = router[routerKey];
8 |
9 | if (route && route.element) {
10 | const {
11 | path,
12 | element: Component
13 | } = route;
14 | // Component should not be hoisted
15 | return }/>;
16 | } else {
17 | return null;
18 | }
19 | }).filter(Boolean)}
20 | ;
21 | }
22 |
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/config.rs:
--------------------------------------------------------------------------------
1 | use napi_derive::napi;
2 | use swc_plugins_collection::types::TransformConfig;
3 |
4 | use super::{extensions::ExtensionsNapi, IntoRawConfig};
5 |
6 | #[napi(object)]
7 | pub struct TransformConfigNapi {
8 | /// Raw swc options
9 | pub swc: String,
10 |
11 | /// Internal rust-swc Plugins
12 | pub extensions: ExtensionsNapi,
13 | }
14 |
15 | impl IntoRawConfig for TransformConfigNapi {
16 | fn into_raw_config(self, env: napi::Env) -> napi::Result {
17 | let Self { swc, extensions } = self;
18 |
19 | Ok(TransformConfig {
20 | swc: serde_json::from_str(&swc).unwrap(),
21 | extensions: extensions.into_raw_config(env)?,
22 | })
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-basic-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/take"));
7 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/reject"));
8 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
9 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/add"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-basic-default/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/reject"));
7 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/take"));
8 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/add"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/map"));
10 | var mapper = (0, _map.default)((0, _add.default)(1));
11 | var result = mapper([]);
12 | (0, _take.default)(1, (0, _reject.default)(Boolean, result));
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-basic-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/take"));
7 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/reject"));
8 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/map"));
9 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/add"));
10 | var mapper = (0, _map.default)((0, _add.default)(1));
11 | var result = mapper([]);
12 | (0, _take.default)(1, (0, _reject.default)(Boolean, result));
13 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-basic-default/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/reject"));
7 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/take"));
8 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/add"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-basic-namespace/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/reject"));
7 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/take"));
8 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/add"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/plugin_lodash.rs:
--------------------------------------------------------------------------------
1 | use std::{env::current_dir, path::PathBuf};
2 |
3 | use napi_derive::napi;
4 | use swc_plugins_collection::swc_plugin_lodash::PluginLodashConfig;
5 |
6 | use super::IntoRawConfig;
7 |
8 | #[napi(object)]
9 | pub struct PluginLodashConfigNapi {
10 | pub cwd: Option,
11 | pub ids: Option>,
12 | }
13 |
14 | impl IntoRawConfig for PluginLodashConfigNapi {
15 | fn into_raw_config(self, _env: napi::Env) -> napi::Result {
16 | Ok(PluginLodashConfig {
17 | cwd: self
18 | .cwd
19 | .map(PathBuf::from)
20 | .unwrap_or_else(|| current_dir().unwrap()),
21 | ids: self.ids.unwrap_or_default(),
22 | })
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/es-basic-default/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash-es/reject"));
7 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash-es/take"));
8 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash-es/add"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash-es/map"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/es-basic-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash-es/take"));
7 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash-es/reject"));
8 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash-es/map"));
9 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash-es/add"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-default-and-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/reject"));
7 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/add"));
8 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/take"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/map"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/mixed-fixtures/object-rest-spread/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _object_spread = require("@swc/helpers/_/_object_spread");
7 | var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
8 | var _keys = /*#__PURE__*/ _interop_require_default._(require("lodash/keys"));
9 | var o1 = {
10 | "a": 1
11 | };
12 | var o2 = {
13 | "b": 2,
14 | "c": 3
15 | };
16 | var o3 = _object_spread._({}, o1, o2);
17 | var foo = o3.b, bar = _object_without_properties._(o3, [
18 | "b"
19 | ]);
20 | (0, _keys.default)(bar);
21 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/es-default-and-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash-es/reject"));
7 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash-es/add"));
8 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash-es/take"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash-es/map"));
10 | var result = (0, _map.default)([], function(n) {
11 | return (0, _add.default)(1, n);
12 | });
13 | (0, _take.default)((0, _reject.default)(result), 1);
14 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_const_elements/deopt/issue-7610/output.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | exports.default = void 0;
7 | var _Parent = babelHelpers.interopRequireDefault(require("./Parent"));
8 | var _Child2 = babelHelpers.interopRequireDefault(require("./Child"));
9 | var _jsxRuntime = require("react/jsx-runtime");
10 | function MyComponent({
11 | closeFn
12 | }) {
13 | var _Child;
14 | return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Parent.default, {
15 | render: () => _Child || (_Child = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Child2.default, {
16 | closeFn: closeFn
17 | }))
18 | });
19 | }
20 | var _default = _Parent.default;
21 | exports.default = _default;
22 |
--------------------------------------------------------------------------------
/packages/react-const-elements/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@modern-js/swc-react-const-elements-plugin",
3 | "version": "0.6.11",
4 | "author": "jserfeng",
5 | "description": "swc port of @babel/plugin-transform-react-constant-elements",
6 | "license": "MIT",
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/web-infra-dev/swc-plugins",
10 | "directory": "packages/react-const-elements"
11 | },
12 | "main": "./swc_plugin_react_const_elements.wasm",
13 | "scripts": {
14 | "wasm": "cargo build --target wasm32-wasi --release && cp ../target/wasm32-wasi/release/swc_plugin_react_const_elements.wasm ."
15 | },
16 | "publishConfig": {
17 | "access": "public"
18 | },
19 | "files": [
20 | "*.wasm"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/additional-libraries-regexp/actual.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import PropTypes from 'prop-types'
3 | import CustomPropTypes from './custom-prop-types'
4 |
5 | export default class Greeting extends Component {
6 | constructor (props, context) {
7 | super(props, context)
8 | const appName = context.store.getState().appName
9 | this.state = {
10 | appName: appName
11 | }
12 | }
13 |
14 | render () {
15 | return Welcome {this.props.name} and {this.props.friends.join(', ')} to {this.state.appName}
;
16 | }
17 | }
18 |
19 | Greeting.propTypes = {
20 | name: PropTypes.string.isRequired,
21 | friends: CustomPropTypes.customValidator
22 | }
23 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/variable-assignment/expected-remove.js:
--------------------------------------------------------------------------------
1 | const FooBasic = ()=>/*#__PURE__*/ React.createElement("div", null);
2 |
3 | const FooExtraReference = ()=>/*#__PURE__*/ React.createElement("div", null);
4 |
5 | const FooExtraReferenceSpread = ()=>/*#__PURE__*/ React.createElement("div", null);
6 |
7 | const FooWrapped = ()=>/*#__PURE__*/ React.createElement("div", null);
8 |
9 | const propTypesReferenced = {
10 | foo: PropTypes.string
11 | };
12 |
13 | const FooReferenced = ()=>/*#__PURE__*/ React.createElement("div", {
14 | bar: propTypesReferenced
15 | });
16 |
17 | export const propTypesExported = {
18 | foo: PropTypes.string
19 | };
20 |
21 | const FooExported = ()=>/*#__PURE__*/ React.createElement("div", null);
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/additional-libraries/actual.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import PropTypes from 'prop-types'
3 | import ImmutablePropTypes from 'react-immutable-proptypes'
4 |
5 | export default class Greeting extends Component {
6 | constructor (props, context) {
7 | super(props, context)
8 | const appName = context.store.getState().appName
9 | this.state = {
10 | appName: appName
11 | }
12 | }
13 |
14 | render () {
15 | return Welcome {this.props.name} and {this.props.friends.join(', ')} to {this.state.appName}
;
16 | }
17 | }
18 |
19 | Greeting.propTypes = {
20 | name: PropTypes.string.isRequired,
21 | friends: ImmutablePropTypes.list.isRequired,
22 | }
23 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-default-and-member/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6 | var _reject = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/reject"));
7 | var _add = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/add"));
8 | var _take = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/take"));
9 | var _map = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/map"));
10 | var mapper = (0, _map.default)((0, _add.default)(1));
11 | var result = mapper([
12 | 1,
13 | 2,
14 | 3
15 | ]);
16 | (0, _take.default)(1, (0, _reject.default)(Boolean, result));
17 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/es-class-inheritance/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import { _ as _define_property } from "@swc/helpers/_/_define_property";
2 | class PureRenderComponent extends Component {
3 | }
4 | class Foo1 extends PureRenderComponent {
5 | render() {}
6 | }
7 | _define_property(Foo1, "propTypes", process.env.NODE_ENV !== "production" ? {
8 | foo1: PropTypes.string.isRequired
9 | } : {});
10 | class Foo2 extends PureRenderComponent {
11 | render() {}
12 | }
13 | Foo2.propTypes = process.env.NODE_ENV !== "production" ? {
14 | foo2: PropTypes.string.isRequired
15 | } : {};
16 | // With no inheritance
17 | export class Foo3 {
18 | render() {}
19 | }
20 | _define_property(Foo3, "propTypes", {
21 | foo3: PropTypes.string
22 | });
23 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/recursive/expected-remove.js:
--------------------------------------------------------------------------------
1 | import { cloneElement } from 'react';
2 |
3 | export default function Composer(props) {
4 | return renderRecursive(props.children, props.components);
5 | }
6 |
7 | function renderRecursive(render, remaining, results) {
8 | results = results || [];
9 |
10 | if (!remaining[0]) {
11 | return render(results);
12 | }
13 |
14 | function nextRender(value) {
15 | return renderRecursive(render, remaining.slice(1), results.concat([
16 | value
17 | ]));
18 | }
19 |
20 | return typeof remaining[0] === 'function' ? remaining[0]({
21 | results,
22 | render: nextRender
23 | }) : /*#__PURE__*/ cloneElement(remaining[0], {
24 | children: nextRender
25 | });
26 | }
27 |
--------------------------------------------------------------------------------
/packages/Cargo.toml:
--------------------------------------------------------------------------------
1 | # We use different scopes is because that swc_core has 2 mutual features
2 | # that plugin-rt and plugin-mode cannot enable at the same time
3 | # If we make plugins and core at the same workspace, cargo check --workspace will fail
4 |
5 | cargo-features = ["strip"]
6 |
7 | [workspace]
8 | members = ["plugin-import", "react-const-elements"]
9 | resolver = "2"
10 |
11 | [profile.release]
12 | strip = "symbols"
13 |
14 | # Enable following optimization on CI, based on env variable
15 | # lto = true
16 | # codegen-units = 1
17 |
18 | [workspace.dependencies]
19 | rustc-hash = { version = "1.1.0" }
20 | anyhow = { version = "1.0.69" }
21 | dashmap = { version = "6.0.1" }
22 | serde = "1.0.163"
23 | serde_json = "1.0.91"
24 | swc_core = { version = "0.103.1", default-features = false }
25 |
--------------------------------------------------------------------------------
/crates/swc_plugins_core/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "swc_plugins_core"
4 | version = "0.1.0"
5 |
6 | [features]
7 | plugin = [
8 | "swc_core/plugin_transform_host_native_filesystem_cache",
9 | "swc_core/plugin_transform_host_native",
10 | ]
11 |
12 | [dependencies]
13 | anyhow = { workspace = true }
14 | swc_core = { workspace = true, features = [
15 | "base",
16 | "common_concurrent",
17 | "css_ast",
18 | "css_codegen",
19 | "css_minifier",
20 | "css_parser",
21 | "ecma_ast",
22 | "ecma_visit",
23 | "ecma_transforms",
24 | "ecma_parser",
25 | "ecma_minifier_concurrent",
26 | ] }
27 | swc_plugins_utils = { path = "../swc_plugins_utils" }
28 | serde_json = { workspace = true }
29 | serde = { workspace = true }
30 | regex = "1.6.0"
31 |
32 | [dev-dependencies]
33 | insta = "1.18.2"
34 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/unimplemented/const-in-anonymous-validator/expected-wrap.js:
--------------------------------------------------------------------------------
1 | import React, { PropTypes } from 'react';
2 |
3 | const Component = () => ;
4 |
5 | const referencedPropTypes = process.env.NODE_ENV !== "production" ? {
6 | variant3: ()=>{
7 | const willBeWrapped = 1;
8 | return null;
9 | }
10 | } : {};
11 | Component.propTypes = process.env.NODE_ENV !== "production" ? babelHelpers.objectSpread({
12 | variant1: props => {
13 | const variants = [null];
14 | return variantſ[0];
15 | },
16 | variant2: chainPropTypes(PropTypes.oneOf(['foo']), props => {
17 | const deprecatedVariants = ['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading'];
18 | return null;
19 | })
20 | }, referencedPropTypes) : {};
21 | export default Component;
22 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/stateless-force-removal/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { PropTypes } from 'react';
2 | var Message = ({ isFetching, isSuccess, isFailure, errorMsg })=>{
3 | let messageType;
4 | let messageTxt;
5 | if (isFetching) {
6 | messageType = 'warning';
7 | messageTxt = 'Pending call...';
8 | } else if (isSuccess) {
9 | messageType = 'success';
10 | messageTxt = 'Repo pushed successfully';
11 | } else if (isFailure) {
12 | messageType = 'danger';
13 | messageTxt = 'Something wrong occured';
14 | }
15 | if (messageTxt === null) {
16 | return;
17 | }
18 | return /*#__PURE__*/ React.createElement("div", {
19 | className: 'alert alert-' + messageType,
20 | role: "alert"
21 | }, messageTxt);
22 | };
23 | export default Message;
24 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/lodash-property-values/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | Object.defineProperty(exports, "formatters", {
6 | enumerable: true,
7 | get: function() {
8 | return formatters;
9 | }
10 | });
11 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12 | var _snakeCase = /*#__PURE__*/ _interop_require_default._(require("lodash/snakeCase"));
13 | var _kebabCase = /*#__PURE__*/ _interop_require_default._(require("lodash/kebabCase"));
14 | var _camelCase = /*#__PURE__*/ _interop_require_default._(require("lodash/camelCase"));
15 | var formatters = {
16 | camelCase: _camelCase.default,
17 | "kebabCase": _kebabCase.default,
18 | "snakeCase": _snakeCase.default
19 | };
20 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/es-property-values/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | Object.defineProperty(exports, "formatters", {
6 | enumerable: true,
7 | get: function() {
8 | return formatters;
9 | }
10 | });
11 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12 | var _snakeCase = /*#__PURE__*/ _interop_require_default._(require("lodash-es/snakeCase"));
13 | var _kebabCase = /*#__PURE__*/ _interop_require_default._(require("lodash-es/kebabCase"));
14 | var _camelCase = /*#__PURE__*/ _interop_require_default._(require("lodash-es/camelCase"));
15 | var formatters = {
16 | camelCase: _camelCase.default,
17 | "kebabCase": _kebabCase.default,
18 | "snakeCase": _snakeCase.default
19 | };
20 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lodash/fixtures/fixtures/fp-property-values/expected.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", {
3 | value: true
4 | });
5 | Object.defineProperty(exports, "formatters", {
6 | enumerable: true,
7 | get: function() {
8 | return formatters;
9 | }
10 | });
11 | var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12 | var _snakeCase = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/snakeCase"));
13 | var _kebabCase = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/kebabCase"));
14 | var _camelCase = /*#__PURE__*/ _interop_require_default._(require("lodash/fp/camelCase"));
15 | var formatters = {
16 | camelCase: _camelCase.default,
17 | "kebabCase": _kebabCase.default,
18 | "snakeCase": _snakeCase.default
19 | };
20 |
--------------------------------------------------------------------------------
/.cargo/config.toml:
--------------------------------------------------------------------------------
1 | [alias]
2 | lint = "clippy --workspace --all-targets --verbose -- --deny warnings"
3 | # AKA `test-update`, handy cargo rst update without install `cargo-rst` binary
4 |
5 | [target.x86_64-apple-darwin]
6 | rustflags = [
7 | "-C", "link-arg=-undefined",
8 | "-C", "link-arg=dynamic_lookup",
9 | ]
10 | [target.aarch64-unknown-linux-gnu]
11 | linker = "aarch64-linux-gnu-gcc"
12 | [target.aarch64-unknown-linux-musl]
13 | linker = "aarch64-linux-musl-gcc"
14 | rustflags = ["-C", "target-feature=-crt-static"]
15 | [target.aarch64-apple-darwin]
16 | rustflags = [
17 | "-C", "link-arg=-undefined",
18 | "-C", "link-arg=dynamic_lookup",
19 | ]
20 |
21 | [target.armv7-unknown-linux-gnueabihf]
22 | linker = "arm-linux-gnueabihf-gcc"
23 |
24 | [target.x86_64-unknown-linux-musl]
25 | rustflags = [
26 | "-C",
27 | "target-feature=-crt-static",
28 | ]
29 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_import/main.rs:
--------------------------------------------------------------------------------
1 | use swc_core::ecma::parser::Syntax;
2 | use swc_plugins_collection::swc_plugin_import::{plugin_import, PluginImportConfig};
3 |
4 | #[test]
5 | fn import_test() {
6 | let config = vec![PluginImportConfig {
7 | library_name: "foo".into(),
8 | library_directory: None,
9 | custom_name: None,
10 | custom_style_name: None,
11 | style: None,
12 | camel_to_dash_component_name: None,
13 | transform_to_default_import: None,
14 | ignore_es_component: None,
15 | ignore_style_component: None,
16 | }];
17 |
18 | integration_tests::testing::test_transform(
19 | Syntax::Es(Default::default()),
20 | |_| plugin_import(&config),
21 | "import {Button} from 'foo';console.log(Button)",
22 | "import Button from \"foo/lib/button\";console.log(Button);",
23 | true,
24 | );
25 | }
26 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_react_utils/fixtures/remove_prop_types/stateless-return-undefined/expected-remove.js:
--------------------------------------------------------------------------------
1 | import React, { PropTypes } from 'react';
2 |
3 | var Message = ({ isFetching, isSuccess, isFailure, errorMsg })=>{
4 | let messageType;
5 | let messageTxt;
6 |
7 | if (isFetching) {
8 | messageType = 'warning';
9 | messageTxt = 'Pending call...';
10 | } else if (isSuccess) {
11 | messageType = 'success';
12 | messageTxt = 'Repo pushed successfully';
13 | } else if (isFailure) {
14 | messageType = 'danger';
15 | messageTxt = 'Something wrong occured';
16 | }
17 |
18 | if (messageTxt === null) {
19 | return;
20 | }
21 |
22 | return /*#__PURE__*/ React.createElement("div", {
23 | className: 'alert alert-' + messageType,
24 | role: "alert"
25 | }, messageTxt);
26 | };
27 |
28 | export default Message;
29 |
--------------------------------------------------------------------------------
/crates/integration_tests/tests/plugin_lock_corejs_version/main.rs:
--------------------------------------------------------------------------------
1 | use std::env::current_dir;
2 |
3 | use integration_tests::{
4 | fixture::{BaseFixtureHook, FixtureTester},
5 | swc_plugins_collection::types::TransformConfig,
6 | };
7 |
8 | #[test]
9 | fn lock_core_js() {
10 | let config: TransformConfig = serde_json::from_str(
11 | r#"{
12 | "swc": { "jsc": { "externalHelpers": true }, "env": { "mode": "usage", "targets": "ie 11" } },
13 | "extensions": {
14 | "lockCorejsVersion": {
15 | "swcHelpers": "@@swc",
16 | "corejs": "@@corejs"
17 | }
18 | }
19 | }"#,
20 | )
21 | .unwrap();
22 | let mut tester = FixtureTester::new(config, BaseFixtureHook, vec![], None);
23 |
24 | tester.fixtures(
25 | ¤t_dir()
26 | .unwrap()
27 | .join("tests/plugin_lock_corejs_version/fixtures"),
28 | );
29 | }
30 |
--------------------------------------------------------------------------------
/crates/plugin_lodash/src/error.rs:
--------------------------------------------------------------------------------
1 | use std::fmt::Display;
2 |
3 | #[derive(Debug)]
4 | pub enum ResolveErrorKind {
5 | ModuleNotFound,
6 | ShouldIgnore,
7 | }
8 |
9 | #[derive(Debug)]
10 | pub struct ResolveError {
11 | pub msg: String,
12 | pub kind: ResolveErrorKind,
13 | }
14 |
15 | impl Display for ResolveError {
16 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 | f.write_str(&format!(
18 | "Error [{}]: {}",
19 | self.msg,
20 | match self.kind {
21 | ResolveErrorKind::ModuleNotFound => "Module not found",
22 | ResolveErrorKind::ShouldIgnore => "This module found but should be ignored",
23 | }
24 | ))
25 | }
26 | }
27 |
28 | impl std::error::Error for ResolveError {}
29 |
30 | impl ResolveError {
31 | pub fn new(msg: String, kind: ResolveErrorKind) -> Self {
32 | Self { msg, kind }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/crates/binding/src/binding_types/plugin_modularize_imports.rs:
--------------------------------------------------------------------------------
1 | use napi_derive::napi;
2 | use serde::Deserialize;
3 | use swc_plugins_collection::modularize_imports::{PackageConfig, Transform};
4 |
5 | use super::IntoRawConfig;
6 |
7 | #[napi(object)]
8 | #[derive(Clone, Debug, Deserialize)]
9 | pub struct PackageConfigNapi {
10 | pub transform: String,
11 | pub prevent_full_import: bool,
12 | pub skip_default_conversion: bool,
13 | }
14 |
15 | impl IntoRawConfig for PackageConfigNapi {
16 | fn into_raw_config(self, _: napi::Env) -> napi::Result {
17 | Ok(PackageConfig {
18 | transform: Transform::String(self.transform),
19 | prevent_full_import: self.prevent_full_import,
20 | skip_default_conversion: self.skip_default_conversion,
21 | handle_default_import: true,
22 | handle_namespace_import: true,
23 | })
24 | }
25 | }
26 |
--------------------------------------------------------------------------------