GithubHelp home page GithubHelp logo

tkow / swc-decorator-reflection-bug Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 63 KB

The project to reproduce swc decorator reflection bug.

License: MIT License

JavaScript 25.78% TypeScript 74.22%

swc-decorator-reflection-bug's Introduction

This is not decorator problem but mangle terser options, you can avoid mangle: false and compress keep_classnames: true and keep_fnames: true.

Settig Reproduction

  1. run pnpm i
  2. run npm run build:watch in subprocess.
  3. run ./bin/run.js switching loader 'babel-loader' and 'swc-loader',

Results

babel-loader or tsc

tsconfig.json

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "rootDir": "./src",
    "declaration": true,
    "declarationMap": true,
    "emitDeclarationOnly": true,
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "include": ["./src"]
}

babel.config.js

module.exports = {
  "presets": [
    [
      "@babel/preset-typescript"
    ]
  ],
  "plugins": [
    "babel-plugin-transform-typescript-metadata",
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
  ]
}

result:

[
  {
    "meta": {
      "value": "A"
    },
    "instance": {},
    "params": [
      {
        "meta": {
          "value": "a"
        },
        "discoveredMethod": {
          "methodName": "method",
          "parentClass": {
            "name": "A",
            "instance": {},
            "parentModule": {
              "name": "AppModule",
              "instance": {}
            }
          }
        }
      }
    ]
  },
  {
    "meta": {
      "value": "B"
    },
    "instance": {},
    "params": [
      {
        "meta": {},
        "discoveredMethod": {
          "methodName": "method",
          "parentClass": {
            "name": "B",
            "instance": {},
            "parentModule": {
              "name": "AppModule",
              "instance": {}
            }
          }
        }
      }
    ]
  }
]

swc

{
  "$schema": "http://json.schemastore.org/swcrc",
  "module": {
    "type": "commonjs",
    "strict": false,
    "strictMode": true,
    "lazy": false,
    "noInterop": false
  },
  "jsc": {
    "externalHelpers": true,
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true,
      "dynamicImport": false
    },
    "transform": {
      "decoratorMetadata": true,
      "legacyDecorator": true
    },
    "minify": {
      "compress": {
        "unused": true
      },
      "mangle": true
    }
  },
  "minify": true
}

result:

[
  {
    "meta": {
      "value": "A"
    },
    "instance": {},
    "params": [
      {
        "meta": {
          "value": "a"
        },
        "discoveredMethod": {
          "methodName": "method",
          "parentClass": {
            "name": "t",
            "instance": {},
            "parentModule": {
              "name": "e",
              "instance": {}
            }
          }
        }
      },
      {
        "meta": {},
        "discoveredMethod": {
          "methodName": "method",
          "parentClass": {
            "name": "t",
            "instance": {},
            "parentModule": {
              "name": "e",
              "instance": {}
            }
          }
        }
      }
    ]
  },
  {
    "meta": {
      "value": "B"
    },
    "instance": {},
    "params": [
      {
        "meta": {
          "value": "a"
        },
        "discoveredMethod": {
          "methodName": "method",
          "parentClass": {
            "name": "t",
            "instance": {},
            "parentModule": {
              "name": "e",
              "instance": {}
            }
          }
        }
      },
      {
        "meta": {},
        "discoveredMethod": {
          "methodName": "method",
          "parentClass": {
            "name": "t",
            "instance": {},
            "parentModule": {
              "name": "e",
              "instance": {}
            }
          }
        }
      }
    ]
  }
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.