-
Notifications
You must be signed in to change notification settings - Fork 8
fix: Support class features when transforming source code #201
Conversation
847c344
to
f9a6dc6
Compare
The official name is
https://github.com/estree/estree/blob/master/es2015.md#methoddefinition |
It will be probably worthwhile to move to a babel-only format so that we do not have to rely to the less used |
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.
Good work!
Let's check that astring
is handling PropertyDefinition
first before merging.
MethodDefinition is a different thing. This is about PropertyDefinition: https://github.com/estree/estree/blob/master/es2022.md#propertydefinition |
I checked manually, it seems to work fine. |
appmap-agent-js uses @babel/parser to parse the ECMAScript code for transformation; the output generated by that library is not 100% estree-compliant [1]. It has an `estree` plugin that reverts the deviations; however, by default not all of them are supported (apparently for @babel/parser's own backward compatibility reasons). Fortunately it has a config setting that enables them. One of these differences is that the standard node type of PropertyDefinition is called ClassProperty instead, which made the transformer unable to correctly handle ES classes. [1] https://babeljs.io/docs/babel-parser#output Fixes #199
f9a6dc6
to
b7760c7
Compare
Added a test on the instrumentation side. |
I don't think that's a good idea unless it's really necessary. It will make it more difficult if we want to switch the parser and/or generator in the future. |
Yeah it is really unfortunate that babel defined its own ast format. Let's keep it like this for the moment then. |
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.
Good work, thanks!
@@ -84,7 +84,7 @@ const parseBabelLog = (content, url) => { | |||
return parseBabel(content, { | |||
sourceType: "module", | |||
sourceFilename: url, | |||
plugins: ["estree"], | |||
plugins: [["estree", { classFeatures: true }]], |
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.
FYI This file is used to build the agent and it does not contain any PropertyDefinition
. But it is fine to add it as well here.
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 figured, but it turned up in grep and I thought it won't hurt for completeness ;)
Arf, I should keep up with the standard :s |
🎉 This PR is included in version 13.5.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
appmap-agent-js uses @babel/parser to parse the ECMAScript code for transformation; the output generated by that library is not 100% estree-compliant [1]. It has an
estree
plugin that reverts the deviations; however, by default not all of them are supported (apparently for @babel/parser's own backward compatibility reasons). Fortunately it has a config setting that enables them.One of these differences is that the standard node type of PropertyDefinition is called ClassProperty instead, which made the transformer unable to correctly handle ES classes.
[1] https://babeljs.io/docs/babel-parser#output
Fixes #199