-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reform internal use of template compiler
Previously, ember-source had a weird custom way of compiling templates that appear within its own source. This PR makes it work the same way we do everywhere else, using babele-plugin-ember-template-compilation. This required solving a boostrapping problem: the babel plugin needs ember-template-compiler.js, our build produces ember-template-compiler.js, but our build wants to use the babel plugin. I solved it by making the template compiler directly evaluatable in node, with no build at all. The *full* legacy ember-template-compiler API has a lot of silly things shoved into it (like a reexport of all of the `Ember` metapackage), and that was inextricably circular, so I introduced `ember-template-compiler/minimal` for this internal use case.
- Loading branch information
Showing
29 changed files
with
1,930 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,4 @@ | ||
'use strict'; | ||
|
||
const Filter = require('broccoli-persistent-filter'); | ||
const { stripIndent } = require('common-tags'); | ||
|
||
GlimmerTemplatePrecompiler.prototype = Object.create(Filter.prototype); | ||
|
||
function GlimmerTemplatePrecompiler(inputTree, options) { | ||
if (!(this instanceof GlimmerTemplatePrecompiler)) { | ||
return new GlimmerTemplatePrecompiler(inputTree, options); | ||
} | ||
|
||
Filter.call(this, inputTree, {}); | ||
|
||
this.inputTree = inputTree; | ||
if (!options.glimmer) { | ||
throw new Error('No glimmer option provided!'); | ||
} | ||
this.precompile = options.glimmer.precompile; | ||
} | ||
|
||
GlimmerTemplatePrecompiler.prototype.extensions = ['hbs']; | ||
GlimmerTemplatePrecompiler.prototype.targetExtension = 'js'; | ||
|
||
GlimmerTemplatePrecompiler.prototype.baseDir = function () { | ||
return __dirname; | ||
}; | ||
|
||
GlimmerTemplatePrecompiler.prototype.processString = function (content, relativePath) { | ||
let compiled = this.precompile(content, { | ||
meta: { moduleName: relativePath }, | ||
}); | ||
return stripIndent` | ||
import { templateFactory } from '@glimmer/opcode-compiler'; | ||
export default templateFactory(${compiled}); | ||
`; | ||
}; | ||
|
||
module.exports = GlimmerTemplatePrecompiler; | ||
require('@swc-node/register'); | ||
module.exports = require('../packages/ember-template-compiler/minimal.ts'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
export default precompileTemplate('', { | ||
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/empty.hbs', | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/@ember/-internals/glimmer/lib/templates/link-to.d.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
export default precompileTemplate(`{{component (-outlet)}}`, { | ||
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/outlet.hbs', | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
export default precompileTemplate(`{{component this}}`, { | ||
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/root.hbs', | ||
}); |
3 changes: 0 additions & 3 deletions
3
packages/@ember/-internals/glimmer/lib/templates/textarea.d.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// The main entrypoint of ember-template-compiler is the fairly-crufty | ||
// backward-compatible API. In contrast, this is the subset of that that's | ||
// actually used by babel-plugin-ember-template-compilation. | ||
// | ||
// This module exists so that ember-source can build itself -- the | ||
// ember-template-compiler.js bundle it an output of the build, but the build | ||
// needs to compile templates. Unlike the full ./index.ts, this module can be | ||
// directly evaluted in node because it doesn't try to pull in the whole kitchen | ||
// sink. | ||
export { default as precompile } from './lib/system/precompile'; | ||
export { buildCompileOptions as _buildCompileOptions } from './lib/system/compile-options'; | ||
export { preprocess as _preprocess, print as _print } from '@glimmer/syntax'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// this file gets replaced with the real value during the build | ||
export default 'VERSION_GOES_HERE' as string; |
Oops, something went wrong.