Skip to content

Commit

Permalink
Merge pull request embroider-build#572 from thoov/direct-super-call
Browse files Browse the repository at this point in the history
Support direct _super call in treeFor hook
  • Loading branch information
ef4 committed Oct 19, 2020
2 parents bf2116c + 0ba72bf commit 296dd52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/compat/src/v1-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export default class V1Addon {
}
let origSuper = this.addonInstance._super;
try {
this.addonInstance._super = returnMarkedEmptyTree;
this.addonInstance._super = stubbedSuper;
let result = this.mainModule.treeFor?.call(this.addonInstance, name);
if (result === markedEmptyTree) {
// the method returns _super unchanged, so tree is not suppressed and we
Expand All @@ -524,7 +524,7 @@ export default class V1Addon {
unsupported(`${this.name} has a custom treeFor() method that is doing some arbitrary broccoli processing.`);
return false;
} finally {
if (this.addonInstance._super === returnMarkedEmptyTree) {
if (this.addonInstance._super === stubbedSuper) {
this.addonInstance._super = origSuper;
}
}
Expand Down Expand Up @@ -958,8 +958,11 @@ function notColocatedTemplate(path: string) {
}

const markedEmptyTree = new UnwatchedDir(process.cwd());
const returnMarkedEmptyTree = {
treeFor() {
return markedEmptyTree;
},

const stubbedSuper = () => {
return markedEmptyTree;
};

stubbedSuper.treeFor = () => {
return markedEmptyTree;
};
2 changes: 1 addition & 1 deletion packages/compat/tests/stage1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ describe('stage1 build', function () {
`
treeFor(name) {
if (name !== 'app') {
return this._super.treeFor(name);
return this._super(name);
} else {
return undefined;
}
Expand Down

0 comments on commit 296dd52

Please sign in to comment.