Skip to content

typeof changed even when "unsafe" is false #2198

@timmywil

Description

@timmywil

We ran into an issue when compressing jQuery with the latest version (3.0.23). The README implies that the typeof should remain unchanged when unsafe is set to false. Nevertheless, only when setting ie8 to true did we get the expected output.

Sometimes, methods are invoked in IE9/IE10 when simply referencing them as properties. In this case, .getAttribute is called despite the lack of parens, throwing an error. Only when typeof remains untouched is the error avoided. Reduced example is below.

Bug report
ES5
Uglify version (uglifyjs -V)
uglify-js 3.0.23

JavaScript input

function attr (elem, name, value) {
	// Fallback to prop when attributes are not supported
	if (typeof elem.getAttribute === "undefined") {
		return jQuery.prop(elem, name, value);
	}
}

The uglifyjs CLI command executed or minify() options used.

uglifyjs --compress -- test.js

or

uglifyjs --compress unsafe=false -- test.js

JavaScript output or error produced.

function attr(elem,name,value){if(void 0===elem.getAttribute)return jQuery.prop(elem,name,value)}

Correct output is produced with

uglifyjs --ie8 --compress -- test.js

Output being:

function attr(elem,name,value){if("undefined"==typeof elem.getAttribute)return jQuery.prop(elem,name,value)}

Problem is, the output is unsafe for IE9/IE10 as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions