ember-repl 3.0.0-beta.7 → 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 +2 -2
- package/declarations/browser/compile/formats.d.ts.map +1 -1
- package/declarations/browser/compile/index.d.ts +5 -10
- package/declarations/browser/compile/index.d.ts.map +1 -1
- package/declarations/browser/gjs.d.ts.map +1 -1
- package/declarations/browser/known-modules.d.ts +22 -0
- package/declarations/browser/known-modules.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/compile/index.js +7 -8
- package/dist/browser/compile/index.js.map +1 -1
- package/dist/browser/gjs.js +7 -3
- package/dist/browser/gjs.js.map +1 -1
- package/dist/browser/hbs.js +7 -1
- package/dist/browser/hbs.js.map +1 -1
- package/dist/browser/known-modules.js +2 -0
- package/dist/browser/known-modules.js.map +1 -1
- package/package.json +43 -42
- package/src/browser/compile/formats.ts +8 -6
- package/src/browser/compile/index.ts +11 -14
- package/src/browser/gjs.ts +7 -5
- package/src/browser/hbs.ts +9 -1
- package/src/browser/known-modules.ts +2 -0
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ resource so that when an error occurs, you could keep rendering the latest succe
|
|
|
91
91
|
import Component from '@glimmer/component';
|
|
92
92
|
import { Compiled } from 'ember-repl';
|
|
93
93
|
import { use } from 'ember-resources';
|
|
94
|
-
import { keepLatest } from '
|
|
94
|
+
import { keepLatest } from 'reactiveweb/keep-latest';
|
|
95
95
|
|
|
96
96
|
export class Renderer extends Component {
|
|
97
97
|
@use compile = Compiled(() => this.args.gjsText, 'gjs');
|
|
@@ -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 '
|
|
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"}
|
|
@@ -62,15 +62,10 @@ export interface Value {
|
|
|
62
62
|
error: string | null;
|
|
63
63
|
component: ComponentLike;
|
|
64
64
|
}
|
|
65
|
-
export declare function
|
|
66
|
-
export declare function
|
|
67
|
-
export declare function
|
|
68
|
-
export declare function
|
|
69
|
-
export declare function
|
|
70
|
-
/**
|
|
71
|
-
* By default, this compiles to `glimdown`. A Markdown format which
|
|
72
|
-
* extracts `live` tagged code snippets and compiles them to components.
|
|
73
|
-
*/
|
|
74
|
-
export declare const Compiled: typeof buildCompiler;
|
|
65
|
+
export declare function Compiled(markdownText: Input | (() => Input)): Value;
|
|
66
|
+
export declare function Compiled(markdownText: Input | (() => Input), options?: Format): Value;
|
|
67
|
+
export declare function Compiled(markdownText: Input | (() => Input), options?: () => Format): Value;
|
|
68
|
+
export declare function Compiled(markdownText: Input | (() => Input), options?: ExtraOptions): Value;
|
|
69
|
+
export declare function Compiled(markdownText: Input | (() => Input), options?: () => ExtraOptions): Value;
|
|
75
70
|
export {};
|
|
76
71
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/compile/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;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AC;IACzB,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,KAAK,CAAC;IACd,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEN;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,aAAa,CAAC;CAC1B;AAED,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,CAAC;AACrE,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;AACvF,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,GAAG,KAAK,CAAC;AAC7F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,KAAK,CAAC;AAC7F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,YAAY,GAAG,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gjs.d.ts","sourceRoot":"","sources":["../../src/browser/gjs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"gjs.d.ts","sourceRoot":"","sources":["../../src/browser/gjs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAOxC,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY7E;AAED,wBAAsB,SAAS,CAC7B,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,GAAQ,GAChB,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CA6BzC"}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/// <reference types="ember-source/types/stable/@glimmer/tracking" />
|
|
2
|
+
/// <reference types="ember-source/types/stable/@ember/application" />
|
|
3
|
+
/// <reference types="ember-source/types/stable/@ember/array" />
|
|
4
|
+
/// <reference types="ember-source/types/stable/@ember/component" />
|
|
5
|
+
/// <reference types="ember-source/types/stable/@ember/component/helper" />
|
|
6
|
+
/// <reference types="ember-source/types/stable/@ember/debug" />
|
|
7
|
+
/// <reference types="ember-source/types/stable/@ember/destroyable" />
|
|
8
|
+
/// <reference types="ember-source/types/stable/@ember/helper" />
|
|
9
|
+
/// <reference types="ember-source/types/stable/@ember/modifier" />
|
|
10
|
+
/// <reference types="ember-source/types/stable/@ember/object" />
|
|
11
|
+
/// <reference types="ember-source/types/stable/@ember/owner" />
|
|
12
|
+
/// <reference types="ember-source/types/stable/@ember/controller/owner-ext" />
|
|
13
|
+
/// <reference types="ember-source/types/stable/@ember/routing/owner-ext" />
|
|
14
|
+
/// <reference types="ember-source/types/stable/@ember/service/owner-ext" />
|
|
15
|
+
/// <reference types="ember-source/types/stable/@ember/runloop" />
|
|
16
|
+
/// <reference types="ember-source/types/stable/@ember/service" />
|
|
17
|
+
/// <reference types="ember-source/types/stable/@ember/routing/service-ext" />
|
|
18
|
+
/// <reference types="ember-source/types/stable/@ember/template" />
|
|
19
|
+
/// <reference types="ember-source/types/stable/@ember/template-factory" />
|
|
20
|
+
/// <reference types="ember-source/types/stable/@ember/utils" />
|
|
1
21
|
/// <reference types="ember-source/types/stable/@ember/component/template-only" />
|
|
2
22
|
/**
|
|
3
23
|
* We need to import and hang on to these references so that they
|
|
@@ -8,6 +28,7 @@ import * as _tracking from '@glimmer/tracking';
|
|
|
8
28
|
import * as _application from '@ember/application';
|
|
9
29
|
import * as _array from '@ember/array';
|
|
10
30
|
import * as _EmberComponent from '@ember/component';
|
|
31
|
+
import * as _EmberComponentHelper from '@ember/component/helper';
|
|
11
32
|
import * as _debug from '@ember/debug';
|
|
12
33
|
import * as _destroyable from '@ember/destroyable';
|
|
13
34
|
import * as _helpers from '@ember/helper';
|
|
@@ -23,6 +44,7 @@ export declare const modules: {
|
|
|
23
44
|
'@ember/application': typeof _application;
|
|
24
45
|
'@ember/array': typeof _array;
|
|
25
46
|
'@ember/component': typeof _EmberComponent;
|
|
47
|
+
'@ember/component/helper': typeof _EmberComponentHelper;
|
|
26
48
|
'@ember/component/template-only': <S>(moduleName?: string | undefined, name?: string | undefined) => import("@ember/component/template-only").TemplateOnlyComponent<S>;
|
|
27
49
|
'@ember/debug': typeof _debug;
|
|
28
50
|
'@ember/destroyable': typeof _destroyable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../src/browser/known-modules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../src/browser/known-modules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,eAAe,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAEvC,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;CAoBnB,CAAC"}
|
|
@@ -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,MAAM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AAI,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;;;;"}
|
|
@@ -69,7 +69,11 @@ async function compile(text, options) {
|
|
|
69
69
|
* @internal
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* By default, this compiles to `glimdown`. A Markdown format which
|
|
74
|
+
* extracts `live` tagged code snippets and compiles them to components.
|
|
75
|
+
*/
|
|
76
|
+
function Compiled(markdownText, maybeOptions) {
|
|
73
77
|
return resource(() => {
|
|
74
78
|
let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;
|
|
75
79
|
let format = (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';
|
|
@@ -103,12 +107,7 @@ function buildCompiler(markdownText, maybeOptions) {
|
|
|
103
107
|
});
|
|
104
108
|
});
|
|
105
109
|
}
|
|
110
|
+
resourceFactory(Compiled);
|
|
106
111
|
|
|
107
|
-
|
|
108
|
-
* By default, this compiles to `glimdown`. A Markdown format which
|
|
109
|
-
* extracts `live` tagged code snippets and compiles them to components.
|
|
110
|
-
*/
|
|
111
|
-
const Compiled = resourceFactory(buildCompiler);
|
|
112
|
-
|
|
113
|
-
export { CACHE, Compiled, buildCompiler, compile };
|
|
112
|
+
export { CACHE, Compiled, compile };
|
|
114
113
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/browser/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport { nameFor } from '../utils.ts';\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { UnifiedPlugin } from './types.ts';\nimport type { EvalImportMap, ScopeMap } from './types.ts';\nimport type { ComponentLike } from '@glint/template';\ntype Format = 'glimdown' | 'gjs' | 'hbs';\n\nexport const CACHE = new Map<string, ComponentLike>();\n\ninterface Events {\n onSuccess: (component: ComponentLike) => Promise<unknown> | unknown;\n onError: (error: string) => Promise<unknown> | unknown;\n onCompileStart: () => Promise<unknown> | unknown;\n}\n\ninterface Scope {\n importMap?: EvalImportMap;\n}\n\nconst SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];\n\ninterface GlimdownOptions extends Scope, Events {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n}\n\n/**\n * Compile GitHub-flavored Markdown with GJS support\n * and optionally render gjs-snippets via a `live` meta tag\n * on the code fences.\n */\nexport async function compile(text: string, options: GlimdownOptions): Promise<void>;\n\n/**\n * Compile GJS\n */\nexport async function compile(text: string, options: GJSOptions): Promise<void>;\n\n/**\n * Compile a stateless component using just the template\n */\nexport async function compile(text: string, options: HBSOptions): Promise<void>;\n\n/**\n * This compileMD is a more robust version of the raw compiling used in \"formats\".\n * This function manages cache, and has events for folks building UIs to hook in to\n */\nexport async function compile(\n text: string,\n options: GlimdownOptions | GJSOptions | HBSOptions\n): Promise<void> {\n let { onSuccess, onError, onCompileStart } = options;\n let id = nameFor(text);\n\n let existing = CACHE.get(id);\n\n if (existing) {\n onSuccess(existing);\n\n return;\n }\n\n if (!SUPPORTED_FORMATS.includes(options.format)) {\n await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);\n\n return;\n }\n\n await onCompileStart();\n\n if (!text) {\n await onError('No Input Document yet');\n\n return;\n }\n\n let result: CompileResult;\n\n if (options.format === 'glimdown') {\n result = await processMD(text, options);\n } else if (options.format === 'gjs') {\n result = await processGJS(text, options.importMap);\n } else if (options.format === 'hbs') {\n result = await processHBS(text, {\n scope: options.topLevelScope,\n });\n } else {\n await onError(\n `Unsupported format: ${(options as any).format}. Supported formats: ${SUPPORTED_FORMATS}`\n );\n\n return;\n }\n\n if (result.error) {\n await onError(result.error.message || `${result.error}`);\n\n return;\n }\n\n CACHE.set(id, result.component as ComponentLike);\n\n await onSuccess(result.component as ComponentLike);\n}\n\ntype Input = string | undefined | null;\n\ntype ExtraOptions =\n | {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n importMap?: EvalImportMap;\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'gjs';\n importMap?: EvalImportMap;\n };\n\n/**\n * @internal\n */\nexport interface Value {\n isReady: boolean;\n error: string | null;\n component: ComponentLike;\n}\n\nexport function
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/browser/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport { nameFor } from '../utils.ts';\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { UnifiedPlugin } from './types.ts';\nimport type { EvalImportMap, ScopeMap } from './types.ts';\nimport type { ComponentLike } from '@glint/template';\ntype Format = 'glimdown' | 'gjs' | 'hbs';\n\nexport const CACHE = new Map<string, ComponentLike>();\n\ninterface Events {\n onSuccess: (component: ComponentLike) => Promise<unknown> | unknown;\n onError: (error: string) => Promise<unknown> | unknown;\n onCompileStart: () => Promise<unknown> | unknown;\n}\n\ninterface Scope {\n importMap?: EvalImportMap;\n}\n\nconst SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];\n\ninterface GlimdownOptions extends Scope, Events {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n}\n\n/**\n * Compile GitHub-flavored Markdown with GJS support\n * and optionally render gjs-snippets via a `live` meta tag\n * on the code fences.\n */\nexport async function compile(text: string, options: GlimdownOptions): Promise<void>;\n\n/**\n * Compile GJS\n */\nexport async function compile(text: string, options: GJSOptions): Promise<void>;\n\n/**\n * Compile a stateless component using just the template\n */\nexport async function compile(text: string, options: HBSOptions): Promise<void>;\n\n/**\n * This compileMD is a more robust version of the raw compiling used in \"formats\".\n * This function manages cache, and has events for folks building UIs to hook in to\n */\nexport async function compile(\n text: string,\n options: GlimdownOptions | GJSOptions | HBSOptions\n): Promise<void> {\n let { onSuccess, onError, onCompileStart } = options;\n let id = nameFor(text);\n\n let existing = CACHE.get(id);\n\n if (existing) {\n onSuccess(existing);\n\n return;\n }\n\n if (!SUPPORTED_FORMATS.includes(options.format)) {\n await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);\n\n return;\n }\n\n await onCompileStart();\n\n if (!text) {\n await onError('No Input Document yet');\n\n return;\n }\n\n let result: CompileResult;\n\n if (options.format === 'glimdown') {\n result = await processMD(text, options);\n } else if (options.format === 'gjs') {\n result = await processGJS(text, options.importMap);\n } else if (options.format === 'hbs') {\n result = await processHBS(text, {\n scope: options.topLevelScope,\n });\n } else {\n await onError(\n `Unsupported format: ${(options as any).format}. Supported formats: ${SUPPORTED_FORMATS}`\n );\n\n return;\n }\n\n if (result.error) {\n await onError(result.error.message || `${result.error}`);\n\n return;\n }\n\n CACHE.set(id, result.component as ComponentLike);\n\n await onSuccess(result.component as ComponentLike);\n}\n\ntype Input = string | undefined | null;\n\ntype ExtraOptions =\n | {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n importMap?: EvalImportMap;\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'gjs';\n importMap?: EvalImportMap;\n };\n\n/**\n * @internal\n */\nexport interface Value {\n isReady: boolean;\n error: string | null;\n component: ComponentLike;\n}\n\nexport function Compiled(markdownText: Input | (() => Input)): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: ExtraOptions): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => ExtraOptions): Value;\n\n/**\n * By default, this compiles to `glimdown`. A Markdown format which\n * extracts `live` tagged code snippets and compiles them to components.\n */\nexport function Compiled(\n markdownText: Input | (() => Input),\n maybeOptions?: Format | (() => Format) | ExtraOptions | (() => ExtraOptions)\n): Value {\n return resource(() => {\n let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;\n let format =\n (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';\n let options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};\n\n let input = typeof markdownText === 'function' ? markdownText() : markdownText;\n let ready = cell(false);\n let error = cell<string | null>();\n let result = cell<ComponentLike>();\n\n if (input) {\n compile(input, {\n // narrowing is hard here, but this is an implementation detail\n format: format as any,\n onSuccess: async (component) => {\n result.current = component;\n ready.set(true);\n error.set(null);\n },\n onError: async (e) => {\n error.set(e);\n },\n onCompileStart: async () => {\n ready.set(false);\n },\n ...options,\n });\n }\n\n return () => ({\n isReady: ready.current,\n error: error.current,\n component: result.current,\n });\n });\n}\n\nresourceFactory(Compiled);\n"],"names":["CACHE","Map","SUPPORTED_FORMATS","compile","text","options","onSuccess","onError","onCompileStart","id","nameFor","existing","get","includes","format","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","markdownText","maybeOptions","resource","maybeObject","input","ready","cell","current","e","isReady","resourceFactory"],"mappings":";;;;MAeaA,KAAK,GAAG,IAAIC,GAAG,GAAyB;AAYrD,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;;AAkBpD;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,eAAeC,OAAOA,CAC3BC,IAAY,EACZC,OAAkD,EACnC;EACf,IAAI;IAAEC,SAAS;IAAEC,OAAO;AAAEC,IAAAA,cAAAA;AAAe,GAAC,GAAGH,OAAO,CAAA;AACpD,EAAA,IAAII,EAAE,GAAGC,OAAO,CAACN,IAAI,CAAC,CAAA;AAEtB,EAAA,IAAIO,QAAQ,GAAGX,KAAK,CAACY,GAAG,CAACH,EAAE,CAAC,CAAA;AAE5B,EAAA,IAAIE,QAAQ,EAAE;IACZL,SAAS,CAACK,QAAQ,CAAC,CAAA;AAEnB,IAAA,OAAA;AACF,GAAA;EAEA,IAAI,CAACT,iBAAiB,CAACW,QAAQ,CAACR,OAAO,CAACS,MAAM,CAAC,EAAE;IAC/C,MAAMP,OAAO,CAAE,CAAsBF,oBAAAA,EAAAA,OAAO,CAACS,MAAO,CAAA,qBAAA,EAAuBZ,iBAAkB,CAAA,CAAC,CAAC,CAAA;AAE/F,IAAA,OAAA;AACF,GAAA;EAEA,MAAMM,cAAc,EAAE,CAAA;EAEtB,IAAI,CAACJ,IAAI,EAAE;IACT,MAAMG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAEtC,IAAA,OAAA;AACF,GAAA;AAEA,EAAA,IAAIQ,MAA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AAQ,CAAC;;;;"}
|
package/dist/browser/gjs.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { importSync } from '@embroider/macros';
|
|
2
2
|
import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';
|
|
3
|
-
import { createPreprocessor } from 'content-tag/standalone';
|
|
4
3
|
|
|
5
4
|
const compiler = importSync('ember-source/dist/ember-template-compiler.js');
|
|
6
5
|
let processor;
|
|
7
6
|
let fetchingPromise;
|
|
8
7
|
async function preprocess(input, name) {
|
|
9
8
|
if (!fetchingPromise) {
|
|
10
|
-
fetchingPromise =
|
|
9
|
+
fetchingPromise = import('content-tag');
|
|
10
|
+
}
|
|
11
|
+
if (!processor) {
|
|
12
|
+
let {
|
|
13
|
+
Preprocessor
|
|
14
|
+
} = await fetchingPromise;
|
|
15
|
+
processor = new Preprocessor();
|
|
11
16
|
}
|
|
12
|
-
processor = await fetchingPromise;
|
|
13
17
|
return processor.process(input, `${name}.js`);
|
|
14
18
|
}
|
|
15
19
|
async function transform(intermediate, name, options = {}) {
|
package/dist/browser/gjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gjs.js","sources":["../../src/browser/gjs.ts"],"sourcesContent":["import { importSync } from '@embroider/macros';\n\nimport babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';\n\nimport type { Babel } from './types.ts';\n\nconst compiler = importSync('ember-source/dist/ember-template-compiler.js');\n\
|
|
1
|
+
{"version":3,"file":"gjs.js","sources":["../../src/browser/gjs.ts"],"sourcesContent":["import { importSync } from '@embroider/macros';\n\nimport babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';\n\nimport type { Babel } from './types.ts';\n\nconst compiler = importSync('ember-source/dist/ember-template-compiler.js');\n\nlet processor: any;\nlet fetchingPromise: Promise<any>;\n\nexport async function preprocess(input: string, name: string): Promise<string> {\n if (!fetchingPromise) {\n fetchingPromise = import('content-tag');\n }\n\n if (!processor) {\n let { Preprocessor } = await fetchingPromise;\n\n processor = new Preprocessor();\n }\n\n return processor.process(input, `${name}.js`);\n}\n\nexport async function transform(\n intermediate: string,\n name: string,\n options: any = {}\n): Promise<ReturnType<Babel['transform']>> {\n let babel = (await import('@babel/standalone')) as Babel;\n\n return babel.transform(intermediate, {\n filename: `${name}.js`,\n plugins: [\n // [babelPluginIntermediateGJS],\n [\n babelPluginEmberTemplateCompilation,\n {\n compiler,\n },\n ],\n [babel.availablePlugins['proposal-decorators'], { legacy: true }],\n [babel.availablePlugins['proposal-class-properties']],\n ],\n presets: [\n [\n babel.availablePresets['env'],\n {\n // false -- keeps ES Modules\n modules: 'cjs',\n targets: { esmodules: true },\n forceAllTransforms: false,\n ...options,\n },\n ],\n ],\n });\n}\n"],"names":["compiler","importSync","processor","fetchingPromise","preprocess","input","name","Preprocessor","process","transform","intermediate","options","babel","filename","plugins","babelPluginEmberTemplateCompilation","availablePlugins","legacy","presets","availablePresets","modules","targets","esmodules","forceAllTransforms"],"mappings":";;;AAMA,MAAMA,QAAQ,GAAGC,UAAU,CAAC,8CAA8C,CAAC,CAAA;AAE3E,IAAIC,SAAc,CAAA;AAClB,IAAIC,eAA6B,CAAA;AAE1B,eAAeC,UAAUA,CAACC,KAAa,EAAEC,IAAY,EAAmB;EAC7E,IAAI,CAACH,eAAe,EAAE;AACpBA,IAAAA,eAAe,GAAG,OAAO,aAAa,CAAC,CAAA;AACzC,GAAA;EAEA,IAAI,CAACD,SAAS,EAAE;IACd,IAAI;AAAEK,MAAAA,YAAAA;KAAc,GAAG,MAAMJ,eAAe,CAAA;AAE5CD,IAAAA,SAAS,GAAG,IAAIK,YAAY,EAAE,CAAA;AAChC,GAAA;EAEA,OAAOL,SAAS,CAACM,OAAO,CAACH,KAAK,EAAG,CAAA,EAAEC,IAAK,CAAA,GAAA,CAAI,CAAC,CAAA;AAC/C,CAAA;AAEO,eAAeG,SAASA,CAC7BC,YAAoB,EACpBJ,IAAY,EACZK,OAAY,GAAG,EAAE,EACwB;AACzC,EAAA,IAAIC,KAAK,GAAI,MAAM,OAAO,mBAAmB,CAAW,CAAA;AAExD,EAAA,OAAOA,KAAK,CAACH,SAAS,CAACC,YAAY,EAAE;IACnCG,QAAQ,EAAG,CAAEP,EAAAA,IAAK,CAAI,GAAA,CAAA;AACtBQ,IAAAA,OAAO,EAAE;AACP;AACA,IAAA,CACEC,mCAAmC,EACnC;AACEf,MAAAA,QAAAA;KACD,CACF,EACD,CAACY,KAAK,CAACI,gBAAgB,CAAC,qBAAqB,CAAC,EAAE;AAAEC,MAAAA,MAAM,EAAE,IAAA;KAAM,CAAC,EACjE,CAACL,KAAK,CAACI,gBAAgB,CAAC,2BAA2B,CAAC,CAAC,CACtD;IACDE,OAAO,EAAE,CACP,CACEN,KAAK,CAACO,gBAAgB,CAAC,KAAK,CAAC,EAC7B;AACE;AACAC,MAAAA,OAAO,EAAE,KAAK;AACdC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,SAAS,EAAE,IAAA;OAAM;AAC5BC,MAAAA,kBAAkB,EAAE,KAAK;MACzB,GAAGZ,OAAAA;AACL,KAAC,CACF,CAAA;AAEL,GAAC,CAAC,CAAA;AACJ;;;;"}
|
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,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;IAAE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,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;;;;"}
|
|
@@ -3,6 +3,7 @@ import * as _tracking from '@glimmer/tracking';
|
|
|
3
3
|
import * as _application from '@ember/application';
|
|
4
4
|
import * as _array from '@ember/array';
|
|
5
5
|
import * as _EmberComponent from '@ember/component';
|
|
6
|
+
import * as _EmberComponentHelper from '@ember/component/helper';
|
|
6
7
|
import _TO from '@ember/component/template-only';
|
|
7
8
|
import * as _debug from '@ember/debug';
|
|
8
9
|
import * as _destroyable from '@ember/destroyable';
|
|
@@ -24,6 +25,7 @@ const modules = {
|
|
|
24
25
|
'@ember/application': _application,
|
|
25
26
|
'@ember/array': _array,
|
|
26
27
|
'@ember/component': _EmberComponent,
|
|
28
|
+
'@ember/component/helper': _EmberComponentHelper,
|
|
27
29
|
'@ember/component/template-only': _TO,
|
|
28
30
|
'@ember/debug': _debug,
|
|
29
31
|
'@ember/destroyable': _destroyable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-modules.js","sources":["../../src/browser/known-modules.ts"],"sourcesContent":["/**\n * We need to import and hang on to these references so that they\n * don't get optimized away during deploy\n */\nimport _GlimmerComponent from '@glimmer/component';\nimport * as _tracking from '@glimmer/tracking';\nimport * as _application from '@ember/application';\nimport * as _array from '@ember/array';\nimport * as _EmberComponent from '@ember/component';\nimport _TO from '@ember/component/template-only';\nimport * as _debug from '@ember/debug';\nimport * as _destroyable from '@ember/destroyable';\nimport * as _helpers from '@ember/helper';\nimport * as _modifier from '@ember/modifier';\nimport * as _object from '@ember/object';\nimport * as _owner from '@ember/owner';\nimport * as _runloop from '@ember/runloop';\nimport * as _service from '@ember/service';\nimport * as _template from '@ember/template';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport * as _utils from '@ember/utils';\n\nexport const modules = {\n '@ember/application': _application,\n '@ember/array': _array,\n '@ember/component': _EmberComponent,\n '@ember/component/template-only': _TO,\n '@ember/debug': _debug,\n '@ember/destroyable': _destroyable,\n '@ember/helper': _helpers,\n '@ember/modifier': _modifier,\n '@ember/object': _object,\n '@ember/runloop': _runloop,\n '@ember/service': _service,\n '@ember/template-factory': { createTemplateFactory },\n '@ember/utils': _utils,\n '@ember/template': _template,\n '@ember/owner': _owner,\n\n '@glimmer/component': _GlimmerComponent,\n '@glimmer/tracking': _tracking,\n};\n"],"names":["modules","_application","_array","_EmberComponent","_TO","_debug","_destroyable","_helpers","_modifier","_object","_runloop","_service","createTemplateFactory","_utils","_template","_owner","_GlimmerComponent","_tracking"],"mappings":"
|
|
1
|
+
{"version":3,"file":"known-modules.js","sources":["../../src/browser/known-modules.ts"],"sourcesContent":["/**\n * We need to import and hang on to these references so that they\n * don't get optimized away during deploy\n */\nimport _GlimmerComponent from '@glimmer/component';\nimport * as _tracking from '@glimmer/tracking';\nimport * as _application from '@ember/application';\nimport * as _array from '@ember/array';\nimport * as _EmberComponent from '@ember/component';\nimport * as _EmberComponentHelper from '@ember/component/helper';\nimport _TO from '@ember/component/template-only';\nimport * as _debug from '@ember/debug';\nimport * as _destroyable from '@ember/destroyable';\nimport * as _helpers from '@ember/helper';\nimport * as _modifier from '@ember/modifier';\nimport * as _object from '@ember/object';\nimport * as _owner from '@ember/owner';\nimport * as _runloop from '@ember/runloop';\nimport * as _service from '@ember/service';\nimport * as _template from '@ember/template';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport * as _utils from '@ember/utils';\n\nexport const modules = {\n '@ember/application': _application,\n '@ember/array': _array,\n '@ember/component': _EmberComponent,\n '@ember/component/helper': _EmberComponentHelper,\n '@ember/component/template-only': _TO,\n '@ember/debug': _debug,\n '@ember/destroyable': _destroyable,\n '@ember/helper': _helpers,\n '@ember/modifier': _modifier,\n '@ember/object': _object,\n '@ember/runloop': _runloop,\n '@ember/service': _service,\n '@ember/template-factory': { createTemplateFactory },\n '@ember/utils': _utils,\n '@ember/template': _template,\n '@ember/owner': _owner,\n\n '@glimmer/component': _GlimmerComponent,\n '@glimmer/tracking': _tracking,\n};\n"],"names":["modules","_application","_array","_EmberComponent","_EmberComponentHelper","_TO","_debug","_destroyable","_helpers","_modifier","_object","_runloop","_service","createTemplateFactory","_utils","_template","_owner","_GlimmerComponent","_tracking"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAsBO,MAAMA,OAAO,GAAG;AACrB,EAAA,oBAAoB,EAAEC,YAAY;AAClC,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,kBAAkB,EAAEC,eAAe;AACnC,EAAA,yBAAyB,EAAEC,qBAAqB;AAChD,EAAA,gCAAgC,EAAEC,GAAG;AACrC,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,oBAAoB,EAAEC,YAAY;AAClC,EAAA,eAAe,EAAEC,QAAQ;AACzB,EAAA,iBAAiB,EAAEC,SAAS;AAC5B,EAAA,eAAe,EAAEC,OAAO;AACxB,EAAA,gBAAgB,EAAEC,QAAQ;AAC1B,EAAA,gBAAgB,EAAEC,QAAQ;AAC1B,EAAA,yBAAyB,EAAE;AAAEC,IAAAA,qBAAAA;GAAuB;AACpD,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,iBAAiB,EAAEC,SAAS;AAC5B,EAAA,cAAc,EAAEC,MAAM;AAEtB,EAAA,oBAAoB,EAAEC,iBAAiB;AACvC,EAAA,mBAAmB,EAAEC,SAAAA;AACvB;;;;"}
|
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,17 +60,18 @@
|
|
|
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
|
-
"@embroider/macros": "1.13.
|
|
65
|
+
"@embroider/macros": "1.13.5",
|
|
66
66
|
"babel-import-util": "^2.0.1",
|
|
67
67
|
"babel-plugin-ember-template-compilation": "^2.2.1",
|
|
68
68
|
"broccoli-file-creator": "^2.1.1",
|
|
69
|
-
"change-case": "^5.2
|
|
69
|
+
"change-case": "^5.4.2",
|
|
70
70
|
"common-tags": "^1.8.2",
|
|
71
|
-
"content-tag": "
|
|
71
|
+
"content-tag": "^1.2.1",
|
|
72
|
+
"decorator-transforms": "^1.1.0",
|
|
72
73
|
"line-column": "^1.0.2",
|
|
73
|
-
"magic-string": "^0.30.
|
|
74
|
+
"magic-string": "^0.30.6",
|
|
74
75
|
"mdast": "^3.0.0",
|
|
75
76
|
"parse-static-imports": "^1.1.0",
|
|
76
77
|
"rehype-raw": "^6.1.1",
|
|
@@ -84,53 +85,53 @@
|
|
|
84
85
|
"vfile": "^6.0.1"
|
|
85
86
|
},
|
|
86
87
|
"devDependencies": {
|
|
87
|
-
"@babel/core": "^7.23.
|
|
88
|
+
"@babel/core": "^7.23.9",
|
|
89
|
+
"@babel/plugin-transform-typescript": "^7.23.6",
|
|
88
90
|
"@babel/preset-typescript": "^7.23.3",
|
|
89
|
-
"@babel/types": "^7.23.
|
|
91
|
+
"@babel/types": "^7.23.9",
|
|
90
92
|
"@ember/test-helpers": "^3.2.1",
|
|
91
93
|
"@ember/test-waiters": "^3.1.0",
|
|
92
|
-
"@embroider/addon-dev": "4.1
|
|
93
|
-
"@glimmer/compiler": "
|
|
94
|
+
"@embroider/addon-dev": "4.2.1",
|
|
95
|
+
"@glimmer/compiler": ">= 0.86.0",
|
|
94
96
|
"@glimmer/component": "^1.1.2",
|
|
95
|
-
"@glimmer/interfaces": "
|
|
96
|
-
"@glimmer/reference": "
|
|
97
|
-
"@glimmer/syntax": "
|
|
97
|
+
"@glimmer/interfaces": ">= 0.86.0",
|
|
98
|
+
"@glimmer/reference": ">= 0.86.0",
|
|
99
|
+
"@glimmer/syntax": ">= 0.86.0",
|
|
98
100
|
"@glimmer/tracking": "^1.1.2",
|
|
99
|
-
"@glimmer/util": "^0.
|
|
100
|
-
"@glint/core": "
|
|
101
|
-
"@glint/environment-ember-loose": "
|
|
102
|
-
"@glint/environment-ember-template-imports": "
|
|
103
|
-
"@glint/template": "
|
|
101
|
+
"@glimmer/util": "^0.88.0",
|
|
102
|
+
"@glint/core": "1.3.0",
|
|
103
|
+
"@glint/environment-ember-loose": "1.3.0",
|
|
104
|
+
"@glint/environment-ember-template-imports": "1.3.0",
|
|
105
|
+
"@glint/template": "1.3.0",
|
|
104
106
|
"@nullvoxpopuli/eslint-configs": "^3.2.2",
|
|
105
107
|
"@rollup/plugin-babel": "^6.0.4",
|
|
106
108
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
107
109
|
"@tsconfig/ember": "^3.0.2",
|
|
108
|
-
"@types/babel__core": "^7.20.
|
|
110
|
+
"@types/babel__core": "^7.20.5",
|
|
109
111
|
"@types/babel__standalone": "^7.1.7",
|
|
110
112
|
"@types/babel__traverse": "^7.20.4",
|
|
111
113
|
"@types/hast": "^3.0.3",
|
|
112
114
|
"@types/mdast": "^4.0.3",
|
|
113
115
|
"@types/unist": "^3.0.2",
|
|
114
|
-
"@types/uuid": "^9.0.
|
|
115
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
116
|
-
"@typescript-eslint/parser": "^6.
|
|
116
|
+
"@types/uuid": "^9.0.8",
|
|
117
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
118
|
+
"@typescript-eslint/parser": "^6.20.0",
|
|
117
119
|
"concurrently": "^8.2.2",
|
|
118
|
-
"ember-resources": "^
|
|
119
|
-
"ember-source": "^5.
|
|
120
|
+
"ember-resources": "^7.0.0",
|
|
121
|
+
"ember-source": "^5.6.0",
|
|
120
122
|
"ember-template-imports": "^3.4.2",
|
|
121
|
-
"ember-template-lint": "^5.
|
|
122
|
-
"eslint": "^8.
|
|
123
|
-
"eslint-plugin-ember": "^
|
|
123
|
+
"ember-template-lint": "^5.13.0",
|
|
124
|
+
"eslint": "^8.55.0",
|
|
125
|
+
"eslint-plugin-ember": "^12.0.0",
|
|
124
126
|
"eslint-plugin-node": "^11.1.0",
|
|
125
|
-
"eslint-plugin-prettier": "^5.
|
|
126
|
-
"prettier": "^3.
|
|
127
|
-
"prettier-plugin-ember-template-tag": "^
|
|
128
|
-
"publint": "^0.2.
|
|
129
|
-
"rollup": "~4.
|
|
127
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
128
|
+
"prettier": "^3.2.5",
|
|
129
|
+
"prettier-plugin-ember-template-tag": "^2.0.0",
|
|
130
|
+
"publint": "^0.2.6",
|
|
131
|
+
"rollup": "~4.9.6",
|
|
130
132
|
"rollup-plugin-copy": "^3.5.0",
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"@nullvoxpopuli/limber-untyped": "0.0.0"
|
|
133
|
+
"typescript": "^5.3.3",
|
|
134
|
+
"@nullvoxpopuli/limber-untyped": "0.0.1"
|
|
134
135
|
},
|
|
135
136
|
"volta": {
|
|
136
137
|
"extends": "../../../package.json"
|
|
@@ -145,12 +146,12 @@
|
|
|
145
146
|
"app-js": {}
|
|
146
147
|
},
|
|
147
148
|
"peerDependencies": {
|
|
148
|
-
"@glimmer/compiler": "
|
|
149
|
+
"@glimmer/compiler": ">= 0.86.0",
|
|
149
150
|
"@glimmer/component": "^1.1.2",
|
|
150
|
-
"@glimmer/syntax": "
|
|
151
|
-
"@glint/template": "
|
|
152
|
-
"ember-resources": "
|
|
153
|
-
"ember-source": "
|
|
151
|
+
"@glimmer/syntax": ">= 0.86.0",
|
|
152
|
+
"@glint/template": ">= 1.3.0",
|
|
153
|
+
"ember-resources": ">= 6.4.2",
|
|
154
|
+
"ember-source": ">= 5.5.0"
|
|
154
155
|
},
|
|
155
156
|
"engines": {
|
|
156
157
|
"node": ">= v16",
|
|
@@ -160,7 +161,6 @@
|
|
|
160
161
|
"scripts": {
|
|
161
162
|
"build": "concurrently 'npm:build:*'",
|
|
162
163
|
"build:js": "rollup --config",
|
|
163
|
-
"build:types": "tsc --emitDeclarationOnly --noEmit false",
|
|
164
164
|
"lint:types": "tsc --noEmit",
|
|
165
165
|
"lint:fix": "pnpm -w exec lint fix",
|
|
166
166
|
"start": "rollup --config --watch",
|
|
@@ -171,6 +171,7 @@
|
|
|
171
171
|
"lint:hbs": "pnpm -w exec lint hbs",
|
|
172
172
|
"lint:hbs:fix": "pnpm -w exec lint hbs:fix",
|
|
173
173
|
"lint:prettier:fix": "pnpm -w exec lint prettier:fix",
|
|
174
|
-
"lint:prettier": "pnpm -w exec lint prettier"
|
|
174
|
+
"lint:prettier": "pnpm -w exec lint prettier",
|
|
175
|
+
"build:types": "tsc --emitDeclarationOnly --noEmit false"
|
|
175
176
|
}
|
|
176
177
|
}
|
|
@@ -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);
|
|
@@ -151,16 +151,17 @@ export interface Value {
|
|
|
151
151
|
component: ComponentLike;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
export function
|
|
155
|
-
export function
|
|
156
|
-
export function
|
|
157
|
-
export function
|
|
158
|
-
export function
|
|
159
|
-
markdownText: Input | (() => Input),
|
|
160
|
-
options?: () => ExtraOptions
|
|
161
|
-
): Value;
|
|
154
|
+
export function Compiled(markdownText: Input | (() => Input)): Value;
|
|
155
|
+
export function Compiled(markdownText: Input | (() => Input), options?: Format): Value;
|
|
156
|
+
export function Compiled(markdownText: Input | (() => Input), options?: () => Format): Value;
|
|
157
|
+
export function Compiled(markdownText: Input | (() => Input), options?: ExtraOptions): Value;
|
|
158
|
+
export function Compiled(markdownText: Input | (() => Input), options?: () => ExtraOptions): Value;
|
|
162
159
|
|
|
163
|
-
|
|
160
|
+
/**
|
|
161
|
+
* By default, this compiles to `glimdown`. A Markdown format which
|
|
162
|
+
* extracts `live` tagged code snippets and compiles them to components.
|
|
163
|
+
*/
|
|
164
|
+
export function Compiled(
|
|
164
165
|
markdownText: Input | (() => Input),
|
|
165
166
|
maybeOptions?: Format | (() => Format) | ExtraOptions | (() => ExtraOptions)
|
|
166
167
|
): Value {
|
|
@@ -202,8 +203,4 @@ export function buildCompiler(
|
|
|
202
203
|
});
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
|
|
206
|
-
* By default, this compiles to `glimdown`. A Markdown format which
|
|
207
|
-
* extracts `live` tagged code snippets and compiles them to components.
|
|
208
|
-
*/
|
|
209
|
-
export const Compiled = resourceFactory(buildCompiler) as typeof buildCompiler;
|
|
206
|
+
resourceFactory(Compiled);
|
package/src/browser/gjs.ts
CHANGED
|
@@ -6,17 +6,19 @@ import type { Babel } from './types.ts';
|
|
|
6
6
|
|
|
7
7
|
const compiler = importSync('ember-source/dist/ember-template-compiler.js');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let processor;
|
|
9
|
+
let processor: any;
|
|
12
10
|
let fetchingPromise: Promise<any>;
|
|
13
11
|
|
|
14
12
|
export async function preprocess(input: string, name: string): Promise<string> {
|
|
15
13
|
if (!fetchingPromise) {
|
|
16
|
-
fetchingPromise =
|
|
14
|
+
fetchingPromise = import('content-tag');
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
processor
|
|
17
|
+
if (!processor) {
|
|
18
|
+
let { Preprocessor } = await fetchingPromise;
|
|
19
|
+
|
|
20
|
+
processor = new Preprocessor();
|
|
21
|
+
}
|
|
20
22
|
|
|
21
23
|
return processor.process(input, `${name}.js`);
|
|
22
24
|
}
|
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 = {
|
|
@@ -7,6 +7,7 @@ import * as _tracking from '@glimmer/tracking';
|
|
|
7
7
|
import * as _application from '@ember/application';
|
|
8
8
|
import * as _array from '@ember/array';
|
|
9
9
|
import * as _EmberComponent from '@ember/component';
|
|
10
|
+
import * as _EmberComponentHelper from '@ember/component/helper';
|
|
10
11
|
import _TO from '@ember/component/template-only';
|
|
11
12
|
import * as _debug from '@ember/debug';
|
|
12
13
|
import * as _destroyable from '@ember/destroyable';
|
|
@@ -26,6 +27,7 @@ export const modules = {
|
|
|
26
27
|
'@ember/application': _application,
|
|
27
28
|
'@ember/array': _array,
|
|
28
29
|
'@ember/component': _EmberComponent,
|
|
30
|
+
'@ember/component/helper': _EmberComponentHelper,
|
|
29
31
|
'@ember/component/template-only': _TO,
|
|
30
32
|
'@ember/debug': _debug,
|
|
31
33
|
'@ember/destroyable': _destroyable,
|