GithubHelp home page GithubHelp logo

Comments (6)

maxmartynov avatar maxmartynov commented on May 27, 2024 1

TLDR;
If you guys are sure the new PR will solve this problem - no problem. Feel free to close the issue. You have already paid attention to the problem which is enough to remember it if necessary. My goal was to tell you about a nasty issue that happens on runtime.

Full story

I use [email protected]. Perhaps this problem will go away with new installation methods (#15502)

@filipsobol

@maxmartynov Are you using the latest version of terser?

I use (Nuxt.js uses under the hood) [email protected]. The latest version is 5.29.2.

it correctly converts ITEMS_PER_REQUEST.toString() to 50..toString()

I confirm that for me disabling the flags reduce_vars: false, collapse_vars: false leads to having 50..toString() in the resulting bundle. And this works.

I've created this issue mostly to point out the fact that (warn: IMHO) using <number>.toString() is not the best practice. My project uses ~70 libs in package.json and that means about 1.4k libs as nested dependencies. And they all play well with these Terser options enabled. The only place I noticed a problem is this one row in ckeditor5. You can check your project and make sure that there are no other places where you stringify numbers this way (not 100% info).

The reason why I've created this issue is to report the problem that appears in runtime only and happens NOT IN 100% CASES. My users got the error SyntaxError: Invalid or unexpected token randomly in different browsers. I assume that some browser engines can handle 50.toString() sometimes, because I don't know the reason why only half of my users get this error sometimes.

from ckeditor5.

maxmartynov avatar maxmartynov commented on May 27, 2024

Fixed in the PR #16041

from ckeditor5.

Witoso avatar Witoso commented on May 27, 2024

Ha, that's very intriguing. What kind of bundler/minifier are you using? Tactical cc to @filipsobol, as we start to bundle ourselves in #15502.

from ckeditor5.

maxmartynov avatar maxmartynov commented on May 27, 2024

I use Terser (Stack: Nuxt.js 3, Vue 3, Vite, Terser).

Disabling these two options of Terser makes ckeditor build correctly:

export default defineNuxtConfig({
  vite: {
    build: {
      minify: 'terser',
      terserOptions: {
        compress: {
          reduce_vars: false,
          collapse_vars: false,
        },
      },
    },
  },
 })

But in general, I had to disable these two options only for two rows in ckeditor lib which I've fixed in my PR. If I disable these options, the expression ITEMS_PER_REQUEST.toString() becomes 50..toString() (with two dots) in the result bundle and it works

from ckeditor5.

filipsobol avatar filipsobol commented on May 27, 2024

We use terser to minify bundles for the new installation methods (#15502) and it correctly converts ITEMS_PER_REQUEST.toString() to 50..toString(). This is consistent with the output in the Terser REPL:

// Input
const test = 50;

console.log(test.toString());

// Output
console.log(50..toString());

@maxmartynov Are you using the latest version of terser?


Out of curiosity, I also checked swc and (when compression is enabled) it converts ITEMS_PER_REQUEST.toString() to "50".

from ckeditor5.

Witoso avatar Witoso commented on May 27, 2024

Hmm, with the options mentioned by @maxmartynov

        compress: {
          reduce_vars: false,
          collapse_vars: false,
        },

the live REPL also produces working code:

const o=50;console.log(o.toString());

It looks like a Terser issue (maybe older version produced wrong results), or maybe something else causes problems in your environment?

TBH I don't see this as a bug on our side 🤔 Changing working code to some other implementation just because minification crashes it, looks like the tail wagging the dog.

from ckeditor5.

Related Issues (20)

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.