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

Return full result from babel.transform. #629

Merged
merged 1 commit into from Jun 22, 2018

Conversation

izaakschroeder
Copy link
Contributor

@izaakschroeder izaakschroeder commented Jun 22, 2018

Previous code only returns an object of the shape { code, map, metadata } which prevents accessing things like the AST when babel is configured to output it. This change allows access to more things that babel spits out.

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

Returns only { code, map, metadata }.

What is the new behavior?

Returns more result data (ast and sourceType).

Does this PR introduce a breaking change?

  • Yes
  • No

src/transform.js Outdated

if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
map.sourcesContent = [source];
}

return { code, map, metadata };
return result;
Copy link
Member

Choose a reason for hiding this comment

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

My one concern here is that result.options is not serializable to JSON. This change makes the full options object available to result override callbacks, but it'll only be useful if you're running without the cache, since the cache version would reload and be missing stuff.

When you asked originally I was fine with removing the whitelist of props, but now I'm leaning toward saying we'd be better to at least blacklist the result.options property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I can alternatively just add ast to the whitelist if that's better?

Copy link
Member

Choose a reason for hiding this comment

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

The full set of props is at https://github.com/babel/babel/blob/9283efaeb7a8c5b505b19332c3407dc44c668777/packages/babel-core/src/transformation/index.js#L64

If you want to expand the whitelist to include all of those except options that sounds good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do! 🎉

Previous code only returns an object of the shape `{ code, map, metadata }` which prevents accessing things like the AST when `babel` is configured to output it. This change allows access to more things that `babel` spits out.
@izaakschroeder
Copy link
Contributor Author

izaakschroeder commented Jun 22, 2018

All set @loganfsmyth 😄 thanks for the feedback and quick turnaround!

@loganfsmyth loganfsmyth merged commit a2d86d9 into babel:master Jun 22, 2018
@loganfsmyth
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants