@@ -28,12 +28,7 @@ import {
28
28
} from '@lwc/shared' ;
29
29
import { getAttrNameFromPropName } from './attributes' ;
30
30
import { EmptyObject } from './utils' ;
31
- import {
32
- ComponentConstructor ,
33
- ErrorCallback ,
34
- ComponentMeta ,
35
- getComponentRegisteredMeta ,
36
- } from './component' ;
31
+ import { ComponentConstructor , ErrorCallback , getComponentRegisteredTemplate } from './component' ;
37
32
import { Template } from './template' ;
38
33
import { BaseLightningElement , lightningBasedDescriptors } from './base-lightning-element' ;
39
34
import { PropType , getDecoratorsMeta } from './decorators/register' ;
@@ -68,11 +63,11 @@ export interface ComponentDef {
68
63
69
64
const CtorToDefMap : WeakMap < any , ComponentDef > = new WeakMap ( ) ;
70
65
71
- function getCtorProto ( Ctor : any , subclassComponentName : string ) : ComponentConstructor {
66
+ function getCtorProto ( Ctor : ComponentConstructor ) : ComponentConstructor {
72
67
let proto : ComponentConstructor | null = getPrototypeOf ( Ctor ) ;
73
68
if ( isNull ( proto ) ) {
74
69
throw new ReferenceError (
75
- `Invalid prototype chain for ${ subclassComponentName } , you must extend LightningElement.`
70
+ `Invalid prototype chain for ${ Ctor . name } , you must extend LightningElement.`
76
71
) ;
77
72
}
78
73
// covering the cases where the ref is circular in AMD
@@ -81,7 +76,7 @@ function getCtorProto(Ctor: any, subclassComponentName: string): ComponentConstr
81
76
if ( process . env . NODE_ENV !== 'production' ) {
82
77
if ( isNull ( p ) ) {
83
78
throw new ReferenceError (
84
- `Circular module dependency for ${ subclassComponentName } , must resolve to a constructor that extends LightningElement.`
79
+ `Circular module dependency for ${ Ctor . name } , must resolve to a constructor that extends LightningElement.`
85
80
) ;
86
81
}
87
82
}
@@ -94,13 +89,8 @@ function getCtorProto(Ctor: any, subclassComponentName: string): ComponentConstr
94
89
return proto ! ;
95
90
}
96
91
97
- function createComponentDef (
98
- Ctor : ComponentConstructor ,
99
- meta : ComponentMeta ,
100
- subclassComponentName : string
101
- ) : ComponentDef {
92
+ function createComponentDef ( Ctor : ComponentConstructor ) : ComponentDef {
102
93
if ( process . env . NODE_ENV !== 'production' ) {
103
- // local to dev block
104
94
const ctorName = Ctor . name ;
105
95
// Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
106
96
// assert.isTrue(ctorName && isString(ctorName), `${toString(Ctor)} should have a "name" property with string value, but found ${ctorName}.`);
@@ -110,8 +100,6 @@ function createComponentDef(
110
100
) ;
111
101
}
112
102
113
- const { name } = meta ;
114
- let { template } = meta ;
115
103
const decoratorsMeta = getDecoratorsMeta ( Ctor ) ;
116
104
const {
117
105
apiFields,
@@ -130,13 +118,12 @@ function createComponentDef(
130
118
errorCallback,
131
119
render,
132
120
} = proto ;
133
- const superProto = getCtorProto ( Ctor , subclassComponentName ) ;
134
- const superDef : ComponentDef =
135
- ( superProto as any ) !== BaseLightningElement
136
- ? getComponentInternalDef ( superProto , subclassComponentName )
121
+ const superProto = getCtorProto ( Ctor ) ;
122
+ const superDef =
123
+ superProto !== BaseLightningElement
124
+ ? getComponentInternalDef ( superProto )
137
125
: lightingElementDef ;
138
- const SuperBridge = isNull ( superDef ) ? BaseBridgeElement : superDef . bridge ;
139
- const bridge = HTMLBridgeElementFactory ( SuperBridge , keys ( apiFields ) , keys ( apiMethods ) ) ;
126
+ const bridge = HTMLBridgeElementFactory ( superDef . bridge , keys ( apiFields ) , keys ( apiMethods ) ) ;
140
127
const props : PropertyDescriptorMap = assign ( create ( null ) , superDef . props , apiFields ) ;
141
128
const propsConfig = assign ( create ( null ) , superDef . propsConfig , apiFieldsConfig ) ;
142
129
const methods : PropertyDescriptorMap = assign ( create ( null ) , superDef . methods , apiMethods ) ;
@@ -151,7 +138,9 @@ function createComponentDef(
151
138
renderedCallback = renderedCallback || superDef . renderedCallback ;
152
139
errorCallback = errorCallback || superDef . errorCallback ;
153
140
render = render || superDef . render ;
154
- template = template || superDef . template ;
141
+
142
+ const template = getComponentRegisteredTemplate ( Ctor ) || superDef . template ;
143
+ const name = Ctor . name || superDef . name ;
155
144
156
145
// installing observed fields into the prototype.
157
146
defineProperties ( proto , observedFields ) ;
@@ -218,7 +207,7 @@ export function isComponentConstructor(ctor: unknown): ctor is ComponentConstruc
218
207
return false ;
219
208
}
220
209
221
- export function getComponentInternalDef ( Ctor : unknown , name ?: string ) : ComponentDef {
210
+ export function getComponentInternalDef ( Ctor : unknown ) : ComponentDef {
222
211
let def = CtorToDefMap . get ( Ctor ) ;
223
212
224
213
if ( isUndefined ( def ) ) {
@@ -237,16 +226,7 @@ export function getComponentInternalDef(Ctor: unknown, name?: string): Component
237
226
) ;
238
227
}
239
228
240
- let meta = getComponentRegisteredMeta ( Ctor ) ;
241
- if ( isUndefined ( meta ) ) {
242
- // TODO [#1295]: remove this workaround after refactoring tests
243
- meta = {
244
- template : undefined ,
245
- name : Ctor . name ,
246
- } ;
247
- }
248
-
249
- def = createComponentDef ( Ctor , meta , name || Ctor . name ) ;
229
+ def = createComponentDef ( Ctor ) ;
250
230
CtorToDefMap . set ( Ctor , def ) ;
251
231
}
252
232
@@ -291,8 +271,8 @@ interface PublicComponentDef {
291
271
* EXPERIMENTAL: This function allows for the collection of internal component metadata. This API is
292
272
* subject to change or being removed.
293
273
*/
294
- export function getComponentDef ( Ctor : any , subclassComponentName ?: string ) : PublicComponentDef {
295
- const def = getComponentInternalDef ( Ctor , subclassComponentName ) ;
274
+ export function getComponentDef ( Ctor : any ) : PublicComponentDef {
275
+ const def = getComponentInternalDef ( Ctor ) ;
296
276
// From the internal def object, we need to extract the info that is useful
297
277
// for some external services, e.g.: Locker Service, usually, all they care
298
278
// is about the shape of the constructor, the internals of it are not relevant
0 commit comments