Coder Social home page Coder Social logo

Comments (2)

alexlamsl avatar alexlamsl commented on August 15, 2024 1

Consider using name cache (--name-cache on CLI or nameCache on API), which tracks renaming of variables thus avoid clashes which you experience.

from uglifyjs.

DEVTomatoCake avatar DEVTomatoCake commented on August 15, 2024

How is nameCache supposed to work, @alexlamsl?

I thought it stores all variables it minified, thus preventing the re-use of mangled names.
However, it looks like it only stores them in the supplied object when minifying a top level variable; if toplevel is set to false, the object is left unchanged.

I've encountered this because a constant at the top level named url was minified to n (which was reflected in the object), but in another file, lang was also renamed to n in an anonymous function.
This obviously causes errors, especially as the const which was in front of lang was also removed, causing it to use the global scope.

Original:

// script.js
const url = "https://api.tomatenkuchen.com/api/"

// language.js
const getLanguage = () => {
	if (getCookie("lang")) return getCookie("lang")

	const userLang = navigator.language || navigator.userLanguage
	if (userLang) {
		const lang = userLang.split("-")[0]
		return lang == "de" || lang == "fr" || lang == "hu" || lang == "ja" ? lang : "en"
	}
	return "en"
}

Minified/mangled:

// script.js
const n="https://api.tomatenkuchen.com/api/"; // [...]

// language.js
const getLanguage=()=>getCookie("lang")?getCookie("lang"):!(n=navigator.language||navigator.userLanguage)||"de"!=(n=n.split("-")[0])&&"fr"!=n&&"hu"!=n&&"ja"!=n?"en":n // [...]

It's quite difficult to provide something easily reproducible, it's probably just caused by having many mangled variables.
I can try to create something easier to reproduce if needed.

from uglifyjs.

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.