Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine): bug introduced that breaks circular on proto chain #505

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/lwc-engine/src/framework/__tests__/def.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,24 @@ describe('def', () => {
});
});
});
describe('circular references', () => {
it('should be resolved on for __proto__', () => {
class A extends LightningElement {}
A.publicProps = {
a: {}
};

// circular artifact for A
function CircularA() {
return A;
}
CircularA.__circular__ = true;

class B extends CircularA {}
// make sure it picks the props from A
expect(getComponentDef(B).props.a).toEqual(getComponentDef(A).props.a);
// make sure it picks the props from LightingElement
expect(getComponentDef(B).props.title).toBeDefined();
});
});
});
2 changes: 1 addition & 1 deletion packages/lwc-engine/src/framework/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const CtorToDefMap: WeakMap<any, ComponentDef> = new WeakMap();

function getCtorProto(Ctor: any): any {
const proto = getPrototypeOf(Ctor);
return isCircularModuleDependency(Ctor) ? resolveCircularModuleDependency(proto) : proto;
return isCircularModuleDependency(proto) ? resolveCircularModuleDependency(proto) : proto;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody saw the issue in the review :( and it was pretty clear that this was wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's worth adding comments here why the resolution works as it is or at least moving the method comments from resolveCircularModuleDependency function here, so that the developer can have a bigger picture on the prototype is retrieved.

Copy link
Contributor

@diervo diervo Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caridy It was a review of dozens of files and million changes...

}

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