Skip to content

Commit

Permalink
Revert "refactor(engine): locker does not longer need to leak base co…
Browse files Browse the repository at this point in the history
…nstructor (#509)" (#510)

This reverts commit fa25e8a.
  • Loading branch information
caridy authored Jul 13, 2018
1 parent fa25e8a commit a4af587
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
12 changes: 0 additions & 12 deletions packages/lwc-engine/src/framework/__tests__/def.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,5 @@ describe('def', () => {
// make sure it picks the props from LightingElement
expect(getComponentDef(B).props.title).toBeDefined();
});

it('should allow escape hatch for Locker and other systems to provide their own base class to mimic LightningElement', () => {
// circular artifact for LightingElement
function CircularA() {
return CircularA; // because it returns itself, the engine knows what to do.
}
CircularA.__circular__ = true;

class B extends CircularA {}
// make sure it picks the props from LightingElement
expect(getComponentDef(B).props.title).toBeDefined();
});
});
});
7 changes: 4 additions & 3 deletions packages/lwc-engine/src/framework/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
vmBeingRendered,
invokeEventListener,
} from "./invoker";
import { isArray, ArrayIndexOf, ArraySplice, isFunction, isUndefined } from "../shared/language";
import { isArray, ArrayIndexOf, ArraySplice, isObject, isFunction, isUndefined } from "../shared/language";
import { invokeServiceHook, Services } from "./services";
import { PropsDef, WireHash } from './def';
import { VM } from "./vm";
Expand Down Expand Up @@ -37,8 +37,9 @@ export function createComponent(vm: VM, Ctor: ComponentConstructor) {
}
// create the component instance
invokeComponentConstructor(vm, Ctor);
if (isUndefined(vm.component)) {
throw new ReferenceError(`Invalid construction for ${vm}, you must extend LightningElement.`);

if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isObject(vm.component), `Invalid construction for ${vm}, maybe you are missing the call to super() on classes extending Element.`);
}
}

Expand Down
13 changes: 2 additions & 11 deletions packages/lwc-engine/src/framework/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,8 @@ import { patchLightningElementPrototypeWithRestrictions } from "./restrictions";
const CtorToDefMap: WeakMap<any, ComponentDef> = new WeakMap();

function getCtorProto(Ctor: any): any {
let proto = getPrototypeOf(Ctor);
// covering the cases where the ref is circular in AMD
if (isCircularModuleDependency(proto)) {
const p = resolveCircularModuleDependency(proto);
// escape hatch for Locker and other abstractions to provide their own base class instead
// of our Base class without having to leak it to user-land. If the circular function returns
// itself, that's the signal that we have hit the end of the proto chain, which must always
// be base.
proto = p === proto ? BaseElement : p;
}
return proto;
const proto = getPrototypeOf(Ctor);
return isCircularModuleDependency(proto) ? resolveCircularModuleDependency(proto) : proto;
}

// According to the WC spec (https://dom.spec.whatwg.org/#dom-element-attachshadow), certain elements
Expand Down

0 comments on commit a4af587

Please sign in to comment.