Skip to content

Plugin is changing outputted code (not imports) #71

Open
@gtjamesa

Description

@gtjamesa

Using 1.0.0-alpha.5. The import statements are being added as expected, but I noticed some code was also being altered. This happens when using the API example .swcrc and also when no rules are configured

...

// typescript source
public static postRaw(req: Request<RawRenderRequest>, res: Response) {
  const chartData = req.body?.chart;
  if (!req.body || !chartData || !chartData?.data.length) {
    //
  }
}

// swc build
static postRaw(req, res) {
  const chartData = req.body?.chart;
  if (!req.body || !chartData || !chartData?.data.length) {
    //
  }
}

// swc build + this plugin
static postRaw(req, res) {
  const chartData = this?.;
  if (!req.body || !chartData || !this.?) {
    //
  }
}

...

.swcrc:

{
  "$schema": "http://json.schemastore.org/swcrc",
  "jsc": {
    "target": "es2022",
    "parser": {
      "syntax": "typescript"
    },
    "experimental": {
      "plugins": [
        [
          "swc-plugin-add-import-extension",
          {
            "^~.*$": {
              "extension": "js",
              "addIndex": true
            },
            "^\\..*": {
              "extension": "js",
              "addIndex": false
            }
          }
        ]
      ]
    }
  },
  "module": {
    "type": "es6",
    "strict": false,
    "strictMode": true,
    "lazy": false,
    "noInterop": false
  },
  "sourceMaps": true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions