3.angular2方法ts反解析

160 阅读1分钟

方法解析只是将方法添加到构造函数的prototype上面

import { Component, Input } from '@angular/core';
@Component({
    selector: 'app-ag-grid',
    templateUrl: './ag-grid-angular.component.html',
    styleUrls: ['./ag-grid-angular.component.less'],
})
export class AgGridComponent {
    onGridReady(params) {
        this.api = params.api;
        this.columnApi = params.columnApi;
    }
}

解析成对应的

define(["require", "exports", "@angular/core"], function (require, exports, core_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AgGridComponent = /** @class */ (function () {
        function AgGridComponent() {
        }
        AgGridComponent.prototype.onGridReady = function (params) {
            this.api = params.api;
            this.columnApi = params.columnApi;
        };
        AgGridComponent = __decorate([
            core_1.Component({
                selector: 'app-ag-grid',
                templateUrl: './ag-grid-angular.component.html',
                styleUrls: ['./ag-grid-angular.component.less'],
            })
        ], AgGridComponent);
        return AgGridComponent;
    }());
    exports.AgGridComponent = AgGridComponent;
});

方法中的set和get的解析的规则就不一样,大部分的set方法跟着@Input一起使用。

import { Component, Input } from '@angular/core';
@Component({
    selector: 'app-ag-grid',
    templateUrl: './ag-grid-angular.component.html',
    styleUrls: ['./ag-grid-angular.component.less'],
})
export class AgGridComponent {
    private _gridOptions = {};
    @Input() set gridOptions(opts) {
        this._gridOptions = Object.assign({}, this._gridOptions, opts);
    }
    get gridOptions() { return this._gridOptions; }
}

解析成

define(["require", "exports", "@angular/core"], function (require, exports, core_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AgGridComponent = /** @class */ (function () {
        function AgGridComponent() {
            this._gridOptions = {};
        }
        Object.defineProperty(AgGridComponent.prototype, "gridOptions", {
            get: function () { return this._gridOptions; },
            set: function (opts) {
                this._gridOptions = Object.assign({}, this._gridOptions, opts);
            },
            enumerable: true,
            configurable: true
        });
        __decorate([
            core_1.Input()
        ], AgGridComponent.prototype, "gridOptions", null);
        AgGridComponent = __decorate([
            core_1.Component({
                selector: 'app-ag-grid',
                templateUrl: './ag-grid-angular.component.html',
                styleUrls: ['./ag-grid-angular.component.less'],
            })
        ], AgGridComponent);
        return AgGridComponent;
    }());
    exports.AgGridComponent = AgGridComponent;
});