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

Use the new runtime compiler #1864

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@fortawesome/free-regular-svg-icons": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@glint/core": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.5.0",
"@glint/environment-ember-template-imports": "1.4.1-unstable.ff9ea6c",
"@glint/template": "1.4.1-unstable.ff9ea6c",
"@nullvoxpopuli/eslint-configs": "^4.0.0",
Expand Down Expand Up @@ -90,7 +90,7 @@
"ember-qunit": "^8.0.2",
"ember-resolver": "^13.0.2",
"ember-route-template": "^1.0.3",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"ember-template-imports": "^4.1.2",
"ember-template-lint": "^6.0.0",
"ember-template-lint-plugin-prettier": "^5.0.0",
Expand Down Expand Up @@ -140,7 +140,7 @@
"@xstate/inspect": "^0.8.0",
"browserslist": "^4.22.3",
"dompurify": "^3.1.3",
"ember-auto-import": "^2.9.0",
"ember-auto-import": "^2.10.0",
"ember-container-query": "5.0.12",
"ember-deep-tracked": "^2.0.0",
"ember-element-helper": "^0.8.5",
Expand Down
3 changes: 2 additions & 1 deletion apps/repl/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"../node_modules/@glimmer/tracking/dist/types"
],
"*": ["types/*"]
}
},
"types": ["./node_modules/ember-source/types/stable"]
},
"include": ["app/**/*", "tests/**/*", "types/**/*"]
}
6 changes: 3 additions & 3 deletions apps/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@fortawesome/free-regular-svg-icons": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@glint/core": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.5.0",
"@glint/environment-ember-template-imports": "1.4.1-unstable.ff9ea6c",
"@glint/template": "1.4.1-unstable.ff9ea6c",
"@nullvoxpopuli/eslint-configs": "^4.0.0",
Expand All @@ -74,7 +74,7 @@
"broccoli-asset-rev": "^3.0.0",
"broccoli-funnel": "^3.0.8",
"concurrently": "^9.0.1",
"ember-auto-import": "^2.9.0",
"ember-auto-import": "^2.10.0",
"ember-cached-decorator-polyfill": "^1.0.2",
"ember-cli": "~5.12.0",
"ember-cli-babel": "^8.2.0",
Expand All @@ -87,7 +87,7 @@
"ember-page-title": "^8.2.1",
"ember-qunit": "^8.0.2",
"ember-resolver": "^13.0.2",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"ember-template-imports": "^4.1.2",
"ember-template-lint": "^6.0.0",
"eslint": "^8.55.0",
Expand Down
3 changes: 2 additions & 1 deletion apps/tutorial/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"tutorial/tests/*": ["./tests/*"],
"tutorial/*": ["./app/*"],
"*": ["./types/*"]
}
},
"types": ["./node_modules/ember-source/types/stable"]
},
"include": ["app/**/*", "tests/**/*", "types/**/*"]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ember-element-helper": "^0.8.5",
"ember-auto-import": "^2.9.0",
"ember-repl": "workspace:*",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"webpack": ">= 5.92.0",
"array-includes": "npm:@nolyfill/array-includes@^1",
"array.prototype.findlastindex": "npm:@nolyfill/array.prototype.findlastindex@^1",
Expand Down Expand Up @@ -79,7 +79,8 @@
]
},
"patchedDependencies": {
"browserslist-generator": "patches/browserslist-generator.patch"
"browserslist-generator": "patches/browserslist-generator.patch",
"@embroider/shared-internals": "patches/@embroider__shared-internals.patch"
}
}
}
8 changes: 4 additions & 4 deletions packages/app-support/limber-ui/addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"ember-modifier": "^4.1.0",
"ember-primitives": ">= 0.11.0",
"ember-resources": ">= 6.4.2",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"webpack": ">= 5.92.0"
},
"dependencies": {
"@babel/runtime": "^7.25.7",
"@embroider/addon-shim": "1.8.9",
"@embroider/addon-shim": "1.9.0",
"@embroider/macros": "1.16.9",
"@fortawesome/ember-fontawesome": "^2.0.0",
"@fortawesome/fontawesome-svg-core": "^6.5.1",
Expand All @@ -67,7 +67,7 @@
"@glimmer/component": "^2.0.0",
"@glimmer/tracking": "^1.1.2",
"@glint/core": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.5.0",
"@glint/environment-ember-template-imports": "1.4.1-unstable.ff9ea6c",
"@glint/template": "1.4.1-unstable.ff9ea6c",
"@nullvoxpopuli/eslint-configs": "^4.0.0",
Expand All @@ -83,7 +83,7 @@
"ember-modifier": "^4.1.0",
"ember-primitives": "^0.23.1",
"ember-resources": "^7.0.1",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"ember-template-imports": "^4.1.2",
"ember-template-lint": "^6.0.0",
"eslint": "^8.55.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/app-support/limber-ui/addon/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
We want our tooling to know how to resolve our custom files so the appropriate plugins
can do the proper transformations on those files.
*/
"allowImportingTsExtensions": true
"allowImportingTsExtensions": true,

"types": ["./node_modules/ember-source/types/stable"]
}
}
4 changes: 2 additions & 2 deletions packages/app-support/limber-ui/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@typescript-eslint/parser": "^8.8.0",
"broccoli-asset-rev": "^3.0.0",
"concurrently": "^9.0.1",
"ember-auto-import": "^2.9.0",
"ember-auto-import": "^2.10.0",
"ember-cli": "~5.12.0",
"ember-cli-babel": "^8.2.0",
"ember-cli-dependency-checker": "^3.3.2",
Expand All @@ -62,7 +62,7 @@
"ember-page-title": "^8.2.1",
"ember-qunit": "^8.0.2",
"ember-resolver": "^13.0.2",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^6.0.0",
"ember-try": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-support/transpilation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"babel-loader": "^9.2.1",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"esbuild": "0.24.0",
"eslint": "^8.55.0",
"prettier": "^3.3.3",
Expand Down
9 changes: 3 additions & 6 deletions packages/ember-repl/addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"dependencies": {
"@babel/helper-plugin-utils": "^7.25.7",
"@babel/standalone": "^7.25.7",
"@embroider/addon-shim": "1.8.9",
"@embroider/addon-shim": "1.9.0",
"@embroider/macros": "1.16.9",
"babel-import-util": "^3.0.0",
"babel-plugin-ember-template-compilation": "^2.3.0",
Expand Down Expand Up @@ -116,7 +116,7 @@
"@glimmer/tracking": "^1.1.2",
"@glimmer/util": "^0.92.0",
"@glint/core": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.5.0",
"@glint/environment-ember-template-imports": "1.4.1-unstable.ff9ea6c",
"@glint/template": "1.4.1-unstable.ff9ea6c",
"@nullvoxpopuli/eslint-configs": "^4.0.0",
Expand All @@ -135,7 +135,7 @@
"@typescript-eslint/parser": "^8.8.0",
"concurrently": "^9.0.1",
"ember-resources": "^7.0.0",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"ember-template-imports": "^4.1.2",
"ember-template-lint": "^6.0.0",
"eslint": "^8.55.0",
Expand All @@ -161,9 +161,6 @@
"version": 2,
"type": "addon",
"main": "addon-main.cjs",
"externals": [
"ember-template-compiler"
],
"app-js": {}
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import * as _owner from '@ember/owner';
import * as _runloop from '@ember/runloop';
import * as _service from '@ember/service';
import * as _template from '@ember/template';
import * as _compiler from '@ember/template-compiler';
import * as _runtimeCompiler from '@ember/template-compiler/runtime';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { createTemplateFactory } from '@ember/template-factory';
Expand All @@ -26,6 +28,9 @@ import * as _utils from '@ember/utils';
import * as _decoratorsRuntime from 'decorator-transforms/runtime';

export const modules = {
'@ember/template-compiler': _compiler,
'@ember/template-compiler/runtime': _runtimeCompiler,

'@ember/application': _application,
'@ember/array': _array,
'@ember/component': _EmberComponent,
Expand Down
74 changes: 7 additions & 67 deletions packages/ember-repl/addon/src/compile/formats/hbs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// import { precompileJSON } from '@glimmer/compiler';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// These things are pre-bundled in the old system.
// ember-template-compiler defines them in AMD/requirejs
import { precompileJSON } from '@glimmer/compiler';
import { getTemplateLocals } from '@glimmer/syntax';
import { setComponentTemplate } from '@ember/component';
import templateOnlyComponent from '@ember/component/template-only';
import { array, concat, fn, get, hash } from '@ember/helper';
import { on } from '@ember/modifier';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { createTemplateFactory } from '@ember/template-factory';
import { template } from '@ember/template-compiler/runtime';

import { nameFor } from '../utils.ts';

Expand All @@ -25,16 +15,16 @@ import type { ComponentLike } from '@glint/template';
*
* (templates alone do not have a way to import / define complex structures)
*/
export function compileHBS(template: string, options: CompileTemplateOptions = {}): CompileResult {
let name = nameFor(template);
export function compileHBS(code: string, options: CompileTemplateOptions = {}): CompileResult {
let name = nameFor(code);
let component: undefined | ComponentLike;
let error: undefined | Error;

try {
component = setComponentTemplate(
compileTemplate(template, { moduleName: options.moduleName || name, ...options }),
templateOnlyComponent(options.moduleName || name)
) as ComponentLike;
component = template(code, {
moduleName: options.moduleName || name,
scope: () => ({ on, hash, array, concat, fn, get }),
}) as unknown as ComponentLike;
} catch (e) {
error = e as Error | undefined;
}
Expand All @@ -49,53 +39,3 @@ interface CompileTemplateOptions {
moduleName?: string;
scope?: Record<string, unknown>;
}

/**
* The reason why we can't use precompile directly is because of this:
* https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132
*
* Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.
* That JSON.stringify (and the lines after) prevent us from easily setting the scope function,
* which means that *everything* is undefined.
*/
function compileTemplate(source: string, { moduleName, scope = {} }: CompileTemplateOptions) {
let localScope = { array, concat, fn, get, hash, on, ...scope } as any;
let locals = getTemplateLocals(source);

let options = {
strictMode: true,
moduleName,
locals,
isProduction: false,
meta: { moduleName },
};

// Copied from @glimmer/compiler/lib/compiler#precompile
let [block, usedLocals] = precompileJSON(source, options);

let usedScope = usedLocals.map((key: string) => {
let value = localScope[key];

if (!value) {
throw new Error(
`Attempt to use ${key} in compiled hbs, but it was not available in scope. ` +
`Available scope includes: ${Object.keys(localScope)}`
);
}

return value;
});

let blockJSON = JSON.stringify(block);
let templateJSONObject = {
id: moduleName,
block: blockJSON,
moduleName: moduleName ?? '(dynamically compiled component)',
scope: () => usedScope,
isStrictMode: true,
};

let factory = createTemplateFactory(templateJSONObject);

return factory;
}
3 changes: 2 additions & 1 deletion packages/ember-repl/addon/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"skipLibCheck": true,
"declaration": true,
"allowImportingTsExtensions": true,
"declarationDir": "declarations"
"declarationDir": "declarations",
"types": ["./node_modules/ember-source/types/stable"]
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import 'ember-source/types';
import 'ember-source/types/preview';
// import 'ember-source/types';
6 changes: 3 additions & 3 deletions packages/ember-repl/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@glimmer/component": "^2.0.0",
"@glimmer/tracking": "^1.1.2",
"@glint/core": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.4.1-unstable.ff9ea6c",
"@glint/environment-ember-loose": "1.5.0",
"@glint/environment-ember-template-imports": "1.4.1-unstable.ff9ea6c",
"@glint/template": "1.4.1-unstable.ff9ea6c",
"@nullvoxpopuli/eslint-configs": "^4.0.0",
Expand All @@ -59,7 +59,7 @@
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"concurrently": "^9.0.1",
"ember-auto-import": "^2.9.0",
"ember-auto-import": "^2.10.0",
"ember-cli": "~5.12.0",
"ember-cli-app-version": "^7.0.0",
"ember-cli-babel": "^8.2.0",
Expand All @@ -71,7 +71,7 @@
"ember-page-title": "^8.2.1",
"ember-qunit": "^8.0.2",
"ember-resolver": "^13.0.2",
"ember-source": ">= 5.10.2",
"ember-source": ">= 6.1.0-alpha.6",
"ember-source-channel-url": "^3.0.0",
"ember-template-imports": "^4.1.2",
"ember-template-lint": "^6.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-repl/test-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test-app/tests/*": ["./tests/*"],
"test-app/*": ["./app/*"],
"*": ["./types/*"]
}
},
"types": ["./node_modules/ember-source/types/stable"]
},
"include": ["./app/**/*", "./tests/**/*", "./types/**/*"]
}
Loading
Loading