Skip to content

Commit

Permalink
build(broccoli): store DiffResult for re-use only if DiffResult
Browse files Browse the repository at this point in the history
One of the non-angular broccoli plugins returns a weird object. We can't
assume that all trees meet the contract that we expect them to meet, so
we do a typecheck before storing the result of the rebuild.

Closes #2662
  • Loading branch information
caitp committed Jun 23, 2015
1 parent a67f231 commit 7a80c6e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tools/broccoli/diffing-broccoli-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ class DiffingPluginWrapper implements BroccoliTree {
// Otherwise, `this.diffResult` was produced from the output of the
// inputTree's rebuild() method, and can be used without being checked.
// Set `this.diffResult` to null and return the previously stored value.
if (!tree.diffResult) {
let differ = index === false ? this.treeDiffer : this.treeDiffers[index];
return differ.diffTree();
}
let diffResult = tree.diffResult;
tree.diffResult = null;
if (!diffResult) {
let differ = index === false ? this.treeDiffer : this.treeDiffers[index];
diffResult = differ.diffTree();
}
return diffResult;
};

Expand All @@ -93,7 +93,8 @@ class DiffingPluginWrapper implements BroccoliTree {
}

private maybeStoreDiffResult(value: (DiffResult | void)) {
this.diffResult = value ? <DiffResult>(value) : null;
if (!(value instanceof DiffResult)) value = null;
this.diffResult = <DiffResult>(value);
}

rebuild() {
Expand All @@ -112,12 +113,14 @@ class DiffingPluginWrapper implements BroccoliTree {
return resultPromise.then((result: (DiffResult | void)) => {
this.maybeStoreDiffResult(result);
this.relinkOutputAndCachePaths();
return result;
});
}
}

this.maybeStoreDiffResult(<(DiffResult | void)>(result));
this.relinkOutputAndCachePaths();
return result;
} catch (e) {
e.message = `[${this.description}]: ${e.message}`;
throw e;
Expand Down

0 comments on commit 7a80c6e

Please sign in to comment.