Inversifyjs: Output optimization

Created on 17 Mar 2017  路  5Comments  路  Source: inversify/InversifyJS

I have a question related to optimization of outputted JavaScript when using InversifyJS.

Current Behavior

I have noticed that every module (class) has the following, exactly the same, methods outputted:

var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};

var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};

var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};

Expected Behavior

Have optimized JavaScript code, maybe to have the mentioned methods outputted only once? Maybe I didn't setup something correctly?

Your Environment

"typescript": "^2.1.6",
"webpack": "^2.2.1",
"inversify": "^3.1.0",
"reflect-metadata": "^0.1.9"

All 5 comments

This is because of TypeScript.

Because we use decorators, these helper functions are generated by TypeScript in order to make it compatible with JavaScript.

So after some research, I found out that there is a Compiler Options flag that reduces the amount of helper functions.

When you add "importHelpers": true to the tsconfig.json file then, a file tslib is importet to every file.
tslib, this contains methods for all helper functions.
Because these just get imported all helper functions should get removed.

Hi,

I have added lines below to my configuration and helper methods are gone. Thanks for the hint.

"importHelpers": true,
"noEmitHelpers": true

Hi @lholznagel thanks a lot for your help here :) @khorvat can this issue be closed?

Yes, thanks

Was this page helpful?
0 / 5 - 0 ratings