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

Add support for components using private methods #343

Merged
merged 1 commit into from
Apr 26, 2021
Merged

Conversation

chadhietala
Copy link
Member

@babel/plugin-proposal-private-methods requires seeing
@babel/plugin-proposal-class-properties being set before it can run. In
Babel plugins run before presets. Because of this, these 2 plugins must
exist in the preset.

packages/@glimmer/babel-preset/index.js Outdated Show resolved Hide resolved
@rwjblue
Copy link
Member

rwjblue commented Apr 13, 2021

Do we actually use private methods? Do we have to?

@chadhietala
Copy link
Member Author

I'm trying to migrate to this and was supporting private methods. The issue is that babel plugins run before presets and the private method plugin depends on the class properties plugin.

Now it would be "fine" to have these as both plugins but the issue is that when the preset runs the fields have already been transformed and thus presets can't find static template = to transforming it. For example this is the current output if you both set as plugins:

Input:

  import { Hello } from "../Hello.js";
  import Component, { hbs } from '@glimmerx/component';
  export default class MyPage extends Component {
    static template = hbs\`
      <Hello />
    \`
  }

Current Output:

class MyPage extends _glimmerx_component__WEBPACK_IMPORTED_MODULE_2__.default {}
MyPage.template = (0,_glimmer_core__WEBPACK_IMPORTED_MODULE_0__.setComponentTemplate)((0,_glimmer_core__WEBPACK_IMPORTED_MODULE_0__.createTemplateFactory)(
/*
          <Hello />
*/
{
  "id": "Ng5WBitS",
  "block": "[[[1,\"\\n          \"],[8,[32,0],null,null,null],[1,\"\\n        \"]],[],false,[]]",
  "moduleName": "(unknown template module)",
  "scope": () => [_var_folders_0_6vsqqq293r1_rddztq1585xc0008c7_T_broccoli_97650kjsjBvbcT6M6_out_2_broccoli_persistent_filter_babel__WEBPACK_IMPORTED_MODULE_1__.Hello],
  "isStrictMode": true
}), (0,_glimmer_core__WEBPACK_IMPORTED_MODULE_0__.templateOnlyComponent)("MyPage", "_MyPage"));

You could do a thing where you have plugins that re-transform transformed code but that seems like a slippery slope.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Chatted with @chadhietala and @pzuraq, and I think the path forward here is to remove { loose: true } (and use strict mode) and then we can land/release.

@babel/plugin-proposal-private-methods requires seeing
@babel/plugin-proposal-class-properties being set before it can run. In
Babel plugins run before presets. Because of this, these 2 plugins must
exist in the preset.
@rwjblue rwjblue changed the title bugfix: Fix usage of private methods Add support for components using private methods Apr 26, 2021
@rwjblue rwjblue merged commit 7dd57e4 into master Apr 26, 2021
@rwjblue rwjblue deleted the fix-babel-plugins branch April 26, 2021 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants