diff --git a/packages/@ember/-internals/glimmer/lib/resolver.ts b/packages/@ember/-internals/glimmer/lib/resolver.ts index 89603e35e98..a5e8cf33366 100644 --- a/packages/@ember/-internals/glimmer/lib/resolver.ts +++ b/packages/@ember/-internals/glimmer/lib/resolver.ts @@ -1,13 +1,15 @@ import { privatize as P } from '@ember/-internals/container'; import { ENV } from '@ember/-internals/environment'; import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner'; -import { lookupPartial, OwnedTemplateMeta } from '@ember/-internals/views'; +import { OwnedTemplateMeta } from '@ember/-internals/views'; import { EMBER_GLIMMER_SET_COMPONENT_TEMPLATE, EMBER_MODULE_UNIFICATION, } from '@ember/canary-features'; import { isTemplateOnlyComponent } from '@ember/component/template-only'; -import { assert } from '@ember/debug'; +import { assert, deprecate } from '@ember/debug'; +import { PARTIALS } from '@ember/deprecated-features'; +import EmberError from '@ember/error'; import { _instrumentStart } from '@ember/instrumentation'; import { ComponentDefinition, @@ -176,6 +178,60 @@ function lookupComponent(owner: Owner, name: string, options: LookupOptions): Op return lookupComponentPair(owner, name); } +let lookupPartial: { templateName: string; owner: Owner } | any; + +if (PARTIALS) { + lookupPartial = function(templateName: string, owner: Owner) { + deprecate( + `The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, + false, + { + id: 'ember-views.partial', + until: '4.0.0', + url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', + } + ); + + if (templateName === null) { + return; + } + + let template = templateFor(owner, parseUnderscoredName(templateName), templateName); + + assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); + + return template; + }; + + function templateFor(owner: any, underscored: string, name: string) { + if (PARTIALS) { + if (!name) { + return; + } + assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); + + if (!owner) { + throw new EmberError( + 'Container was not found when looking up a views template. ' + + 'This is most likely due to manually instantiating an Ember.View. ' + + 'See: http://git.io/EKPpnA' + ); + } + + return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); + } + } + + function parseUnderscoredName(templateName: string) { + let nameParts = templateName.split('/'); + let lastPart = nameParts[nameParts.length - 1]; + + nameParts[nameParts.length - 1] = `_${lastPart}`; + + return nameParts.join('/'); + } +} + interface IBuiltInHelpers { [name: string]: Helper | undefined; } @@ -306,8 +362,12 @@ export default class RuntimeResolver implements IRuntimeResolver { - let partial = this._lookupPartial(name, meta); - return this.handle(partial); + if (PARTIALS) { + let partial = this._lookupPartial(name, meta); + return this.handle(partial); + } else { + return null; + } } // end CompileTimeLookup diff --git a/packages/@ember/-internals/views/index.d.ts b/packages/@ember/-internals/views/index.d.ts index 079c0f6e758..143017ca5ae 100644 --- a/packages/@ember/-internals/views/index.d.ts +++ b/packages/@ember/-internals/views/index.d.ts @@ -35,10 +35,6 @@ export function isSimpleClick(event: Event): boolean; export function constructStyleDeprecationMessage(affectedStyle: any): string; -export function hasPartial(name: string, owner: any): boolean; - -export function lookupPartial(templateName: string, owner: Owner): TemplateFactory; - export function getViewId(view: any): string; export const MUTABLE_CELL: string; diff --git a/packages/@ember/-internals/views/index.js b/packages/@ember/-internals/views/index.js index 7b14200d9be..6224d9e17bf 100644 --- a/packages/@ember/-internals/views/index.js +++ b/packages/@ember/-internals/views/index.js @@ -26,5 +26,4 @@ export { default as ViewStateSupport } from './lib/mixins/view_state_support'; export { default as ViewMixin } from './lib/mixins/view_support'; export { default as ActionSupport } from './lib/mixins/action_support'; export { MUTABLE_CELL } from './lib/compat/attrs'; -export { default as lookupPartial, hasPartial } from './lib/system/lookup_partial'; export { default as ActionManager } from './lib/system/action_manager'; diff --git a/packages/@ember/-internals/views/lib/system/lookup_partial.js b/packages/@ember/-internals/views/lib/system/lookup_partial.js deleted file mode 100644 index 951f62f8b70..00000000000 --- a/packages/@ember/-internals/views/lib/system/lookup_partial.js +++ /dev/null @@ -1,74 +0,0 @@ -import { assert, deprecate } from '@ember/debug'; -import EmberError from '@ember/error'; -import { PARTIALS } from '@ember/deprecated-features'; - -function parseUnderscoredName(templateName) { - if (PARTIALS) { - let nameParts = templateName.split('/'); - let lastPart = nameParts[nameParts.length - 1]; - - nameParts[nameParts.length - 1] = `_${lastPart}`; - - return nameParts.join('/'); - } -} - -export default function lookupPartial(templateName, owner) { - if (PARTIALS) { - deprecate( - `The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, - false, - { - id: 'ember-views.partial', - until: '4.0.0', - url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', - } - ); - - if (templateName == null) { - return; - } - - let template = templateFor(owner, parseUnderscoredName(templateName), templateName); - - assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); - - return template; - } -} - -export function hasPartial(name, owner) { - if (PARTIALS) { - if (!owner) { - throw new EmberError( - 'Container was not found when looking up a views template. ' + - 'This is most likely due to manually instantiating an Ember.View. ' + - 'See: http://git.io/EKPpnA' - ); - } - - return ( - owner.hasRegistration(`template:${parseUnderscoredName(name)}`) || - owner.hasRegistration(`template:${name}`) - ); - } -} - -function templateFor(owner, underscored, name) { - if (PARTIALS) { - if (!name) { - return; - } - assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); - - if (!owner) { - throw new EmberError( - 'Container was not found when looking up a views template. ' + - 'This is most likely due to manually instantiating an Ember.View. ' + - 'See: http://git.io/EKPpnA' - ); - } - - return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); - } -}