Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimizer.simplify: true is wrongly stripping code it shouldn't #9981

Open
dalimian opened this issue Jan 31, 2025 · 0 comments
Open

optimizer.simplify: true is wrongly stripping code it shouldn't #9981

dalimian opened this issue Jan 31, 2025 · 0 comments
Labels

Comments

@dalimian
Copy link

Describe the bug

given this code const someVar = someNonExistentVarSoThisCodeShouldTriggerAnError;

when compiled with jsc.transform.optimizer.simplify set to true in .swcrc the above code is dropped from the compiled output. that seems wrong, optimization should not change any behavior. The end effect is that SWC is essentially silencing what would have been a loud failure.

side question, is optimizer.simplify feature considered stable

Input code

Config

{
  "$schema": "https://swc.rs/schema.json",
  "env": {
    "loose": true,
    "targets": [
      "current node"
    ],
  },
  "jsc": {
    "baseUrl": "../../../",
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "transform": {
      "react": {
        "development": false,
      },
      "optimizer": {
        "simplify": true,
        "globals": {
          "vars": {
            "NODE_ENV": "true"
          }
        }
      }
    },
    "paths": {
      "site-modules/*": [
        "./client/site-modules/*"
      ],
      "client/*": [
        "./client/*"
      ],
      "server/*": [
        "./server/*"
      ],
      "shared/*": [
        "./shared/*"
      ],
      "stubs/*": [
        "./stubs/*"
      ],
      "archetype/*": [
        "./archetype/*"
      ],
      "package.json/*": [
        "./package.json/*"
      ]
    },
  },
  "module": {
    "type": "commonjs",
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.12&code=H4sIAAAAAAAAA0vOzysuUUhUsFUozs9N9cvPc63ILC5JzSsJSywKzg%2FJyCx2zk9JDc7IL81JCSnKTE9PLXLMcy0qyi%2By5koG600iW29%2BTqpeTn66RpImFwBhzhuZhwAAAA%3D%3D&config=H4sIAAAAAAAAA21QSQ7CMAy89xWVzxwACQ78gUdEwalSZZOdSpSqfydNk9JKXCJ7xjNjZ2raFnqW8GinVKYmCGKkrU8Ijy6Kd0IApRUsSYcIp8r2vFBKGMYMzSsDUVCHMav4er7cigKM94xVUTCrnVbjPlN6GwiZj4PLqHCdwf%2BJJBwrT3Zv5EPUVn8OFy03aRvMmhlpwELMTX2zJ1j%2FGnJY%2BZs4BlwvusNvqC6%2FLQqan1WZ3ecva2l8K2cBAAA%3D

SWC Info output

No response

Expected behavior

it should not drop the line

Actual behavior

No response

Version

1.10.12

Additional context

No response

@dalimian dalimian added the C-bug label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant