Skip to content

Conversation

rbuckton
Copy link
Contributor

This change removes the unnecessary extra var declarations when we merge enums or namespaces with preceding declarations. This also helps to avoid the extra export var declarations in #11258.

Given the following source:

// @module: es6
// @target: es5
export class C { }
export namespace C {
  export const x = 1;
}

enum E { x = 0 }
enum E { y = 1 }

Previously we would emit:

export var C = (function () { 
  function C() {
  }
  return C;
})();
export var C;
(function (C) {
  C.x = 1;
})(C || (C = {}));
var E;
(function (E) {
  E[E["x"] = 0] = "x";
})(E || (E = {}));
var E;
(function (E) {
  E[E["y"] = 1] = "y";
})(E || (E = {}));

With this change we now emit:

export var C = (function () { 
  function C() {
  }
  return C;
})();
(function (C) {
  C.x = 1;
})(C || (C = {}));
var E;
(function (E) {
  E[E["x"] = 0] = "x";
})(E || (E = {}));
(function (E) {
  E[E["y"] = 1] = "y";
})(E || (E = {}));

Fixes #11258

@mhegazy
Copy link
Contributor

mhegazy commented Sep 30, 2016

Fixes #5553

@rbuckton rbuckton merged commit c302893 into master Sep 30, 2016
@rbuckton rbuckton deleted the noEmitExtraVars branch September 30, 2016 22:10
@mihailik
Copy link
Contributor

mihailik commented Oct 3, 2016

Does it 'merges' var declarations in case of outFile emit?

@rbuckton
Copy link
Contributor Author

rbuckton commented Oct 3, 2016

No, it will not remove var declarations for namespaces or enums merged across files when emitting to a single file, just from within a single source file.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants