diff --git a/packages/ember-template-compiler/lib/public-api.ts b/packages/ember-template-compiler/lib/public-api.ts index 923bcef2101..c2afc1b16a4 100644 --- a/packages/ember-template-compiler/lib/public-api.ts +++ b/packages/ember-template-compiler/lib/public-api.ts @@ -1,5 +1,3 @@ -export { default as _Ember } from 'ember'; - import VERSION from 'ember/version'; import * as _GlimmerSyntax from '@glimmer/syntax'; diff --git a/packages/ember-testing/tests/reexports_test.js b/packages/ember-testing/tests/reexports_test.js deleted file mode 100644 index 3ed8273e389..00000000000 --- a/packages/ember-testing/tests/reexports_test.js +++ /dev/null @@ -1,36 +0,0 @@ -import Ember from 'ember'; -import { confirmExport, testUnless } from 'internal-test-helpers'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; -import * as emberTesting from 'ember-testing'; -import { DEPRECATIONS } from '@ember/-internals/deprecations'; - -class ReexportsTestCase extends AbstractTestCase {} - -[ - // ember-testing - ['Test', 'ember-testing'], - ['Test.Adapter', 'ember-testing', 'Adapter'], - ['Test.QUnitAdapter', 'ember-testing', 'QUnitAdapter'], - ['setupForTesting', 'ember-testing'], -].forEach((reexport) => { - let [path, moduleId, exportName] = reexport; - - // default path === exportName if none present - if (!exportName) { - exportName = path; - } - - ReexportsTestCase.prototype[ - `${testUnless( - DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path).isRemoved - )} Ember.${path} exports correctly` - ] = function (assert) { - expectDeprecation( - /'ember' barrel file is deprecated/, - DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path || exportName).isEnabled - ); - confirmExport(Ember, assert, path, moduleId, exportName, emberTesting); - }; -}); - -moduleFor('ember-testing reexports', ReexportsTestCase); diff --git a/packages/ember/barrel.ts b/packages/ember/barrel.ts deleted file mode 100644 index e4ee87a0676..00000000000 --- a/packages/ember/barrel.ts +++ /dev/null @@ -1,682 +0,0 @@ -/** -@module ember -*/ - -import { getENV, getLookup, setLookup } from '@ember/-internals/environment'; -import * as utils from '@ember/-internals/utils'; -import { - Registry as InternalRegistry, - Container as InternalContainer, -} from '@ember/-internals/container'; -import * as instrumentation from '@ember/instrumentation'; -import { meta as internalMeta } from '@ember/-internals/meta'; -import * as metal from '@ember/-internals/metal'; -import { FEATURES as EmberFEATURES, isEnabled } from '@ember/canary-features'; -import * as EmberDebug from '@ember/debug'; -import { assert as emberAssert, captureRenderTree } from '@ember/debug'; -import Backburner from 'backburner.js'; -import EmberController, { inject as injectController } from '@ember/controller'; -import EmberService, { service } from '@ember/service'; - -import EmberObject, { - action, - computed as emberComputed, - defineProperty as emberDefineProperty, - notifyPropertyChange as emberNotifyPropertyChange, - observer as emberObserver, - get as emberGet, - getProperties as emberGetProperties, - set as emberSet, - setProperties as emberSetProperties, - trySet as emberTrySet, -} from '@ember/object'; -import { cacheFor as emberCacheFor } from '@ember/object/-internals'; -import { dependentKeyCompat } from '@ember/object/compat'; -import EmberComputedProperty, { - expandProperties as emberExpandProperties, -} from '@ember/object/computed'; -import { - addListener as emberAddListener, - removeListener as emberRemoveListener, - sendEvent as emberSendEvent, -} from '@ember/object/events'; - -import { RSVP as _RSVP } from '@ember/-internals/runtime'; -import { - componentCapabilities, - modifierCapabilities, - setComponentManager, - getTemplates, - setTemplates, - template, - isSerializationFirstNode, - type TemplatesRegistry, -} from '@ember/-internals/glimmer'; -import Version from './version'; -import * as views from '@ember/-internals/views'; -import EmberContainerDebugAdapter from '@ember/debug/container-debug-adapter'; -import EmberDataAdapter from '@ember/debug/data-adapter'; -import { run as emberRun } from '@ember/runloop'; -import { getOnerror, setOnerror } from '@ember/-internals/error-handling'; -import { isArray as emberIsArray, makeArray as emberMakeArray } from '@ember/array'; -import EmberApplication, { - getOwner as applicationGetOwner, - setOwner as applicationSetOwner, - onLoad as applicationOnLoad, - runLoadHooks as applicationRunLoadHooks, -} from '@ember/application'; -import EmberApplicationInstance from '@ember/application/instance'; -import EmberNamespace from '@ember/application/namespace'; -import EmberComponent, { Input as EmberInput } from '@ember/component'; -import EmberHelper from '@ember/component/helper'; -import EmberEngine from '@ember/engine'; -import EmberEngineInstance from '@ember/engine/instance'; -import EmberCoreObject from '@ember/object/core'; -import EmberMixin, { mixin as emberMixin } from '@ember/object/mixin'; -import { - addObserver as emberAddObserver, - removeObserver as emberRemoveObserver, -} from '@ember/object/observers'; -import EmberHashLocation from '@ember/routing/hash-location'; -import EmberHistoryLocation from '@ember/routing/history-location'; -import EmberNoneLocation from '@ember/routing/none-location'; -import EmberRoute from '@ember/routing/route'; -import EmberRouter from '@ember/routing/router'; -import { - controllerFor as emberControllerFor, - generateController as emberGenerateController, - generateControllerFactory as emberGenerateControllerFactory, - DSL as EmberRouterDSL, -} from '@ember/routing/-internals'; -import { - isNone as emberIsNone, - isBlank as emberIsBlank, - isEmpty as emberIsEmpty, - isPresent as emberIsPresent, - isEqual as emberIsEqual, - typeOf as emberTypeOf, - compare as emberCompare, -} from '@ember/utils'; - -import * as glimmerRuntime from '@glimmer/runtime'; - -import { - helperCapabilities, - setModifierManager, - setComponentTemplate, - getComponentTemplate, - setHelperManager, -} from '@glimmer/manager'; - -import { - assertDestroyablesDestroyed, - associateDestroyableChild, - destroy as emberDestroy, - enableDestroyableTracking, - isDestroying, - isDestroyed, - registerDestructor, - unregisterDestructor, -} from '@ember/destroyable'; - -import type { precompile, compile } from 'ember-template-compiler'; -import { _impl as EmberTestingImpl } from '@ember/test'; -import * as templateCompilation from '@ember/template-compilation'; - -// eslint-disable-next-line @typescript-eslint/no-namespace -namespace Ember { - export const isNamespace = true; - - export function toString() { - return 'Ember'; - } - - // ****@ember/-internals/container**** - export const Container = InternalContainer; - export type Container = InternalContainer; - export const Registry = InternalRegistry; - export type Registry = InternalRegistry; - - // ****@ember/-internals/glimmer**** - // Partially re-exported from @glimmer/manager - export const _setComponentManager = setComponentManager; - export const _componentManagerCapabilities = componentCapabilities; - export const _modifierManagerCapabilities = modifierCapabilities; - - // ****@ember/-internals/meta**** - export const meta = internalMeta; - - // ****@ember/-internals/metal**** - export const _createCache = metal.createCache; // Also @glimmer/validator - export const _cacheGetValue = metal.getValue; // Also @glimmer/validator - export const _cacheIsConst = metal.isConst; // Also @glimmer/validator - export const _descriptor = metal.nativeDescDecorator; - export const _getPath = metal._getPath; - export const _setClassicDecorator = metal.setClassicDecorator; - export const _tracked = metal.tracked; // Also exported from @glimmer/tracking - export const beginPropertyChanges = metal.beginPropertyChanges; - export const changeProperties = metal.changeProperties; - export const endPropertyChanges = metal.endPropertyChanges; - export const hasListeners = metal.hasListeners; - export const libraries = metal.libraries; - - // ****@ember/-internals/view**** - export const ComponentLookup = views.ComponentLookup; - export const EventDispatcher = views.EventDispatcher; - - // ****@ember/-internals/utils**** - export const _Cache = utils.Cache; - export const GUID_KEY = utils.GUID_KEY; - export const canInvoke = utils.canInvoke; - export const generateGuid = utils.generateGuid; - export const guidFor = utils.guidFor; - export const uuid = utils.uuid; - export const wrap = utils.wrap; - - // ****@ember/application**** - export const getOwner = applicationGetOwner; - export const onLoad = applicationOnLoad; - export const runLoadHooks = applicationRunLoadHooks; - export const setOwner = applicationSetOwner; - export const Application = EmberApplication; - export type Application = EmberApplication; - - // ****@ember/application/instance**** - export const ApplicationInstance = EmberApplicationInstance; - export type ApplicationInstance = EmberApplicationInstance; - - // // ****@ember/application/namespace**** - export const Namespace = EmberNamespace; - export type Namespace = EmberNamespace; - - // ****@ember/array**** - export const isArray = emberIsArray; - export const makeArray = emberMakeArray; - - // ****@ember/canary-features**** - export const FEATURES = { isEnabled, ...EmberFEATURES }; - - // ****@ember/component**** - export const _Input = EmberInput; - export const Component = EmberComponent; - export type Component = EmberComponent; - - // // ****@ember/component/helper**** - export const Helper = EmberHelper; - export type Helper = EmberHelper; - - // ****@ember/controller**** - export const Controller = EmberController; - export type Controller = EmberController; - - // ****@ember/debug**** - export const _captureRenderTree = captureRenderTree; - export const assert = EmberDebug.assert; - export const warn = EmberDebug.warn; - export const debug = EmberDebug.debug; - export const deprecate = EmberDebug.deprecate; - export const deprecateFunc = EmberDebug.deprecateFunc; - export const runInDebug = EmberDebug.runInDebug; - export const inspect = EmberDebug.inspect; - - export const Debug = { - registerDeprecationHandler: EmberDebug.registerDeprecationHandler, - registerWarnHandler: EmberDebug.registerWarnHandler, - // ****@ember/-internals/metal**** - isComputed: metal.isComputed, - }; - - // ****@ember/debug/container-debug-adapter**** - export const ContainerDebugAdapter = EmberContainerDebugAdapter; - export type ContainerDebugAdapter = EmberContainerDebugAdapter; - - // ****@ember/debug/data-adapter**** - export const DataAdapter = EmberDataAdapter; - export type DataAdapter = EmberDataAdapter; - - // ****@ember/destroyable**** - export const _assertDestroyablesDestroyed = assertDestroyablesDestroyed; - export const _associateDestroyableChild = associateDestroyableChild; - export const _enableDestroyableTracking = enableDestroyableTracking; - export const _isDestroying = isDestroying; - export const _isDestroyed = isDestroyed; - export const _registerDestructor = registerDestructor; - export const _unregisterDestructor = unregisterDestructor; - export const destroy = emberDestroy; - - // ****@ember/engine**** - export const Engine = EmberEngine; - export type Engine = EmberEngine; - - // ****@ember/engine/instance**** - export const EngineInstance = EmberEngineInstance; - export type EngineInstance = EmberEngineInstance; - - // ****@ember/instrumentation**** - /** @private */ - export const instrument = instrumentation.instrument; - /** @private */ - export const subscribe = instrumentation.subscribe; - - /** @private */ - export const Instrumentation = { - instrument: instrumentation.instrument, - subscribe: instrumentation.subscribe, - unsubscribe: instrumentation.unsubscribe, - reset: instrumentation.reset, - }; - - // ****@ember/object**** - export const Object = EmberObject; - export type Object = EmberObject; - export const _action = action; - export const computed = emberComputed; - export const defineProperty = emberDefineProperty; - export const get = emberGet; - export const getProperties = emberGetProperties; - export const notifyPropertyChange = emberNotifyPropertyChange; - export const observer = emberObserver; - export const set = emberSet; - export const trySet = emberTrySet; - export const setProperties = emberSetProperties; - - // ****@ember/object/-internals**** - export const cacheFor = emberCacheFor; - - // ****@ember/object/compat**** - export const _dependentKeyCompat = dependentKeyCompat; - - // ****@ember/object/computed**** - export const ComputedProperty = EmberComputedProperty; - export type ComputedProperty = EmberComputedProperty; - export const expandProperties = emberExpandProperties; - - // ****@ember/object/core**** - export const CoreObject = EmberCoreObject; - export type CoreObject = EmberCoreObject; - - // ****@ember/object/events**** - export const addListener = emberAddListener; - export const removeListener = emberRemoveListener; - export const sendEvent = emberSendEvent; - - // ****@ember/object/mixin**** - export const Mixin = EmberMixin; - export type Mixin = EmberMixin; - export const mixin = emberMixin; - - // ****@ember/object/observers**** - export const addObserver = emberAddObserver; - export const removeObserver = emberRemoveObserver; - - // ****@ember/routing/-internals**** - export const RouterDSL = EmberRouterDSL; - export type RouterDSL = EmberRouterDSL; - export const controllerFor = emberControllerFor; - export const generateController = emberGenerateController; - export const generateControllerFactory = emberGenerateControllerFactory; - - // ****@ember/routing/hash-location**** - export const HashLocation = EmberHashLocation; - export type HashLocation = EmberHashLocation; - - // ****@ember/routing/history-location**** - export const HistoryLocation = EmberHistoryLocation; - export type HistoryLocation = EmberHistoryLocation; - - // ****@ember/routing/none-location**** - export const NoneLocation = EmberNoneLocation; - export type NoneLocation = EmberNoneLocation; - - // ****@ember/routing/route**** - export const Route = EmberRoute; - export type Route = EmberRoute; - - // ****@ember/routing/router**** - export const Router = EmberRouter; - export type Router = EmberRouter; - - // // ****@ember/runloop**** - export const run = emberRun; - - // // ****@ember/service**** - export const Service = EmberService; - export type Service = EmberService; - - // ****@ember/utils**** - export const compare = emberCompare; - export const isBlank = emberIsBlank; - export const isEmpty = emberIsEmpty; - export const isEqual = emberIsEqual; - export const isNone = emberIsNone; - export const isPresent = emberIsPresent; - export const typeOf = emberTypeOf; - - // ****@ember/version**** - /** - The semantic version - - @property VERSION - @type String - @public - */ - export const VERSION = Version; - - export const ViewUtils = { - // ****@ember/-internals/views**** - getChildViews: views.getChildViews, - getElementView: views.getElementView, - getRootViews: views.getRootViews, - getViewBounds: views.getViewBounds, - getViewBoundingClientRect: views.getViewBoundingClientRect, - getViewClientRects: views.getViewClientRects, - getViewElement: views.getViewElement, - isSimpleClick: views.isSimpleClick, - - // ****@ember/-internals/glimmer**** - isSerializationFirstNode, - }; - - // ****@glimmer/manager**** - export const _getComponentTemplate = getComponentTemplate; - export const _helperManagerCapabilities = helperCapabilities; - export const _setComponentTemplate = setComponentTemplate; - export const _setHelperManager = setHelperManager; - export const _setModifierManager = setModifierManager; - - // ****@glimmer/runtime**** - export const _templateOnlyComponent = glimmerRuntime.templateOnlyComponent; - export const _invokeHelper = glimmerRuntime.invokeHelper; - export const _hash = glimmerRuntime.hash; - export const _array = glimmerRuntime.array; - export const _concat = glimmerRuntime.concat; - export const _get = glimmerRuntime.get; - export const _on = glimmerRuntime.on; - export const _fn = glimmerRuntime.fn; - - // Backburner - export const _Backburner = Backburner; - export type _Backburner = Backburner; - - // // ****@ember/controller, @ember/service**** - /** - Namespace for injection helper methods. - - @class inject - @namespace Ember - @static - @public - */ - export function inject() { - // uses `globalThis` to avoid clobbering with `Ember.Object` in TS namespace - emberAssert( - `Injected properties must be created through helpers, see '${globalThis.Object.keys(inject) - .map((k) => `'inject.${k}'`) - .join(' or ')}'` - ); - } - // ****@ember/controller**** - inject.controller = injectController; - // ****@ember/service**** - inject.service = service; - - export const __loader = { - get require() { - return (globalThis as any).require; - }, - get define() { - return (globalThis as any).define; - }, - get registry() { - let g = globalThis as any; - return g.requirejs?.entries ?? g.require.entries; - }, - }; - - // ------------------------------------------------------------------------ // - // These properties are assigned to the namespace with getters (and, in some - // cases setters) with `Object.defineProperty` below. - // ------------------------------------------------------------------------ // - - export declare const ENV: Readonly; - - // ****@ember/-internals/environment**** - export declare let lookup: Record; - - /** - A function may be assigned to `Ember.onerror` to be called when Ember - internals encounter an error. This is useful for specialized error handling - and reporting code. - - ```javascript - - Ember.onerror = function(error) { - const payload = { - stack: error.stack, - otherInformation: 'whatever app state you want to provide' - }; - - fetch('/report-error', { - method: 'POST', - body: JSON.stringify(payload) - }); - }; - ``` - - Internally, `Ember.onerror` is used as Backburner's error handler. - - @event onerror - @for Ember - @param {Error} error the error object - @public - */ - // ****@ember/-internals/error-handling**** - export declare let onerror: ((error: Error) => unknown) | undefined; - - export declare let testing: boolean; - - /** - Whether searching on the global for new Namespace instances is enabled. - - This is only exported here as to not break any addons. Given the new - visit API, you will have issues if you treat this as a indicator of - booted. - - Internally this is only exposing a flag in Namespace. - - @property BOOTED - @for Ember - @type Boolean - @private - */ - export declare let BOOTED: boolean; - - /** - Global hash of shared templates. This will automatically be populated - by the build tools so that you can store your Handlebars templates in - separate files that get loaded into JavaScript at buildtime. - - @property TEMPLATES - @for Ember - @type Object - @private - */ - export declare let TEMPLATES: TemplatesRegistry; - - export declare let HTMLBars: EmberHTMLBars; - export declare let Handlebars: EmberHandlebars; - export declare let Test: - | (NonNullable['Test'] & { - Adapter: NonNullable['Adapter']; - QUnitAdapter: NonNullable['QUnitAdapter']; - }) - | undefined; - export declare let setupForTesting: - | NonNullable['setupForTesting'] - | undefined; -} - -// This syntax is not reliably implemented by TypeScript transpilers, but -// we need to re-export the`RSVP` *namespace* for type compatibility. -// To achieve this, we use a type-only `declare namespace` block to get the -// types to behave correctly, and separately set the `RSVP` property on the -// `Ember` object dynamically. (The types behave correctly because of -// namespace merging semantics.) -// eslint-disable-next-line @typescript-eslint/no-namespace -declare namespace Ember { - export import RSVP = _RSVP; -} - -Reflect.set(Ember, 'RSVP', _RSVP); - -interface EmberHandlebars { - template: typeof template; - // eslint-disable-next-line @typescript-eslint/no-empty-object-type - Utils: {}; - compile?: typeof compile; - precompile?: typeof precompile; -} - -interface EmberHTMLBars { - template: typeof template; - compile?: typeof compile; - precompile?: typeof precompile; -} - -Object.defineProperty(Ember, 'ENV', { - get: getENV, - enumerable: false, -}); - -Object.defineProperty(Ember, 'lookup', { - get: getLookup, - set: setLookup, - enumerable: false, -}); - -Object.defineProperty(Ember, 'onerror', { - get: getOnerror, - set: setOnerror, - enumerable: false, -}); - -Object.defineProperty(Ember, 'testing', { - get: EmberDebug.isTesting, - set: EmberDebug.setTesting, - enumerable: false, -}); - -Object.defineProperty(Ember, 'BOOTED', { - configurable: false, - enumerable: false, - get: metal.isNamespaceSearchDisabled, - set: metal.setNamespaceSearchDisabled, -}); - -Object.defineProperty(Ember, 'TEMPLATES', { - get: getTemplates, - set: setTemplates, - configurable: false, - enumerable: false, -}); - -Object.defineProperty(Ember, 'TEMPLATES', { - get: getTemplates, - set: setTemplates, - configurable: false, - enumerable: false, -}); - -// ****@ember/debug**** -Object.defineProperty(Ember, 'testing', { - get: EmberDebug.isTesting, - set: EmberDebug.setTesting, - enumerable: false, -}); - -applicationRunLoadHooks('Ember.Application', EmberApplication); - -let EmberHandlebars: EmberHandlebars = { - template, - Utils: {}, -}; - -let EmberHTMLBars: EmberHTMLBars = { - template, -}; - -function defineEmberTemplateCompilerLazyLoad(key: 'HTMLBars' | 'Handlebars') { - Object.defineProperty(Ember, key, { - configurable: true, - enumerable: true, - get() { - if (templateCompilation.__emberTemplateCompiler) { - EmberHTMLBars.precompile = EmberHandlebars.precompile = - templateCompilation.__emberTemplateCompiler.precompile; - EmberHTMLBars.compile = EmberHandlebars.compile = templateCompilation.compileTemplate; - - Object.defineProperty(Ember, 'HTMLBars', { - configurable: true, - writable: true, - enumerable: true, - value: EmberHTMLBars, - }); - Object.defineProperty(Ember, 'Handlebars', { - configurable: true, - writable: true, - enumerable: true, - value: EmberHandlebars, - }); - } - - return key === 'Handlebars' ? EmberHandlebars : EmberHTMLBars; - }, - }); -} - -defineEmberTemplateCompilerLazyLoad('HTMLBars'); -defineEmberTemplateCompilerLazyLoad('Handlebars'); - -// do this to ensure that Ember.Test is defined properly on the global -// if it is present. -function defineEmberTestingLazyLoad(key: 'Test' | 'setupForTesting') { - Object.defineProperty(Ember, key, { - configurable: true, - enumerable: true, - get() { - if (EmberTestingImpl) { - let { Test, Adapter, QUnitAdapter, setupForTesting } = EmberTestingImpl; - - // @ts-expect-error We should not do this - Test.Adapter = Adapter; - // @ts-expect-error We should not do this - Test.QUnitAdapter = QUnitAdapter; - - Object.defineProperty(Ember, 'Test', { - configurable: true, - writable: true, - enumerable: true, - value: Test, - }); - Object.defineProperty(Ember, 'setupForTesting', { - configurable: true, - writable: true, - enumerable: true, - value: setupForTesting, - }); - - return key === 'Test' ? Test : setupForTesting; - } - - return undefined; - }, - }); -} - -defineEmberTestingLazyLoad('Test'); -defineEmberTestingLazyLoad('setupForTesting'); - -// @ts-expect-error Per types, runLoadHooks requires a second parameter. Should we loosen types? -applicationRunLoadHooks('Ember'); - -export default Ember; diff --git a/packages/ember/index.ts b/packages/ember/index.ts index fece0ffddda..e69de29bb2d 100644 --- a/packages/ember/index.ts +++ b/packages/ember/index.ts @@ -1,26 +0,0 @@ -import { DEPRECATIONS, deprecateUntil } from '@ember/-internals/deprecations'; -import doNotUseThis from './barrel'; - -export default new Proxy(doNotUseThis, { - get(target, key, receiver) { - // We don't have symbol exports, so this is probably fine. - if (typeof key === 'string') { - deprecateUntil( - `importing ${key} from the 'ember' barrel file is deprecated.`, - DEPRECATIONS.DEPRECATE_IMPORT_EMBER(key) - ); - } - - return Reflect.get(target, key, receiver); - }, - getOwnPropertyDescriptor(target, key) { - if (typeof key === 'string') { - deprecateUntil( - `importing ${key} from the 'ember' barrel file is deprecated.`, - DEPRECATIONS.DEPRECATE_IMPORT_EMBER(key) - ); - } - - return Object.getOwnPropertyDescriptor(target, key); - }, -}) as typeof doNotUseThis; diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index 81f013259fa..9ee45c063d4 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -1,4 +1,3 @@ -import Ember from '../index'; import { FEATURES } from '@ember/canary-features'; import { AbstractTestCase, @@ -21,36 +20,9 @@ class ReExportTests extends AbstractTestCase { exportName = path; } - expectDeprecation( - /'ember' barrel file is deprecated/, - DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path || exportName).isEnabled - ); - confirmExport(Ember, assert, path, moduleId, exportName, mod); }); } - - [`${testUnless( - DEPRECATIONS.DEPRECATE_IMPORT_EMBER('FEATURES').isRemoved - )} Ember.FEATURES is exported`](assert) { - if (Object.keys(FEATURES).length === 0) { - assert.expect(0); - } - - for (let feature in FEATURES) { - expectDeprecation( - () => { - assert.equal( - Ember.FEATURES[feature], - FEATURES[feature], - 'Ember.FEATURES contains ${feature} with correct value' - ); - }, - /importing FEATURES from the 'ember' barrel file is deprecated/, - DEPRECATIONS.DEPRECATE_IMPORT_EMBER('FEATURES').isEnabled - ); - } - } } moduleFor('ember reexports', ReExportTests); diff --git a/packages/ember/type-tests/ember.test.ts b/packages/ember/type-tests/ember.test.ts deleted file mode 100644 index 8ff5bc0b446..00000000000 --- a/packages/ember/type-tests/ember.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Ember from 'ember'; - -import { expectTypeOf } from 'expect-type'; - -expectTypeOf(Ember.onerror).toEqualTypeOf<((error: Error) => unknown) | undefined>(); - -expectTypeOf(Ember.HTMLBars).toMatchTypeOf(); diff --git a/packages/internal-test-helpers/lib/confirm-export.ts b/packages/internal-test-helpers/lib/confirm-export.ts index 702cc9b8d94..07a450d5a42 100644 --- a/packages/internal-test-helpers/lib/confirm-export.ts +++ b/packages/internal-test-helpers/lib/confirm-export.ts @@ -14,49 +14,15 @@ function getDescriptor(obj: Record, path: string) { } export default function confirmExport( - Ember: Record, assert: QUnit['assert'], - path: string, + _path: string, moduleId: string, exportName: string | { value: unknown; get: string; set: string }, mod: any ) { - let desc: PropertyDescriptor | null | undefined; - - if (path !== null) { - desc = getDescriptor(Ember, path); - assert.ok(desc, `the ${path} property exists on the Ember global`); - } else { - desc = null; - } - - if (desc == null) { - assert.notEqual( - mod[exportName as string], - undefined, - `${moduleId}#${exportName} is not \`undefined\`` - ); - } else if (typeof exportName === 'string') { - let value = 'value' in desc ? desc.value : desc.get!.call(Ember); - // Access early so we still trigger deprecation - let actual = mod[exportName]; - // mod[exportName] has no name, but value has a name here. - // This could have something to do with how the proxy is working, - // but it's not all that important, as deprecate users will still have - // the same behavior, including the deprecation message - if (exportName !== 'deprecate') { - assert.equal(value, actual, `Ember.${path} is exported correctly`); - } - assert.notEqual(mod[exportName], undefined, `Ember.${path} is not \`undefined\``); - } else if ('value' in desc) { - assert.equal(desc.value, exportName.value, `Ember.${path} is exported correctly`); - } else { - assert.equal(desc.get, mod[exportName.get], `Ember.${path} getter is exported correctly`); - assert.notEqual(desc.get, undefined, `Ember.${path} getter is not undefined`); - - if (exportName.set) { - assert.equal(desc.set, mod[exportName.set], `Ember.${path} setter is exported correctly`); - assert.notEqual(desc.set, undefined, `Ember.${path} setter is not undefined`); - } - } + assert.notEqual( + mod[exportName as string], + undefined, + `${moduleId}#${exportName} is not \`undefined\`` + ); } diff --git a/type-tests/ember/application-instance.ts b/type-tests/ember/application-instance.ts deleted file mode 100644 index ecff4b7b087..00000000000 --- a/type-tests/ember/application-instance.ts +++ /dev/null @@ -1,29 +0,0 @@ -import ApplicationInstance from '@ember/application/instance'; - -const appInstance = ApplicationInstance.create(); -appInstance.register('some:injection', class Foo {}); - -appInstance.register('some:injection', class Foo {}, { - singleton: true, -}); - -appInstance.register('some:injection', class Foo {}, { - instantiate: false, -}); - -// just check basic registration, doesn't yet have to be a template -appInstance.register('templates:foo/bar', {}); - -appInstance.register('some:injection', class Foo {}, { - singleton: false, - instantiate: true, -}); - -appInstance.factoryFor('router:main'); -appInstance.lookup('route:basic'); - -appInstance.boot(); - -(async () => { - await appInstance.boot(); -})(); diff --git a/type-tests/ember/application.ts b/type-tests/ember/application.ts deleted file mode 100755 index 3f4aa047652..00000000000 --- a/type-tests/ember/application.ts +++ /dev/null @@ -1,46 +0,0 @@ -import EmberObject from '@ember/object'; -import Ember from 'ember'; - -const BaseApp = Ember.Application.extend({ - modulePrefix: 'my-app', -}); - -class Obj extends EmberObject.extend({ foo: 'bar' }) {} - -BaseApp.initializer({ - name: 'my-initializer', - initialize(app) { - app.register('foo:bar', Obj); - }, -}); - -BaseApp.instanceInitializer({ - name: 'my-instance-initializer', - initialize(app) { - (app.lookup('foo:bar') as Obj).get('foo'); - }, -}); - -const App1 = BaseApp.create({ - rootElement: '#app-one', - customEvents: { - paste: 'paste', - }, -}); - -const App2 = BaseApp.create({ - rootElement: '#app-two', - customEvents: { - mouseenter: null, - mouseleave: null, - }, -}); - -const App3 = BaseApp.create(); - -const App3Instance1 = App3.buildInstance(); - -// @ts-expect-error -const App3Instance2 = App3.buildInstance({ foo: 'bar' }); - -const App3Instance3 = App3.buildInstance({ mountPoint: 'somewhere', routable: true }); diff --git a/type-tests/ember/component.ts b/type-tests/ember/component.ts deleted file mode 100755 index 493645d31e2..00000000000 --- a/type-tests/ember/component.ts +++ /dev/null @@ -1,119 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -Ember.Component.extend({ - layout: 'my-layout', -}); - -const MyComponent = Ember.Component.extend(); -expectTypeOf(Ember.get(MyComponent, 'positionalParams')).toEqualTypeOf(); - -const component1 = Ember.Component.extend({ - actions: { - hello(name: string) { - console.log('Hello', name); - }, - }, -}); - -class AnotherComponent extends Ember.Component { - name = ''; - - hello(name: string) { - this.set('name', name); - this.name = name; - } -} - -Ember.Component.extend({ - tagName: 'em', -}); - -Ember.Component.extend({ - classNames: ['my-class', 'my-other-class'], -}); - -class Bindings extends Ember.Component { - classNameBindings = ['propertyA', 'propertyB']; - propertyA = 'from-a'; - - @Ember.computed() - get propertyB() { - if (!this.get('propertyA')) { - return 'from-b'; - } - } -} - -Ember.Component.extend({ - classNameBindings: ['hovered'], - hovered: true, -}); - -class Message extends Ember.Object { - empty = false; -} - -Ember.Component.extend({ - classNameBindings: ['messages.empty'], - messages: Message.create({ - empty: true, - }), -}); - -Ember.Component.extend({ - classNameBindings: ['isEnabled:enabled:disabled'], - isEnabled: true, -}); - -Ember.Component.extend({ - classNameBindings: ['isEnabled::disabled'], - isEnabled: true, -}); - -Ember.Component.extend({ - tagName: 'a', - attributeBindings: ['href'], - href: 'http://google.com', -}); - -Ember.Component.extend({ - tagName: 'a', - attributeBindings: ['url:href'], - url: 'http://google.com', -}); - -Ember.Component.extend({ - tagName: 'use', - attributeBindings: ['xlinkHref:xlink:href'], - xlinkHref: '#triangle', -}); - -Ember.Component.extend({ - tagName: 'input', - attributeBindings: ['disabled'], - disabled: false, -}); - -Ember.Component.extend({ - tagName: 'input', - attributeBindings: ['disabled'], - disabled: Ember.computed(() => { - return someLogic(); - }), -}); - -declare function someLogic(): boolean; - -Ember.Component.extend({ - tagName: 'form', - attributeBindings: ['novalidate'], - novalidate: null, -}); - -Ember.Component.extend({ - click(event: object) { - // will be called when an instance's - // rendered element is clicked - }, -}); diff --git a/type-tests/ember/computed.ts b/type-tests/ember/computed.ts deleted file mode 100755 index a2207e734a5..00000000000 --- a/type-tests/ember/computed.ts +++ /dev/null @@ -1,100 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -function customMacro(message: string) { - return Ember.computed(() => { - return [message, message]; - }); -} - -class Person extends Ember.Object { - firstName = ''; - lastName = ''; - age = 0; - - // Equivalent to a per-instance `defineProperty` call. - @Ember.computed() - get noArgs() { - return 'test'; - } - - @Ember.computed('firstName', 'lastName') - get fullName(): string { - return `${this.get('firstName')} ${this.get('lastName')}`; - } - - @(Ember.computed('fullName').readOnly()) - get fullNameReadonly() { - return this.get('fullName'); - } - - @Ember.computed('firstName', 'lastName') - get fullNameWritable(): string { - return this.get('fullName'); - } - - set fullNameWritable(value: string) { - const [first, last] = value.split(' '); - this.set('firstName', first); - this.set('lastName', last); - } - - @(Ember.computed().meta({ foo: 'bar' }).readOnly()) - get combinators() { - return this.get('firstName'); - } - - @customMacro('hi') - declare hiTwice: string[]; -} - -const person = Person.create({ - firstName: 'Fred', - lastName: 'Smith', - age: 29, -}); - -expectTypeOf(person.firstName).toEqualTypeOf(); -expectTypeOf(person.age).toEqualTypeOf(); -expectTypeOf(person.noArgs).toEqualTypeOf(); -expectTypeOf(person.fullName).toEqualTypeOf(); -expectTypeOf(person.fullNameReadonly).toEqualTypeOf(); -expectTypeOf(person.fullNameWritable).toEqualTypeOf(); -expectTypeOf(person.combinators).toEqualTypeOf(); - -expectTypeOf(person.get('firstName')).toEqualTypeOf(); -expectTypeOf(person.get('age')).toEqualTypeOf(); -expectTypeOf(person.get('noArgs')).toEqualTypeOf(); -expectTypeOf(person.get('fullName')).toEqualTypeOf(); -expectTypeOf(person.get('fullNameReadonly')).toEqualTypeOf(); -expectTypeOf(person.get('fullNameWritable')).toEqualTypeOf(); -expectTypeOf(person.get('combinators')).toEqualTypeOf(); - -expectTypeOf(person.getProperties('firstName', 'fullName', 'age')).toMatchTypeOf<{ - firstName: string; - fullName: string; - age: number; -}>(); - -const person2 = Person.create({ - fullName: 'Fred Smith', -}); - -expectTypeOf(person2.get('firstName')).toEqualTypeOf(); -expectTypeOf(person2.get('fullName')).toEqualTypeOf(); - -const person3 = Person.extend({ - firstName: 'Fred', - fullName: 'Fred Smith', -}).create(); - -expectTypeOf(person3.get('firstName')).toEqualTypeOf(); -expectTypeOf(person3.get('fullName')).toEqualTypeOf(); - -const person4 = Person.extend({ - firstName: Ember.computed(() => 'Fred'), - fullName: Ember.computed(() => 'Fred Smith'), -}).create(); - -expectTypeOf(person4.get('firstName')).toEqualTypeOf(); -expectTypeOf(person4.get('fullName')).toEqualTypeOf(); diff --git a/type-tests/ember/controller.ts b/type-tests/ember/controller.ts deleted file mode 100755 index 7e89a8d8334..00000000000 --- a/type-tests/ember/controller.ts +++ /dev/null @@ -1,11 +0,0 @@ -import Ember from 'ember'; - -class MyController extends Ember.Controller { - queryParams = ['category']; - category = null; - isExpanded = false; - - toggleBody() { - this.toggleProperty('isExpanded'); - } -} diff --git a/type-tests/ember/core-object.ts b/type-tests/ember/core-object.ts deleted file mode 100644 index 57fdb990321..00000000000 --- a/type-tests/ember/core-object.ts +++ /dev/null @@ -1,55 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -const { CoreObject } = Ember; - -/** Newable tests */ -const co1 = new CoreObject(); - -expectTypeOf(co1.isDestroyed).toBeBoolean(); -expectTypeOf(co1.isDestroying).toBeBoolean(); -expectTypeOf(co1.destroy()).toEqualTypeOf(); -expectTypeOf(co1.toString()).toBeString(); - -/** .create tests */ -const co2 = CoreObject.create(); -expectTypeOf(co2.isDestroyed).toBeBoolean(); -expectTypeOf(co2.isDestroying).toBeBoolean(); -expectTypeOf(co2.destroy()).toEqualTypeOf(); -expectTypeOf(co2.toString()).toBeString(); - -/** .create tests w/ initial instance data passed in */ -declare class CO3 extends CoreObject { - foo: string; - bar: number; -} -const co3 = CO3.create({ foo: '123', bar: 456 }); - -expectTypeOf(co3.foo).toBeString(); -expectTypeOf(co3.bar).toBeNumber(); - -/** .extend with a zero-argument .create() */ -class CO4 extends CO3 { - baz(): [string, number] { - return [this.foo, this.bar]; - } -} -const co4 = CO4.create(); - -expectTypeOf(co4.foo).toBeString(); -expectTypeOf(co4.bar).toBeNumber(); -expectTypeOf(co4.baz).toEqualTypeOf<() => [string, number]>(); - -/** .extend with inconsistent arguments passed into .create() */ -class CO5 extends CoreObject { - foo: string | boolean = 'hello'; - bar = 123; - baz() { - return [this.foo, this.bar]; - } -} -// @ts-expect-error -class05.create({ foo: 99 }); -expectTypeOf(CO5.create({ foo: true })).toEqualTypeOf(); -expectTypeOf(CO5.create({ foo: 'abc' })).toEqualTypeOf(); -expectTypeOf(CO5.create().foo).toEqualTypeOf(); diff --git a/type-tests/ember/create-negative.ts b/type-tests/ember/create-negative.ts deleted file mode 100644 index 86557265951..00000000000 --- a/type-tests/ember/create-negative.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Person } from './create'; - -// @ts-expect-error -Person.create({ firstName: 99 }); -// @ts-expect-error -Person.create({}, { firstName: 99 }); -// @ts-expect-error -Person.create({}, {}, { firstName: 99 }); diff --git a/type-tests/ember/create.ts b/type-tests/ember/create.ts deleted file mode 100755 index 5846fd2b037..00000000000 --- a/type-tests/ember/create.ts +++ /dev/null @@ -1,57 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -/** - * Zero-argument case - */ -const o = Ember.Object.create(); -// create returns an object -expectTypeOf(o).toBeObject(); -// object returned by create type-checks as an instance of Ember.Object -expectTypeOf(o.isDestroyed).toBeBoolean(); -expectTypeOf(o.isDestroying).toBeBoolean(); -expectTypeOf(o.get).toMatchTypeOf<(key: K) => Ember.Object[K]>(); - -/** - * One-argument case - */ -class O1 extends Ember.Object { - declare x: number; - declare y: string; - declare z: boolean; -} - -const o1 = O1.create({ x: 9, y: 'hello', z: false }); -expectTypeOf(o1.x).toBeNumber(); -expectTypeOf(o1.y).toBeString(); -expectTypeOf(o1.z).toBeBoolean(); - -class O2 extends Ember.Object { - declare a: number; - declare b: number; - declare c: number; -} -const obj = O2.create({ a: 1 }, { b: 2 }, { c: 3 }); -expectTypeOf(obj.b).toBeNumber(); -expectTypeOf(obj.a).toBeNumber(); -expectTypeOf(obj.c).toBeNumber(); - -export class Person extends Ember.Object { - declare firstName: string; - declare lastName: string; - declare age: number; - - @Ember.computed('firstName', 'lastName') - get fullName() { - return [this.firstName + this.lastName].join(' '); - } -} -const p = Person.create(); - -expectTypeOf(p.firstName).toBeString(); -expectTypeOf(p.fullName).toBeString(); -expectTypeOf(p.get('fullName')).toBeString(); - -Person.create({ firstName: 'string' }); -Person.create({}, { firstName: 'string' }); -Person.create({}, {}, { firstName: 'string' }); diff --git a/type-tests/ember/data-adapter.ts b/type-tests/ember/data-adapter.ts deleted file mode 100644 index a7e0096691c..00000000000 --- a/type-tests/ember/data-adapter.ts +++ /dev/null @@ -1,59 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -const da = Ember.DataAdapter.create(); - -const filters = da.getFilters(); -expectTypeOf(filters.includes({ name: 'foo', desc: 'bar' })).toBeBoolean(); -filters.includes({ name: 'lol', desc: 'wut' }); - -expectTypeOf(filters[0]?.name).toEqualTypeOf(); -expectTypeOf(filters[0]?.desc).toEqualTypeOf(); - -expectTypeOf( - da.watchModelTypes( - function added(wrappedTypes) { - wrappedTypes; - expectTypeOf(wrappedTypes[0]?.columns[0]?.desc).toEqualTypeOf(); - expectTypeOf(wrappedTypes[0]?.columns[0]?.name).toEqualTypeOf(); - expectTypeOf(wrappedTypes[0]?.count).toEqualTypeOf(); - expectTypeOf(wrappedTypes[0]?.name).toEqualTypeOf(); - }, - function updated(wrappedTypes) { - wrappedTypes; - expectTypeOf(wrappedTypes[0]?.columns[0]?.desc).toEqualTypeOf(); - expectTypeOf(wrappedTypes[0]?.columns[0]?.name).toEqualTypeOf(); - expectTypeOf(wrappedTypes[0]?.count).toEqualTypeOf(); - expectTypeOf(wrappedTypes[0]?.name).toEqualTypeOf(); - } - ) -).toEqualTypeOf<() => void>(); -// @ts-expect-error -da.watchModelTypes(() => {}); - -expectTypeOf( - da.watchRecords( - 'house', - function added(records) { - expectTypeOf(records[0]?.object).toBeUnknown(); - expectTypeOf(records[0]?.columnValues).toEqualTypeOf(); - }, - function updated(records) { - expectTypeOf(records[0]?.object).toEqualTypeOf(); - expectTypeOf(records[0]?.columnValues).toEqualTypeOf(); - }, - function removed(records) { - expectTypeOf(records[0]?.object).toEqualTypeOf(); - expectTypeOf(records[0]?.columnValues).toEqualTypeOf(); - } - ) -).toEqualTypeOf<() => void>(); -// @ts-expect-error -da.watchRecords(() => {}); - -expectTypeOf(da.acceptsModelName).toEqualTypeOf(); -expectTypeOf(da.containerDebugAdapter).toEqualTypeOf(); - -const ca: Ember.ContainerDebugAdapter = da.containerDebugAdapter; -expectTypeOf(ca.canCatalogEntriesByType('controller')).toEqualTypeOf(); -expectTypeOf(ca.catalogEntriesByType('controller')).toEqualTypeOf(); diff --git a/type-tests/ember/debug.ts b/type-tests/ember/debug.ts deleted file mode 100644 index 75ff474845c..00000000000 --- a/type-tests/ember/debug.ts +++ /dev/null @@ -1,127 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -const { - runInDebug, - warn, - debug, - Debug: { registerDeprecationHandler, registerWarnHandler }, -} = Ember; - -// Workaround for https://github.com/microsoft/TypeScript/issues/36931. -const assert: typeof Ember.assert = Ember.assert; - -/** - * @ember/debug tests - */ -// @ts-expect-error -runInDebug(); -expectTypeOf(runInDebug(() => console.log('Should not show up in prod'))).toBeVoid(); - -// Log a warning if we have more than 3 tomsters -const tomsterCount = 2; -warn('Too many tomsters!'); -expectTypeOf(warn('Too many tomsters!', { id: 'some-warning' })).toBeVoid(); -warn('Too many tomsters!', tomsterCount <= 3); -expectTypeOf(warn('Too many tomsters!', tomsterCount <= 3, { id: 'some-warning' })).toBeVoid(); -expectTypeOf( - warn('Too many tomsters!', tomsterCount <= 3, { - id: 'ember-debug.too-many-tomsters', - }) -).toBeVoid(); - -// @ts-expect-error -debug(); -expectTypeOf(debug('Too many tomsters!')).toBeVoid(); -// @ts-expect-error -debug('Too many tomsters!', 'foo'); - -// next is not called, so no warnings get the default behavior -// @ts-expect-error -registerWarnHandler(); -expectTypeOf(registerWarnHandler(() => {})).toBeVoid(); -expectTypeOf( - registerWarnHandler((message, options, next) => { - expectTypeOf(message).toEqualTypeOf(); - expectTypeOf(options).toEqualTypeOf<{ id: string } | undefined>(); - expectTypeOf(next).toEqualTypeOf< - (message: string, options?: { id: string } | undefined) => void - >(); - }) -).toBeVoid(); -expectTypeOf( - registerWarnHandler((message, options, next) => { - expectTypeOf(message).toEqualTypeOf(); - expectTypeOf(options).toEqualTypeOf<{ id: string } | undefined>(); - // @ts-expect-error - next(); - }) -).toBeVoid(); -expectTypeOf( - registerWarnHandler((message, options, next) => { - expectTypeOf(message).toEqualTypeOf(); - expectTypeOf(options).toEqualTypeOf<{ id: string } | undefined>(); - expectTypeOf(next(message)).toBeVoid(); - }) -).toBeVoid(); -expectTypeOf( - registerWarnHandler((message, options, next) => { - expectTypeOf(message).toEqualTypeOf(); - expectTypeOf(options).toEqualTypeOf<{ id: string } | undefined>(); - expectTypeOf(next(message, options)).toBeVoid(); - }) -).toBeVoid(); - -type ExpectedOptions = { - id: string; - until: string; - url?: string; - for: string; - since: { available: string } | { available: string; enabled: string }; -}; - -// next is not called, so no warnings get the default behavior -// @ts-expect-error -registerDeprecationHandler(); -expectTypeOf(registerDeprecationHandler(() => {})).toBeVoid(); -expectTypeOf( - registerDeprecationHandler((message, options, next) => { - expectTypeOf(message).toBeString(); - expectTypeOf(options).toEqualTypeOf(); - expectTypeOf(next).toEqualTypeOf< - (message: string, options?: ExpectedOptions | undefined) => void - >(); - }) -).toBeVoid(); -expectTypeOf( - registerDeprecationHandler((message, options, next) => { - expectTypeOf(message).toBeString(); - expectTypeOf(options).toEqualTypeOf(); - // @ts-expect-error - next(); - }) -).toBeVoid(); -expectTypeOf( - registerDeprecationHandler((message, options, next) => { - expectTypeOf(message).toBeString(); - expectTypeOf(options).toEqualTypeOf(); - expectTypeOf(next(message)).toBeVoid(); - }) -).toBeVoid(); -expectTypeOf( - registerDeprecationHandler((message, options, next) => { - expectTypeOf(message).toBeString(); - expectTypeOf(options).toEqualTypeOf(); - expectTypeOf(next(message, options)).toBeVoid(); - }) -).toBeVoid(); - -// Test for truthiness -const str: unknown = 'hello'; -assert('Must pass a string', typeof str === 'string'); -expectTypeOf(str).toBeString(); - -// Fail unconditionally -// This has to be last because `assert never` will raise TS's checks for -// unreachable code. -expectTypeOf(assert('This code path should never be run')).toBeNever(); diff --git a/type-tests/ember/ember-module-tests.ts b/type-tests/ember/ember-module-tests.ts deleted file mode 100644 index 219032d8a4f..00000000000 --- a/type-tests/ember/ember-module-tests.ts +++ /dev/null @@ -1,236 +0,0 @@ -import type Owner from '@ember/owner'; -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -// addListener -Ember.addListener({ a: 'foo' }, 'event', {}, () => {}); -Ember.addListener({ a: 'foo' }, 'event', {}, 'a'); -Ember.addListener({ a: 'foo' }, 'event', {}, 'b'); -Ember.addListener({ a: 'foo' }, 'event', null, () => {}); -// addObserver -Ember.addObserver({ a: 'foo' }, 'a', null, () => {}); -Ember.addObserver({ a: 'foo' }, 'a', {}, () => {}); -// assert -Ember.assert('2+2 should always be 4', 2 + 2 === 4); -// assign -// Ember.bind // @ts-expect-error -// cacheFor -expectTypeOf(Ember.cacheFor({ a: 123 }, 'a')).toEqualTypeOf(); -Ember.cacheFor({ a: 123 }, 'x'); -// compare -expectTypeOf(Ember.compare('31', '114')).toEqualTypeOf<-1 | 0 | 1>(); -// debug -Ember.debug('some info for developers'); -// deprecate -Ember.deprecate("you shouldn't use this anymore", 3 === 3, { - id: 'no-longer-allowed', - until: '99.0.0', - for: 'Ember', - since: { available: '4.0.0', enabled: '4.1.1' }, -}); -// get -expectTypeOf(Ember.get({ z: 23 }, 'z')).toEqualTypeOf(); -expectTypeOf(Ember.get({ z: 23 }, 'zz')).toEqualTypeOf(); -// getOwner -expectTypeOf(Ember.getOwner(new Ember.Component())).toEqualTypeOf(); -// getProperties -expectTypeOf(Ember.getProperties({ z: 23 }, 'z').z).toEqualTypeOf(); -expectTypeOf(Ember.getProperties({ z: 23 }, 'z', 'z').z).toEqualTypeOf(); -// We cannot get both known and unknown keys at the same time. -expectTypeOf(Ember.getProperties({ z: 23 }, 'z', 'a').z).toBeUnknown(); -expectTypeOf(Ember.getProperties({ z: 23 }, ['z', 'z']).z).toEqualTypeOf(); -expectTypeOf(Ember.getProperties({ z: 23 }, ['z', 'a'])['z']).toBeUnknown(); - -// guidFor -expectTypeOf(Ember.guidFor({})).toEqualTypeOf(); -expectTypeOf(Ember.guidFor('')).toEqualTypeOf(); -// isArray -expectTypeOf(Ember.isArray('')).toEqualTypeOf(); -expectTypeOf(Ember.isArray([])).toEqualTypeOf(); -// isBlank -expectTypeOf(Ember.isBlank('')).toEqualTypeOf(); -expectTypeOf(Ember.isBlank([])).toEqualTypeOf(); -// isEmpty -expectTypeOf(Ember.isEmpty('')).toEqualTypeOf(); -expectTypeOf(Ember.isEmpty([])).toEqualTypeOf(); -// isEqual -expectTypeOf(Ember.isEqual('', 'foo')).toEqualTypeOf(); -expectTypeOf(Ember.isEqual([], '')).toEqualTypeOf(); -// isNone -expectTypeOf(Ember.isNone('')).toEqualTypeOf(); -expectTypeOf(Ember.isNone([])).toEqualTypeOf(); -// isPresent -expectTypeOf(Ember.isPresent('')).toEqualTypeOf(); -expectTypeOf(Ember.isPresent([])).toEqualTypeOf(); -// observer -class O2 extends Ember.Object { - name = 'foo'; - age = 3; - - nameWatcher = Ember.observer('name', () => {}); - nameWatcher2 = Ember.observer('name', 'fullName', () => {}); -} -const o2 = O2.create({ - name: 'foo', - age: 3, -}); -// removeListener -Ember.removeListener(O2, 'create', null, () => {}); -Ember.removeListener(O2, 'create', null, 'create'); -Ember.removeListener({}, 'create', null, 'blah'); -// removeObserver -Ember.removeObserver(O2, 'create', () => {}); -Ember.removeObserver({}, 'create', () => {}); -// runInDebug -Ember.runInDebug(() => {}); -// sendEvent -expectTypeOf(Ember.sendEvent(o2, 'clicked', [1, 2])).toBeBoolean(); -// set -expectTypeOf(Ember.set(O2.create(), 'name', 'bar')).toEqualTypeOf(); -expectTypeOf(Ember.set(O2.create(), 'age', 4)).toEqualTypeOf(); -// We allow setting arbitrary properties with `set`. -expectTypeOf(Ember.set(O2.create(), 'nam', 'bar')).toBeString(); -// setOwner -declare let app: Ember.ApplicationInstance; -Ember.setOwner(O2.create(), app); -// setProperties -expectTypeOf(Ember.setProperties(O2.create(), { name: 'bar' }).name).toEqualTypeOf(); -// trySet -expectTypeOf(Ember.trySet(O2, 'nam', '')).toEqualTypeOf(); -// typeOf -expectTypeOf(Ember.typeOf('')).toBeString(); -// warn -Ember.warn('be caseful!'); -Ember.warn('be caseful!', { id: 'some-warning' }); -// VERSION -expectTypeOf(Ember.VERSION).toEqualTypeOf(); - -// onerror - -Ember.onerror = (err: Error) => console.error(err); -// @ts-expect-error -Ember.onerror = (num: number, err: Error) => console.error(err); -Ember.onerror = undefined; - -// Classes -// TODO ContainerProxyMixin -// Ember -// Ember.Application -expectTypeOf(new Ember.Application()).toEqualTypeOf(); -expectTypeOf(Ember.Application.create()).toEqualTypeOf(); -// Ember.ApplicationInstance -expectTypeOf(new Ember.ApplicationInstance()).toEqualTypeOf(); -expectTypeOf(Ember.ApplicationInstance.create()).toEqualTypeOf(); -// Ember.Component -const C1 = Ember.Component.extend({ classNames: ['foo'] }); -class C2 extends Ember.Component { - classNames = ['foo']; -} -const c1 = new C1(); -const c2 = new C2(); -C1.create(); -C2.create(); -c1.didInsertElement(); -c2.didInsertElement(); - -class Foo { - foo = ''; - - @Ember.computed('foo') - get wat(): string { - return this.foo; - } - - set wat(newValue: string) { - this.foo = newValue; - } -} - -declare let owner: Ember.ApplicationInstance; - -// Ember.ContainerDebugAdapter -expectTypeOf(new Ember.ContainerDebugAdapter(owner)).toEqualTypeOf(); -// Ember.Controller -expectTypeOf(new Ember.Controller()).toEqualTypeOf(); -// Ember.CoreObject -expectTypeOf(new Ember.CoreObject()).toEqualTypeOf(); -// Ember.DataAdapter -expectTypeOf(new Ember.DataAdapter(owner)).toEqualTypeOf>(); -// Ember.Debug -Ember.Debug.registerDeprecationHandler(() => {}); -Ember.Debug.registerWarnHandler(() => {}); -// Ember.Engine -const e1 = new Ember.Engine(); -e1.register('data:foo', {}, { instantiate: false }); -// Ember.EngineInstance -const ei1 = new Ember.EngineInstance(); -ei1.lookup('data:foo'); -// Ember.HashLocation -const hl = new Ember.HashLocation(); -expectTypeOf(hl).toEqualTypeOf(); -// Ember.Helper -class H1 extends Ember.Helper { - compute() { - this.recompute(); - return ''; - } -} -// Ember.HistoryLocation -const hil = Ember.HistoryLocation.create(); -expectTypeOf(hil).toEqualTypeOf(); -// Ember.Mixin -interface UsesMixin { - foo: string; -} -class UsesMixin extends Ember.Object { - baz() { - expectTypeOf(this.foo).toBeString(); - } -} -// Ember.Namespace -const myNs = Ember.Namespace.extend({}); -// Ember.NoneLocation -expectTypeOf(new Ember.NoneLocation()).toEqualTypeOf(); -// Ember.Object -new Ember.Object(); -// Ember.Route -new Ember.Route(owner); -// Ember.Router -new Ember.Router(); -// Ember.Service -new Ember.Service(); -// Ember.Test -if (Ember.Test) { - new Ember.Test.Adapter(); - new Ember.Test.QUnitAdapter(); - // Ember.Test - expectTypeOf(Ember.Test.checkWaiters()).toEqualTypeOf(); -} -// Ember.Helper -// helper -Ember.Helper.helper(([a, b]: [number, number]) => a + b); -// checkWaiters - -/** - * == REMOVED FEATURES == - * These are deprecated and/or private things that have been removed from the - * Ember.* namespace. These tests asserts that the types of these things - * stay gone - */ - -// @ts-expect-error -Ember.bind; -// @ts-expect-error -Ember.deprecate('foo', 'bar'); -// @ts-expect-error -Ember.K; -// @ts-expect-error -Ember.Binding; -// @ts-expect-error -Ember.Transition; -// @ts-expect-error -Ember.create; -// @ts-expect-error -Ember.reset; -// @ts-expect-error -Ember.unsubscribe; diff --git a/type-tests/ember/ember-tests.ts b/type-tests/ember/ember-tests.ts deleted file mode 100755 index 1439f1200f1..00000000000 --- a/type-tests/ember/ember-tests.ts +++ /dev/null @@ -1,144 +0,0 @@ -import type { AnyFn } from '@ember/-internals/utility-types'; -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class President extends Ember.Object { - name = 'Barack Obama'; -} - -class DetailedPresident extends President { - firstName = 'Barack'; - lastName = 'Obama'; - @Ember.computed() - get fullName() { - return `${this.get('firstName')} ${this.get('lastName')}`; - } -} - -class Country extends Ember.Object { - presidentNameBinding = 'MyApp.president.name'; -} - -class MyApp extends Ember.Application { - president = President.create(); - country = Country.create(); - - todosController?: TodosController; -} - -const App = MyApp.create(); -App.country.get('presidentName'); -App.president = DetailedPresident.create(); -App.president.get('fullName'); - -declare class MyPerson extends Ember.Object { - static createMan(): MyPerson; -} -MyPerson.createMan(); - -class Person1 extends Ember.Object { - name?: string; - say = (thing: string) => { - alert(thing); - }; -} - -declare class MyPerson2 extends Ember.Object { - helloWorld(): void; -} -MyPerson2.create().helloWorld(); - -class Tom extends Person1 { - name = 'Tom Dale'; - helloWorld() { - this.say('Hi my name is ' + this.get('name')); - } -} -const tom = Tom.create(); -tom.helloWorld(); - -const PersonReopened = Person1.reopen({ isPerson: true }); -PersonReopened.create().get('isPerson'); - -class Todo extends Ember.Object { - isDone = false; -} - -class TodosController extends Ember.Object { - todos = [Todo.create()]; - - @Ember.computed('todos.@each.isDone') - get remaining() { - const todos = this.get('todos'); - return todos.filter((todo) => todo.get('isDone') === false).length; - } -} - -App.todosController = TodosController.create(); - -const todos = App.todosController.get('todos'); -let todo = todos[0]; -todo?.set('isDone', true); -App.todosController.get('remaining'); -todo = Todo.create({ isDone: true }); -todos.push(todo); -App.todosController.get('remaining'); - -const NormalApp = Ember.Application.create({ - rootElement: '#sidebar', -}); - -class Person2 extends Ember.Object { - name = ''; - - sayHello() { - console.log('Hello from ' + this.get('name')); - } -} -class Person3 extends Ember.Object { - name?: string; - isHappy = false; -} -const people2 = [ - Person3.create({ name: 'Yehuda', isHappy: true }), - Person3.create({ name: 'Majd', isHappy: false }), -]; -const isHappy = (person: Person3): boolean => { - return Boolean(person.get('isHappy')); -}; -people2.every(isHappy); - -// Examples taken from http://emberjs.com/api/classes/Em.RSVP.Promise.html -const promise = new Ember.RSVP.Promise((resolve: AnyFn, reject: AnyFn) => { - // on success - resolve('ok!'); - - // on failure - reject('no-k!'); -}); - -promise.then( - (value) => { - // on fulfillment - expectTypeOf(value).toBeString(); - }, - (reason: unknown) => { - // on rejection - } -); - -// make sure Ember.RSVP.Promise can be reference as a type -declare function promiseReturningFunction(urn: string): Ember.RSVP.Promise; - -const mix1 = Ember.Mixin.create({ - foo: 1, -}); - -const mix2 = Ember.Mixin.create({ - bar: 2, -}); - -const component1 = Ember.Component.extend(mix1, mix2, { - lyft: Ember.inject.service(), - cars: Ember.computed('lyft.cars').readOnly(), -}); diff --git a/type-tests/ember/engine-instance.ts b/type-tests/ember/engine-instance.ts deleted file mode 100644 index 0da036e13af..00000000000 --- a/type-tests/ember/engine-instance.ts +++ /dev/null @@ -1,27 +0,0 @@ -import Ember from 'ember'; -const { EngineInstance } = Ember; - -const engineInstance = EngineInstance.create(); -engineInstance.register('some:injection', class Foo {}); - -engineInstance.register('some:injection', class Foo {}, { - singleton: true, -}); - -engineInstance.register('some:injection', class Foo {}, { - instantiate: false, -}); - -engineInstance.register('some:injection', class Foo {}, { - singleton: false, - instantiate: true, -}); - -engineInstance.factoryFor('router:main'); -engineInstance.lookup('route:basic'); - -engineInstance.boot(); - -(async () => { - await engineInstance.boot(); -})(); diff --git a/type-tests/ember/engine.ts b/type-tests/ember/engine.ts deleted file mode 100755 index f409fb708c4..00000000000 --- a/type-tests/ember/engine.ts +++ /dev/null @@ -1,47 +0,0 @@ -import Ember from 'ember'; - -class BaseEngine extends Ember.Engine { - modulePrefix = 'my-engine'; -} - -class Obj extends Ember.Object { - foo = 'bar'; -} - -BaseEngine.initializer({ - name: 'my-initializer', - initialize(engine) { - engine.register('foo:bar', Obj); - }, -}); - -BaseEngine.instanceInitializer({ - name: 'my-instance-initializer', - initialize(engine) { - (engine.lookup('foo:bar') as Obj).get('foo'); - }, -}); - -class Engine1 extends BaseEngine { - rootElement = '#engine-one'; - customEvents = { - paste: 'paste', - }; -} - -class Engine2 extends BaseEngine { - rootElement = '#engine-two'; - customEvents = { - mouseenter: null, - mouseleave: null, - }; -} - -const Engine3 = BaseEngine.create(); - -const Engine3Instance1 = Engine3.buildInstance(); - -// @ts-expect-error -const Engine3Instance2 = Engine3.buildInstance({ foo: 'bar' }); - -const Engine3Instance3 = Engine3.buildInstance({ mountPoint: 'somewhere', routable: true }); diff --git a/type-tests/ember/event.ts b/type-tests/ember/event.ts deleted file mode 100755 index e34eb37e0c6..00000000000 --- a/type-tests/ember/event.ts +++ /dev/null @@ -1,23 +0,0 @@ -import Ember from 'ember'; - -function testObserver() { - Ember.Object.extend({ - valueObserver: Ember.observer('value', () => { - // Executes whenever the "value" property changes - }), - }); -} - -function testListener() { - class TestListener extends Ember.Component { - init() { - Ember.addListener(this, 'willDestroyElement', this, 'willDestroyListener'); - Ember.addListener(this, 'willDestroyElement', this, 'willDestroyListener', true); - Ember.addListener(this, 'willDestroyElement', this, this.willDestroyListener); - Ember.addListener(this, 'willDestroyElement', this, this.willDestroyListener, true); - Ember.removeListener(this, 'willDestroyElement', this, 'willDestroyListener'); - Ember.removeListener(this, 'willDestroyElement', this, this.willDestroyListener); - } - willDestroyListener() {} - } -} diff --git a/type-tests/ember/extend.ts b/type-tests/ember/extend.ts deleted file mode 100755 index a994fa39867..00000000000 --- a/type-tests/ember/extend.ts +++ /dev/null @@ -1,37 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class Person extends Ember.Object { - declare firstName: string; - declare lastName: string; - - get fullName() { - return `${this.firstName} ${this.lastName}`; - } - get fullName2(): string { - return `${this.get('firstName')} ${this.get('lastName')}`; - } -} - -expectTypeOf(Person.prototype.firstName).toBeString(); -expectTypeOf(Person.prototype.fullName).toBeString(); - -const person = Person.create({ - firstName: 'Joe', - lastName: 'Blow', - extra: 42, -}); - -expectTypeOf(person.fullName).toBeString(); -expectTypeOf(person.extra).toBeNumber(); - -class PersonWithStatics extends Ember.Object { - static isPerson = true; -} -const PersonWithStatics2 = PersonWithStatics.extend({}); -class PersonWithStatics3 extends PersonWithStatics {} -class PersonWithStatics4 extends PersonWithStatics2 {} -expectTypeOf(PersonWithStatics.isPerson).toBeBoolean(); -expectTypeOf(PersonWithStatics2.isPerson).toBeBoolean(); -expectTypeOf(PersonWithStatics3.isPerson).toBeBoolean(); -expectTypeOf(PersonWithStatics4.isPerson).toBeBoolean(); diff --git a/type-tests/ember/helper.ts b/type-tests/ember/helper.ts deleted file mode 100755 index 2cfc4141a60..00000000000 --- a/type-tests/ember/helper.ts +++ /dev/null @@ -1,44 +0,0 @@ -import Ember from 'ember'; - -const FormatCurrencyHelper = Ember.Helper.helper((params: [number], hash: { currency: string }) => { - const cents = params[0]; - const currency = hash.currency; - return `${currency}${cents * 0.01}`; -}); - -class User extends Ember.Object { - declare email: string; -} - -class SessionService extends Ember.Service { - declare currentUser: User; -} - -declare module '@ember/service' { - interface Registry { - session: SessionService; - } -} - -class CurrentUserEmailHelper extends Ember.Helper { - @Ember.inject.service('session') - declare session: SessionService; - - compute(): string { - return this.get('session').get('currentUser').get('email'); - } -} - -import { helper } from '@ember/component/helper'; - -function typedHelp(/*params, hash*/) { - return 'my type of help'; -} - -export default helper(typedHelp); - -function arrayNumHelp(/*params, hash*/) { - return [1, 2, 3]; -} - -helper(arrayNumHelp); diff --git a/type-tests/ember/inject.ts b/type-tests/ember/inject.ts deleted file mode 100755 index 4f7fdc9ae95..00000000000 --- a/type-tests/ember/inject.ts +++ /dev/null @@ -1,74 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class AuthService extends Ember.Service { - declare isAuthenticated: boolean; -} - -class ApplicationController extends Ember.Controller { - // @ts-expect-error TODO: Should this actually work? - model = {}; - declare string: string; - transitionToLogin() {} -} - -declare module '@ember/service' { - interface Registry { - auth: AuthService; - } -} - -declare module '@ember/controller' { - interface Registry { - emberApplication: ApplicationController; - } -} - -class LoginRoute extends Ember.Route { - @Ember.inject.service('auth') - declare auth: AuthService; - - @Ember.inject.controller('emberApplication') - declare application: ApplicationController; - - didTransition() { - if (!this.get('auth').get('isAuthenticated')) { - this.get('application').transitionToLogin(); - } - } - - anyOldMethod() { - this.get('application').set('string', 'must be a string'); - expectTypeOf(this.controllerFor('emberApplication')).toEqualTypeOf(); - } -} - -// New module injection style. -import RouterService from '@ember/routing/router-service'; -import Controller from '@ember/controller'; - -class ComponentInjection extends Ember.Component { - @Ember.inject.controller('emberApplication') - declare applicationController: ApplicationController; - - @Ember.inject.service('auth') - declare auth: AuthService; - - @Ember.inject.service('router') - declare router: RouterService; - - @Ember.inject.service - declare misc: Ember.Service; - - testem() { - expectTypeOf(this.misc).toEqualTypeOf(); - - const url = this.router.urlFor('some-route', 1, 2, 3, { - queryParams: { seriously: 'yes' }, - }); - expectTypeOf(url).toBeString(); - if (!this.get('auth').isAuthenticated) { - this.get('applicationController').transitionToLogin(); - } - } -} diff --git a/type-tests/ember/mixin.ts b/type-tests/ember/mixin.ts deleted file mode 100755 index 55176a725ce..00000000000 --- a/type-tests/ember/mixin.ts +++ /dev/null @@ -1,66 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -interface EditableMixin extends Ember.Mixin { - edit(): void; - isEditing: boolean; -} - -const EditableMixin = Ember.Mixin.create({ - edit(this: EditableMixin & Ember.Object) { - this.get('controller'); - console.log('starting to edit'); - this.set('isEditing', true); - }, - isEditing: false, -}); - -interface EditableComment extends EditableMixin {} -class EditableComment extends Ember.Route.extend(EditableMixin) { - postId = 0; - - canEdit() { - return !this.isEditing; - } - - tryEdit() { - if (this.canEdit()) { - this.edit(); - } - } -} - -const comment = EditableComment.create({ - postId: 42, -}); - -comment.edit(); -comment.canEdit(); -comment.tryEdit(); -expectTypeOf(comment.isEditing).toBeBoolean(); -expectTypeOf(comment.postId).toBeNumber(); - -// We do not expect this to update the type; we do expect it to minimally check -const LiteralMixins = Ember.Object.extend({ a: 1 }, { b: 2 }, { c: 3 }); -const obj = LiteralMixins.create(); -// @ts-expect-error -obj.a; -// @ts-expect-error -obj.b; -// @ts-expect-error -obj.c; - -/* Test composition of mixins */ -interface EditableAndCancelableMixin extends EditableMixin { - cancelled: boolean; -} -const EditableAndCancelableMixin = Ember.Mixin.create(EditableMixin, { - cancelled: false, -}); - -interface EditableAndCancelableComment extends EditableAndCancelableMixin {} -class EditableAndCancelableComment extends Ember.Route.extend(EditableAndCancelableMixin) {} - -const editableAndCancelable = EditableAndCancelableComment.create(); -expectTypeOf(editableAndCancelable.isEditing).toBeBoolean(); -expectTypeOf(editableAndCancelable.cancelled).toBeBoolean(); diff --git a/type-tests/ember/object.ts b/type-tests/ember/object.ts deleted file mode 100755 index 9ae285df6a1..00000000000 --- a/type-tests/ember/object.ts +++ /dev/null @@ -1,86 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class LifetimeHooks extends Ember.Object { - resource: {} | undefined; - - init() { - this._super(); - this.resource = {}; - } - - willDestroy() { - this.resource = undefined; - this._super(); - } -} - -class MyObject30 extends Ember.Object { - constructor() { - super(); - } -} - -class MyObject31 extends Ember.Object { - constructor(owner: Ember.EngineInstance) { - super(owner); - } -} - -class Foo extends Ember.Object { - @Ember.computed() - get a() { - return ''; - } - - set a(newVal: string) { - /* no-op */ - } - - b = 5; - - baz() { - this.b = 10; - expectTypeOf(this.get('b').toFixed(4)).toEqualTypeOf(); - expectTypeOf(this.set('a', 'abc').split(',')).toEqualTypeOf(); - expectTypeOf(this.set('b', 10).toFixed(4)).toEqualTypeOf(); - - this.setProperties({ b: 11 }); - // this.setProperties({ b: '11' }); // @ts-expect-error - this.setProperties({ - a: 'def', - b: 11, - }); - } -} - -export class Foo2 extends Ember.Object { - name = ''; - - changeName(name: string) { - expectTypeOf(Ember.set(this, 'name', name)).toBeString(); - - // For some reason, `this` type lookup does not resolve correctly here. Used - // outside a class, like `get(someFoo, 'name')`, this works correctly. Since - // there are basically no cases inside a class where you *have* to use `get` - // today, this is an acceptable workaround for now. It is assignable *or* - // castable. - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const s: string = this.get('name'); - expectTypeOf(Ember.get(this as Foo2, 'name')).toBeString(); - expectTypeOf((this as Foo2).get('name')).toBeString(); - - expectTypeOf(this.setProperties({ name })).toEqualTypeOf<{ name: string }>(); - expectTypeOf(Ember.setProperties(this, { name })).toEqualTypeOf<{ name: string }>(); - } - - bar() { - Ember.notifyPropertyChange(this, 'name'); - // @ts-expect-error - Ember.notifyPropertyChange(this); - // @ts-expect-error - Ember.notifyPropertyChange('name'); - // @ts-expect-error - Ember.notifyPropertyChange(this, 'name', 'bar'); - } -} diff --git a/type-tests/ember/observable.ts b/type-tests/ember/observable.ts deleted file mode 100755 index 88fc7634aff..00000000000 --- a/type-tests/ember/observable.ts +++ /dev/null @@ -1,150 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class MyComponent extends Ember.Component { - foo = 'bar'; - - init() { - this._super(); - this.addObserver('foo', this, 'fooDidChange'); - this.addObserver('foo', this, this.fooDidChange); - Ember.addObserver(this, 'foo', this, 'fooDidChange'); - Ember.addObserver(this, 'foo', this, this.fooDidChange); - this.removeObserver('foo', this, 'fooDidChange'); - this.removeObserver('foo', this, this.fooDidChange); - Ember.removeObserver(this, 'foo', this, 'fooDidChange'); - Ember.removeObserver(this, 'foo', this, this.fooDidChange); - const lambda = () => { - this.fooDidChange(this, 'foo'); - }; - this.addObserver('foo', lambda); - this.removeObserver('foo', lambda); - Ember.addObserver(this, 'foo', lambda); - Ember.removeObserver(this, 'foo', lambda); - } - - @Ember.computed('foo') - get bar(): string { - return this.foo; - } - - fooDidChange(sender: MyComponent, key: string) { - // your code - } -} - -const myComponent = MyComponent.create(); -myComponent.addObserver('foo', null, () => {}); -myComponent.set('foo', 'baz'); -expectTypeOf(myComponent.get('foo')).toEqualTypeOf(); - -class Person extends Ember.Object { - name = ''; - age = 0; - - @Ember.computed() - get capitalized() { - return this.get('name').toUpperCase(); - } -} -const person = Person.create({ - name: 'Fred', - age: 29, -}); - -const pojo = { name: 'Fred', age: 29 }; - -function testGet() { - expectTypeOf(Ember.get(person, 'name')).toEqualTypeOf(); - expectTypeOf(Ember.get(person, 'age')).toEqualTypeOf(); - expectTypeOf(Ember.get(person, 'capitalized')).toEqualTypeOf(); - expectTypeOf(person.get('name')).toEqualTypeOf(); - expectTypeOf(person.get('age')).toEqualTypeOf(); - expectTypeOf(person.get('capitalized')).toEqualTypeOf(); - expectTypeOf(Ember.get(pojo, 'name')).toEqualTypeOf(); -} - -function testGetProperties() { - expectTypeOf(Ember.getProperties(person, 'name')).toEqualTypeOf<{ name: string }>(); - expectTypeOf(Ember.getProperties(person, 'name', 'age')).toEqualTypeOf<{ - name: string; - age: number; - }>(); - expectTypeOf(Ember.getProperties(person, ['name', 'age'])).toEqualTypeOf<{ - name: string; - age: number; - }>(); - expectTypeOf(Ember.getProperties(person, 'name', 'age', 'capitalized')).toEqualTypeOf< - Pick - >(); - expectTypeOf(person.getProperties('name')).toEqualTypeOf<{ name: string }>(); - expectTypeOf(person.getProperties('name', 'age')).toEqualTypeOf<{ name: string; age: number }>(); - expectTypeOf(person.getProperties(['name', 'age'])).toEqualTypeOf<{ - name: string; - age: number; - }>(); - expectTypeOf(person.getProperties('name', 'age', 'capitalized')).toEqualTypeOf<{ - name: string; - age: number; - capitalized: string; - }>(); - expectTypeOf(Ember.getProperties(pojo, 'name', 'age')).toEqualTypeOf< - Pick - >(); -} - -function testSet() { - expectTypeOf(Ember.set(person, 'name', 'Joe')).toBeString(); - expectTypeOf(Ember.set(person, 'age', 35)).toBeNumber(); - expectTypeOf(Ember.set(person, 'capitalized', 'JOE')).toBeString(); - expectTypeOf(person.set('name', 'Joe')).toBeString(); - expectTypeOf(person.set('age', 35)).toBeNumber(); - expectTypeOf(person.set('capitalized', 'JOE')).toBeString(); - expectTypeOf(Ember.set(pojo, 'name', 'Joe')).toBeString(); -} - -function testSetProperties() { - expectTypeOf(Ember.setProperties(person, { name: 'Joe' })).toEqualTypeOf<{ name: string }>(); - expectTypeOf(Ember.setProperties(person, { name: 'Joe', age: 35 })).toEqualTypeOf<{ - name: string; - age: number; - }>(); - expectTypeOf(Ember.setProperties(person, { name: 'Joe', capitalized: 'JOE' })).toEqualTypeOf< - Pick - >(); - expectTypeOf(person.setProperties({ name: 'Joe' })).toEqualTypeOf>(); - expectTypeOf(person.setProperties({ name: 'Joe', age: 35 })).toEqualTypeOf< - Pick - >(); - expectTypeOf(person.setProperties({ name: 'Joe', capitalized: 'JOE' })).toEqualTypeOf<{ - name: string; - capitalized: string; - }>(); - expectTypeOf(Ember.setProperties(pojo, { name: 'Joe', age: 35 })).toEqualTypeOf< - Pick - >(); -} - -function testDynamic() { - const obj: Record = {}; - const dynamicKey = 'dummy' as string; - - // These all are "too loose" in `noUncheckedIndexedAccess`, but `get` has - // never properly supported that flag, and there is no path to doing so. If - // someone wants that support, they should switch to using direct property - // access instead of using `get` (which has many other advantages). - expectTypeOf(Ember.get(obj, 'dummy')).toEqualTypeOf(); - expectTypeOf(Ember.get(obj, dynamicKey)).toEqualTypeOf(); - expectTypeOf(Ember.getProperties(obj, 'dummy')).toEqualTypeOf<{ dummy: string }>(); - expectTypeOf(Ember.getProperties(obj, ['dummy'])).toEqualTypeOf<{ dummy: string }>(); - expectTypeOf(Ember.getProperties(obj, dynamicKey)).toEqualTypeOf>(); - expectTypeOf(Ember.getProperties(obj, [dynamicKey])).toEqualTypeOf>(); - expectTypeOf(Ember.set(obj, 'dummy', 'value')).toBeString(); - expectTypeOf(Ember.set(obj, dynamicKey, 'value')).toBeString(); - expectTypeOf(Ember.setProperties(obj, { dummy: 'value ' })).toEqualTypeOf< - Record<'dummy', string> - >(); - expectTypeOf(Ember.setProperties(obj, { [dynamicKey]: 'value' })).toEqualTypeOf< - Record - >(); -} diff --git a/type-tests/ember/private/computed-tests.ts b/type-tests/ember/private/computed-tests.ts deleted file mode 100644 index 7a5448faa93..00000000000 --- a/type-tests/ember/private/computed-tests.ts +++ /dev/null @@ -1,26 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class Example1 extends Ember.Object { - firstName = ''; - lastName = ''; - - @Ember.computed('fullName') - get allNames() { - return [this.fullName]; - } - - @Ember.computed('firstName', 'lastName') - get fullName() { - return `${this.firstName} ${this.lastName}`; - } -} - -class Example2 extends Example1 { - foo() { - expectTypeOf(this.get('fullName').split(',')).toEqualTypeOf(); - expectTypeOf(this.get('allNames')[0]).toEqualTypeOf(); - expectTypeOf(this.get('firstName').split(',')).toEqualTypeOf(); - expectTypeOf(this.get('lastName').split(',')).toEqualTypeOf(); - } -} diff --git a/type-tests/ember/reopen.ts b/type-tests/ember/reopen.ts deleted file mode 100755 index a4cf4673dcf..00000000000 --- a/type-tests/ember/reopen.ts +++ /dev/null @@ -1,78 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -class Person extends Ember.Object { - name = ''; - - sayHello() { - alert(`Hello. My name is ${this.get('name')}`); - } -} - -expectTypeOf(Person.reopen()).toMatchTypeOf(); - -expectTypeOf(Person.create().name).toEqualTypeOf(); -expectTypeOf(Person.create().sayHello()).toBeVoid(); - -// Here, a basic check that `reopenClass` *works*, but we intentionally do not -// provide types for how it changes the original class (as spec'd in RFC 0800). -const Person2 = Person.reopenClass({ - species: 'Homo sapiens', - - createPerson(name: string): Person { - return Person.create({ name }); - }, -}); - -// The original class types are carried along -expectTypeOf(Person2.create().name).toEqualTypeOf(); -expectTypeOf(Person2.create().sayHello()).toBeVoid(); -// But we aren't trying to merge in new classes anymore. -// @ts-expect-error -Person2.species; - -const tom = Person2.create({ - name: 'Tom Dale', -}); - -// @ts-expect-error -const badTom = Person2.create({ name: 99 }); - -// @ts-expect-error -const yehuda = Person2.createPerson('Yehuda Katz'); - -tom.sayHello(); // "Hello. My name is Tom Dale" -yehuda.sayHello(); // "Hello. My name is Yehuda Katz" -// @ts-expect-error -alert(Person2.species); // "Homo sapiens" - -// The same goes for `.reopen()`: it will "work" in a bare minimum sense, but it -// will not try to change the types. -const Person3 = Person2.reopen({ - goodbyeMessage: 'goodbye', - - sayGoodbye(this: Person) { - alert(`${this.get('goodbyeMessage')}, ${this.get('name')}`); - }, -}); - -const person3 = Person3.create(); -person3.get('name'); -person3.get('goodbyeMessage'); -person3.sayHello(); -// @ts-expect-error -person3.sayGoodbye(); - -interface AutoResizeMixin { - resizable: true; -} -const AutoResizeMixin = Ember.Mixin.create({ resizable: true }); - -// And the same here. -const Reopened = Ember.Object.reopenClass({ a: 1 }, { b: 2 }, { c: 3 }); -// @ts-expect-error -Reopened.a; -// @ts-expect-error -Reopened.b; -// @ts-expect-error -Reopened.c; diff --git a/type-tests/ember/route.ts b/type-tests/ember/route.ts deleted file mode 100755 index 7e3bcf0e155..00000000000 --- a/type-tests/ember/route.ts +++ /dev/null @@ -1,96 +0,0 @@ -import Route from '@ember/routing/route'; -import Array from '@ember/array'; -import Ember from 'ember'; // currently needed for Transition -import type Transition from '@ember/routing/transition'; -import { expectTypeOf } from 'expect-type'; -import { service } from '@ember/service'; -import RouterService from '@ember/routing/router-service'; - -// Ensure that Ember.Transition is private -// @ts-expect-error -Ember.Transition; - -interface Post extends Ember.Object { - title: string; -} - -interface Posts extends Array {} - -class Test extends Route { - @service declare router: RouterService; - queryParams = { - memberQp: { refreshModel: true }, - }; - - beforeModel(transition: Transition) { - this.router.transitionTo('someOtherRoute'); - } - - model() { - return this.modelFor('post'); - } - - afterModel(posts: Posts, transition: Transition) { - if (posts[0]) { - this.router.transitionTo('post.show', posts[0]); - } - } - - setupController(controller: Ember.Controller, model: {}) { - this._super(controller, model); - this.controllerFor('application').set('model', model); - } - - resetController(controller: Ember.Controller, isExiting: boolean, transition: Transition) { - if (isExiting) { - // controller.set('page', 1); - } - } - - intermediateTransitionWithoutModel() { - this.intermediateTransitionTo('some-route'); - } - intermediateTransitionWithModel() { - this.intermediateTransitionTo('some.other.route', {}); - } - intermediateTransitionWithMultiModel() { - this.intermediateTransitionTo('some.other.route', 1, 2, {}); - } -} - -class ReturningPromises extends Route { - beforeModel() { - return Promise.resolve('beforeModel can return promises'); - } - afterModel(resolvedModel: unknown, transition: Transition) { - return Promise.resolve('afterModel can also return promises'); - } -} - -class WithNonReturningBeforeAndModelHooks extends Route { - beforeModel(transition: Transition): void | Promise { - return; - } - - afterModel(resolvedModel: unknown, transition: Transition): void { - return; - } -} - -class WithBadReturningBeforeAndModelHooks extends Route { - beforeModel(transition: Transition): void | Promise { - // @ts-expect-error - return "returning anything else is nonsensical (if 'legal')"; - } - - afterModel(resolvedModel: unknown, transition: Transition): void { - // @ts-expect-error - return "returning anything else is nonsensical (if 'legal')"; - } -} - -class HasActionHandler extends Route { - methodUsingActionHandler() { - expectTypeOf(this.actions).toEqualTypeOf any>>(); - } -} diff --git a/type-tests/ember/router.ts b/type-tests/ember/router.ts deleted file mode 100755 index 849677e4716..00000000000 --- a/type-tests/ember/router.ts +++ /dev/null @@ -1,52 +0,0 @@ -import RouterService from '@ember/routing/router-service'; -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -const AppRouter = Ember.Router.extend({}); - -AppRouter.map(function () { - this.route('index', { path: '/' }); - this.route('about'); - this.route('favorites', { path: '/favs' }); - this.route('posts', function () { - this.route('index', { path: '/' }); - this.route('new'); - this.route('post', { path: '/post/:post_id', resetNamespace: true }); - this.route('comments', { resetNamespace: true }, function () { - this.route('new'); - }); - }); - this.route('photo', { path: '/photo/:id' }, function () { - this.route('comment', { path: '/comment/:id' }); - }); - this.route('not-found', { path: '/*path' }); - this.mount('my-engine'); - this.mount('my-engine', { as: 'some-other-engine', path: '/some-other-engine' }); -}); - -class RouterServiceConsumer extends Ember.Service { - @Ember.inject.service('router') - declare router: RouterService; - - currentRouteName() { - expectTypeOf(this.router.currentRouteName).toEqualTypeOf(); - } - currentURL() { - expectTypeOf(this.router.currentURL).toEqualTypeOf(); - } - transitionWithoutModel() { - Ember.get(this, 'router').transitionTo('some-route'); - } - transitionWithModel() { - const model = Ember.Object.create(); - Ember.get(this, 'router').transitionTo('some.other.route', model); - } - transitionWithMultiModel() { - const model = Ember.Object.create(); - Ember.get(this, 'router').transitionTo('some.other.route', model, model); - } - transitionWithModelAndOptions() { - const model = Ember.Object.create(); - Ember.get(this, 'router').transitionTo('index', model, { queryParams: { search: 'ember' } }); - } -} diff --git a/type-tests/ember/run.ts b/type-tests/ember/run.ts deleted file mode 100755 index ad9bf421c2b..00000000000 --- a/type-tests/ember/run.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -function testRun() { - const r = Ember.run(() => { - // code to be executed within a RunLoop - return 123; - }); - expectTypeOf(r).toEqualTypeOf(); - - function destroyApp(application: Ember.Application) { - Ember.run(application, 'destroy'); - Ember.run(application, function () { - this.destroy(); - }); - } -} diff --git a/type-tests/ember/techniques/properties-from-this.ts b/type-tests/ember/techniques/properties-from-this.ts deleted file mode 100644 index f5d4323d289..00000000000 --- a/type-tests/ember/techniques/properties-from-this.ts +++ /dev/null @@ -1,72 +0,0 @@ -/** - * These tests validate that the method of pulling property types off of this - * continues to work. - */ - -import { expectTypeOf } from 'expect-type'; - -class BoxedProperty { - private declare [GetType]: Get; - private declare [SetType]: Set; -} - -declare const GetType: unique symbol; -declare const SetType: unique symbol; - -type UnboxGetProperty = T extends BoxedProperty ? V : T; -type UnboxSetProperty = T extends BoxedProperty ? V : T; - -class GetAndSet { - get(key: K): UnboxGetProperty { - return this[key] as UnboxGetProperty; - } - set(key: K, newVal: UnboxSetProperty): UnboxSetProperty { - const rawVal = this[key]; - if (rawVal instanceof BoxedProperty) { - rawVal[SetType] = newVal; - } - this[key] = newVal as this[K]; - return newVal; - } -} - -class Foo123 extends GetAndSet { - a: number; - b: [boolean, boolean]; - c: string; - cpA!: BoxedProperty; - constructor() { - super(); - this.a = 1; - this.b = [true, false]; - this.c = 'hello'; - } -} - -let f = new Foo123(); - -expectTypeOf(f.get('a')).toEqualTypeOf(); -// @ts-expect-error -f.set('a'); -// @ts-expect-error -f.set('a', '1'); -expectTypeOf(f.set('a', 1)).toEqualTypeOf(); - -expectTypeOf(f.get('b')).toEqualTypeOf<[boolean, boolean]>(); -// @ts-expect-error -f.set('b', 1); -// @ts-expect-error -f.set('b', []); -// @ts-expect-error -f.set('b', [true]); -expectTypeOf(f.set('b', [false, true])).toEqualTypeOf<[boolean, boolean]>(); -// @ts-expect-error -f.set('b', [false, true, false]); - -expectTypeOf(f.get('c')).toEqualTypeOf(); -expectTypeOf(f.set('c', '1')).toEqualTypeOf(); - -expectTypeOf(f.get('cpA')).toEqualTypeOf(); -// @ts-expect-error -f.set('cpA', ['newValue']); -expectTypeOf(f.set('cpA', 'newValue')).toEqualTypeOf(); diff --git a/type-tests/ember/test.ts b/type-tests/ember/test.ts deleted file mode 100755 index 09cbeaa21db..00000000000 --- a/type-tests/ember/test.ts +++ /dev/null @@ -1,46 +0,0 @@ -import Ember from 'ember'; - -const pending = 0; - -declare const MyDb: { - hasPendingTransactions(): boolean; -}; - -if (Ember.Test) { - Ember.Test.registerWaiter(() => pending !== 0); - - Ember.Test.registerWaiter(MyDb, MyDb.hasPendingTransactions); - - Ember.Test.promise((resolve) => { - window.setTimeout(resolve, 500); - }); - - Ember.Test.registerHelper('boot', (app) => { - Ember.run(app, app.advanceReadiness); - }); - - Ember.Test.registerAsyncHelper('boot', (app) => { - Ember.run(app, app.advanceReadiness); - }); - - Ember.Test.registerAsyncHelper('waitForPromise', (app, promise) => { - if (!Ember.Test) { - return; - } - - return new Ember.Test.Promise((resolve) => { - if (!Ember.Test) { - return; - } - Ember.Test.Adapter.asyncStart(); - - promise.then(() => { - if (!Ember.Test) { - return; - } - - Ember.Test.Adapter.asyncEnd(); - }); - }); - }); -} diff --git a/type-tests/ember/transition.ts b/type-tests/ember/transition.ts deleted file mode 100755 index 74aad7a0863..00000000000 --- a/type-tests/ember/transition.ts +++ /dev/null @@ -1,5 +0,0 @@ -import Ember from 'ember'; -import type Transition from '@ember/routing/transition'; -import { expectTypeOf } from 'expect-type'; - -expectTypeOf[0]>().toEqualTypeOf(); diff --git a/type-tests/ember/utils.ts b/type-tests/ember/utils.ts deleted file mode 100755 index fa5d9a36ff3..00000000000 --- a/type-tests/ember/utils.ts +++ /dev/null @@ -1,109 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -function testTypeOf() { - // @ts-expect-error - Ember.typeOf(); - const str: string = Ember.typeOf({}); -} - -function testIsNoneType() { - const maybeUndefined: string | undefined = 'not actually undefined'; - if (Ember.isNone(maybeUndefined)) { - return; - } - - const anotherString = maybeUndefined + 'another string'; - expectTypeOf(Ember.isNone(anotherString)).toBeBoolean(); -} - -function testIsBlank() { - expectTypeOf(Ember.isBlank(undefined)).toBeBoolean(); - expectTypeOf(Ember.isBlank('')).toBeBoolean(); - // @ts-expect-error - Ember.isBlank('', ''); -} - -function testIsEmpty() { - expectTypeOf(Ember.isEmpty(undefined)).toBeBoolean(); - expectTypeOf(Ember.isEmpty('')).toBeBoolean(); - // @ts-expect-error - Ember.isEmpty('', ''); -} - -function testIsPresent() { - expectTypeOf(Ember.isPresent(undefined)).toBeBoolean(); - expectTypeOf(Ember.isPresent('')).toBeBoolean(); - // @ts-expect-error - Ember.isPresent('', ''); -} - -function testIsNone() { - expectTypeOf(Ember.isNone(undefined)).toBeBoolean(); - expectTypeOf(Ember.isNone('')).toBeBoolean(); - // @ts-expect-error - Ember.isNone('', ''); -} - -function testOnError() { - Ember.onerror = (error) => { - fetch('/report-error', { - method: 'POST', - body: JSON.stringify({ - stack: error.stack, - otherInformation: 'whatever app state you want to provide', - }), - }); - }; -} - -function testDefineProperty() { - type Contact = { firstName?: string; lastName?: string }; - const contact: Contact = {}; - - // ES5 compatible mode - Ember.defineProperty(contact, 'firstName', { - writable: true, - configurable: false, - enumerable: true, - value: 'Charles', - }); - - // define a simple property - Ember.defineProperty(contact, 'lastName', undefined, 'Jolley'); - - // define a computed property - Ember.defineProperty( - contact, - 'fullName', - Ember.computed('firstName', 'lastName', function (this: Contact) { - return `${this.firstName} ${this.lastName}`; - }) - ); -} - -// For use in IIFE below. -declare const fileList: FileList; - -(() => { - /** typeOf */ - expectTypeOf(Ember.typeOf(null)).toBeString(); - expectTypeOf(Ember.typeOf(undefined)).toBeString(); - expectTypeOf(Ember.typeOf('michael')).toBeString(); - expectTypeOf(Ember.typeOf(new String('michael'))).toBeString(); - expectTypeOf(Ember.typeOf(101)).toBeString(); - expectTypeOf(Ember.typeOf(new Number(101))).toBeString(); - expectTypeOf(Ember.typeOf(true)).toBeString(); - expectTypeOf(Ember.typeOf(new Boolean(true))).toBeString(); - expectTypeOf(Ember.typeOf(() => 4)).toBeString(); - - expectTypeOf(Ember.typeOf([1, 2, 90])).toBeString(); - expectTypeOf(Ember.typeOf(/abc/)).toBeString(); - expectTypeOf(Ember.typeOf(new Date())).toBeString(); - expectTypeOf(Ember.typeOf(fileList)).toBeString(); - expectTypeOf(Ember.typeOf(Ember.Object.extend())).toBeString(); - expectTypeOf(Ember.typeOf(Ember.Object.create())).toBeString(); - expectTypeOf(Ember.typeOf(new Error('teamocil'))).toBeString(); - expectTypeOf(Ember.typeOf(new Date() as RegExp | Date)).toBeString(); - expectTypeOf(Ember.typeOf({ randomObject: true })).toBeString(); -})(); diff --git a/type-tests/ember/view-utils.ts b/type-tests/ember/view-utils.ts deleted file mode 100644 index d032ede90dc..00000000000 --- a/type-tests/ember/view-utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Ember from 'ember'; -import { expectTypeOf } from 'expect-type'; - -const { - ViewUtils: { isSimpleClick }, -} = Ember; -expectTypeOf(isSimpleClick(new Event('wat'))).toBeBoolean(); diff --git a/types/publish.mjs b/types/publish.mjs index cf6c3ac925f..b90f9f24fb0 100755 --- a/types/publish.mjs +++ b/types/publish.mjs @@ -104,13 +104,6 @@ async function main() { doOrDie(() => spawnSync('pnpm', ['tsc', '--project', 'tsconfig/publish-types.json'])); - // We're deprecating the barrel file, so this is temporary. The Ember global is a namespace, - // and namespaces can't be both exported and used as a type with the same semantics and - // capabilities as when defined in the original file -- so we're going to LIE and - // pretend that the barrel file is the index file (which is the same behavior as - // prior to the deprecation) - await fs.cp(path.join(TYPES_DIR, 'ember/barrel.d.ts'), path.join(TYPES_DIR, 'ember/index.d.ts')); - let remappedLocationExcludes = await doOrDie(copyHandwrittenDefinitions); let sideEffectExcludes = await doOrDie(copyRemappedLocationModules);