closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Feature request: Cross module code motion should move pure calls

Open nicks opened this issue 8 years ago • 1 comments

Create two modules:

// module 1
/** @constructor */ function Point(x, y) { this.x = x; this.y = y; }
var ZERO = new Point(0, 0);
// module 2
alert(ZERO)

It would be nice if cross-module code motion could figure out that Point is "pure" and so everything can be moved into the second module.

http://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540constructor%2520*%252F%2520function%2520Point(x%252C%2520y)%2520%257B%2520this.x%2520%253D%2520x%253B%2520this.y%2520%253D%2520y%253B%2520%257D%250Avar%2520ZERO%2520%253D%2520new%2520Point(0%252C%25200)%253B%26input1%3Dalert(ZERO)%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26MISSING_PROPERTIES%3D1%26TRANSPILE%3D1%26CHECK_TYPES%3D1%26COMPUTE_FUNCTION_SIDE_EFFECTS%3D1%26MARK_NO_SIDE_EFFECT_CALLS%3D1%26CROSS_MODULE_CODE_MOTION%3D1%26CROSS_MODULE_METHOD_MOTION%3D1%26CLOSURE_PASS%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1

nicks avatar Feb 17 '17 17:02 nicks

I've raised a PR for this feature here: https://github.com/google/closure-compiler/pull/3751

WearyMonkey avatar Jan 12 '21 11:01 WearyMonkey