-
Notifications
You must be signed in to change notification settings - Fork 137
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
template compilation improvements #1010
Conversation
That is, instead of having different code paths for standalone hbs files vs templates embedded inside Javascript, we do a small transportation to the standalone hbs files to make them into JS first, and then share all the template compilation machinery. This is also setting us up to take advantage of lexical scope in non-strict-mode which landed in ember-source 3.28.4.
Reminder to self: |
These changes can also address a cache-safety hole we currently have: the stage1
It doesn't incorporate a checksum over the set of plugins. |
This code was duplicated *and* doesn't really belong on TemplateCompiler anyway
I'm going to land this long-running branch, it has a good refactor and all tests are passing. The actual feature work on top to use lexical scope can be a followup. |
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).
First, I'm refactoring so that we standardize all template compilation as inline template compilation, within Javascript, because that is the more fully-featured case. Specifically, a standalone HBS file can go through a trivial transformation to make it into a Javascript file:
<Hello />
After which point we can share all the same standard machinery for compiling forward from there.
Second, I'm going to take advantage of template lexical scope in non-strict mode which we just successfully landed in ember-source 3.28.4. That will significantly streamline the build output when using
staticComponents
, etc, because we can pass the statically-resolved things directly into the template and completely sidestep the runtime resolver.The first commit here is just testing out the basic idea, it needs further cleanup refactoring.