From 48a01dfd0bec14b3a20b56bd2591b1fd1bc57247 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Wed, 30 Oct 2024 13:29:29 -0700 Subject: [PATCH] rm get-errors-for helper and companion transform. --- .../addon/helpers/get-errors-for.js | 16 ---- .../app/helpers/get-errors-for.js | 1 - packages/ilios-common/index.js | 2 - .../lib/get-errors-for-transform.js | 73 ------------------- .../helpers/get-errors-for-test.js | 38 ---------- 5 files changed, 130 deletions(-) delete mode 100644 packages/ilios-common/addon/helpers/get-errors-for.js delete mode 100644 packages/ilios-common/app/helpers/get-errors-for.js delete mode 100644 packages/ilios-common/lib/get-errors-for-transform.js delete mode 100644 packages/test-app/tests/integration/helpers/get-errors-for-test.js diff --git a/packages/ilios-common/addon/helpers/get-errors-for.js b/packages/ilios-common/addon/helpers/get-errors-for.js deleted file mode 100644 index b3d00b3545..0000000000 --- a/packages/ilios-common/addon/helpers/get-errors-for.js +++ /dev/null @@ -1,16 +0,0 @@ -import { tracked } from '@glimmer/tracking'; -import { Resource } from 'ember-could-get-used-to-this'; -export default class GetErrorsFor extends Resource { - @tracked data = []; - - get value() { - return this.data; - } - - async setup() { - const caller = this.args.positional[0]; - const prop = this.args.positional[1]; - - this.data = await caller.getErrorsFor(prop); - } -} diff --git a/packages/ilios-common/app/helpers/get-errors-for.js b/packages/ilios-common/app/helpers/get-errors-for.js deleted file mode 100644 index f0e3b6a291..0000000000 --- a/packages/ilios-common/app/helpers/get-errors-for.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ilios-common/helpers/get-errors-for'; diff --git a/packages/ilios-common/index.js b/packages/ilios-common/index.js index 6e9932ef8e..457982dd43 100644 --- a/packages/ilios-common/index.js +++ b/packages/ilios-common/index.js @@ -4,7 +4,6 @@ const Funnel = require('broccoli-funnel'); const MergeTrees = require('broccoli-merge-trees'); const path = require('path'); const HasErrorForTransform = require('./lib/has-error-for-transform'); -const GetErrorsForTransform = require('./lib/get-errors-for-transform'); module.exports = { name: require('./package').name, @@ -40,7 +39,6 @@ module.exports = { setupPreprocessorRegistry: function (type, registry) { registry.add('htmlbars-ast-plugin', HasErrorForTransform.instantiate()); - registry.add('htmlbars-ast-plugin', GetErrorsForTransform.instantiate()); }, treeForApp(appTree) { diff --git a/packages/ilios-common/lib/get-errors-for-transform.js b/packages/ilios-common/lib/get-errors-for-transform.js deleted file mode 100644 index aea6c54cb1..0000000000 --- a/packages/ilios-common/lib/get-errors-for-transform.js +++ /dev/null @@ -1,73 +0,0 @@ -/* eslint-env node */ -'use strict'; - -/* - ```hbs - {{get-errors-for this.bar}} - ``` - - becomes - - ```hbs - {{get-errors-for this "bar"}} - ``` -*/ -module.exports = class GetErrorsForTransform { - constructor(env, options) { - this.syntax = env.syntax; - this.builders = env.syntax.builders; - this.options = options; - this.visitor = this.buildVisitor(); - } - - static instantiate() { - return { - name: 'ilios-common-get-errors-for-transform', - plugin: (env) => new this(env), - parallelBabel: { - requireFile: __filename, - buildUsing: 'instantiate', - params: {}, - }, - baseDir() { - return `${__dirname}/..`; - }, - }; - } - - buildVisitor() { - return { - SubExpression: (node) => this.transformNode(node), - MustacheStatement: (node) => this.transformNode(node), - }; - } - - transformNode(node) { - if (node.path.type === 'PathExpression' && node.path.original === 'get-errors-for') { - if (!node.params[0] || node.params[0].type !== 'PathExpression') { - throw new Error( - 'the (get-errors-for) helper requires a path to be passed in as its first parameter, received: ' + - node.params[0], - ); - } - - if (node.params.length === 1) { - const path = node.params.shift(); - const splitPoint = path.original.lastIndexOf('.'); - const key = path.original.substr(splitPoint + 1); - const targetName = splitPoint === -1 ? 'this' : path.original.substr(0, splitPoint); - - let target; - - if (targetName[0] === '@') { - target = this.builders.path(targetName.slice(1)); - target.data = true; - } else { - target = this.builders.path(targetName); - } - - node.params.unshift(target, this.builders.string(key)); - } - } - } -}; diff --git a/packages/test-app/tests/integration/helpers/get-errors-for-test.js b/packages/test-app/tests/integration/helpers/get-errors-for-test.js deleted file mode 100644 index 1b349a19fc..0000000000 --- a/packages/test-app/tests/integration/helpers/get-errors-for-test.js +++ /dev/null @@ -1,38 +0,0 @@ -import { module, test } from 'qunit'; -import { setupRenderingTest } from 'test-app/tests/helpers'; -import { render } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; - -module('Integration | Helper | get-errors-for', function (hooks) { - setupRenderingTest(hooks); - - test('it calls errorFor', async function (assert) { - assert.expect(2); - const obj = { - getErrorsFor(what) { - assert.strictEqual(what, 'test'); - return ['foo']; - }, - }; - this.set('obj', obj); - - await render(hbs`{{get-errors-for this.obj 'test'}}`); - - assert.dom(this.element).hasText('foo'); - }); - - test('it transforms', async function (assert) { - assert.expect(2); - const obj = { - getErrorsFor(what) { - assert.strictEqual(what, 'test'); - return ['foo']; - }, - }; - this.set('obj', obj); - - await render(hbs`{{get-errors-for this.obj.test}}`); - - assert.dom(this.element).hasText('foo'); - }); -});