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

Terser rewrites private fields instead of throwing a parser error #1011

Closed
TimvdLippe opened this issue Jun 18, 2021 · 1 comment
Closed
Labels
bug parser Issue in the parse step

Comments

@TimvdLippe
Copy link

Bug report or Feature request?

Bug

Version (complete output of terser -V or specific git commit)
The version of https://try.terser.org/ (I am assuming latest, but the website doesn't show me what version it is running)

Complete CLI command or minify() options used

{
  module: true,
  compress: {},
  mangle: {},
  output: {},
  parse: {},
  rename: {},
}

terser input

export const myObject = {
  foo: 'bar',
  #something: 5,
}

terser output or error

export const myObject={foo:"bar",something:5};

Expected result
Terser should error on this, as you can't use private fields in an object. However, terser rewrites it to a regular object field which is legal syntax. So even though the input is illegal JavaScript, if users don't catch this issue, terser rewrites it to legal syntax and leading to incorrect code. Therefore, if users don't check their code in any other way, running the terser output will result in runtime errors.

@fabiosantoscode
Copy link
Collaborator

Usually Terser doesn't check for valid syntax on purpose, but admittedly this isn't good behaviour. It can cause confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug parser Issue in the parse step
Projects
None yet
Development

No branches or pull requests

3 participants