|
1 | 1 | import { privatize as P } from '@ember/-internals/container'; |
2 | 2 | import { ENV } from '@ember/-internals/environment'; |
3 | 3 | import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner'; |
4 | | -import { lookupPartial, OwnedTemplateMeta } from '@ember/-internals/views'; |
| 4 | +import { OwnedTemplateMeta } from '@ember/-internals/views'; |
5 | 5 | import { |
6 | 6 | EMBER_GLIMMER_SET_COMPONENT_TEMPLATE, |
7 | 7 | EMBER_MODULE_UNIFICATION, |
8 | 8 | } from '@ember/canary-features'; |
9 | 9 | import { isTemplateOnlyComponent } from '@ember/component/template-only'; |
10 | | -import { assert } from '@ember/debug'; |
| 10 | +import { assert, deprecate } from '@ember/debug'; |
| 11 | +import { PARTIALS } from '@ember/deprecated-features'; |
| 12 | +import EmberError from '@ember/error'; |
11 | 13 | import { _instrumentStart } from '@ember/instrumentation'; |
12 | 14 | import { |
13 | 15 | ComponentDefinition, |
@@ -176,6 +178,62 @@ function lookupComponent(owner: Owner, name: string, options: LookupOptions): Op |
176 | 178 | return lookupComponentPair(owner, name); |
177 | 179 | } |
178 | 180 |
|
| 181 | +let lookupPartial: { templateName: string; owner: Owner } | any; |
| 182 | +let templateFor: { owner: Owner; underscored: string; name: string } | any; |
| 183 | +let parseUnderscoredName: { templateName: string } | any; |
| 184 | + |
| 185 | +if (PARTIALS) { |
| 186 | + lookupPartial = function(templateName: string, owner: Owner) { |
| 187 | + deprecate( |
| 188 | + `The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, |
| 189 | + false, |
| 190 | + { |
| 191 | + id: 'ember-views.partial', |
| 192 | + until: '4.0.0', |
| 193 | + url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', |
| 194 | + } |
| 195 | + ); |
| 196 | + |
| 197 | + if (templateName === null) { |
| 198 | + return; |
| 199 | + } |
| 200 | + |
| 201 | + let template = templateFor(owner, parseUnderscoredName(templateName), templateName); |
| 202 | + |
| 203 | + assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); |
| 204 | + |
| 205 | + return template; |
| 206 | + }; |
| 207 | + |
| 208 | + templateFor = function(owner: any, underscored: string, name: string) { |
| 209 | + if (PARTIALS) { |
| 210 | + if (!name) { |
| 211 | + return; |
| 212 | + } |
| 213 | + assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); |
| 214 | + |
| 215 | + if (!owner) { |
| 216 | + throw new EmberError( |
| 217 | + 'Container was not found when looking up a views template. ' + |
| 218 | + 'This is most likely due to manually instantiating an Ember.View. ' + |
| 219 | + 'See: http://git.io/EKPpnA' |
| 220 | + ); |
| 221 | + } |
| 222 | + |
| 223 | + return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); |
| 224 | + } |
| 225 | + }; |
| 226 | + |
| 227 | + parseUnderscoredName = function(templateName: string) { |
| 228 | + let nameParts = templateName.split('/'); |
| 229 | + let lastPart = nameParts[nameParts.length - 1]; |
| 230 | + |
| 231 | + nameParts[nameParts.length - 1] = `_${lastPart}`; |
| 232 | + |
| 233 | + return nameParts.join('/'); |
| 234 | + }; |
| 235 | +} |
| 236 | + |
179 | 237 | interface IBuiltInHelpers { |
180 | 238 | [name: string]: Helper | undefined; |
181 | 239 | } |
@@ -306,8 +364,12 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe |
306 | 364 | * Called by CompileTimeLookup to lookup partial |
307 | 365 | */ |
308 | 366 | lookupPartial(name: string, meta: OwnedTemplateMeta): Option<number> { |
309 | | - let partial = this._lookupPartial(name, meta); |
310 | | - return this.handle(partial); |
| 367 | + if (PARTIALS) { |
| 368 | + let partial = this._lookupPartial(name, meta); |
| 369 | + return this.handle(partial); |
| 370 | + } else { |
| 371 | + return null; |
| 372 | + } |
311 | 373 | } |
312 | 374 |
|
313 | 375 | // end CompileTimeLookup |
|
0 commit comments