From a0f1b0ea9c159de9bf8aa605ff006d7bba7cb099 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 23 Mar 2020 00:24:02 -0400 Subject: [PATCH] Make Form._lines public and remove the accessor. --- src/core/Form.test.ts | 18 +++++++++--------- src/core/Form.ts | 14 +++++--------- src/core/Line.test.ts | 28 ++++++++++++++-------------- src/core/TaxReturn.test.ts | 10 +++++----- src/core/Trace.test.ts | 4 ++-- src/fed2019/Form1040.ts | 8 ++++---- src/fed2019/Form1099B.ts | 4 ++-- src/fed2019/Form1099DIV.ts | 4 ++-- src/fed2019/Form1099INT.ts | 4 ++-- src/fed2019/Form1099R.ts | 4 ++-- src/fed2019/Form1116.ts | 4 ++-- src/fed2019/Form8606.ts | 4 ++-- src/fed2019/Form8949.ts | 4 ++-- src/fed2019/Form8959.ts | 4 ++-- src/fed2019/Form8960.ts | 4 ++-- src/fed2019/Form8995.ts | 4 ++-- src/fed2019/Schedule1.ts | 8 ++++---- src/fed2019/Schedule2.ts | 4 ++-- src/fed2019/Schedule3.ts | 4 ++-- src/fed2019/ScheduleD.ts | 8 ++++---- src/fed2019/W2.ts | 4 ++-- 21 files changed, 73 insertions(+), 77 deletions(-) diff --git a/src/core/Form.test.ts b/src/core/Form.test.ts index 41677fd..8098759 100644 --- a/src/core/Form.test.ts +++ b/src/core/Form.test.ts @@ -16,10 +16,10 @@ class TestTaxReturn extends TaxReturn { test('add and get line', () => { const l = new ComputedLine(() => 42); - class TestForm extends Form { + class TestForm extends Form { readonly name = 'Test Form'; - protected readonly _lines = { '1': l }; + readonly lines = { '1': l }; }; const f = new TestForm(); @@ -27,9 +27,9 @@ test('add and get line', () => { }); test('get non-existent line', () => { - class TestForm extends Form { + class TestForm extends Form { readonly name = 'Test'; - protected readonly _lines = {}; + readonly lines = {}; }; const f = new TestForm(); @@ -48,7 +48,7 @@ test('input', () => { class TestForm extends Form { readonly name = '1040'; - protected readonly _lines = null; + readonly lines = null; }; const f = new TestForm({ filingStatus: 'S', money: 100.0 }); @@ -56,10 +56,10 @@ test('input', () => { }); test('get value', () => { - class TestForm extends Form { + class TestForm extends Form { readonly name = 'Form'; - protected readonly _lines = { + readonly lines = { line: new ComputedLine(() => 42), }; }; @@ -80,11 +80,11 @@ test('get value', () => { test('form types', () => { class FormA extends Form { readonly name = 'A'; - protected readonly _lines = {}; + readonly lines = {}; }; class FormB extends Form { readonly name = 'B'; - protected readonly _lines = {}; + readonly lines = {}; }; expect(isFormT(new FormA(), FormA)).toBe(true); diff --git a/src/core/Form.ts b/src/core/Form.ts index b8c16e8..c713f17 100644 --- a/src/core/Form.ts +++ b/src/core/Form.ts @@ -13,23 +13,19 @@ export default abstract class Form }, I = unknown> { abstract readonly name: string; - protected abstract readonly _lines: L; + abstract readonly lines: L; readonly supportsMultipleCopies: boolean = false; private readonly _input?: I; - // Avoid using this; prefer the getLine() helpers declared below. This - // is only exposed for propagating line type information. - get lines(): L { return this._lines; } - constructor(input?: I) { this._input = input; } init() { - for (const id in this._lines) { - let l = this._lines[id]; + for (const id in this.lines) { + let l = this.lines[id]; l._id = id; l.form = this; } @@ -40,9 +36,9 @@ export default abstract class Form }, } getLine(id: K): L[K] { - if (!(id in this._lines)) + if (!(id in this.lines)) throw new NotFoundError(`Form ${this.name} does not have line ${id}`); - return this._lines[id]; + return this.lines[id]; } getValue(tr: TaxReturn, id: K): ReturnType { diff --git a/src/core/Line.test.ts b/src/core/Line.test.ts index 98b4171..27ec6a3 100644 --- a/src/core/Line.test.ts +++ b/src/core/Line.test.ts @@ -39,9 +39,9 @@ test('computed line', () => { }); test('reference line', () => { - class TestForm extends Form { + class TestForm extends Form { readonly name = 'Form 1'; - protected readonly _lines = { + readonly lines = { '6b': new ConstantLine(12.34), 's': new ConstantLine('abc'), }; @@ -65,15 +65,15 @@ test('reference line', () => { }); test('self reference line', () => { - class OtherForm extends Form { + class OtherForm extends Form { readonly name = 'Form A'; - protected readonly _lines = { + readonly lines = { '6c': new ConstantLine(55) }; }; - class TestForm extends Form { + class TestForm extends Form { readonly name = 'Form 1'; - protected readonly _lines = { + readonly lines = { 'a': new ConstantLine(100.2), 'b': new ReferenceLine(OtherForm, '6c'), 'c': new ReferenceLine((TestForm as unknown) as FormClass>, 'b'), @@ -97,9 +97,9 @@ test('input line', () => { key: string; key2?: string; } - class TestForm extends Form { + class TestForm extends Form { readonly name = 'F1'; - protected readonly _lines = { + readonly lines = { '1': new InputLine('key'), '2': new InputLine('key2'), '3': new InputLine('key2', undefined, 'FALLBACK') @@ -119,16 +119,16 @@ test('input line', () => { }); test('line stack', () => { - class FormZ extends Form { + class FormZ extends Form { readonly name = 'Z'; - protected readonly _lines = { + readonly lines = { '3': new InputLine('input') } }; - class FormZ2 extends Form { + class FormZ2 extends Form { readonly name = 'Z-2'; - protected readonly _lines = { + readonly lines = { '2c': new ComputedLine((tr: TaxReturn): any => { return tr.getForm(FormZ).getLine('3').value(tr) * 0.2; }) @@ -144,10 +144,10 @@ test('line stack', () => { }); test('accumulator line', () => { - class TestForm extends Form { + class TestForm extends Form { readonly name = 'Form B'; readonly supportsMultipleCopies = true; - protected readonly _lines = { + readonly lines = { g: new ConstantLine(100.25) }; }; diff --git a/src/core/TaxReturn.test.ts b/src/core/TaxReturn.test.ts index 497a8b4..4da4fcb 100644 --- a/src/core/TaxReturn.test.ts +++ b/src/core/TaxReturn.test.ts @@ -61,7 +61,7 @@ test('get non-existent person', () => { test('single-copy forms', () => { class TestForm extends Form { readonly name = 'Test Form'; - protected readonly _lines = null; + readonly lines = null; }; const tr = new TestTaxReturn(); @@ -76,7 +76,7 @@ test('multiple-copy forms', () => { class TestForm extends Form { readonly name = 'Test Form'; readonly supportsMultipleCopies = true; - protected readonly _lines = null; + readonly lines = null; }; const tr = new TestTaxReturn(); @@ -99,7 +99,7 @@ test('multiple-copy forms', () => { test('get non-existent form', () => { class TestForm extends Form { readonly name = 'Test Form'; - protected readonly _lines = null; + readonly lines = null; } const tr = new TestTaxReturn(); expect(() => tr.getForm(TestForm)).toThrow(NotFoundError); @@ -107,14 +107,14 @@ test('get non-existent form', () => { expect(tr.findForms(TestForm)).toEqual([]); }); -class PerPersonForm extends Form { +class PerPersonForm extends Form { private _person?: Person; readonly name = 'Per Person'; readonly supportsMultipleCopies = true; - protected readonly _lines = {}; + readonly lines = {}; constructor(person?: Person) { super(undefined); diff --git a/src/core/Trace.test.ts b/src/core/Trace.test.ts index 3f49fde..1bdf55b 100644 --- a/src/core/Trace.test.ts +++ b/src/core/Trace.test.ts @@ -19,10 +19,10 @@ interface Input { value: number; }; -class TestForm extends Form { +class TestForm extends Form { readonly name = 'TF'; - readonly _lines = { + readonly lines = { 'i1': new InputLine('name'), 'i2': new InputLine('value'), 'c1': new ComputedLine((tr): string => { diff --git a/src/fed2019/Form1040.ts b/src/fed2019/Form1040.ts index ab6f59e..584a823 100644 --- a/src/fed2019/Form1040.ts +++ b/src/fed2019/Form1040.ts @@ -30,10 +30,10 @@ export interface Form1040Input { filingStatus: FilingStatus; }; -export default class Form1040 extends Form { +export default class Form1040 extends Form { readonly name = '1040'; - protected readonly _lines = { + readonly lines = { '1': new AccumulatorLine(W2, '1', 'Wages, salaries, tips, etc.'), '2a': new ComputedLine((tr): number => { const value = (new AccumulatorLine(Form1099INT, '8')).value(tr) + @@ -247,10 +247,10 @@ export function computeTax(income: number, filingStatus: FilingStatus): number { return ((income - bracketStart) * bracket[1]) + bracket[2]; }; -export class QDCGTaxWorksheet extends Form { +export class QDCGTaxWorksheet extends Form { readonly name = 'QDCG Tax Worksheet'; - protected readonly _lines = { + readonly lines = { '1': new ReferenceLine(Form1040, '11b', 'Taxable income'), '2': new ReferenceLine(Form1040, '3a', 'Qualified dividends'), '3': new ComputedLine((tr): number => { diff --git a/src/fed2019/Form1099B.ts b/src/fed2019/Form1099B.ts index 816cfef..67a41a3 100644 --- a/src/fed2019/Form1099B.ts +++ b/src/fed2019/Form1099B.ts @@ -36,14 +36,14 @@ export interface Form1099BInput { class Input extends InputLine {}; -export default class Form1099B extends Form { +export default class Form1099B extends Form { readonly name = '1099-B'; readonly supportsMultipleCopies = true; person() { return this.getInput('payee'); } - protected readonly _lines = { + readonly lines = { 'payer': new Input('payer'), 'recipient': new Input('payee'), 'shortTermBasisReported': new Input('shortTermBasisReported'), diff --git a/src/fed2019/Form1099DIV.ts b/src/fed2019/Form1099DIV.ts index f9561a1..dc00476 100644 --- a/src/fed2019/Form1099DIV.ts +++ b/src/fed2019/Form1099DIV.ts @@ -29,14 +29,14 @@ export interface Form1099DIVInput { class Input extends InputLine {}; -export default class Form1099DIV extends Form { +export default class Form1099DIV extends Form { readonly name = '1099-DIV'; readonly supportsMultipleCopies = true; person() { return this.getInput('payee'); } - protected readonly _lines = { + readonly lines = { 'payer': new Input('payer'), 'recipient': new Input('payee'), '1a': new Input('ordinaryDividends', undefined, 0), diff --git a/src/fed2019/Form1099INT.ts b/src/fed2019/Form1099INT.ts index e339031..adf4823 100644 --- a/src/fed2019/Form1099INT.ts +++ b/src/fed2019/Form1099INT.ts @@ -26,14 +26,14 @@ export interface Form1099INTInput { class Input extends InputLine {}; -export default class Form1099INT extends Form { +export default class Form1099INT extends Form { readonly name = '1099-INT'; readonly supportsMultipleCopies = true; person() { return this.getInput('payee'); } - protected readonly _lines = { + readonly lines = { 'payer': new Input('payer'), 'recipient': new Input('payee'), '1': new Input('interest'), diff --git a/src/fed2019/Form1099R.ts b/src/fed2019/Form1099R.ts index c30bb5a..744741a 100644 --- a/src/fed2019/Form1099R.ts +++ b/src/fed2019/Form1099R.ts @@ -54,14 +54,14 @@ export interface Form1099RInput { class Input extends InputLine {}; -export default class Form1099R extends Form { +export default class Form1099R extends Form { readonly name = '1099-R'; readonly supportsMultipleCopies = true; person() { return this.getInput('payee'); } - protected readonly _lines = { + readonly lines = { 'payer': new Input('payer'), 'recipeint': new Input('payee'), '1': new Input('grossDistribution'), diff --git a/src/fed2019/Form1116.ts b/src/fed2019/Form1116.ts index 0b9253f..bbec8fb 100644 --- a/src/fed2019/Form1116.ts +++ b/src/fed2019/Form1116.ts @@ -34,10 +34,10 @@ export interface Form1116Input { class Input extends InputLine {}; -export default class Form1116 extends Form { +export default class Form1116 extends Form { readonly name = '1116'; - protected readonly _lines = { + readonly lines = { 'category': new ComputedLine((tr: TaxReturn): ForeignIncomeCategory => { const input = this.getInput('incomeCategory'); if (input != ForeignIncomeCategory.C) diff --git a/src/fed2019/Form8606.ts b/src/fed2019/Form8606.ts index 4ce135a..38c9fe9 100644 --- a/src/fed2019/Form8606.ts +++ b/src/fed2019/Form8606.ts @@ -20,14 +20,14 @@ export interface Form8606Input { class Input extends InputLine {}; -export default class Form8606 extends Form { +export default class Form8606 extends Form { readonly name = '8606'; readonly supportsMultipleCopies = true; person() { return this.getInput('person'); } - protected readonly _lines = { + readonly lines = { 'person': new Input('person'), // Part 1 diff --git a/src/fed2019/Form8949.ts b/src/fed2019/Form8949.ts index 814d4e7..51bd291 100644 --- a/src/fed2019/Form8949.ts +++ b/src/fed2019/Form8949.ts @@ -76,12 +76,12 @@ class Form8949Line extends Line { } }; -export default class Form8949 extends Form { +export default class Form8949 extends Form { readonly name = '8949'; readonly supportsMultipleCopies = true; - protected readonly _lines = { + readonly lines = { 'boxA': new Form8949Line(Form8949Box.A), 'boxB': new Form8949Line(Form8949Box.B), 'boxC': new Form8949Line(Form8949Box.C), diff --git a/src/fed2019/Form8959.ts b/src/fed2019/Form8959.ts index 83b439b..844261f 100644 --- a/src/fed2019/Form8959.ts +++ b/src/fed2019/Form8959.ts @@ -10,10 +10,10 @@ import { clampToZero } from '../core/Math'; import Form1040, { FilingStatus } from './Form1040'; import W2 from './W2'; -export default class Form8959 extends Form { +export default class Form8959 extends Form { readonly name = '8959'; - protected readonly _lines = { + readonly lines = { '1': new AccumulatorLine(W2, '5', 'Medicare wages'), // 2 is not supported (Unreported tips from Form 4137) // 3 is not supported (Wages from Form 8919) diff --git a/src/fed2019/Form8960.ts b/src/fed2019/Form8960.ts index 46f45a8..a871e82 100644 --- a/src/fed2019/Form8960.ts +++ b/src/fed2019/Form8960.ts @@ -10,10 +10,10 @@ import { clampToZero, undefinedToZero } from '../core/Math'; import Form1040, { FilingStatus } from './Form1040'; import Schedule1 from './Schedule1'; -export default class Form8960 extends Form { +export default class Form8960 extends Form { readonly name = '8960'; - protected readonly _lines = { + readonly lines = { // Part 1 // Section 6013 elections not supported. '1': new ReferenceLine(Form1040, '2b', 'Taxable interest'), diff --git a/src/fed2019/Form8995.ts b/src/fed2019/Form8995.ts index ad94894..677f9e2 100644 --- a/src/fed2019/Form8995.ts +++ b/src/fed2019/Form8995.ts @@ -18,11 +18,11 @@ export interface Form8995REITInput { // Dividends from REITs get preferential tax treatment, but the form used to // calculate that differs based off taxable income amounts. But the QBI // computation for RETIs is the same. This just models the REIT portion. -export default class Form8995REIT extends Form { +export default class Form8995REIT extends Form { readonly name = '8995 REIT'; // This uses line numbers from 8995-A. - protected readonly _lines = { + readonly lines = { // 1-26 not supported '27': new ComputedLine(() => 0, 'Total qualified business income component'), // Not supported. '28': new AccumulatorLine(Form1099DIV, '5', 'Qualified REIT dividends'), diff --git a/src/fed2019/Schedule1.ts b/src/fed2019/Schedule1.ts index 7cea3e8..ef6707c 100644 --- a/src/fed2019/Schedule1.ts +++ b/src/fed2019/Schedule1.ts @@ -58,10 +58,10 @@ class Input extends InputLine } }; -export default class Schedule1 extends Form { +export default class Schedule1 extends Form { readonly name = 'Schedule 1'; - readonly _lines = { + readonly lines = { // Part 1 '1': new ComputedLine((tr): number => { if (this.hasInput('stateAndLocalTaxableRefunds')) @@ -150,10 +150,10 @@ export interface SALTWorksheetInput { prevYearFilingStatus?: FilingStatus; }; -export class SALTWorksheet extends Form { +export class SALTWorksheet extends Form { readonly name = 'SALT Refund Worksheet'; - protected readonly _lines = { + readonly lines = { '1': new ComputedLine((tr): number => { const refunds = tr.findForm(Schedule1).getInput('stateAndLocalTaxableRefunds'); const prevYear = this.getInput('prevYearSalt'); diff --git a/src/fed2019/Schedule2.ts b/src/fed2019/Schedule2.ts index 3ea8c8f..eb9899c 100644 --- a/src/fed2019/Schedule2.ts +++ b/src/fed2019/Schedule2.ts @@ -13,10 +13,10 @@ import Form1099INT from './Form1099INT'; import Form8959 from './Form8959'; import Form8960 from './Form8960'; -export default class Schedule2 extends Form { +export default class Schedule2 extends Form { readonly name = 'Schedule 2'; - protected readonly _lines = { + readonly lines = { '1': new ComputedLine((tr): number => { // TODO - this is just using Taxable Income, rather than AMT-limited // income diff --git a/src/fed2019/Schedule3.ts b/src/fed2019/Schedule3.ts index d683560..98da58c 100644 --- a/src/fed2019/Schedule3.ts +++ b/src/fed2019/Schedule3.ts @@ -17,10 +17,10 @@ export interface Schedule3Input { estimatedTaxPayments?: number; }; -export default class Schedule3 extends Form { +export default class Schedule3 extends Form { readonly name = 'Schedule 3'; - readonly _lines = { + readonly lines = { // Part 1 '1': new ComputedLine((tr): number => { const f1040 = tr.getForm(Form1040); diff --git a/src/fed2019/ScheduleD.ts b/src/fed2019/ScheduleD.ts index 17fd11a..08264c1 100644 --- a/src/fed2019/ScheduleD.ts +++ b/src/fed2019/ScheduleD.ts @@ -12,10 +12,10 @@ import Form8949, { Form8949Box } from './Form8949'; import Form1099DIV from './Form1099DIV'; import Form1040, { FilingStatus, QDCGTaxWorksheet, computeTax } from './Form1040'; -export default class ScheduleD extends Form { +export default class ScheduleD extends Form { readonly name = 'Schedule D'; - protected readonly _lines = { + readonly lines = { // 1a not supported (Totals for all short-term transactions reported on Form 1099-B for which basis was reported to the IRS and for which you have no adjustments) // 4 is not supported (Short-term gain from Form 6252 and short-term gain or (loss) from Forms 4684, 6781, and 8824) // 5 is not supported (Net short-term gain or (loss) from partnerships, S corporations, estates, and trusts from Schedule(s) K-1) @@ -89,10 +89,10 @@ export default class ScheduleD extends Form { }; }; -export class ScheduleDTaxWorksheet extends Form { +export class ScheduleDTaxWorksheet extends Form { readonly name = 'Schedule D Tax Worksheet'; - protected readonly _lines = { + readonly lines = { '1': new ReferenceLine(Form1040, '11b'), '2': new ReferenceLine(Form1040, '3a'), // TODO 3 - form 4952 diff --git a/src/fed2019/W2.ts b/src/fed2019/W2.ts index 2bac4d4..a0f7fff 100644 --- a/src/fed2019/W2.ts +++ b/src/fed2019/W2.ts @@ -37,7 +37,7 @@ export interface W2Input { class Input extends InputLine {}; -export default class W2 extends Form { +export default class W2 extends Form { readonly name = 'W-2'; readonly supportsMultipleCopies = true; @@ -46,7 +46,7 @@ export default class W2 extends Form { return this.getInput('employee'); } - protected readonly _lines = { + readonly lines = { 'c': new Input('employer', 'Employer name'), 'e': new Input('employee', 'Emplyee name'), '1': new Input('wages', 'Wages, tips, other compensation'), -- 2.43.5