Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change calls
Error
twice, which means that stack trace capturing (which is expensive) is done twice as well.What are the reasons for this change as it makes the code slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code depended on accidental, incorrect behavior that closure-compiler and the TypeScript compiler happened to share. The
super()
keyword call was transpiled to basicallyError.call(this, message)
, which ignores thethis
parameter and just returns a newError
object.I needed to fix this behavior.
google/closure-compiler#2102
as part of the effort to make
super()
's behavior match the ES spec.google/closure-compiler#1669
I've now made these fixes. If my code change in
errors.ts
is reverted, thennativeError
will be an alias forthis
, and the getters and setters will become infinite loops when this code is used with the tool chain TypeScript -> (TypeScript compiler) -> ES6 code -> (closure-compiler) -> ES5 code.Personally, I think TypeScript should do special-case handling of
Error
classes like closure-compiler now does. Then all of this hacky workaround in theerrors.ts
code could go away entirely.I said so in another angular issue, but I don't have the number handy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense.