ember-repl 3.0.0-beta.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/declarations/browser/compile/formats.d.ts.map +1 -1
- package/dist/browser/compile/formats.js +7 -6
- package/dist/browser/compile/formats.js.map +1 -1
- package/dist/browser/hbs.js +7 -1
- package/dist/browser/hbs.js.map +1 -1
- package/package.json +15 -17
- package/src/browser/compile/formats.ts +8 -6
- package/src/browser/hbs.ts +9 -1
package/README.md
CHANGED
|
@@ -198,7 +198,7 @@ resource so that when an error occurs, you could keep rendering the latest succe
|
|
|
198
198
|
import Component from '@glimmer/component';
|
|
199
199
|
import { Compiled } from 'ember-repl';
|
|
200
200
|
import { use } from 'ember-resources';
|
|
201
|
-
import { keepLatest } from 'reactiveweb/keep-latest';
|
|
201
|
+
import { keepLatest } from 'reactiveweb/util/keep-latest';
|
|
202
202
|
|
|
203
203
|
export class Renderer extends Component {
|
|
204
204
|
@use compile = Compiled(() => this.args.mdText, 'glimdown');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../../src/browser/compile/formats.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY1D,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,aAAa,CAAC,CAQxB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GACA,OAAO,CAAC,aAAa,CAAC,CAQxB;
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../../src/browser/compile/formats.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY1D,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,aAAa,CAAC,CAQxB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GACA,OAAO,CAAC,aAAa,CAAC,CAQxB;AA2CD,wBAAsB,SAAS,CAC7B,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACA,OAAO,CAAC,aAAa,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAiFpD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invocationName } from '../utils.js';
|
|
2
2
|
|
|
3
|
-
async function
|
|
3
|
+
async function compileGJSArray(js, importMap) {
|
|
4
4
|
let modules = await Promise.all(js.map(async ({
|
|
5
5
|
code
|
|
6
6
|
}) => {
|
|
@@ -34,12 +34,12 @@ async function compileHBS(hbsInput, options) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
async function extractScope(liveCode,
|
|
37
|
+
async function extractScope(liveCode, options) {
|
|
38
38
|
let scope = [];
|
|
39
39
|
let hbs = liveCode.filter(code => code.lang === 'hbs');
|
|
40
40
|
let js = liveCode.filter(code => ['js', 'gjs'].includes(code.lang));
|
|
41
41
|
if (js.length > 0) {
|
|
42
|
-
let compiled = await
|
|
42
|
+
let compiled = await compileGJSArray(js, options?.importMap);
|
|
43
43
|
await Promise.all(compiled.map(async info => {
|
|
44
44
|
// using web worker + import maps is not available yet (need firefox support)
|
|
45
45
|
// (and to somehow be able to point at npm)
|
|
@@ -57,13 +57,14 @@ async function extractScope(liveCode, importMap) {
|
|
|
57
57
|
for (let {
|
|
58
58
|
code
|
|
59
59
|
} of hbs) {
|
|
60
|
-
let compiled = await compileHBS(code
|
|
60
|
+
let compiled = await compileHBS(code, {
|
|
61
|
+
scope: options?.topLevelScope
|
|
62
|
+
});
|
|
61
63
|
scope.push(compiled);
|
|
62
64
|
}
|
|
63
65
|
return scope;
|
|
64
66
|
}
|
|
65
67
|
async function compileMD(glimdownInput, options) {
|
|
66
|
-
let importMap = options?.importMap;
|
|
67
68
|
let topLevelScope = options?.topLevelScope ?? {};
|
|
68
69
|
let rootTemplate;
|
|
69
70
|
let liveCode;
|
|
@@ -104,7 +105,7 @@ async function compileMD(glimdownInput, options) {
|
|
|
104
105
|
*/
|
|
105
106
|
if (liveCode.length > 0) {
|
|
106
107
|
try {
|
|
107
|
-
scope = await extractScope(liveCode,
|
|
108
|
+
scope = await extractScope(liveCode, options);
|
|
108
109
|
} catch (error) {
|
|
109
110
|
console.info({
|
|
110
111
|
scope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sources":["../../../src/browser/compile/formats.ts"],"sourcesContent":["import { invocationName } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ExtractedCode } from './markdown-to-ember.ts';\nimport type { UnifiedPlugin } from './types.ts';\nimport type { EvalImportMap, ScopeMap } from './types.ts';\n\nasync function
|
|
1
|
+
{"version":3,"file":"formats.js","sources":["../../../src/browser/compile/formats.ts"],"sourcesContent":["import { invocationName } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ExtractedCode } from './markdown-to-ember.ts';\nimport type { UnifiedPlugin } from './types.ts';\nimport type { EvalImportMap, ScopeMap } from './types.ts';\n\nasync function compileGJSArray(js: { code: string }[], importMap?: EvalImportMap) {\n let modules = await Promise.all(\n js.map(async ({ code }) => {\n return await compileGJS(code, importMap);\n })\n );\n\n return modules;\n}\n\nexport async function compileGJS(\n gjsInput: string,\n importMap?: EvalImportMap\n): Promise<CompileResult> {\n try {\n let { compileJS } = await import('../js.ts');\n\n return await compileJS(gjsInput, importMap);\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n}\n\nexport async function compileHBS(\n hbsInput: string,\n options?: {\n moduleName?: string;\n scope?: Record<string, unknown>;\n }\n): Promise<CompileResult> {\n try {\n let { compileHBS } = await import('../hbs.ts');\n\n return compileHBS(hbsInput, options);\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n}\n\nasync function extractScope(\n liveCode: ExtractedCode[],\n options?: {\n importMap?: EvalImportMap;\n topLevelScope?: ScopeMap;\n }\n): Promise<CompileResult[]> {\n let scope: CompileResult[] = [];\n\n let hbs = liveCode.filter((code) => code.lang === 'hbs');\n let js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));\n\n if (js.length > 0) {\n let compiled = await compileGJSArray(js, options?.importMap);\n\n await Promise.all(\n compiled.map(async (info) => {\n // using web worker + import maps is not available yet (need firefox support)\n // (and to somehow be able to point at npm)\n //\n // if ('importPath' in info) {\n // return scope.push({\n // moduleName: name,\n // component: await import(/* webpackIgnore: true */ info.importPath),\n // });\n // }\n\n return scope.push(info);\n })\n );\n }\n\n for (let { code } of hbs) {\n let compiled = await compileHBS(code, { scope: options?.topLevelScope });\n\n scope.push(compiled);\n }\n\n return scope;\n}\n\nexport async function compileMD(\n glimdownInput: string,\n options?: {\n importMap?: EvalImportMap;\n topLevelScope?: ScopeMap;\n remarkPlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n }\n): Promise<CompileResult & { rootTemplate?: string }> {\n let topLevelScope = options?.topLevelScope ?? {};\n let rootTemplate: string;\n let liveCode: ExtractedCode[];\n let scope: CompileResult[] = [];\n\n /**\n * Step 1: Convert Markdown To HTML (Ember).\n *\n * The remark plugin, remark-code-extra also extracts\n * and transforms the code blocks we care about.\n *\n * These blocks will be compiled through babel and eval'd so the\n * compiled rootTemplate can invoke them\n */\n try {\n let { parseMarkdown } = await import('./markdown-to-ember.ts');\n let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\n ShadowComponent: options?.ShadowComponent,\n remarkPlugins: options?.remarkPlugins,\n });\n\n rootTemplate = templateOnlyGlimdown;\n liveCode = blocks;\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n\n /**\n * Step 2: Compile the live code samples\n */\n if (liveCode.length > 0) {\n try {\n scope = await extractScope(liveCode, options);\n } catch (error) {\n console.info({ scope });\n console.error(error);\n\n return { error: error as Error, rootTemplate, name: 'unknown' };\n }\n }\n\n /**\n * Make sure non of our snippets errored\n *\n * TODO: for these errors, report them differently so that we\n * can render the 'Ember' and still highlight the correct line?\n * or maybe there is a way to highlight in the editor instead?\n */\n for (let { error, component } of scope) {\n if (!component) {\n if (error) {\n return { error, rootTemplate, name: 'unknown' };\n }\n }\n }\n\n /**\n * Step 4: Compile the Ember Template\n */\n try {\n let localScope = scope.reduce(\n (accum, { component, name }) => {\n accum[invocationName(name)] = component;\n\n return accum;\n },\n {} as Record<string, unknown>\n );\n\n return await compileHBS(rootTemplate, {\n moduleName: 'DynamicRootTemplate',\n scope: {\n ...topLevelScope,\n ...localScope,\n },\n });\n } catch (error) {\n return { error: error as Error, rootTemplate, name: 'unknown' };\n }\n}\n"],"names":["compileGJSArray","js","importMap","modules","Promise","all","map","code","compileGJS","gjsInput","compileJS","error","name","compileHBS","hbsInput","options","extractScope","liveCode","scope","hbs","filter","lang","includes","length","compiled","info","push","topLevelScope","compileMD","glimdownInput","rootTemplate","parseMarkdown","templateOnlyGlimdown","blocks","CopyComponent","ShadowComponent","remarkPlugins","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAOA,eAAeA,eAAeA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAChF,IAAIC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC7BJ,EAAE,CAACK,GAAG,CAAC,OAAO;AAAEC,IAAAA,IAAAA;AAAK,GAAC,KAAK;AACzB,IAAA,OAAO,MAAMC,UAAU,CAACD,IAAI,EAAEL,SAAS,CAAC,CAAA;AAC1C,GAAC,CACH,CAAC,CAAA;AAED,EAAA,OAAOC,OAAO,CAAA;AAChB,CAAA;AAEO,eAAeK,UAAUA,CAC9BC,QAAgB,EAChBP,SAAyB,EACD;EACxB,IAAI;IACF,IAAI;AAAEQ,MAAAA,SAAAA;AAAU,KAAC,GAAG,MAAM,OAAO,UAAU,CAAC,CAAA;AAE5C,IAAA,OAAO,MAAMA,SAAS,CAACD,QAAQ,EAAEP,SAAS,CAAC,CAAA;GAC5C,CAAC,OAAOS,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACnD,GAAA;AACF,CAAA;AAEO,eAAeC,UAAUA,CAC9BC,QAAgB,EAChBC,OAGC,EACuB;EACxB,IAAI;IACF,IAAI;AAAEF,MAAAA,UAAAA;AAAW,KAAC,GAAG,MAAM,OAAO,WAAW,CAAC,CAAA;AAE9C,IAAA,OAAOA,UAAU,CAACC,QAAQ,EAAEC,OAAO,CAAC,CAAA;GACrC,CAAC,OAAOJ,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;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E,EAAA,KAAK,IAAI;IAAED,KAAK;AAAE2B,IAAAA,SAAAA;GAAW,IAAIpB,KAAK,EAAE;IACtC,IAAI,CAACoB,SAAS,EAAE;AACd,MAAA,IAAI3B,KAAK,EAAE;QACT,OAAO;UAAEA,KAAK;UAAEmB,YAAY;AAAElB,UAAAA,IAAI,EAAE,SAAA;SAAW,CAAA;AACjD,OAAA;AACF,KAAA;AACF,GAAA;;AAEA;AACF;AACA;EACE,IAAI;IACF,IAAI2B,UAAU,GAAGrB,KAAK,CAACsB,MAAM,CAC3B,CAACC,KAAK,EAAE;MAAEH,SAAS;AAAE1B,MAAAA,IAAAA;AAAK,KAAC,KAAK;AAC9B6B,MAAAA,KAAK,CAACC,cAAc,CAAC9B,IAAI,CAAC,CAAC,GAAG0B,SAAS,CAAA;AAEvC,MAAA,OAAOG,KAAK,CAAA;KACb,EACD,EACF,CAAC,CAAA;AAED,IAAA,OAAO,MAAM5B,UAAU,CAACiB,YAAY,EAAE;AACpCa,MAAAA,UAAU,EAAE,qBAAqB;AACjCzB,MAAAA,KAAK,EAAE;AACL,QAAA,GAAGS,aAAa;QAChB,GAAGY,UAAAA;AACL,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAC,OAAO5B,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;MAAEmB,YAAY;AAAElB,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACjE,GAAA;AACF;;;;"}
|
package/dist/browser/hbs.js
CHANGED
|
@@ -77,7 +77,13 @@ function compileTemplate(source, {
|
|
|
77
77
|
|
|
78
78
|
// Copied from @glimmer/compiler/lib/compiler#precompile
|
|
79
79
|
let [block, usedLocals] = precompileJSON(source, options);
|
|
80
|
-
let usedScope = usedLocals.map(key =>
|
|
80
|
+
let usedScope = usedLocals.map(key => {
|
|
81
|
+
let value = localScope[key];
|
|
82
|
+
if (!value) {
|
|
83
|
+
throw new Error(`Attempt to use ${key} in compiled hbs, but it was not available in scope.`);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
});
|
|
81
87
|
let blockJSON = JSON.stringify(block);
|
|
82
88
|
let templateJSONObject = {
|
|
83
89
|
id: moduleName,
|
package/dist/browser/hbs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hbs.js","sources":["../../src/browser/hbs.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// import { precompileJSON } from '@glimmer/compiler';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { setComponentTemplate } from '@ember/component';\nimport templateOnlyComponent from '@ember/component/template-only';\nimport { array, concat, fn, get, hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport { importSync } from '@embroider/macros';\n\nimport { nameFor } from './utils.ts';\n\nimport type { CompileResult } from './types.ts';\nimport type { ComponentLike } from '@glint/template';\n\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nconst { precompileJSON } = importSync('@glimmer/compiler') as any;\nconst { getTemplateLocals } = importSync('@glimmer/syntax') as any;\n\n/**\n * compile a template with an empty scope\n * to use components, helpers, etc, you will need to compile with JS\n *\n * (templates alone do not have a way to import / define complex structures)\n */\nexport function compileHBS(template: string, options: CompileTemplateOptions = {}): CompileResult {\n let name = nameFor(template);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n component = setComponentTemplate(\n compileTemplate(template, { moduleName: options.moduleName || name, ...options }),\n templateOnlyComponent(options.moduleName || name)\n ) as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\ninterface CompileTemplateOptions {\n /**\n * Used for debug viewing\n */\n moduleName?: string;\n scope?: Record<string, unknown>;\n}\n\n/**\n * The reason why we can't use precompile directly is because of this:\n * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132\n *\n * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.\n * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,\n * which means that *everything* is undefined.\n */\nfunction compileTemplate(source: string, { moduleName, scope = {} }: CompileTemplateOptions) {\n let localScope = { array, concat, fn, get, hash, on, ...scope } as any;\n let locals = getTemplateLocals(source);\n\n let options = {\n strictMode: true,\n moduleName,\n locals,\n isProduction: false,\n meta: { moduleName },\n };\n\n // Copied from @glimmer/compiler/lib/compiler#precompile\n let [block, usedLocals] = precompileJSON(source, options);\n\n let usedScope = usedLocals.map((key: string) => localScope[key]);\n\n let blockJSON = JSON.stringify(block);\n let templateJSONObject = {\n id: moduleName,\n block: blockJSON,\n moduleName: moduleName ?? '(unknown template module)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n let factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["precompileJSON","importSync","getTemplateLocals","compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","strictMode","isProduction","meta","block","usedLocals","usedScope","map","key","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAeA;AACA;AACA,MAAM;AAAEA,EAAAA,cAAAA;AAAe,CAAC,GAAGC,UAAU,CAAC,mBAAmB,CAAQ,CAAA;AACjE,MAAM;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,GAAGD,UAAU,CAAC,iBAAiB,CAAQ,CAAA;;AAElE;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,UAAUA,CAACC,QAAgB,EAAEC,OAA+B,GAAG,EAAE,EAAiB;AAChG,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,QAAQ,CAAC,CAAA;AAC5B,EAAA,IAAII,SAAoC,CAAA;AACxC,EAAA,IAAIC,KAAwB,CAAA;EAE5B,IAAI;AACFD,IAAAA,SAAS,GAAGE,oBAAoB,CAC9BC,eAAe,CAACP,QAAQ,EAAE;AAAEQ,MAAAA,UAAU,EAAEP,OAAO,CAACO,UAAU,IAAIN,IAAI;MAAE,GAAGD,OAAAA;KAAS,CAAC,EACjFQ,GAAqB,CAACR,OAAO,CAACO,UAAU,IAAIN,IAAI,CAClD,CAAkB,CAAA;GACnB,CAAC,OAAOQ,CAAC,EAAE;AACVL,IAAAA,KAAK,GAAGK,CAAsB,CAAA;AAChC,GAAA;EAEA,OAAO;IAAER,IAAI;IAAEE,SAAS;AAAEC,IAAAA,KAAAA;GAAO,CAAA;AACnC,CAAA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAeA,CAACI,MAAc,EAAE;EAAEH,UAAU;AAAEI,EAAAA,KAAK,GAAG,EAAC;AAA0B,CAAC,EAAE;AAC3F,EAAA,IAAIC,UAAU,GAAG;IAAEC,KAAK;IAAEC,MAAM;IAAEC,EAAE;IAAEC,GAAG;IAAEC,IAAI;IAAEC,EAAE;IAAE,GAAGP,KAAAA;GAAc,CAAA;AACtE,EAAA,IAAIQ,MAAM,GAAGtB,iBAAiB,CAACa,MAAM,CAAC,CAAA;AAEtC,EAAA,IAAIV,OAAO,GAAG;AACZoB,IAAAA,UAAU,EAAE,IAAI;IAChBb,UAAU;IACVY,MAAM;AACNE,IAAAA,YAAY,EAAE,KAAK;AACnBC,IAAAA,IAAI,EAAE;AAAEf,MAAAA,UAAAA;AAAW,KAAA;GACpB,CAAA;;AAED;EACA,IAAI,CAACgB,KAAK,EAAEC,UAAU,CAAC,GAAG7B,cAAc,CAACe,MAAM,EAAEV,OAAO,CAAC,CAAA;AAEzD,EAAA,IAAIyB,SAAS,GAAGD,UAAU,CAACE,GAAG,CAAEC,GAAW,
|
|
1
|
+
{"version":3,"file":"hbs.js","sources":["../../src/browser/hbs.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// import { precompileJSON } from '@glimmer/compiler';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { setComponentTemplate } from '@ember/component';\nimport templateOnlyComponent from '@ember/component/template-only';\nimport { array, concat, fn, get, hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport { importSync } from '@embroider/macros';\n\nimport { nameFor } from './utils.ts';\n\nimport type { CompileResult } from './types.ts';\nimport type { ComponentLike } from '@glint/template';\n\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nconst { precompileJSON } = importSync('@glimmer/compiler') as any;\nconst { getTemplateLocals } = importSync('@glimmer/syntax') as any;\n\n/**\n * compile a template with an empty scope\n * to use components, helpers, etc, you will need to compile with JS\n *\n * (templates alone do not have a way to import / define complex structures)\n */\nexport function compileHBS(template: string, options: CompileTemplateOptions = {}): CompileResult {\n let name = nameFor(template);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n component = setComponentTemplate(\n compileTemplate(template, { moduleName: options.moduleName || name, ...options }),\n templateOnlyComponent(options.moduleName || name)\n ) as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\ninterface CompileTemplateOptions {\n /**\n * Used for debug viewing\n */\n moduleName?: string;\n scope?: Record<string, unknown>;\n}\n\n/**\n * The reason why we can't use precompile directly is because of this:\n * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132\n *\n * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.\n * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,\n * which means that *everything* is undefined.\n */\nfunction compileTemplate(source: string, { moduleName, scope = {} }: CompileTemplateOptions) {\n let localScope = { array, concat, fn, get, hash, on, ...scope } as any;\n let locals = getTemplateLocals(source);\n\n let options = {\n strictMode: true,\n moduleName,\n locals,\n isProduction: false,\n meta: { moduleName },\n };\n\n // Copied from @glimmer/compiler/lib/compiler#precompile\n let [block, usedLocals] = precompileJSON(source, options);\n\n let usedScope = usedLocals.map((key: string) => {\n let value = localScope[key];\n\n if (!value) {\n throw new Error(`Attempt to use ${key} in compiled hbs, but it was not available in scope.`);\n }\n\n return value;\n });\n\n let blockJSON = JSON.stringify(block);\n let templateJSONObject = {\n id: moduleName,\n block: blockJSON,\n moduleName: moduleName ?? '(unknown template module)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n let factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["precompileJSON","importSync","getTemplateLocals","compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","strictMode","isProduction","meta","block","usedLocals","usedScope","map","key","value","Error","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAeA;AACA;AACA,MAAM;AAAEA,EAAAA,cAAAA;AAAe,CAAC,GAAGC,UAAU,CAAC,mBAAmB,CAAQ,CAAA;AACjE,MAAM;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,GAAGD,UAAU,CAAC,iBAAiB,CAAQ,CAAA;;AAElE;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,UAAUA,CAACC,QAAgB,EAAEC,OAA+B,GAAG,EAAE,EAAiB;AAChG,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,QAAQ,CAAC,CAAA;AAC5B,EAAA,IAAII,SAAoC,CAAA;AACxC,EAAA,IAAIC,KAAwB,CAAA;EAE5B,IAAI;AACFD,IAAAA,SAAS,GAAGE,oBAAoB,CAC9BC,eAAe,CAACP,QAAQ,EAAE;AAAEQ,MAAAA,UAAU,EAAEP,OAAO,CAACO,UAAU,IAAIN,IAAI;MAAE,GAAGD,OAAAA;KAAS,CAAC,EACjFQ,GAAqB,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AACC,SAAS,CAACT,KAAK,CAAC,CAAA;AACrC,EAAA,IAAIU,kBAAkB,GAAG;AACvBC,IAAAA,EAAE,EAAE3B,UAAU;AACdgB,IAAAA,KAAK,EAAEO,SAAS;IAChBvB,UAAU,EAAEA,UAAU,IAAI,2BAA2B;IACrDI,KAAK,EAAEA,MAAMc,SAAS;AACtBU,IAAAA,YAAY,EAAE,IAAA;GACf,CAAA;AAED,EAAA,IAAIC,OAAO,GAAGC,qBAAqB,CAACJ,kBAAkB,CAAC,CAAA;AAEvD,EAAA,OAAOG,OAAO,CAAA;AAChB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-repl",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Addon for enabling REPL and Playground creation with Ember/Glimmer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -60,23 +60,20 @@
|
|
|
60
60
|
],
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@babel/helper-plugin-utils": "^7.22.5",
|
|
63
|
-
"@babel/standalone": "^7.23.
|
|
63
|
+
"@babel/standalone": "^7.23.10",
|
|
64
64
|
"@embroider/addon-shim": "1.8.7",
|
|
65
65
|
"@embroider/macros": "1.13.5",
|
|
66
|
-
"@glimmer/compiler": ">= 0.86.0",
|
|
67
|
-
"@glimmer/syntax": ">= 0.86.0",
|
|
68
66
|
"babel-import-util": "^2.0.1",
|
|
69
67
|
"babel-plugin-ember-template-compilation": "^2.2.1",
|
|
70
68
|
"broccoli-file-creator": "^2.1.1",
|
|
71
|
-
"change-case": "^5.
|
|
69
|
+
"change-case": "^5.4.2",
|
|
72
70
|
"common-tags": "^1.8.2",
|
|
73
71
|
"content-tag": "^1.2.1",
|
|
74
72
|
"decorator-transforms": "^1.1.0",
|
|
75
73
|
"line-column": "^1.0.2",
|
|
76
|
-
"magic-string": "^0.30.
|
|
74
|
+
"magic-string": "^0.30.6",
|
|
77
75
|
"mdast": "^3.0.0",
|
|
78
76
|
"parse-static-imports": "^1.1.0",
|
|
79
|
-
"reactiveweb": "^1.2.0",
|
|
80
77
|
"rehype-raw": "^6.1.1",
|
|
81
78
|
"rehype-stringify": "^9.0.4",
|
|
82
79
|
"remark-gfm": "^3.0.1",
|
|
@@ -88,16 +85,18 @@
|
|
|
88
85
|
"vfile": "^6.0.1"
|
|
89
86
|
},
|
|
90
87
|
"devDependencies": {
|
|
91
|
-
"@babel/core": "^7.23.
|
|
88
|
+
"@babel/core": "^7.23.9",
|
|
92
89
|
"@babel/plugin-transform-typescript": "^7.23.6",
|
|
93
90
|
"@babel/preset-typescript": "^7.23.3",
|
|
94
91
|
"@babel/types": "^7.23.9",
|
|
95
92
|
"@ember/test-helpers": "^3.2.1",
|
|
96
93
|
"@ember/test-waiters": "^3.1.0",
|
|
97
|
-
"@embroider/addon-dev": "4.1
|
|
94
|
+
"@embroider/addon-dev": "4.2.1",
|
|
95
|
+
"@glimmer/compiler": ">= 0.86.0",
|
|
98
96
|
"@glimmer/component": "^1.1.2",
|
|
99
97
|
"@glimmer/interfaces": ">= 0.86.0",
|
|
100
98
|
"@glimmer/reference": ">= 0.86.0",
|
|
99
|
+
"@glimmer/syntax": ">= 0.86.0",
|
|
101
100
|
"@glimmer/tracking": "^1.1.2",
|
|
102
101
|
"@glimmer/util": "^0.88.0",
|
|
103
102
|
"@glint/core": "1.3.0",
|
|
@@ -114,26 +113,25 @@
|
|
|
114
113
|
"@types/hast": "^3.0.3",
|
|
115
114
|
"@types/mdast": "^4.0.3",
|
|
116
115
|
"@types/unist": "^3.0.2",
|
|
117
|
-
"@types/uuid": "^9.0.
|
|
116
|
+
"@types/uuid": "^9.0.8",
|
|
118
117
|
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
119
118
|
"@typescript-eslint/parser": "^6.20.0",
|
|
120
119
|
"concurrently": "^8.2.2",
|
|
121
|
-
"ember-resources": "^
|
|
122
|
-
"ember-source": "^5.
|
|
120
|
+
"ember-resources": "^7.0.0",
|
|
121
|
+
"ember-source": "^5.6.0",
|
|
123
122
|
"ember-template-imports": "^3.4.2",
|
|
124
123
|
"ember-template-lint": "^5.13.0",
|
|
125
124
|
"eslint": "^8.55.0",
|
|
126
125
|
"eslint-plugin-ember": "^12.0.0",
|
|
127
126
|
"eslint-plugin-node": "^11.1.0",
|
|
128
|
-
"eslint-plugin-prettier": "^5.
|
|
129
|
-
"prettier": "^3.
|
|
127
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
128
|
+
"prettier": "^3.2.5",
|
|
130
129
|
"prettier-plugin-ember-template-tag": "^2.0.0",
|
|
131
130
|
"publint": "^0.2.6",
|
|
132
|
-
"rollup": "~4.9.
|
|
131
|
+
"rollup": "~4.9.6",
|
|
133
132
|
"rollup-plugin-copy": "^3.5.0",
|
|
134
|
-
"rollup-plugin-glimmer-template-tag": "^0.4.1",
|
|
135
133
|
"typescript": "^5.3.3",
|
|
136
|
-
"@nullvoxpopuli/limber-untyped": "0.0.
|
|
134
|
+
"@nullvoxpopuli/limber-untyped": "0.0.1"
|
|
137
135
|
},
|
|
138
136
|
"volta": {
|
|
139
137
|
"extends": "../../../package.json"
|
|
@@ -5,7 +5,7 @@ import type { ExtractedCode } from './markdown-to-ember.ts';
|
|
|
5
5
|
import type { UnifiedPlugin } from './types.ts';
|
|
6
6
|
import type { EvalImportMap, ScopeMap } from './types.ts';
|
|
7
7
|
|
|
8
|
-
async function
|
|
8
|
+
async function compileGJSArray(js: { code: string }[], importMap?: EvalImportMap) {
|
|
9
9
|
let modules = await Promise.all(
|
|
10
10
|
js.map(async ({ code }) => {
|
|
11
11
|
return await compileGJS(code, importMap);
|
|
@@ -46,7 +46,10 @@ export async function compileHBS(
|
|
|
46
46
|
|
|
47
47
|
async function extractScope(
|
|
48
48
|
liveCode: ExtractedCode[],
|
|
49
|
-
|
|
49
|
+
options?: {
|
|
50
|
+
importMap?: EvalImportMap;
|
|
51
|
+
topLevelScope?: ScopeMap;
|
|
52
|
+
}
|
|
50
53
|
): Promise<CompileResult[]> {
|
|
51
54
|
let scope: CompileResult[] = [];
|
|
52
55
|
|
|
@@ -54,7 +57,7 @@ async function extractScope(
|
|
|
54
57
|
let js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));
|
|
55
58
|
|
|
56
59
|
if (js.length > 0) {
|
|
57
|
-
let compiled = await
|
|
60
|
+
let compiled = await compileGJSArray(js, options?.importMap);
|
|
58
61
|
|
|
59
62
|
await Promise.all(
|
|
60
63
|
compiled.map(async (info) => {
|
|
@@ -74,7 +77,7 @@ async function extractScope(
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
for (let { code } of hbs) {
|
|
77
|
-
let compiled = await compileHBS(code);
|
|
80
|
+
let compiled = await compileHBS(code, { scope: options?.topLevelScope });
|
|
78
81
|
|
|
79
82
|
scope.push(compiled);
|
|
80
83
|
}
|
|
@@ -92,7 +95,6 @@ export async function compileMD(
|
|
|
92
95
|
ShadowComponent?: string;
|
|
93
96
|
}
|
|
94
97
|
): Promise<CompileResult & { rootTemplate?: string }> {
|
|
95
|
-
let importMap = options?.importMap;
|
|
96
98
|
let topLevelScope = options?.topLevelScope ?? {};
|
|
97
99
|
let rootTemplate: string;
|
|
98
100
|
let liveCode: ExtractedCode[];
|
|
@@ -126,7 +128,7 @@ export async function compileMD(
|
|
|
126
128
|
*/
|
|
127
129
|
if (liveCode.length > 0) {
|
|
128
130
|
try {
|
|
129
|
-
scope = await extractScope(liveCode,
|
|
131
|
+
scope = await extractScope(liveCode, options);
|
|
130
132
|
} catch (error) {
|
|
131
133
|
console.info({ scope });
|
|
132
134
|
console.error(error);
|
package/src/browser/hbs.ts
CHANGED
|
@@ -75,7 +75,15 @@ function compileTemplate(source: string, { moduleName, scope = {} }: CompileTemp
|
|
|
75
75
|
// Copied from @glimmer/compiler/lib/compiler#precompile
|
|
76
76
|
let [block, usedLocals] = precompileJSON(source, options);
|
|
77
77
|
|
|
78
|
-
let usedScope = usedLocals.map((key: string) =>
|
|
78
|
+
let usedScope = usedLocals.map((key: string) => {
|
|
79
|
+
let value = localScope[key];
|
|
80
|
+
|
|
81
|
+
if (!value) {
|
|
82
|
+
throw new Error(`Attempt to use ${key} in compiled hbs, but it was not available in scope.`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return value;
|
|
86
|
+
});
|
|
79
87
|
|
|
80
88
|
let blockJSON = JSON.stringify(block);
|
|
81
89
|
let templateJSONObject = {
|