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 babel-plugin-codegen crash when export init is null #33387

Closed

Conversation

janicduplessis
Copy link
Contributor

Summary

It is possible that init is null when using the following code.

export var a;

The typescript compiler actually generates something like this for enums so a lot of third party libraries triggered this issue.

For example in expo-apple-authentication/build/AppleAuthentication.types.js

export var AppleAuthenticationScope;
(function (AppleAuthenticationScope) {
    AppleAuthenticationScope[AppleAuthenticationScope["FULL_NAME"] = 0] = "FULL_NAME";
    AppleAuthenticationScope[AppleAuthenticationScope["EMAIL"] = 1] = "EMAIL";
})(AppleAuthenticationScope || (AppleAuthenticationScope = {}));

This simply adds a null check.

Changelog

[General] [Fixed] - Fix babel-plugin-codegen crash when export init is null

Test Plan

Tested that this fixed the crash in an app.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Mar 5, 2022
@analysis-bot
Copy link

analysis-bot commented Mar 5, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 2829146
Branch: main

@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@philIip
Copy link
Contributor

philIip commented Mar 10, 2022

hi @janicduplessis, can you rebase your changes? i will go for the land when possible. thanks for working on this!

@janicduplessis
Copy link
Contributor Author

@philIip done!

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,214,206 +0
android hermes armeabi-v7a 7,799,915 +0
android hermes x86 8,587,706 +0
android hermes x86_64 8,538,641 +0
android jsc arm64-v8a 9,882,916 +0
android jsc armeabi-v7a 8,853,159 +0
android jsc x86 9,852,501 +0
android jsc x86_64 10,447,566 +0

Base commit: 2829146
Branch: main

@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @janicduplessis in ae75664.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Mar 12, 2022
@janicduplessis janicduplessis deleted the babel-codegen-fix branch March 12, 2022 11:35
cortinico pushed a commit to cortinico/react-native that referenced this pull request Mar 12, 2022
Summary:
It is possible that `init` is null when using the following code.

```js
export var a;
```

The typescript compiler actually generates something like this for enums so a lot of third party libraries triggered this issue.

For example in expo-apple-authentication/build/AppleAuthentication.types.js

```js
export var AppleAuthenticationScope;
(function (AppleAuthenticationScope) {
    AppleAuthenticationScope[AppleAuthenticationScope["FULL_NAME"] = 0] = "FULL_NAME";
    AppleAuthenticationScope[AppleAuthenticationScope["EMAIL"] = 1] = "EMAIL";
})(AppleAuthenticationScope || (AppleAuthenticationScope = {}));
```

This simply adds a null check.

## Changelog

[General] [Fixed] - Fix babel-plugin-codegen crash when export init is null

Pull Request resolved: facebook#33387

Test Plan: Tested that this fixed the crash in an app.

Reviewed By: javache

Differential Revision: D34687271

Pulled By: philIip

fbshipit-source-id: 7a7e0fe1bb6a7a21a5b442af26b221a263d4173d
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2023
Summary:
It is possible that `init` is null when using the following code.

```js
export var a;
```

The typescript compiler actually generates something like this for enums so a lot of third party libraries triggered this issue.

For example in expo-apple-authentication/build/AppleAuthentication.types.js

```js
export var AppleAuthenticationScope;
(function (AppleAuthenticationScope) {
    AppleAuthenticationScope[AppleAuthenticationScope["FULL_NAME"] = 0] = "FULL_NAME";
    AppleAuthenticationScope[AppleAuthenticationScope["EMAIL"] = 1] = "EMAIL";
})(AppleAuthenticationScope || (AppleAuthenticationScope = {}));
```

This simply adds a null check.

## Changelog

[General] [Fixed] - Fix babel-plugin-codegen crash when export init is null

Pull Request resolved: facebook#33387

Test Plan: Tested that this fixed the crash in an app.

Reviewed By: javache

Differential Revision: D34687271

Pulled By: philIip

fbshipit-source-id: 7a7e0fe1bb6a7a21a5b442af26b221a263d4173d
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants