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

Fix transpilation of typescript-specific class keywords #714

Merged
merged 2 commits into from
Oct 23, 2022

Conversation

askoufis
Copy link
Contributor

@askoufis askoufis commented Oct 21, 2022

Something in @babel/babel-plugin-transform-typescript@7.18.0 broke transpilation of typescript-specific class keywords. Users could run into this issue when updating to sku@11.6.0 because the version range of @babel/babel-plugin-transform-typescript was updated.

Something like:

export class MyClass {
  constructor(protected foo: number) {}
}

is being transpiled to:

var MyClass = /*#__PURE__*/_createClass(function MyClass(protected foo) {
//                               not valid javascript -> ^^^^^^^^^
  _classCallCheck(this, MyClass);
});

protected is a typescript-specific keyword, so this is invalid code.

I'm unsure as to why this has suddenly become an issue in that version of the babel plugin, but it turns out that babel presets are executed in reverse, and we had preset-typescript before preset-env in the presets array, meaning preset-tyepscript was executing after preset-env, but preset-env doesn't understand the protected keyword (because it's typescript), so 💥 .

This PR fixes the ordering of presets so preset-typescript executes before preset-env, and adds a test class in one of the test cases with a typescript file because there isn't really a good place to put it (suggestions welcome) and I didn't want to make the test run any longer than it already is.

@askoufis askoufis requested a review from a team as a code owner October 21, 2022 05:15
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2022

🦋 Changeset detected

Latest commit: 8522306

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sku Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@mrm007 mrm007 left a comment

Choose a reason for hiding this comment

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

Nice work 🕵️

@askoufis askoufis merged commit 51ffd65 into master Oct 23, 2022
@askoufis askoufis deleted the babel-preset-ordering branch October 23, 2022 23:23
@seek-oss-ci seek-oss-ci mentioned this pull request Oct 23, 2022
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