From aa41d5ec80b8eec3a52ec0c67bb94a7018cc4d42 Mon Sep 17 00:00:00 2001 From: Bj Tecu Date: Mon, 3 May 2021 18:14:16 -0400 Subject: [PATCH] Remove `Ember.DefaultResolver` / `Ember.Resolver` --- .../@ember/application/globals-resolver.js | 468 ------------------ packages/@ember/application/resolver.js | 1 - .../application/tests/application_test.js | 55 +- .../application/tests/bootstrap-test.js | 27 - .../custom_resolver_test.js | 31 -- .../default_resolver_test.js | 384 -------------- .../normalization_test.js | 75 --- packages/@ember/deprecated-features/index.ts | 1 - packages/@ember/engine/index.js | 12 +- packages/ember/index.js | 27 - packages/ember/tests/reexports_test.js | 13 - packages/internal-test-helpers/index.js | 1 - .../default-resolver-application.js | 55 -- tests/docs/expected.js | 13 - 14 files changed, 3 insertions(+), 1160 deletions(-) delete mode 100644 packages/@ember/application/globals-resolver.js delete mode 100644 packages/@ember/application/resolver.js delete mode 100644 packages/@ember/application/tests/bootstrap-test.js delete mode 100644 packages/@ember/application/tests/dependency_injection/custom_resolver_test.js delete mode 100644 packages/@ember/application/tests/dependency_injection/default_resolver_test.js delete mode 100644 packages/@ember/application/tests/dependency_injection/normalization_test.js delete mode 100644 packages/internal-test-helpers/lib/test-cases/default-resolver-application.js diff --git a/packages/@ember/application/globals-resolver.js b/packages/@ember/application/globals-resolver.js deleted file mode 100644 index 67cad755c4d..00000000000 --- a/packages/@ember/application/globals-resolver.js +++ /dev/null @@ -1,468 +0,0 @@ -/** -@module @ember/application -*/ - -import { dictionary, getName } from '@ember/-internals/utils'; -import { get, findNamespace } from '@ember/-internals/metal'; -import { assert, info, deprecate } from '@ember/debug'; -import { capitalize, classify, dasherize, decamelize } from '@ember/string'; -import { Object as EmberObject } from '@ember/-internals/runtime'; -import { getTemplate } from '@ember/-internals/glimmer'; -import { DEBUG } from '@glimmer/env'; -import { GLOBALS_RESOLVER } from '@ember/deprecated-features'; -import { processAllNamespaces } from '@ember/-internals/metal'; - -/** - The DefaultResolver defines the default lookup rules to resolve - container lookups before consulting the container for registered - items: - - * templates are looked up on `Ember.TEMPLATES` - * other names are looked up on the application after converting - the name. For example, `controller:post` looks up - `App.PostController` by default. - * there are some nuances (see examples below) - - ### How Resolving Works - - The container calls this object's `resolve` method with the - `fullName` argument. - - It first parses the fullName into an object using `parseName`. - - Then it checks for the presence of a type-specific instance - method of the form `resolve[Type]` and calls it if it exists. - For example if it was resolving 'template:post', it would call - the `resolveTemplate` method. - - Its last resort is to call the `resolveOther` method. - - The methods of this object are designed to be easy to override - in a subclass. For example, you could enhance how a template - is resolved like so: - - ```app/app.js - import Application from '@ember/application'; - import GlobalsResolver from '@ember/application/globals-resolver'; - - App = Application.create({ - Resolver: GlobalsResolver.extend({ - resolveTemplate(parsedName) { - let resolvedTemplate = this._super(parsedName); - if (resolvedTemplate) { return resolvedTemplate; } - - return Ember.TEMPLATES['not_found']; - } - }) - }); - ``` - - Some examples of how names are resolved: - - ```text - 'template:post' //=> Ember.TEMPLATES['post'] - 'template:posts/byline' //=> Ember.TEMPLATES['posts/byline'] - 'template:posts.byline' //=> Ember.TEMPLATES['posts/byline'] - 'template:blogPost' //=> Ember.TEMPLATES['blog-post'] - 'controller:post' //=> App.PostController - 'controller:posts.index' //=> App.PostsIndexController - 'controller:blog/post' //=> Blog.PostController - 'controller:basic' //=> Controller - 'route:post' //=> App.PostRoute - 'route:posts.index' //=> App.PostsIndexRoute - 'route:blog/post' //=> Blog.PostRoute - 'route:basic' //=> Route - 'foo:post' //=> App.PostFoo - 'model:post' //=> App.Post - ``` - - @class GlobalsResolver - @extends EmberObject - @public - @deprecated -*/ - -let DefaultResolver; - -if (GLOBALS_RESOLVER) { - DefaultResolver = class DefaultResolver extends EmberObject { - static create(props) { - // DO NOT REMOVE even though this doesn't do anything - // This is required for a FireFox 60+ JIT bug with our tests. - // without it, create(props) in our tests would lose props on a deopt. - return super.create(props); - } - - /** - This will be set to the Application instance when it is - created. - - @property namespace - @public - @deprecated - */ - - init() { - deprecate( - 'Using the globals resolver is deprecated. Use the ember-resolver package instead. See https://deprecations.emberjs.com/v3.x#toc_ember-deprecate-globals-resolver', - false, - { - until: '4.0.0', - id: 'globals-resolver', - url: 'https://deprecations.emberjs.com/v3.x#toc_ember-deprecate-globals-resolver', - for: 'ember-source', - since: { - enabled: '3.16.0', - }, - } - ); - - this._parseNameCache = dictionary(null); - } - - normalize(fullName) { - let [type, name] = fullName.split(':'); - - assert( - 'Tried to normalize a container name without a colon (:) in it. ' + - 'You probably tried to lookup a name that did not contain a type, ' + - 'a colon, and a name. A proper lookup name would be `view:post`.', - fullName.split(':').length === 2 - ); - - if (type !== 'template') { - let result = name.replace(/(\.|_|-)./g, (m) => m.charAt(1).toUpperCase()); - - return `${type}:${result}`; - } else { - return fullName; - } - } - - /** - This method is called via the container's resolver method. - It parses the provided `fullName` and then looks up and - returns the appropriate template or class. - - @method resolve - @param {String} fullName the lookup string - @return {Object} the resolved factory - @public - */ - resolve(fullName) { - let parsedName = this.parseName(fullName); - let resolveMethodName = parsedName.resolveMethodName; - let resolved; - - if (this[resolveMethodName]) { - resolved = this[resolveMethodName](parsedName); - } - - resolved = resolved || this.resolveOther(parsedName); - - if (DEBUG) { - if (parsedName.root && parsedName.root.LOG_RESOLVER) { - this._logLookup(resolved, parsedName); - } - - if (resolved) { - let VALIDATED_TYPES = { - route: ['isRouteFactory', 'Ember.Route'], - component: ['isComponentFactory', 'Ember.Component'], - view: ['isViewFactory', 'Ember.View'], - service: ['isServiceFactory', 'Ember.Service'], - }; - - let validationAttributes = VALIDATED_TYPES[parsedName.type]; - - if (validationAttributes) { - let [factoryFlag, expectedType] = validationAttributes; - - processAllNamespaces(); - - assert( - `Expected ${parsedName.fullName} to resolve to an ${expectedType} but ` + - `instead it was ${getName(resolved)}.`, - Boolean(resolved[factoryFlag]) - ); - } - } - } - - return resolved; - } - - /** - Convert the string name of the form 'type:name' to - a Javascript object with the parsed aspects of the name - broken out. - - @param {String} fullName the lookup string - @method parseName - @protected - */ - - parseName(fullName) { - return ( - this._parseNameCache[fullName] || - (this._parseNameCache[fullName] = this._parseName(fullName)) - ); - } - - _parseName(fullName) { - let [type, fullNameWithoutType] = fullName.split(':'); - - let name = fullNameWithoutType; - let namespace = get(this, 'namespace'); - let root = namespace; - let lastSlashIndex = name.lastIndexOf('/'); - let dirname = lastSlashIndex !== -1 ? name.slice(0, lastSlashIndex) : null; - - if (type !== 'template' && lastSlashIndex !== -1) { - let parts = name.split('/'); - name = parts[parts.length - 1]; - let namespaceName = capitalize(parts.slice(0, -1).join('.')); - root = findNamespace(namespaceName); - - assert( - `You are looking for a ${name} ${type} in the ${namespaceName} namespace, but the namespace could not be found`, - root - ); - } - - let resolveMethodName = fullNameWithoutType === 'main' ? 'Main' : classify(type); - - if (!(name && type)) { - throw new TypeError( - `Invalid fullName: \`${fullName}\`, must be of the form \`type:name\` ` - ); - } - - return { - fullName, - type, - fullNameWithoutType, - dirname, - name, - root, - resolveMethodName: `resolve${resolveMethodName}`, - }; - } - - /** - Returns a human-readable description for a fullName. Used by the - Application namespace in assertions to describe the - precise name of the class that Ember is looking for, rather than - container keys. - - @param {String} fullName the lookup string - @method lookupDescription - @protected - */ - lookupDescription(fullName) { - let parsedName = this.parseName(fullName); - let description; - - if (parsedName.type === 'template') { - return `template at ${parsedName.fullNameWithoutType.replace(/\./g, '/')}`; - } - - description = `${parsedName.root}.${classify(parsedName.name).replace(/\./g, '')}`; - - if (parsedName.type !== 'model') { - description += classify(parsedName.type); - } - - return description; - } - - makeToString(factory) { - return typeof factory === 'string' ? factory : factory.name ?? '(unknown class)'; - } - - /** - Given a parseName object (output from `parseName`), apply - the conventions expected by `Router` - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method useRouterNaming - @protected - */ - useRouterNaming(parsedName) { - if (parsedName.name === 'basic') { - parsedName.name = ''; - } else { - parsedName.name = parsedName.name.replace(/\./g, '_'); - } - } - /** - Look up the template in Ember.TEMPLATES - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveTemplate - @protected - */ - resolveTemplate(parsedName) { - let templateName = parsedName.fullNameWithoutType.replace(/\./g, '/'); - - return getTemplate(templateName) || getTemplate(decamelize(templateName)); - } - - /** - Lookup the view using `resolveOther` - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveView - @protected - */ - resolveView(parsedName) { - this.useRouterNaming(parsedName); - return this.resolveOther(parsedName); - } - - /** - Lookup the controller using `resolveOther` - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveController - @protected - */ - resolveController(parsedName) { - this.useRouterNaming(parsedName); - return this.resolveOther(parsedName); - } - /** - Lookup the route using `resolveOther` - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveRoute - @protected - */ - resolveRoute(parsedName) { - this.useRouterNaming(parsedName); - return this.resolveOther(parsedName); - } - - /** - Lookup the model on the Application namespace - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveModel - @protected - */ - resolveModel(parsedName) { - let className = classify(parsedName.name); - let factory = get(parsedName.root, className); - - return factory; - } - /** - Look up the specified object (from parsedName) on the appropriate - namespace (usually on the Application) - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveHelper - @protected - */ - resolveHelper(parsedName) { - return this.resolveOther(parsedName); - } - /** - Look up the specified object (from parsedName) on the appropriate - namespace (usually on the Application) - - @param {Object} parsedName a parseName object with the parsed - fullName lookup string - @method resolveOther - @protected - */ - resolveOther(parsedName) { - let className = classify(parsedName.name) + classify(parsedName.type); - let factory = get(parsedName.root, className); - return factory; - } - - resolveMain(parsedName) { - let className = classify(parsedName.type); - return get(parsedName.root, className); - } - - /** - Used to iterate all items of a given type. - - @method knownForType - @param {String} type the type to search for - @private - */ - knownForType(type) { - let namespace = get(this, 'namespace'); - let suffix = classify(type); - let typeRegexp = new RegExp(`${suffix}$`); - - let known = dictionary(null); - let knownKeys = Object.keys(namespace); - for (let index = 0; index < knownKeys.length; index++) { - let name = knownKeys[index]; - - if (typeRegexp.test(name)) { - let containerName = this.translateToContainerFullname(type, name); - - known[containerName] = true; - } - } - - return known; - } - - /** - Converts provided name from the backing namespace into a container lookup name. - - Examples: - - * App.FooBarHelper -> helper:foo-bar - * App.THelper -> helper:t - - @method translateToContainerFullname - @param {String} type - @param {String} name - @private - */ - translateToContainerFullname(type, name) { - let suffix = classify(type); - let namePrefix = name.slice(0, suffix.length * -1); - let dasherizedName = dasherize(namePrefix); - - return `${type}:${dasherizedName}`; - } - }; - - if (DEBUG) { - /** - @method _logLookup - @param {Boolean} found - @param {Object} parsedName - @private - */ - DefaultResolver.prototype._logLookup = function (found, parsedName) { - let symbol = found ? '[✓]' : '[ ]'; - - let padding; - if (parsedName.fullName.length > 60) { - padding = '.'; - } else { - padding = new Array(60 - parsedName.fullName.length).join('.'); - } - - info(symbol, parsedName.fullName, padding, this.lookupDescription(parsedName.fullName)); - }; - } -} - -export default DefaultResolver; diff --git a/packages/@ember/application/resolver.js b/packages/@ember/application/resolver.js deleted file mode 100644 index 731dbc19767..00000000000 --- a/packages/@ember/application/resolver.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './globals-resolver'; diff --git a/packages/@ember/application/tests/application_test.js b/packages/@ember/application/tests/application_test.js index 5988677d2c8..729ef0f5beb 100644 --- a/packages/@ember/application/tests/application_test.js +++ b/packages/@ember/application/tests/application_test.js @@ -1,21 +1,18 @@ import { DEBUG } from '@glimmer/env'; import VERSION from 'ember/version'; -import { ENV, context } from '@ember/-internals/environment'; -import { libraries, processAllNamespaces } from '@ember/-internals/metal'; -import { getName } from '@ember/-internals/utils'; +import { ENV } from '@ember/-internals/environment'; +import { libraries } from '@ember/-internals/metal'; import { getDebugFunction, setDebugFunction } from '@ember/debug'; import { Router, NoneLocation, Route as EmberRoute } from '@ember/-internals/routing'; import { jQueryDisabled, jQuery } from '@ember/-internals/views'; import { _loaded } from '@ember/application'; import Controller from '@ember/controller'; import { Object as EmberObject } from '@ember/-internals/runtime'; -import { setTemplates } from '@ember/-internals/glimmer'; import { moduleFor, ApplicationTestCase, AbstractTestCase, AutobootApplicationTestCase, - DefaultResolverApplicationTestCase, verifyInjection, verifyRegistration, runTask, @@ -171,54 +168,6 @@ moduleFor( } ); -moduleFor( - 'Application, default resolver with autoboot', - class extends DefaultResolverApplicationTestCase { - constructor() { - super(...arguments); - this.originalLookup = context.lookup; - } - - teardown() { - context.lookup = this.originalLookup; - super.teardown(); - setTemplates({}); - } - - get applicationOptions() { - return Object.assign(super.applicationOptions, { - autoboot: true, - }); - } - - [`@test acts like a namespace`](assert) { - this.application = runTask(() => this.createApplication()); - let Foo = (this.application.Foo = EmberObject.extend()); - processAllNamespaces(); - assert.equal(getName(Foo), 'TestApp.Foo', 'Classes pick up their parent namespace'); - } - - [`@test can specify custom router`](assert) { - let MyRouter = Router.extend(); - runTask(() => { - this.createApplication(); - this.application.Router = MyRouter; - }); - - assert.ok( - this.application.__deprecatedInstance__.lookup('router:main') instanceof MyRouter, - 'application resolved the correct router' - ); - } - - [`@test Minimal Application initialized with just an application template`]() { - this.setupFixture(''); - runTask(() => this.createApplication()); - this.assertInnerHTML('Hello World'); - } - } -); - moduleFor( 'Application, autobooting', class extends AutobootApplicationTestCase { diff --git a/packages/@ember/application/tests/bootstrap-test.js b/packages/@ember/application/tests/bootstrap-test.js deleted file mode 100644 index 41689a361cf..00000000000 --- a/packages/@ember/application/tests/bootstrap-test.js +++ /dev/null @@ -1,27 +0,0 @@ -import { moduleFor, DefaultResolverApplicationTestCase, runTask } from 'internal-test-helpers'; - -moduleFor( - 'Application with default resolver and autoboot', - class extends DefaultResolverApplicationTestCase { - get fixture() { - return ` -
- - - - `; - } - - get applicationOptions() { - return Object.assign(super.applicationOptions, { - autoboot: true, - rootElement: '#app', - }); - } - - ['@test templates in script tags are extracted at application creation'](assert) { - runTask(() => this.createApplication()); - assert.equal(document.getElementById('app').textContent, 'Hello World!'); - } - } -); diff --git a/packages/@ember/application/tests/dependency_injection/custom_resolver_test.js b/packages/@ember/application/tests/dependency_injection/custom_resolver_test.js deleted file mode 100644 index cab5dbf46fb..00000000000 --- a/packages/@ember/application/tests/dependency_injection/custom_resolver_test.js +++ /dev/null @@ -1,31 +0,0 @@ -import DefaultResolver from '@ember/application/globals-resolver'; -import { moduleFor, DefaultResolverApplicationTestCase, runTask } from 'internal-test-helpers'; - -moduleFor( - 'Application with extended default resolver and autoboot', - class extends DefaultResolverApplicationTestCase { - get applicationOptions() { - let applicationTemplate = this.compile(`

Fallback

`); - - let Resolver = DefaultResolver.extend({ - resolveTemplate(resolvable) { - if (resolvable.fullNameWithoutType === 'application') { - return applicationTemplate; - } else { - return this._super(resolvable); - } - }, - }); - - return Object.assign(super.applicationOptions, { - Resolver, - autoboot: true, - }); - } - - [`@test a resolver can be supplied to application`]() { - runTask(() => this.createApplication()); - this.assertText('Fallback'); - } - } -); diff --git a/packages/@ember/application/tests/dependency_injection/default_resolver_test.js b/packages/@ember/application/tests/dependency_injection/default_resolver_test.js deleted file mode 100644 index 46b9a68ffa6..00000000000 --- a/packages/@ember/application/tests/dependency_injection/default_resolver_test.js +++ /dev/null @@ -1,384 +0,0 @@ -import { DEBUG } from '@glimmer/env'; - -import { moduleFor, DefaultResolverApplicationTestCase, runTask } from 'internal-test-helpers'; - -import { context } from '@ember/-internals/environment'; -import Controller from '@ember/controller'; -import Service from '@ember/service'; -import { Object as EmberObject, Namespace } from '@ember/-internals/runtime'; -import { Route } from '@ember/-internals/routing'; -import { Component, Helper, helper as makeHelper } from '@ember/-internals/glimmer'; -import { getDebugFunction, setDebugFunction } from '@ember/debug'; - -moduleFor( - 'Application Dependency Injection - Integration - globals resolver [DEPRECATED]', - class extends DefaultResolverApplicationTestCase { - beforeEach() { - runTask(() => this.createApplication()); - return this.visit('/'); - } - - get privateRegistry() { - return this.application.__registry__; - } - - /* - * This first batch of tests are integration tests against the public - * applicationInstance API. - */ - - [`@test the default resolver looks up templates in Ember.TEMPLATES`](assert) { - let fooTemplate = this.addTemplate('foo', `foo template`); - let fooBarTemplate = this.addTemplate('fooBar', `fooBar template`); - let fooBarBazTemplate = this.addTemplate('fooBar/baz', `fooBar/baz template`); - - assert.equal( - this.applicationInstance.factoryFor('template:foo').class, - fooTemplate, - 'resolves template:foo' - ); - assert.equal( - this.applicationInstance.factoryFor('template:fooBar').class, - fooBarTemplate, - 'resolves template:foo_bar' - ); - assert.equal( - this.applicationInstance.factoryFor('template:fooBar.baz').class, - fooBarBazTemplate, - 'resolves template:foo_bar.baz' - ); - } - - [`@test the default resolver looks up basic name as no prefix`](assert) { - let instance = this.applicationInstance.lookup('controller:basic'); - assert.ok(Controller.detect(instance), 'locator looks up correct controller'); - } - - [`@test the default resolver looks up arbitrary types on the namespace`](assert) { - let Class = (this.application.FooManager = EmberObject.extend()); - let resolvedClass = this.application.resolveRegistration('manager:foo'); - assert.equal(Class, resolvedClass, 'looks up FooManager on application'); - } - - [`@test the default resolver resolves models on the namespace`](assert) { - let Class = (this.application.Post = EmberObject.extend()); - let factoryClass = this.applicationInstance.factoryFor('model:post').class; - assert.equal(Class, factoryClass, 'looks up Post model on application'); - } - - [`@test the default resolver resolves *:main on the namespace`](assert) { - let Class = (this.application.FooBar = EmberObject.extend()); - let factoryClass = this.applicationInstance.factoryFor('foo-bar:main').class; - assert.equal(Class, factoryClass, 'looks up FooBar type without name on application'); - } - - [`@test the default resolver resolves container-registered helpers`](assert) { - let shorthandHelper = makeHelper(() => {}); - let helper = Helper.extend(); - - this.application.register('helper:shorthand', shorthandHelper); - this.application.register('helper:complete', helper); - - let lookedUpShorthandHelper = this.applicationInstance.factoryFor('helper:shorthand').class; - - assert.ok(lookedUpShorthandHelper.isHelperFactory, 'shorthand helper isHelper'); - - let lookedUpHelper = this.applicationInstance.factoryFor('helper:complete').class; - - assert.ok(lookedUpHelper.isHelperFactory, 'complete helper is factory'); - assert.ok(helper.detect(lookedUpHelper), 'looked up complete helper'); - } - - [`@test the default resolver resolves container-registered helpers via lookupFor`](assert) { - let shorthandHelper = makeHelper(() => {}); - let helper = Helper.extend(); - - this.application.register('helper:shorthand', shorthandHelper); - this.application.register('helper:complete', helper); - - let lookedUpShorthandHelper = this.applicationInstance.factoryFor('helper:shorthand').class; - - assert.ok(lookedUpShorthandHelper.isHelperFactory, 'shorthand helper isHelper'); - - let lookedUpHelper = this.applicationInstance.factoryFor('helper:complete').class; - - assert.ok(lookedUpHelper.isHelperFactory, 'complete helper is factory'); - assert.ok(helper.detect(lookedUpHelper), 'looked up complete helper'); - } - - [`@test the default resolver resolves helpers on the namespace`](assert) { - let ShorthandHelper = makeHelper(() => {}); - let CompleteHelper = Helper.extend(); - - this.application.ShorthandHelper = ShorthandHelper; - this.application.CompleteHelper = CompleteHelper; - - let resolvedShorthand = this.application.resolveRegistration('helper:shorthand'); - let resolvedComplete = this.application.resolveRegistration('helper:complete'); - - assert.equal( - resolvedShorthand, - ShorthandHelper, - 'resolve fetches the shorthand helper factory' - ); - assert.equal(resolvedComplete, CompleteHelper, 'resolve fetches the complete helper factory'); - } - - [`@test the default resolver resolves to the same instance, no matter the notation `](assert) { - this.application.NestedPostController = Controller.extend({}); - - assert.equal( - this.applicationInstance.lookup('controller:nested-post'), - this.applicationInstance.lookup('controller:nested_post'), - 'looks up NestedPost controller on application' - ); - } - - [`@test the default resolver throws an error if the fullName to resolve is invalid`]() { - expectAssertion(() => { - this.applicationInstance.resolveRegistration(undefined); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration(null); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration(''); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration(''); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration(':'); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration('model'); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration('model:'); - }, /fullName must be a proper full name/); - expectAssertion(() => { - this.applicationInstance.resolveRegistration(':type'); - }, /fullName must be a proper full name/); - } - - ['@test the default resolver normalizes lookups'](assert) { - let locator = this.applicationInstance.__container__; - this.application.PostIndexController = EmberObject.extend({}); - this.application.register('controller:postIndex', this.application.PostIndexController, { - singleton: true, - }); - - let dotNotationController = locator.lookup('controller:post.index'); - let camelCaseController = locator.lookup('controller:postIndex'); - - assert.ok(dotNotationController instanceof this.application.PostIndexController); - assert.ok(camelCaseController instanceof this.application.PostIndexController); - - assert.equal(dotNotationController, camelCaseController); - } - - /* - * The following are integration tests against the private registry API. - */ - - [`@test lookup description`](assert) { - this.application.toString = () => 'App'; - - assert.equal( - this.privateRegistry.describe('controller:foo'), - 'App.FooController', - 'Type gets appended at the end' - ); - assert.equal( - this.privateRegistry.describe('controller:foo.bar'), - 'App.FooBarController', - 'dots are removed' - ); - assert.equal( - this.privateRegistry.describe('model:foo'), - 'App.Foo', - "models don't get appended at the end" - ); - } - - [`@test assertion for routes without isRouteFactory property`]() { - this.application.FooRoute = Component.extend(); - - expectAssertion( - () => { - this.privateRegistry.resolve(`route:foo`); - }, - /to resolve to an Ember.Route/, - 'Should assert' - ); - } - - [`@test no assertion for routes that extend from Route`](assert) { - assert.test.assertions = []; // clear assertions that occurred in beforeEach so they don't affect count - assert.expect(0); - this.application.FooRoute = Route.extend(); - this.privateRegistry.resolve(`route:foo`); - } - - [`@test assertion for service factories without isServiceFactory property`]() { - expectAssertion(() => { - this.application.FooService = EmberObject.extend(); - this.privateRegistry.resolve('service:foo'); - }, /Expected service:foo to resolve to an Ember.Service but instead it was TestApp\.FooService\./); - } - - [`@test no assertion for service factories that extend from Service`](assert) { - assert.test.assertions = []; // clear assertions that occurred in beforeEach so they don't affect count - assert.expect(0); - this.application.FooService = Service.extend(); - this.privateRegistry.resolve('service:foo'); - } - - [`@test assertion for component factories without isComponentFactory property`]() { - expectAssertion(() => { - this.application.FooComponent = EmberObject.extend(); - this.privateRegistry.resolve('component:foo'); - }, /Expected component:foo to resolve to an Ember\.Component but instead it was TestApp\.FooComponent\./); - } - - [`@test no assertion for component factories that extend from Component`]() { - expectNoDeprecation(); - this.application.FooView = Component.extend(); - this.privateRegistry.resolve('component:foo'); - } - - [`@test knownForType returns each item for a given type found`](assert) { - this.application.FooBarHelper = 'foo'; - this.application.BazQuxHelper = 'bar'; - - let found = this.privateRegistry.resolver.knownForType('helper'); - - assert.deepEqual(found, { - 'helper:foo-bar': true, - 'helper:baz-qux': true, - }); - } - - [`@test knownForType is not required to be present on the resolver`](assert) { - delete this.privateRegistry.resolver.knownForType; - - this.privateRegistry.resolver.knownForType('helper', () => {}); - - assert.ok(true, 'does not error'); - } - } -); - -moduleFor( - 'Application Dependency Injection - Integration - default resolver w/ other namespace', - class extends DefaultResolverApplicationTestCase { - beforeEach() { - this.UserInterface = context.lookup.UserInterface = Namespace.create(); - runTask(() => this.createApplication()); - return this.visit('/'); - } - - teardown() { - let UserInterfaceNamespace = Namespace.NAMESPACES_BY_ID['UserInterface']; - if (UserInterfaceNamespace) { - runTask(() => { - UserInterfaceNamespace.destroy(); - }); - } - super.teardown(); - } - - [`@test the default resolver can look things up in other namespaces`](assert) { - this.UserInterface.NavigationController = Controller.extend(); - - let nav = this.applicationInstance.lookup('controller:userInterface/navigation'); - - assert.ok( - nav instanceof this.UserInterface.NavigationController, - 'the result should be an instance of the specified class' - ); - } - } -); - -moduleFor( - 'Application Dependency Injection - Integration - default resolver', - class extends DefaultResolverApplicationTestCase { - constructor() { - super(); - this._originalLookup = context.lookup; - this._originalInfo = getDebugFunction('info'); - } - - beforeEach() { - runTask(() => this.createApplication()); - return this.visit('/'); - } - - teardown() { - setDebugFunction('info', this._originalInfo); - context.lookup = this._originalLookup; - super.teardown(); - } - - [`@test the default resolver logs hits if 'LOG_RESOLVER' is set`](assert) { - if (!DEBUG) { - assert.ok(true, 'Logging does not occur in production builds'); - return; - } - - assert.test.assertions = []; // clear assertions that occurred in beforeEach so they don't affect count - assert.expect(3); - - this.application.LOG_RESOLVER = true; - this.application.ScoobyDoo = EmberObject.extend(); - this.application.toString = () => 'App'; - - setDebugFunction('info', function (symbol, name, padding, lookupDescription) { - assert.equal(symbol, '[✓]', 'proper symbol is printed when a module is found'); - assert.equal(name, 'doo:scooby', 'proper lookup value is logged'); - assert.equal(lookupDescription, 'App.ScoobyDoo'); - }); - - this.applicationInstance.resolveRegistration('doo:scooby'); - } - - [`@test the default resolver logs misses if 'LOG_RESOLVER' is set`](assert) { - if (!DEBUG) { - assert.ok(true, 'Logging does not occur in production builds'); - return; - } - - assert.test.assertions = []; // clear assertions that occurred in beforeEach so they don't affect count - assert.expect(3); - - this.application.LOG_RESOLVER = true; - this.application.toString = () => 'App'; - - setDebugFunction('info', function (symbol, name, padding, lookupDescription) { - assert.equal(symbol, '[ ]', 'proper symbol is printed when a module is not found'); - assert.equal(name, 'doo:scooby', 'proper lookup value is logged'); - assert.equal(lookupDescription, 'App.ScoobyDoo'); - }); - - this.applicationInstance.resolveRegistration('doo:scooby'); - } - - [`@test doesn't log without LOG_RESOLVER`](assert) { - if (!DEBUG) { - assert.ok(true, 'Logging does not occur in production builds'); - return; - } - - let infoCount = 0; - - this.application.ScoobyDoo = EmberObject.extend(); - - setDebugFunction('info', () => (infoCount = infoCount + 1)); - - this.applicationInstance.resolveRegistration('doo:scooby'); - this.applicationInstance.resolveRegistration('doo:scrappy'); - assert.equal(infoCount, 0, 'console.info should not be called if LOG_RESOLVER is not set'); - } - } -); diff --git a/packages/@ember/application/tests/dependency_injection/normalization_test.js b/packages/@ember/application/tests/dependency_injection/normalization_test.js deleted file mode 100644 index d6f726cbc22..00000000000 --- a/packages/@ember/application/tests/dependency_injection/normalization_test.js +++ /dev/null @@ -1,75 +0,0 @@ -import { run } from '@ember/runloop'; -import Application from '@ember/application'; -import { moduleFor, AbstractTestCase as TestCase } from 'internal-test-helpers'; - -let application, registry; - -moduleFor( - 'Application Dependency Injection - Globals Resolver - normalize [DEPRECATED]', - class extends TestCase { - constructor() { - super(); - - // Must use default resolver because test resolver does not normalize - run(() => { - expectDeprecation(() => { - application = Application.create(); - }); - }); - registry = application.__registry__; - } - - teardown() { - super.teardown(); - run(application, 'destroy'); - application = undefined; - registry = undefined; - } - - ['@test normalization'](assert) { - assert.ok(registry.normalize, 'registry#normalize is present'); - - assert.equal(registry.normalize('foo:bar'), 'foo:bar'); - - assert.equal(registry.normalize('controller:posts'), 'controller:posts'); - assert.equal(registry.normalize('controller:posts_index'), 'controller:postsIndex'); - assert.equal(registry.normalize('controller:posts.index'), 'controller:postsIndex'); - assert.equal(registry.normalize('controller:posts-index'), 'controller:postsIndex'); - assert.equal(registry.normalize('controller:posts.post.index'), 'controller:postsPostIndex'); - assert.equal(registry.normalize('controller:posts_post.index'), 'controller:postsPostIndex'); - assert.equal(registry.normalize('controller:posts.post_index'), 'controller:postsPostIndex'); - assert.equal(registry.normalize('controller:posts.post-index'), 'controller:postsPostIndex'); - assert.equal(registry.normalize('controller:postsIndex'), 'controller:postsIndex'); - assert.equal(registry.normalize('controller:blogPosts.index'), 'controller:blogPostsIndex'); - assert.equal(registry.normalize('controller:blog/posts.index'), 'controller:blog/postsIndex'); - assert.equal(registry.normalize('controller:blog/posts-index'), 'controller:blog/postsIndex'); - assert.equal( - registry.normalize('controller:blog/posts.post.index'), - 'controller:blog/postsPostIndex' - ); - assert.equal( - registry.normalize('controller:blog/posts_post.index'), - 'controller:blog/postsPostIndex' - ); - assert.equal( - registry.normalize('controller:blog/posts_post-index'), - 'controller:blog/postsPostIndex' - ); - - assert.equal(registry.normalize('template:blog/posts_index'), 'template:blog/posts_index'); - } - - ['@test normalization is indempotent'](assert) { - let examples = [ - 'controller:posts', - 'controller:posts.post.index', - 'controller:blog/posts.post_index', - 'template:foo_bar', - ]; - - examples.forEach((example) => { - assert.equal(registry.normalize(registry.normalize(example)), registry.normalize(example)); - }); - } - } -); diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index 354f3956f66..16d2379ae79 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -10,4 +10,3 @@ export const JQUERY_INTEGRATION = !!'3.9.0'; export const APP_CTRL_ROUTER_PROPS = !!'3.10.0-beta.1'; export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = !!'3.13.0-beta.1'; export const PARTIALS = !!'3.15.0-beta.1'; -export const GLOBALS_RESOLVER = !!'3.16.0-beta.1'; diff --git a/packages/@ember/engine/index.js b/packages/@ember/engine/index.js index 7901e14908e..270e5d04869 100644 --- a/packages/@ember/engine/index.js +++ b/packages/@ember/engine/index.js @@ -7,7 +7,6 @@ import { Registry } from '@ember/-internals/container'; import DAG from 'dag-map'; import { assert } from '@ember/debug'; import { get, set } from '@ember/-internals/metal'; -import DefaultResolver from '@ember/application/globals-resolver'; import EngineInstance from '@ember/engine/instance'; import { RoutingService } from '@ember/-internals/routing'; import { ContainerDebugAdapter } from '@ember/-internals/extension-support'; @@ -417,15 +416,6 @@ Engine.reopenClass({ return registry; }, - /** - Set this to provide an alternate class to `DefaultResolver` - - @deprecated Use 'Resolver' instead - @property resolver - @public - */ - resolver: null, - /** Set this to provide an alternate class to `DefaultResolver` @@ -452,7 +442,7 @@ Engine.reopenClass({ @return {*} the resolved value for a given lookup */ function resolverFor(namespace) { - let ResolverClass = get(namespace, 'Resolver') || DefaultResolver; + let ResolverClass = get(namespace, 'Resolver'); let props = { namespace }; return ResolverClass.create(props); } diff --git a/packages/ember/index.js b/packages/ember/index.js index 02a8fb88b68..efc2635c2b1 100644 --- a/packages/ember/index.js +++ b/packages/ember/index.js @@ -94,7 +94,6 @@ import { run } from '@ember/runloop'; import { getOnerror, setOnerror } from '@ember/-internals/error-handling'; import { getOwner, setOwner } from '@ember/-internals/owner'; import Application, { onLoad, runLoadHooks } from '@ember/application'; -import Resolver from '@ember/application/globals-resolver'; import ApplicationInstance from '@ember/application/instance'; import Engine from '@ember/engine'; import EngineInstance from '@ember/engine/instance'; @@ -156,32 +155,6 @@ Ember.setOwner = setOwner; Ember.Application = Application; Ember.ApplicationInstance = ApplicationInstance; -Object.defineProperty(Ember, 'Resolver', { - get() { - deprecate( - 'Using the globals resolver is deprecated. Use the ember-resolver package instead. See https://deprecations.emberjs.com/v3.x#toc_ember-deprecate-globals-resolver', - false, - { - id: 'ember.globals-resolver', - until: '4.0.0', - url: 'https://deprecations.emberjs.com/v3.x#toc_ember-deprecate-globals-resolver', - for: 'ember-source', - since: { - enabled: '3.16.0', - }, - } - ); - - return Resolver; - }, -}); - -Object.defineProperty(Ember, 'DefaultResolver', { - get() { - return Ember.Resolver; - }, -}); - // ****@ember/engine**** Ember.Engine = Engine; Ember.EngineInstance = EngineInstance; diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index b239bfaf707..9557b31c8ff 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -2,7 +2,6 @@ import Ember from '../index'; import require from 'require'; import { EMBER_MODERNIZED_BUILT_IN_COMPONENTS, FEATURES } from '@ember/canary-features'; import { AbstractTestCase, confirmExport, moduleFor } from 'internal-test-helpers'; -import Resolver from '@ember/application/globals-resolver'; import { DEBUG } from '@glimmer/env'; import { ENV } from '@ember/-internals/environment'; @@ -109,18 +108,6 @@ moduleFor( ); } } - - ['@test Ember.Resolver is present (but deprecated)'](assert) { - expectDeprecation(() => { - assert.strictEqual(Ember.Resolver, Resolver, 'Ember.Resolver exists'); - }, /Using the globals resolver is deprecated/); - } - - ['@test Ember.DefaultResolver is present (but deprecated)'](assert) { - expectDeprecation(() => { - assert.strictEqual(Ember.DefaultResolver, Resolver, 'Ember.DefaultResolver exists'); - }, /Using the globals resolver is deprecated/); - } } ); diff --git a/packages/internal-test-helpers/index.js b/packages/internal-test-helpers/index.js index 5a287432277..49cb9317178 100644 --- a/packages/internal-test-helpers/index.js +++ b/packages/internal-test-helpers/index.js @@ -31,7 +31,6 @@ export { default as RenderingTestCase } from './lib/test-cases/rendering'; export { default as RouterNonApplicationTestCase } from './lib/test-cases/router-non-application'; export { default as RouterTestCase } from './lib/test-cases/router'; export { default as AutobootApplicationTestCase } from './lib/test-cases/autoboot-application'; -export { default as DefaultResolverApplicationTestCase } from './lib/test-cases/default-resolver-application'; export { default as TestResolver, diff --git a/packages/internal-test-helpers/lib/test-cases/default-resolver-application.js b/packages/internal-test-helpers/lib/test-cases/default-resolver-application.js deleted file mode 100644 index 83e9559fbcd..00000000000 --- a/packages/internal-test-helpers/lib/test-cases/default-resolver-application.js +++ /dev/null @@ -1,55 +0,0 @@ -import AbstractApplicationTestCase from './abstract-application'; -import DefaultResolver from '@ember/application/globals-resolver'; -import Application from '@ember/application'; -import { setTemplates, setTemplate } from '@ember/-internals/glimmer'; -import { Router } from '@ember/-internals/routing'; - -import { runTask } from '../run'; - -export default class DefaultResolverApplicationTestCase extends AbstractApplicationTestCase { - createApplication() { - let application; - expectDeprecation(() => { - application = this.application = Application.create(this.applicationOptions); - }, /(Using the globals resolver is deprecated|Usage of the Ember Global is deprecated)/); - - // If the test expects a certain number of assertions, increment that number - let { assert } = QUnit.config.current; - if (typeof assert.test.expected === 'number') { - assert.test.expected += 1; - QUnit.config.current.expected += 1; - } - - application.Router = Router.extend(this.routerOptions); - return application; - } - - get applicationOptions() { - return Object.assign(super.applicationOptions, { - name: 'TestApp', - autoboot: false, - Resolver: DefaultResolver, - }); - } - - afterEach() { - setTemplates({}); - return super.afterEach(); - } - - get appRouter() { - return this.applicationInstance.lookup('router:main'); - } - - transitionTo() { - return runTask(() => { - return this.appRouter.transitionTo(...arguments); - }); - } - - addTemplate(name, templateString) { - let compiled = this.compile(templateString); - setTemplate(name, compiled); - return compiled; - } -} diff --git a/tests/docs/expected.js b/tests/docs/expected.js index 354287d995e..5898e758a20 100644 --- a/tests/docs/expected.js +++ b/tests/docs/expected.js @@ -36,7 +36,6 @@ module.exports = { '_internalReset', '_invoke', '_lazyInjections', - '_logLookup', '_normalizeCache', '_onLookup', '_options', @@ -352,7 +351,6 @@ module.exports = { 'location', 'log', 'lookup', - 'lookupDescription', 'lt', 'lte', 'makeArray', @@ -375,7 +373,6 @@ module.exports = { 'mount', 'mut', 'name', - 'namespace', 'nearestOfType', 'nearestWithProperty', 'next', @@ -411,7 +408,6 @@ module.exports = { 'parent', 'parentView', 'parentViewDidChange', - 'parseName', 'partial', 'pattern', 'pauseTest', @@ -482,16 +478,9 @@ module.exports = { 'reset', 'resetController', 'resolve', - 'resolveController', - 'resolveHelper', - 'resolveModel', - 'resolveOther', 'resolver', 'resolveRegistration', 'resolverFor', - 'resolveRoute', - 'resolveTemplate', - 'resolveView', 'resumeTest', 'rethrow', 'retry', @@ -563,7 +552,6 @@ module.exports = { 'tracked', 'transitionTo', 'transitionToRoute', - 'translateToContainerFullname', 'trigger', 'triggerAction', 'triggerEvent', @@ -588,7 +576,6 @@ module.exports = { 'url', 'urlFor', 'userAgent', - 'useRouterNaming', 'validationCache', 'value', 'visit',