diff --git a/app/javascript/packages/decorators/index.ts b/app/javascript/packages/decorators/index.ts deleted file mode 100644 index e784b1ac9d3..00000000000 --- a/app/javascript/packages/decorators/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { once } from './once'; diff --git a/app/javascript/packages/decorators/once.spec.ts b/app/javascript/packages/decorators/once.spec.ts deleted file mode 100644 index 2a5caf55141..00000000000 --- a/app/javascript/packages/decorators/once.spec.ts +++ /dev/null @@ -1,106 +0,0 @@ -import sinon from 'sinon'; -import { once } from './once'; - -describe('once', () => { - let spy: sinon.SinonSpy; - - beforeEach(() => { - spy = sinon.spy(); - }); - - context('getter', () => { - class Example { - expectedResult?: any; - - constructor(expectedResult?: any) { - this.expectedResult = expectedResult; - } - - @once() - get foo() { - spy(); - return this.expectedResult; - } - } - - it('returns the value of the original function', () => { - const example = new Example(); - const result = example.foo; - - expect(result).to.equal(example.expectedResult); - }); - - it('returns the value of the original function, once', () => { - const example = new Example(); - const result1 = example.foo; - const result2 = example.foo; - - expect(result1).to.equal(example.expectedResult); - expect(result2).to.equal(example.expectedResult); - expect(spy).to.have.been.calledOnce(); - }); - - it('returns the value of the original function, once per instance', () => { - const example1 = new Example(1); - const result1 = example1.foo; - const result2 = example1.foo; - const example2 = new Example(2); - const result3 = example2.foo; - const result4 = example2.foo; - - expect(result1).to.equal(example1.expectedResult); - expect(result2).to.equal(example1.expectedResult); - expect(result3).to.equal(example2.expectedResult); - expect(result4).to.equal(example2.expectedResult); - expect(spy).to.have.been.calledTwice(); - }); - }); - - context('function', () => { - class Example { - expectedResult?: any; - - constructor(expectedResult?: any) { - this.expectedResult = expectedResult; - } - - @once() - getFoo() { - spy(); - return this.expectedResult; - } - } - - it('returns the value of the original function', () => { - const example = new Example(); - const result = example.getFoo(); - - expect(result).to.equal(example.expectedResult); - }); - - it('returns the value of the original function, once', () => { - const example = new Example(); - const result1 = example.getFoo(); - const result2 = example.getFoo(); - - expect(result1).to.equal(example.expectedResult); - expect(result2).to.equal(example.expectedResult); - expect(spy).to.have.been.calledOnce(); - }); - - it('returns the value of the original function, once per instance', () => { - const example1 = new Example(1); - const result1 = example1.getFoo(); - const result2 = example1.getFoo(); - const example2 = new Example(2); - const result3 = example2.getFoo(); - const result4 = example2.getFoo(); - - expect(result1).to.equal(example1.expectedResult); - expect(result2).to.equal(example1.expectedResult); - expect(result3).to.equal(example2.expectedResult); - expect(result4).to.equal(example2.expectedResult); - expect(spy).to.have.been.calledTwice(); - }); - }); -}); diff --git a/app/javascript/packages/decorators/once.ts b/app/javascript/packages/decorators/once.ts deleted file mode 100644 index a5fee066961..00000000000 --- a/app/javascript/packages/decorators/once.ts +++ /dev/null @@ -1,20 +0,0 @@ -export const once = - (): MethodDecorator => - (_target, propertyKey, descriptor) => { - const { value, get } = descriptor; - if (typeof value === 'function') { - descriptor.value = function () { - const result = value.call(this) as T; - Object.defineProperty(this, propertyKey, { value: () => result }); - return result; - }; - } else if (get) { - descriptor.get = function () { - const result = get.call(this) as T; - Object.defineProperty(this, propertyKey, { value: result }); - return result; - }; - } - - return descriptor; - }; diff --git a/app/javascript/packages/decorators/package.json b/app/javascript/packages/decorators/package.json deleted file mode 100644 index a9d64aefc66..00000000000 --- a/app/javascript/packages/decorators/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@18f/identity-decorators", - "private": true, - "version": "1.0.0" -} diff --git a/app/javascript/packages/form-link/form-link-element.ts b/app/javascript/packages/form-link/form-link-element.ts index b6b425f9198..0e59ab55697 100644 --- a/app/javascript/packages/form-link/form-link-element.ts +++ b/app/javascript/packages/form-link/form-link-element.ts @@ -1,16 +1,12 @@ -import { once } from '@18f/identity-decorators'; - class FormLinkElement extends HTMLElement { connectedCallback() { this.link.addEventListener('click', this.submit); } - @once() get form(): HTMLFormElement { return this.querySelector('form')!; } - @once() get link(): HTMLAnchorElement { return this.querySelector('a')!; } diff --git a/babel.config.js b/babel.config.js index 06b4afcc909..35c888c385b 100644 --- a/babel.config.js +++ b/babel.config.js @@ -18,7 +18,6 @@ module.exports = (api) => { ], ], plugins: [ - ['@babel/plugin-proposal-decorators', { version: 'legacy' }], [ 'polyfill-corejs3', { diff --git a/package.json b/package.json index b5bfba8e247..62ecc844f87 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ }, "dependencies": { "@babel/core": "^7.20.7", - "@babel/plugin-proposal-decorators": "^7.17.2", "@babel/preset-env": "^7.15.6", "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.16.7", diff --git a/scripts/validate-workspaces.js b/scripts/validate-workspaces.js index 2886a48a314..85ce5b71906 100755 --- a/scripts/validate-workspaces.js +++ b/scripts/validate-workspaces.js @@ -139,7 +139,6 @@ const EXCEPTIONS = { checkHaveDocumentation: [ 'app/javascript/packages/assets/package.json', 'app/javascript/packages/config/package.json', - 'app/javascript/packages/decorators/package.json', 'app/javascript/packages/device/package.json', 'app/javascript/packages/document-capture/package.json', 'app/javascript/packages/document-capture-polling/package.json', diff --git a/tsconfig.json b/tsconfig.json index 3e3a130dcea..54510067dec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,6 @@ "strictNullChecks": true, "jsx": "react-jsx", "esModuleInterop": true, - "experimentalDecorators": true, "resolveJsonModule": true, "moduleResolution": "node", "module": "ESNext", diff --git a/yarn.lock b/yarn.lock index a85288c398c..68ec4a24eaf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -78,7 +78,7 @@ lru-cache "^5.1.1" semver "^6.3.0" -"@babel/helper-create-class-features-plugin@^7.14.5", "@babel/helper-create-class-features-plugin@^7.15.4", "@babel/helper-create-class-features-plugin@^7.16.7", "@babel/helper-create-class-features-plugin@^7.17.1": +"@babel/helper-create-class-features-plugin@^7.14.5", "@babel/helper-create-class-features-plugin@^7.15.4", "@babel/helper-create-class-features-plugin@^7.16.7": version "7.17.6" resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.17.6.tgz#3778c1ed09a7f3e65e6d6e0f6fbfcc53809d92c9" integrity sha512-SogLLSxXm2OkBbSsHZMM4tUi8fUzjs63AT/d0YQIzr6GSd8Hxsbk2KYDX0k0DweAzGMj/YWeiCsorIdtdcW8Eg== @@ -319,17 +319,6 @@ "@babel/helper-plugin-utils" "^7.14.5" "@babel/plugin-syntax-class-static-block" "^7.14.5" -"@babel/plugin-proposal-decorators@^7.17.2": - version "7.17.2" - resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.17.2.tgz#c36372ddfe0360cac1ee331a238310bddca11493" - integrity sha512-WH8Z95CwTq/W8rFbMqb9p3hicpt4RX4f0K659ax2VHxgOyT6qQmUaEVEjIh4WR9Eh9NymkVn5vwsrE68fAQNUw== - dependencies: - "@babel/helper-create-class-features-plugin" "^7.17.1" - "@babel/helper-plugin-utils" "^7.16.7" - "@babel/helper-replace-supers" "^7.16.7" - "@babel/plugin-syntax-decorators" "^7.17.0" - charcodes "^0.2.0" - "@babel/plugin-proposal-dynamic-import@^7.14.5": version "7.14.5" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.14.5.tgz#0c6617df461c0c1f8fff3b47cd59772360101d2c" @@ -453,13 +442,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.14.5" -"@babel/plugin-syntax-decorators@^7.17.0": - version "7.17.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.17.0.tgz#a2be3b2c9fe7d78bd4994e790896bc411e2f166d" - integrity sha512-qWe85yCXsvDEluNP0OyeQjH63DlhAR3W7K9BxxU1MvbDb48tgBG+Ao6IJJ6smPDrrVzSQZrbF6donpkFBMcs3A== - dependencies: - "@babel/helper-plugin-utils" "^7.16.7" - "@babel/plugin-syntax-dynamic-import@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.3.tgz#62bf98b2da3cd21d626154fc96ee5b3cb68eacb3" @@ -2346,11 +2328,6 @@ chalk@^4.0, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1: ansi-styles "^4.1.0" supports-color "^7.1.0" -charcodes@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/charcodes/-/charcodes-0.2.0.tgz#5208d327e6cc05f99eb80ffc814707572d1f14e4" - integrity sha512-Y4kiDb+AM4Ecy58YkuZrrSRJBDQdQ2L+NyS1vHHFtNtUjgutcZfx3yp1dAONI/oPaPmyGfCLx5CxL+zauIMyKQ== - chardet@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"