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

Allow AST plugins to manipulate Javascript scope #5

Merged
merged 34 commits into from
Nov 17, 2022
Merged

Allow AST plugins to manipulate Javascript scope #5

merged 34 commits into from
Nov 17, 2022

Conversation

ef4
Copy link
Contributor

@ef4 ef4 commented Jun 30, 2022

This spikes out the ability for AST plugins to access Javascript imports and expression.

Still needs more practical testing.

Does not support Ember < 3.28 because that's where we gained the option to use lexically scoped values in non-strict templates.

This spikes out the ability for AST plugins to access Javascript imports and expression.

Still needs more practical testing.

Does not support Ember < 3.28 because that's where we gained the option to use lexically scoped values in non-strict templates.
@ef4
Copy link
Contributor Author

ef4 commented Jun 30, 2022

The usefulness of this will depend on getting ember-cli-htmlbars to process all templates through babel-plugin-ember-template-compilation. At the moment:

  • route templates
  • non-colocated component templates
  • co-located component templates
  • all inline (in JS) templates

@ef4
Copy link
Contributor Author

ef4 commented Jun 30, 2022

(All those cases already work in embroider, but addons can't realistically adopt if we don't make it work in classic builds too)

ef4 added a commit to ember-cli/ember-cli-htmlbars that referenced this pull request Jun 30, 2022
Classically, standalone templates got a dedicated preprocessor that had nothing to do with Javascript transpilation.

Later came inline templates that appear inside Javascript. Those were handled as a totally separate code path from the standalone templates. To this day, there are two different code paths for handling these two cases.

But at this point, templates-inside-javascript are the foundational primitive that is aligned with [where Ember is heading](emberjs/rfcs#779), because they have access to Javascript scope and this solves a lot of problems.

We can treat standalone HBS as just a degenerate kind of JS that is easily up-compiled via a pure function, allowing them to go down the Javascript code path and allowing us to drop all the old code path.

This also makes it easier to support new features like [AST transforms that can manipulate Javascript scope](emberjs/babel-plugin-ember-template-compilation#5).

Embroider already [implemented this same pattern](embroider-build/embroider#1010).
@ef4
Copy link
Contributor Author

ef4 commented Jun 30, 2022

I confirmed in a test app that ember-cli/ember-cli-htmlbars#749 is enough to make this new feature work in all templates including the stand-alone, non-colocated ones.

@ef4 ef4 added internal enhancement New feature or request and removed internal labels Jun 30, 2022
@ef4
Copy link
Contributor Author

ef4 commented Jul 31, 2022

ember-cli-babel 6.1 shipped with the changes required to make this useful in all templates.

@ef4
Copy link
Contributor Author

ef4 commented Jul 31, 2022

My next action here is to test this new API in Embroider, since we already do the same class of things in a less elegant way.

@ef4 ef4 mentioned this pull request Aug 3, 2022
2 tasks
@ef4 ef4 marked this pull request as ready for review October 31, 2022 20:49
@ef4
Copy link
Contributor Author

ef4 commented Nov 17, 2022

Embroider is now happily refactored onto this feature as the foundational primitive for getting static components, helpers, and modifiers into templates. See embroider-build/embroider#1276

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

Successfully merging this pull request may close these issues.

2 participants