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

minify.mangle causes variable confusion #6730

Closed
noyobo opened this issue Dec 30, 2022 · 2 comments · Fixed by #6741
Closed

minify.mangle causes variable confusion #6730

noyobo opened this issue Dec 30, 2022 · 2 comments · Fixed by #6741
Assignees
Labels
Milestone

Comments

@noyobo
Copy link

noyobo commented Dec 30, 2022

Describe the bug

In the case , output code :

// ....other code
export const styleLoader = ()=>{
    return {
        name: 'style-loader',
        setup (n) {
            n.onLoad({
                filter: /.*/,
                namespace: 'less'
            }, function() {
                var n = t(function*(n) {});
                return function(n) {
                    // n is args variable
                    return n.apply(this, arguments); 
                    // when run the code get an error `n.apply is not a function`
                };
            }());
        }
    };
};

before mangle output code is :

// ....other code
export const styleLoader = ()=>{
    return {
        name: 'style-loader',
        setup (build) {
            build.onLoad({
                filter: /.*/,
                namespace: 'less'
            }, function() {
                var _ref = _asyncToGenerator(function*(args) {});
                return function(args) {
                    // _ref variable is async 
                    return _ref.apply(this, arguments);
                };
            }());
        }
    };
};

Input code

import { OnResolveArgs, PartialMessage, Plugin, PluginBuild } from 'esbuild';
import fs from 'fs';
import path from 'path';

export const styleLoader = (): Plugin => {
  return {
    name: 'style-loader',
    setup(build: PluginBuild) {
      build.onLoad({ filter: /.*/, namespace: 'less' }, async (args) => {
        
      });
    },
  };
};

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2015",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.24&code=H4sIAAAAAAAAA01QQW7DIBC8%2BxVzw67c5G4rlZpzq1b9AXHWLhIGi8VVI4u%2FBwhRgpCY3WFmB9S8WOex4cv8EFv9R%2B9u4hbf0nkl9Scxy4lirddJmft5XJU%2BI2B0doYgPqVa9JW6uY1cmJEfzUX639JOMBIV%2FWdmsIY92F80fVh5JocD6qYrs3B4w1YBjvzqTIaAkTN1EFnzqrNItJnheG2pc6DuOW1TlEDmdtakWfWGUWlPrsN%2B97JvszEvckjuOj5eILSQfDEDahl%2FprnHua0CQtNnFFKG0FdxXwGJ3Ag3WQEAAA%3D%3D&config=H4sIAAAAAAAAA22P3QrCMAyF3yXXu9gERfYOPoOEmo5q14YmG47Rd7eT%2FSB4leR8h3DODE8x0M7AmITSsskUFN%2FQgk5MYpJjhQpUimTRC%2BVyYOpIi4XkVDfngn2MQquhgt4FZ6flmYk9JxI5EIbO04I0sqeR%2FI5eRHw3HkUC9iS%2Fuv2jcXIjKpUZ%2BUCOrvsuaDG5pt6i5xK%2Bj49hTVAKfktcIB%2BhtzdyW42aBsofcZ6zHCkBAAA%3D

Expected behavior

The mangle results are the same as terser

Actual behavior

variable confusion

Version

1.3.24

Additional context

No response

@noyobo noyobo added the C-bug label Dec 30, 2022
@kdy1 kdy1 added this to the Planned milestone Dec 30, 2022
@kdy1 kdy1 self-assigned this Dec 30, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Feb 4, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants