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

Compatibility fixes for Babel 7 #211

Merged
merged 10 commits into from
Sep 13, 2018
Merged

Conversation

NilSet
Copy link
Contributor

@NilSet NilSet commented Mar 14, 2018

Fixed an issue where modules were interpreted as commonjs even when es6
Removed direct imports of babel-types and babel-template

Fixes #209 maybe

import { wasProcessed, noRewire } from './RewireHelpers.js';
import * as t from 'babel-types';
var t;
var universalAccesorsTemplate;
Copy link

Choose a reason for hiding this comment

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

Why not use scope these variables to the RewireState class with this.<variable>, similar to this.isES6Module and the others? Also we should probably prefer const or let to var.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into issues with this.t, because of a few places it is referenced from unbound functions. Also it was a larger change. This way we just inject the lib at the top level when we get it from babel invoking us.

@@ -126,6 +134,8 @@ export default class RewireState {
UNIVERSAL_RESETTER_ID :this.getUniversalResetterID(),
UNIVERSAL_WITH_ID :this.getUniversalWithID(),
API_OBJECT_ID: this.getAPIObjectID(),
INTENTIONAL_UNDEFINED: t.identifier('INTENTIONAL_UNDEFINED'),
__INTENTIONAL_UNDEFINED__: '__INTENTIONAL_UNDEFINED__',
Copy link

Choose a reason for hiding this comment

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

What is this one used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

babel 7's template is more picky about strings that look like placeholders but are not filled in. This was the simplest way to fix it without changing the generated code.

src/Templates.js Outdated
if (REWIRED_DATA_IDENTIFIER === undefined || REWIRED_DATA_IDENTIFIER[variableName] === undefined) {
return ORIGINAL_VARIABLE_ACCESSOR_IDENTIFIER(variableName);
} else {
var value = REWIRED_DATA_IDENTIFIER[variableName];
Copy link

Choose a reason for hiding this comment

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

const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just fixed the tabs to be consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

All of these vars and so on are from original code, so should probably not be changed in this PR.

@NilSet
Copy link
Contributor Author

NilSet commented Mar 14, 2018

@speedskater I just noticed the version-1.1.0 branch. Should I have based this off of that branch?

Thomas Levy added 3 commits March 14, 2018 12:41
Fixed an issue where modules were interpreted as commonjs even when es6
Removed direct imports of babel-types and babel-template
@damassi
Copy link
Contributor

damassi commented Mar 14, 2018

Can confirm this PR works in our new Babel 7 codebase

@speedskater
Copy link
Owner

@NilSet, @ilias-t, @damassi thank you all for your work on this pull request. I am currently not in the office but I will review it tomorrow in the evening. Regarding the branch, i think the current branch would indeed be version-1.1.0 branch. Neverthless I will try to merge the version 1.1.0 branch into master and than using this PR an if possible some other open PRs to create a 1.2.0 branch and based on this a 1.2.0-RC1.

Regarding the var/const/let issues I would propose to remain with the vars until we reach babel 7 support, and to tackle this in a separate branch/PR.

Is this procedure okay for you?

@damassi
Copy link
Contributor

damassi commented Mar 14, 2018

That would be fantastic, thanks @speedskater 👍

@NilSet
Copy link
Contributor Author

NilSet commented Mar 14, 2018

I have a rebase onto 1.1.0 mostly done. I may switch to a less hacky solution for the template placeholder thing.

@NilSet
Copy link
Contributor Author

NilSet commented Mar 14, 2018

I'll keep this pointed at master, but compare the branch with version-1.1.0 to see only my changes

@speedskater
Copy link
Owner

@NilSet thanks again for you PR. I have merged it into the 1.2.0 branch and puglished 1.2.0-rc.1 and on npm as a prerelease.
Could you all please test this release in your code bases. If I won't get any negativ feedback till next monday I will convert it to the final 1.2.0 and will then merge it onto master.
@damassi could you please test it in your babel 7 codebase ?

@speedskater
Copy link
Owner

speedskater commented Mar 15, 2018

@NilSet I also added you as a contributor to the README. I hope this is okay with you?

@NilSet
Copy link
Contributor Author

NilSet commented Mar 15, 2018

1.2.0-rc.1 seems to be working great!

@NilSet
Copy link
Contributor Author

NilSet commented Mar 26, 2018

@speedskater How has the feedback been? Do we look ok to merge version-1.2.0 into master and release it as latest?

@augbog
Copy link

augbog commented May 17, 2018

Also curious about the progress of this? Would love to see this merged :)

@villesau
Copy link

Would love to see this merged!

@adamnoakes
Copy link

adamnoakes commented Aug 30, 2018

I've tried 1.2.0-rc.1 with the 7.0.0 babel release and am having an issue

export { _get__2 as __get__, _get__2 as __GetDependency__, _set__2 as __Rewire__, _set__2 as __set__, _reset__2 as __ResetDependency__, _RewireAPI__2 as __RewireAPI__ };
^^^^^^

SyntaxError: Unexpected token export

Has anyone else tried with 7.0.0?

@ghost
Copy link

ghost commented Aug 30, 2018

@adamnoakes - I've tested with babel 7, seems to be working.

@ilias-t
Copy link

ilias-t commented Aug 31, 2018

Commit history doesn't look clean, @NilSet are you pointing to the correct branch or maybe to rebase again?

@adamnoakes
Copy link

adamnoakes commented Aug 31, 2018

@miguel-orange i done some more investigation and it works ok for me when i use babel cli but when using babel register i get the issues, not sure if it's an issue with this, babel register or my setup. Are you using babel-register?

When i remove this plugin, everything compiles fine using babel-register.

@kibertoad
Copy link

@speedskater Does this still need anything to be done before it can be merged to master?

@damassi
Copy link
Contributor

damassi commented Sep 11, 2018

@speedskater has unfortunately gone missing :( That said, the rc candidate release works great.

@speedskater speedskater merged commit 2455d34 into speedskater:master Sep 13, 2018
@speedskater
Copy link
Owner

@kibertoad @damassi sorry for beeing not available for the project over the last month and neglecting the project. Unfortunately, I am currently changing jobs and finishing my PhD thesis at the same time. Therefore it won't get better soon. I hope I will be able to contribute some improvement in the future, but it will take some time.
In the meantime I will add a former coworker of mine as a contributer to the project, so he will be able to provide bugfixes.

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.

10 participants