1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var determineIndent_1 = require("../utils/determineIndent");
|
5 | var NodePatcher_1 = require("./NodePatcher");
|
6 | var ProgramPatcher = (function (_super) {
|
7 | tslib_1.__extends(ProgramPatcher, _super);
|
8 | function ProgramPatcher(patcherContext, body) {
|
9 | var _this = _super.call(this, patcherContext) || this;
|
10 | _this.helpers = new Map();
|
11 | _this._indentString = null;
|
12 | _this.body = body;
|
13 | return _this;
|
14 | }
|
15 | ProgramPatcher.prototype.shouldTrimContentRange = function () {
|
16 | return true;
|
17 | };
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 | ProgramPatcher.prototype.registerHelper = function (name, code) {
|
24 | code = code.trim();
|
25 | if (this.helpers.has(name)) {
|
26 | if (this.helpers.get(name) !== code) {
|
27 | throw new Error("BUG: cannot override helper '" + name + "'");
|
28 | }
|
29 | }
|
30 | else {
|
31 | this.helpers.set(name, code);
|
32 | }
|
33 | return name;
|
34 | };
|
35 | ProgramPatcher.prototype.patchHelpers = function () {
|
36 | var e_1, _a;
|
37 | try {
|
38 | for (var _b = tslib_1.__values(this.helpers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
39 | var helper = _c.value;
|
40 | this.editor.append("\n" + helper);
|
41 | }
|
42 | }
|
43 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
44 | finally {
|
45 | try {
|
46 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
47 | }
|
48 | finally { if (e_1) throw e_1.error; }
|
49 | }
|
50 | };
|
51 | |
52 |
|
53 |
|
54 | ProgramPatcher.prototype.getProgramIndentString = function () {
|
55 | if (!this._indentString) {
|
56 | this._indentString = determineIndent_1.default(this.context.source);
|
57 | }
|
58 | return this._indentString;
|
59 | };
|
60 | return ProgramPatcher;
|
61 | }(NodePatcher_1.default));
|
62 | exports.default = ProgramPatcher;
|