google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.35k stars 1.14k forks source link

Smart name removal deletes essential code from web animations next polyfill #1172

Open johnheroy opened 8 years ago

johnheroy commented 8 years ago

The smart name removal pass removes an IIFE in the web-animations-next polyfill which has the side effect of polyfilling Element.prototype.animate in this non-minified code snippet. This was seen when compiling the minified library which lives here.

johnheroy commented 8 years ago

Still cuts out this IIFE when I manually patch in a change to substitute "window.Element..." with "Element..."

MatrixFrog commented 8 years ago

I'm not able to repro at least with this simple example. Might be a combination of smart name removal with some other pass.

http://closure-compiler-debugger.appspot.com/#input0%3D(function(scope)%2520%257B%250A%2520%2520Element.prototype.animate%2520%253D%2520function()%2520%257B%250A%2520%2520%2520%2520alert('I%2520am%2520animating.')%253B%250A%2520%2520%257D%253B%250A%257D)(window)%253B%250A%250Avar%2520el%2520%253D%2520document.createElement('div')%253B%250Ael.animate()%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26MISSING_PROPERTIES%3D1%26PRETTY_PRINT%3D1%26SMART_NAME_REMOVAL%3D1

concavelenz commented 8 years ago

This is "remove unused prototype properties" doing what it is suppose to do. Make sure you have two things: 1) an extern definition for animate 2) "remove unused prototype properties in externs" disabled.