ember-repl 3.0.0-beta.8 → 4.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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/package.json +48 -41
  3. package/src/compile/formats/gjs/babel.ts +7 -0
  4. package/src/{browser/cjs → compile/formats/gjs}/eval.ts +2 -4
  5. package/src/compile/formats/gjs/index.ts +123 -0
  6. package/src/{browser → compile/formats}/hbs.ts +15 -4
  7. package/src/{browser/compile/markdown-to-ember.ts → compile/formats/markdown.ts} +8 -1
  8. package/src/{browser/compile → compile}/formats.ts +14 -13
  9. package/src/{browser/compile → compile}/index.ts +2 -3
  10. package/src/compile/types.ts +26 -0
  11. package/src/index.ts +5 -0
  12. package/src/test-support/index.ts +1 -1
  13. package/declarations/browser/__PRIVATE__.d.ts +0 -2
  14. package/declarations/browser/__PRIVATE__.d.ts.map +0 -1
  15. package/declarations/browser/cjs/eval.d.ts +0 -9
  16. package/declarations/browser/cjs/eval.d.ts.map +0 -1
  17. package/declarations/browser/cjs/index.d.ts +0 -7
  18. package/declarations/browser/cjs/index.d.ts.map +0 -1
  19. package/declarations/browser/compile/formats.d.ts +0 -18
  20. package/declarations/browser/compile/formats.d.ts.map +0 -1
  21. package/declarations/browser/compile/index.d.ts +0 -71
  22. package/declarations/browser/compile/index.d.ts.map +0 -1
  23. package/declarations/browser/compile/markdown-to-ember.d.ts +0 -21
  24. package/declarations/browser/compile/markdown-to-ember.d.ts.map +0 -1
  25. package/declarations/browser/compile/types.d.ts +0 -9
  26. package/declarations/browser/compile/types.d.ts.map +0 -1
  27. package/declarations/browser/esm/index.d.ts +0 -8
  28. package/declarations/browser/esm/index.d.ts.map +0 -1
  29. package/declarations/browser/gjs.d.ts +0 -4
  30. package/declarations/browser/gjs.d.ts.map +0 -1
  31. package/declarations/browser/hbs.d.ts +0 -17
  32. package/declarations/browser/hbs.d.ts.map +0 -1
  33. package/declarations/browser/index.d.ts +0 -7
  34. package/declarations/browser/index.d.ts.map +0 -1
  35. package/declarations/browser/js.d.ts +0 -20
  36. package/declarations/browser/js.d.ts.map +0 -1
  37. package/declarations/browser/known-modules.d.ts +0 -65
  38. package/declarations/browser/known-modules.d.ts.map +0 -1
  39. package/declarations/browser/types.d.ts +0 -21
  40. package/declarations/browser/types.d.ts.map +0 -1
  41. package/declarations/browser/utils.d.ts +0 -19
  42. package/declarations/browser/utils.d.ts.map +0 -1
  43. package/declarations/test-support/index.d.ts +0 -2
  44. package/declarations/test-support/index.d.ts.map +0 -1
  45. package/dist/browser/__PRIVATE__.js +0 -2
  46. package/dist/browser/__PRIVATE__.js.map +0 -1
  47. package/dist/browser/cjs/eval.js +0 -22
  48. package/dist/browser/cjs/eval.js.map +0 -1
  49. package/dist/browser/cjs/index.js +0 -43
  50. package/dist/browser/cjs/index.js.map +0 -1
  51. package/dist/browser/compile/formats.js +0 -171
  52. package/dist/browser/compile/formats.js.map +0 -1
  53. package/dist/browser/compile/index.js +0 -113
  54. package/dist/browser/compile/index.js.map +0 -1
  55. package/dist/browser/compile/markdown-to-ember.js +0 -254
  56. package/dist/browser/compile/markdown-to-ember.js.map +0 -1
  57. package/dist/browser/compile/types.js +0 -2
  58. package/dist/browser/compile/types.js.map +0 -1
  59. package/dist/browser/esm/index.js +0 -67
  60. package/dist/browser/esm/index.js.map +0 -1
  61. package/dist/browser/gjs.js +0 -43
  62. package/dist/browser/gjs.js.map +0 -1
  63. package/dist/browser/hbs.js +0 -94
  64. package/dist/browser/hbs.js.map +0 -1
  65. package/dist/browser/index.js +0 -6
  66. package/dist/browser/index.js.map +0 -1
  67. package/dist/browser/js.js +0 -38
  68. package/dist/browser/js.js.map +0 -1
  69. package/dist/browser/known-modules.js +0 -48
  70. package/dist/browser/known-modules.js.map +0 -1
  71. package/dist/browser/types.js +0 -2
  72. package/dist/browser/types.js.map +0 -1
  73. package/dist/browser/utils.js +0 -46
  74. package/dist/browser/utils.js.map +0 -1
  75. package/dist/build/ember-cli.cjs +0 -36
  76. package/dist/test-support/index.js +0 -8
  77. package/dist/test-support/index.js.map +0 -1
  78. package/src/browser/cjs/index.ts +0 -44
  79. package/src/browser/compile/types.ts +0 -11
  80. package/src/browser/esm/index.ts +0 -80
  81. package/src/browser/gjs.ts +0 -59
  82. package/src/browser/index.ts +0 -8
  83. package/src/browser/js.ts +0 -42
  84. package/src/browser/types.ts +0 -24
  85. package/src/build/ember-cli.cjs +0 -36
  86. /package/src/{browser/__PRIVATE__.ts → __PRIVATE__.ts} +0 -0
  87. /package/src/{browser → compile/formats/gjs}/known-modules.ts +0 -0
  88. /package/src/{browser → compile}/utils.ts +0 -0
@@ -1,113 +0,0 @@
1
- import { resourceFactory, resource, cell } from 'ember-resources';
2
- import { nameFor } from '../utils.js';
3
- import { compileMD, compileGJS, compileHBS } from './formats.js';
4
-
5
- const CACHE = new Map();
6
- const SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];
7
-
8
- /**
9
- * Compile GitHub-flavored Markdown with GJS support
10
- * and optionally render gjs-snippets via a `live` meta tag
11
- * on the code fences.
12
- */
13
-
14
- /**
15
- * Compile GJS
16
- */
17
-
18
- /**
19
- * Compile a stateless component using just the template
20
- */
21
-
22
- /**
23
- * This compileMD is a more robust version of the raw compiling used in "formats".
24
- * This function manages cache, and has events for folks building UIs to hook in to
25
- */
26
- async function compile(text, options) {
27
- let {
28
- onSuccess,
29
- onError,
30
- onCompileStart
31
- } = options;
32
- let id = nameFor(text);
33
- let existing = CACHE.get(id);
34
- if (existing) {
35
- onSuccess(existing);
36
- return;
37
- }
38
- if (!SUPPORTED_FORMATS.includes(options.format)) {
39
- await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
40
- return;
41
- }
42
- await onCompileStart();
43
- if (!text) {
44
- await onError('No Input Document yet');
45
- return;
46
- }
47
- let result;
48
- if (options.format === 'glimdown') {
49
- result = await compileMD(text, options);
50
- } else if (options.format === 'gjs') {
51
- result = await compileGJS(text, options.importMap);
52
- } else if (options.format === 'hbs') {
53
- result = await compileHBS(text, {
54
- scope: options.topLevelScope
55
- });
56
- } else {
57
- await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
58
- return;
59
- }
60
- if (result.error) {
61
- await onError(result.error.message || `${result.error}`);
62
- return;
63
- }
64
- CACHE.set(id, result.component);
65
- await onSuccess(result.component);
66
- }
67
-
68
- /**
69
- * @internal
70
- */
71
-
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) {
77
- return resource(() => {
78
- let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;
79
- let format = (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';
80
- let options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};
81
- let input = typeof markdownText === 'function' ? markdownText() : markdownText;
82
- let ready = cell(false);
83
- let error = cell();
84
- let result = cell();
85
- if (input) {
86
- compile(input, {
87
- // narrowing is hard here, but this is an implementation detail
88
- format: format,
89
- onSuccess: async component => {
90
- result.current = component;
91
- ready.set(true);
92
- error.set(null);
93
- },
94
- onError: async e => {
95
- error.set(e);
96
- },
97
- onCompileStart: async () => {
98
- ready.set(false);
99
- },
100
- ...options
101
- });
102
- }
103
- return () => ({
104
- isReady: ready.current,
105
- error: error.current,
106
- component: result.current
107
- });
108
- });
109
- }
110
- resourceFactory(Compiled);
111
-
112
- export { CACHE, Compiled, compile };
113
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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,C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K,CAACY,OAAO;MACpBT,SAAS,EAAEV,MAAM,CAACmB,OAAAA;AACpB,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AACJ,CAAA;AAEAG,eAAe,CAACX,QAAQ,CAAC;;;;"}
@@ -1,254 +0,0 @@
1
- import rehypeRaw from 'rehype-raw';
2
- import rehypeStringify from 'rehype-stringify';
3
- import remarkGfm from 'remark-gfm';
4
- import remarkParse from 'remark-parse';
5
- import remarkRehype from 'remark-rehype';
6
- import { unified } from 'unified';
7
- import { visit } from 'unist-util-visit';
8
- import { nameFor, invocationOf } from '../utils.js';
9
-
10
- const GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');
11
- const GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');
12
- const ALLOWED_LANGUAGES = ['gjs', 'hbs'];
13
- const escapeCurlies = node => {
14
- if ('value' in node && node.value) {
15
- node.value = node.value.replace(/{{/g, '\\{{');
16
- }
17
- if ('children' in node && node.children) {
18
- node.children.forEach(child => escapeCurlies(child));
19
- }
20
- if (!node.data) {
21
- return;
22
- }
23
- if ('hChildren' in node.data && Array.isArray(node.data['hChildren'])) {
24
- node.data['hChildren'].forEach(escapeCurlies);
25
- return;
26
- }
27
- };
28
- function isLive(meta) {
29
- return meta.includes('live');
30
- }
31
- function isPreview(meta) {
32
- return meta.includes('preview');
33
- }
34
- function isBelow(meta) {
35
- return meta.includes('below');
36
- }
37
-
38
- // TODO: extract and publish remark plugin
39
- function liveCodeExtraction(options = {}) {
40
- let {
41
- copyComponent,
42
- snippets,
43
- demo
44
- } = options;
45
- let {
46
- classList: snippetClasses
47
- } = snippets || {};
48
- let {
49
- classList: demoClasses
50
- } = demo || {};
51
- snippetClasses ??= [];
52
- demoClasses ??= [];
53
- function isRelevantCode(node) {
54
- if (node.type !== 'code') return false;
55
- let {
56
- meta,
57
- lang
58
- } = node;
59
- meta = meta?.trim();
60
- if (!meta || !lang) return false;
61
- if (!meta.includes('live')) {
62
- return false;
63
- }
64
- if (!ALLOWED_LANGUAGES.includes(lang)) return false;
65
- return true;
66
- }
67
- let copyNode = {
68
- type: 'html',
69
- value: copyComponent
70
- };
71
- function enhance(code) {
72
- code.data ??= {};
73
- code.data['hProperties'] ??= {};
74
- // This is secret-to-us-only API, so we don't really care about the type
75
- code.data['hProperties'][GLIMDOWN_PREVIEW] = true;
76
- return {
77
- data: {
78
- hProperties: {
79
- className: snippetClasses
80
- }
81
- },
82
- type: 'div',
83
- hProperties: {
84
- className: snippetClasses
85
- },
86
- children: [code, copyNode]
87
- };
88
- }
89
- function flatReplaceAt(array, index, replacement) {
90
- array.splice(index, 1, ...replacement);
91
- }
92
-
93
- // because we mutate the tree as we iterate,
94
- // we need to make sure we don't loop forever
95
- const seen = new Set();
96
- return function transformer(tree, file) {
97
- visit(tree, ['code'], function (node, index, parent) {
98
- if (parent === null || parent === undefined) return;
99
- if (index === null || index === undefined) return;
100
- if (!isRelevantCode(node)) {
101
- let enhanced = enhance(node);
102
- parent.children[index] = enhanced;
103
- return 'skip';
104
- }
105
- if (seen.has(node)) return 'skip';
106
- seen.add(node);
107
- let {
108
- meta,
109
- lang,
110
- value
111
- } = node;
112
- if (!meta) return 'skip';
113
- if (!lang) return 'skip';
114
- file.data.liveCode ??= [];
115
- let code = value.trim();
116
- let name = nameFor(code);
117
- let invocation = invocationOf(name);
118
- let shadow = options.shadowComponent;
119
- let wrapInShadow = shadow && !meta?.includes('no-shadow');
120
- if (wrapInShadow) {
121
- invocation = `<${shadow}>${invocation}</${shadow}>`;
122
- }
123
- let invokeNode = {
124
- type: 'html',
125
- data: {
126
- hProperties: {
127
- [GLIMDOWN_RENDER]: true
128
- }
129
- },
130
- value: `<div class="${demoClasses}">${invocation}</div>`
131
- };
132
- let wrapper = enhance(node);
133
- file.data.liveCode.push({
134
- lang,
135
- name,
136
- code
137
- });
138
- let live = isLive(meta);
139
- let preview = isPreview(meta);
140
- let below = isBelow(meta);
141
- if (live && preview && below) {
142
- flatReplaceAt(parent.children, index, [wrapper, invokeNode]);
143
- return 'skip';
144
- }
145
- if (live && preview) {
146
- flatReplaceAt(parent.children, index, [invokeNode, wrapper]);
147
- return 'skip';
148
- }
149
- if (live) {
150
- parent.children[index] = invokeNode;
151
- return 'skip';
152
- }
153
- parent.children[index] = wrapper;
154
- return;
155
- });
156
- };
157
- }
158
- function buildCompiler(options) {
159
- let compiler = unified().use(remarkParse).use(remarkGfm);
160
-
161
- // TODO: we only want to do this when we have pre > code.
162
- // code can exist inline.
163
- compiler = compiler.use(liveCodeExtraction, {
164
- snippets: {
165
- classList: ['glimdown-snippet', 'relative']
166
- },
167
- demo: {
168
- classList: ['glimdown-render']
169
- },
170
- copyComponent: options?.CopyComponent,
171
- shadowComponent: options?.ShadowComponent
172
- });
173
-
174
- /**
175
- * If this were "use"d after `remarkRehype`,
176
- * remark is gone, and folks would need to work with rehype trees
177
- */
178
- if (options.remarkPlugins) {
179
- options.remarkPlugins.forEach(plugin => {
180
- compiler = compiler.use(plugin);
181
- });
182
- }
183
-
184
- // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))
185
- // remark rehype is needed to convert markdown to HTML
186
- // However, it also changes all the nodes, so we need another pass
187
- // to make sure our Glimmer-aware nodes are in tact
188
- compiler = compiler.use(remarkRehype, {
189
- allowDangerousHtml: true
190
- });
191
-
192
- // Convert invocables to raw format, so Glimmer can invoke them
193
- compiler = compiler.use(() => tree => {
194
- visit(tree, function (node) {
195
- // We rely on an implicit transformation of data.hProperties => properties
196
- let properties = node.properties;
197
- if (properties?.[GLIMDOWN_PREVIEW]) {
198
- // Have to sanitize anything Glimmer could try to render
199
- escapeCurlies(node);
200
- return 'skip';
201
- }
202
- if (node.type === 'element' || 'tagName' in node && node.tagName === 'code') {
203
- if (properties?.[GLIMDOWN_RENDER]) {
204
- node.type = 'glimmer_raw';
205
- return;
206
- }
207
- escapeCurlies(node);
208
- return 'skip';
209
- }
210
- if (node.type === 'text' || node.type === 'raw') {
211
- // definitively not the better way, but this is supposed to detect "glimmer" nodes
212
- if ('value' in node && typeof node.value === 'string' && node.value.match(/<\/?[_A-Z:0-9].*>/g)) {
213
- node.type = 'glimmer_raw';
214
- }
215
- node.type = 'glimmer_raw';
216
- return 'skip';
217
- }
218
- return;
219
- });
220
- });
221
- compiler = compiler.use(rehypeRaw, {
222
- passThrough: ['glimmer_raw', 'raw']
223
- }).use(() => tree => {
224
- visit(tree, 'glimmer_raw', node => {
225
- node.type = 'raw';
226
- });
227
- });
228
-
229
- // Finally convert to string! oofta!
230
- compiler = compiler.use(rehypeStringify, {
231
- collapseEmptyAttributes: true,
232
- closeSelfClosing: true,
233
- allowParseErrors: true,
234
- allowDangerousCharacters: true,
235
- allowDangerousHtml: true
236
- });
237
- return compiler;
238
- }
239
- /**
240
- * @internal not under semver
241
- */
242
- async function parseMarkdown(input, options = {}) {
243
- let markdownCompiler = buildCompiler(options);
244
- let processed = await markdownCompiler.process(input);
245
- let liveCode = processed.data.liveCode || [];
246
- let templateOnly = processed.toString();
247
- return {
248
- templateOnlyGlimdown: templateOnly,
249
- blocks: liveCode
250
- };
251
- }
252
-
253
- export { parseMarkdown };
254
- //# sourceMappingURL=markdown-to-ember.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-to-ember.js","sources":["../../../src/browser/compile/markdown-to-ember.ts"],"sourcesContent":["import rehypeRaw from 'rehype-raw';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport { unified } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nimport { invocationOf, nameFor } from '../utils.ts';\n\nimport type { UnifiedPlugin } from './types.ts';\nimport type { Node } from 'hast';\nimport type { Code, Text } from 'mdast';\nimport type { Parent } from 'unist';\nimport type { VFile } from 'vfile';\n\nexport interface ExtractedCode {\n name: string;\n code: string;\n lang: string;\n}\n\nexport interface LiveCodeExtraction {\n templateOnlyGlimdown: string;\n blocks: ExtractedCode[];\n}\ntype LiveData = {\n liveCode?: ExtractedCode[];\n};\ntype VFileWithMeta = VFile & {\n data: LiveData;\n};\n\ninterface Options {\n snippets?: {\n classList?: string[];\n };\n demo?: {\n classList?: string[];\n };\n copyComponent?: string;\n shadowComponent?: string;\n}\n\nconst GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');\nconst GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');\nconst ALLOWED_LANGUAGES = ['gjs', 'hbs'] as const;\n\ntype AllowedLanguage = (typeof ALLOWED_LANGUAGES)[number];\ntype RelevantCode = Omit<Code, 'lang'> & { lang: AllowedLanguage };\n\nconst escapeCurlies = (node: Text | Parent) => {\n if ('value' in node && node.value) {\n node.value = node.value.replace(/{{/g, '\\\\{{');\n }\n\n if ('children' in node && node.children) {\n node.children.forEach((child) => escapeCurlies(child as Parent));\n }\n\n if (!node.data) {\n return;\n }\n\n if ('hChildren' in node.data && Array.isArray(node.data['hChildren'])) {\n node.data['hChildren'].forEach(escapeCurlies);\n\n return;\n }\n};\n\nfunction isLive(meta: string) {\n return meta.includes('live');\n}\n\nfunction isPreview(meta: string) {\n return meta.includes('preview');\n}\n\nfunction isBelow(meta: string) {\n return meta.includes('below');\n}\n\n// TODO: extract and publish remark plugin\nfunction liveCodeExtraction(options: Options = {}) {\n let { copyComponent, snippets, demo } = options;\n let { classList: snippetClasses } = snippets || {};\n let { classList: demoClasses } = demo || {};\n\n snippetClasses ??= [];\n demoClasses ??= [];\n\n function isRelevantCode(node: Code): node is RelevantCode {\n if (node.type !== 'code') return false;\n\n let { meta, lang } = node;\n\n meta = meta?.trim();\n\n if (!meta || !lang) return false;\n\n if (!meta.includes('live')) {\n return false;\n }\n\n if (!(ALLOWED_LANGUAGES as unknown as string[]).includes(lang)) return false;\n\n return true;\n }\n\n let copyNode = {\n type: 'html',\n value: copyComponent,\n };\n\n function enhance(code: Code) {\n code.data ??= {};\n (code.data as any)['hProperties'] ??= {};\n // This is secret-to-us-only API, so we don't really care about the type\n (code.data as any)['hProperties'][GLIMDOWN_PREVIEW] = true;\n\n return {\n data: {\n hProperties: { className: snippetClasses },\n },\n type: 'div',\n hProperties: { className: snippetClasses },\n children: [code, copyNode],\n };\n }\n\n function flatReplaceAt<T>(array: T[], index: number, replacement: T[]) {\n array.splice(index, 1, ...replacement);\n }\n\n // because we mutate the tree as we iterate,\n // we need to make sure we don't loop forever\n const seen = new Set();\n\n return function transformer(tree: Parent, file: VFileWithMeta) {\n visit(tree, ['code'], function (node, index, parent) {\n if (parent === null || parent === undefined) return;\n if (index === null || index === undefined) return;\n\n if (!isRelevantCode(node as Code)) {\n let enhanced = enhance(node as Code);\n\n parent.children[index] = enhanced;\n\n return 'skip';\n }\n\n if (seen.has(node)) return 'skip';\n\n seen.add(node);\n\n let { meta, lang, value } = node as Code;\n\n if (!meta) return 'skip';\n if (!lang) return 'skip';\n\n file.data.liveCode ??= [];\n\n let code = value.trim();\n let name = nameFor(code);\n let invocation = invocationOf(name);\n\n let shadow = options.shadowComponent;\n\n let wrapInShadow = shadow && !meta?.includes('no-shadow');\n\n if (wrapInShadow) {\n invocation = `<${shadow}>${invocation}</${shadow}>`;\n }\n\n let invokeNode = {\n type: 'html',\n data: {\n hProperties: { [GLIMDOWN_RENDER]: true },\n },\n value: `<div class=\"${demoClasses}\">${invocation}</div>`,\n };\n\n let wrapper = enhance(node as Code);\n\n file.data.liveCode.push({\n lang,\n name,\n code,\n });\n\n let live = isLive(meta);\n let preview = isPreview(meta);\n let below = isBelow(meta);\n\n if (live && preview && below) {\n flatReplaceAt(parent.children, index, [wrapper, invokeNode]);\n\n return 'skip';\n }\n\n if (live && preview) {\n flatReplaceAt(parent.children, index, [invokeNode, wrapper]);\n\n return 'skip';\n }\n\n if (live) {\n parent.children[index] = invokeNode;\n\n return 'skip';\n }\n\n parent.children[index] = wrapper;\n\n return;\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\n\n // TODO: we only want to do this when we have pre > code.\n // code can exist inline.\n compiler = compiler.use(liveCodeExtraction, {\n snippets: {\n classList: ['glimdown-snippet', 'relative'],\n },\n demo: {\n classList: ['glimdown-render'],\n },\n copyComponent: options?.CopyComponent,\n shadowComponent: options?.ShadowComponent,\n });\n\n /**\n * If this were \"use\"d after `remarkRehype`,\n * remark is gone, and folks would need to work with rehype trees\n */\n if (options.remarkPlugins) {\n options.remarkPlugins.forEach((plugin) => {\n compiler = compiler.use(plugin) as any;\n });\n }\n\n // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))\n // remark rehype is needed to convert markdown to HTML\n // However, it also changes all the nodes, so we need another pass\n // to make sure our Glimmer-aware nodes are in tact\n compiler = compiler.use(remarkRehype, { allowDangerousHtml: true });\n\n // Convert invocables to raw format, so Glimmer can invoke them\n compiler = compiler.use(() => (tree: Node) => {\n visit(tree, function (node) {\n // We rely on an implicit transformation of data.hProperties => properties\n let properties = (node as any).properties;\n\n if (properties?.[GLIMDOWN_PREVIEW]) {\n // Have to sanitize anything Glimmer could try to render\n escapeCurlies(node as Parent);\n\n return 'skip';\n }\n\n if (node.type === 'element' || ('tagName' in node && node.tagName === 'code')) {\n if (properties?.[GLIMDOWN_RENDER]) {\n node.type = 'glimmer_raw';\n\n return;\n }\n\n escapeCurlies(node as Parent);\n\n return 'skip';\n }\n\n if (node.type === 'text' || node.type === 'raw') {\n // definitively not the better way, but this is supposed to detect \"glimmer\" nodes\n if (\n 'value' in node &&\n typeof node.value === 'string' &&\n node.value.match(/<\\/?[_A-Z:0-9].*>/g)\n ) {\n node.type = 'glimmer_raw';\n }\n\n node.type = 'glimmer_raw';\n\n return 'skip';\n }\n\n return;\n });\n });\n\n compiler = compiler.use(rehypeRaw, { passThrough: ['glimmer_raw', 'raw'] }).use(() => (tree) => {\n visit(tree, 'glimmer_raw', (node: Node) => {\n node.type = 'raw';\n });\n });\n\n // Finally convert to string! oofta!\n compiler = compiler.use(rehypeStringify, {\n collapseEmptyAttributes: true,\n closeSelfClosing: true,\n allowParseErrors: true,\n allowDangerousCharacters: true,\n allowDangerousHtml: true,\n }) as any;\n\n return compiler as ReturnType<typeof unified>;\n}\n\ninterface ParseMarkdownOptions {\n CopyComponent?: string;\n ShadowComponent?: string;\n remarkPlugins?: UnifiedPlugin[];\n}\n\n/**\n * @internal not under semver\n */\nexport async function parseMarkdown(\n input: string,\n options: ParseMarkdownOptions = {}\n): Promise<LiveCodeExtraction> {\n let markdownCompiler = buildCompiler(options);\n let processed = await markdownCompiler.process(input);\n let liveCode = (processed.data as LiveData).liveCode || [];\n let templateOnly = processed.toString();\n\n return { templateOnlyGlimdown: templateOnly, blocks: liveCode };\n}\n"],"names":["GLIMDOWN_PREVIEW","Symbol","GLIMDOWN_RENDER","ALLOWED_LANGUAGES","escapeCurlies","node","value","replace","children","forEach","child","data","Array","isArray","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","type","lang","trim","copyNode","enhance","code","hProperties","className","flatReplaceAt","array","index","replacement","splice","seen","Set","transformer","tree","file","visit","parent","undefined","enhanced","has","add","liveCode","name","nameFor","invocation","invocationOf","shadow","shadowComponent","wrapInShadow","invokeNode","wrapper","push","live","preview","below","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","CopyComponent","ShadowComponent","remarkPlugins","plugin","remarkRehype","allowDangerousHtml","properties","tagName","match","rehypeRaw","passThrough","rehypeStringify","collapseEmptyAttributes","closeSelfClosing","allowParseErrors","allowDangerousCharacters","parseMarkdown","input","markdownCompiler","processed","process","templateOnly","toString","templateOnlyGlimdown","blocks"],"mappings":";;;;;;;;;AA4CA,MAAMA,gBAAgB,GAAGC,MAAM,CAAC,sBAAsB,CAAC,CAAA;AACvD,MAAMC,eAAe,GAAGD,MAAM,CAAC,qBAAqB,CAAC,CAAA;AACrD,MAAME,iBAAiB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAA;AAKjD,MA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,OAAO,CAAC,CAAA;EAC7C,IAAIuE,SAAS,GAAG,MAAMD,gBAAgB,CAACE,OAAO,CAACH,KAAK,CAAC,CAAA;EACrD,IAAIrC,QAAQ,GAAIuC,SAAS,CAAChF,IAAI,CAAcyC,QAAQ,IAAI,EAAE,CAAA;AAC1D,EAAA,IAAIyC,YAAY,GAAGF,SAAS,CAACG,QAAQ,EAAE,CAAA;EAEvC,OAAO;AAAEC,IAAAA,oBAAoB,EAAEF,YAAY;AAAEG,IAAAA,MAAM,EAAE5C,QAAAA;GAAU,CAAA;AACjE;;;;"}
@@ -1,2 +0,0 @@
1
- import 'unified';
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,67 +0,0 @@
1
- import { preprocess, transform } from '../gjs.js';
2
- import { modules } from '../known-modules.js';
3
- import { nameFor } from '../utils.js';
4
-
5
- async function compileJS(code, extraModules) {
6
- let name = nameFor(code);
7
- let component;
8
- let error;
9
- try {
10
- let compiled = await compileGJS({
11
- code: code,
12
- name
13
- });
14
- if (!compiled) {
15
- throw new Error(`Compiled output is missing`);
16
- }
17
-
18
- // NOTE: we cannot `eval` ESM
19
- compiled = proxyToSkypack(compiled, extraModules);
20
- component = await evalSnippet(compiled);
21
- } catch (e) {
22
- error = e;
23
- }
24
- return {
25
- name,
26
- component,
27
- error
28
- };
29
- }
30
- function proxyToSkypack(code, extraModules) {
31
- let knownModules = [...Object.keys(extraModules || {}), ...Object.keys(modules)];
32
- let origin = location.origin;
33
- let result = code.replaceAll(/from ('|")([^"']+)('|")/g, (_, __, modulePath) => {
34
- if (knownModules.includes(modulePath)) {
35
- return `from '${origin}/${modulePath}'`;
36
- }
37
- return `from 'https://cdn.skypack.dev/${modulePath}'`;
38
- });
39
- return result;
40
- }
41
- async function evalSnippet(code) {
42
- let encodedJs = encodeURIComponent(code);
43
- let result = await import( /* webpackIgnore: true */`data:text/javascript;charset=utf-8,${encodedJs}`);
44
- if (!result.default) {
45
- throw new Error(`Expected module to have a default export, found ${Object.keys(result)}`);
46
- }
47
- return result;
48
- }
49
- async function compileGJS({
50
- code: input,
51
- name
52
- }) {
53
- let preprocessed = await preprocess(input, name);
54
- let result = await transform(preprocessed, name, {
55
- modules: false
56
- });
57
- if (!result) {
58
- return;
59
- }
60
- let {
61
- code
62
- } = result;
63
- return code;
64
- }
65
-
66
- export { compileJS, proxyToSkypack };
67
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/browser/esm/index.ts"],"sourcesContent":["import { preprocess, transform } from '../gjs.ts';\nimport { modules } from '../known-modules.ts';\nimport { nameFor } from '../utils.ts';\n\nimport type { CompileResult, ExtraModules } from '../types.ts';\nimport type Component from '@glimmer/component';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\nexport async function compileJS(code: string, extraModules?: ExtraModules): Promise<CompileResult> {\n let name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n let compiled = await compileGJS({ code: code, name });\n\n if (!compiled) {\n throw new Error(`Compiled output is missing`);\n }\n\n // NOTE: we cannot `eval` ESM\n compiled = proxyToSkypack(compiled, extraModules);\n component = (await evalSnippet(compiled)) as unknown as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\nexport function proxyToSkypack(code: string, extraModules?: ExtraModules) {\n let knownModules = [...Object.keys(extraModules || {}), ...Object.keys(modules)];\n let origin = location.origin;\n\n let result = code.replaceAll(/from ('|\")([^\"']+)('|\")/g, (_, __, modulePath) => {\n if (knownModules.includes(modulePath)) {\n return `from '${origin}/${modulePath}'`;\n }\n\n return `from 'https://cdn.skypack.dev/${modulePath}'`;\n });\n\n return result;\n}\n\nasync function evalSnippet(code: string) {\n let encodedJs = encodeURIComponent(code);\n let result = await import(\n /* webpackIgnore: true */ `data:text/javascript;charset=utf-8,${encodedJs}`\n );\n\n if (!result.default) {\n throw new Error(`Expected module to have a default export, found ${Object.keys(result)}`);\n }\n\n return result as {\n default: Component;\n services?: { [key: string]: unknown };\n };\n}\n\nasync function compileGJS({ code: input, name }: Info) {\n let preprocessed = await preprocess(input, name);\n let result = await transform(preprocessed, name, {\n modules: false,\n });\n\n if (!result) {\n return;\n }\n\n let { code } = result;\n\n return code;\n}\n"],"names":["compileJS","code","extraModules","name","nameFor","component","error","compiled","compileGJS","Error","proxyToSkypack","evalSnippet","e","knownModules","Object","keys","modules","origin","location","result","replaceAll","_","__","modulePath","includes","encodedJs","encodeURIComponent","default","input","preprocessed","preprocess","transform"],"mappings":";;;;AAaO,eAAeA,SAASA,CAACC,IAAY,EAAEC,YAA2B,EAA0B;AACjG,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,IAAI,CAAC,CAAA;AACxB,EAAA,IAAII,SAAoC,CAAA;AACxC,EAAA,IAAIC,KAAwB,CAAA;EAE5B,IAAI;AACF,IAAA,IAAIC,QAAQ,GAAG,MAAMC,UAAU,CAAC;AAAEP,MAAAA,IAAI,EAAEA,IAAI;AAAEE,MAAAA,IAAAA;AAAK,KAAC,CAAC,CAAA;IAErD,IAAI,CAACI,QAAQ,EAAE;AACb,MAAA,MAAM,IAAIE,KAAK,CAAE,CAAA,0BAAA,CAA2B,CAAC,CAAA;AAC/C,KAAA;;AAEA;AACAF,IAAAA,QAAQ,GAAGG,cAAc,CAACH,QAAQ,EAAEL,YAAY,CAAC,CAAA;AACjDG,IAAAA,SAAS,GAAI,MAAMM,WAAW,CAACJ,QAAQ,CAA8B,CAAA;GACtE,CAAC,OAAOK,CAAC,EAAE;AACVN,IAAAA,KAAK,GAAGM,CAAsB,CAAA;AAChC,GAAA;EAEA,OAAO;IAAET,IAAI;IAAEE,SAAS;AAAEC,IAAAA,KAAAA;GAAO,CAAA;AACnC,CAAA;AAEO,SAASI,cAAcA,CAACT,IAAY,EAAEC,YAA2B,EAAE;EACxE,IAAIW,YA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AM,GAAG,MAAMY,SAAS,CAACF,YAAY,EAAE1B,IAAI,EAAE;AAC/Ca,IAAAA,OAAO,EAAE,KAAA;AACX,GAAC,CAAC,CAAA;EAEF,IAAI,CAACG,MAAM,EAAE;AACX,IAAA,OAAA;AACF,GAAA;EAEA,IAAI;AAAElB,IAAAA,IAAAA;AAAK,GAAC,GAAGkB,MAAM,CAAA;AAErB,EAAA,OAAOlB,IAAI,CAAA;AACb;;;;"}
@@ -1,43 +0,0 @@
1
- import { importSync } from '@embroider/macros';
2
- import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';
3
-
4
- const compiler = importSync('ember-source/dist/ember-template-compiler.js');
5
- let processor;
6
- let fetchingPromise;
7
- async function preprocess(input, name) {
8
- if (!fetchingPromise) {
9
- fetchingPromise = import('content-tag');
10
- }
11
- if (!processor) {
12
- let {
13
- Preprocessor
14
- } = await fetchingPromise;
15
- processor = new Preprocessor();
16
- }
17
- return processor.process(input, `${name}.js`);
18
- }
19
- async function transform(intermediate, name, options = {}) {
20
- let babel = await import('@babel/standalone');
21
- return babel.transform(intermediate, {
22
- filename: `${name}.js`,
23
- plugins: [
24
- // [babelPluginIntermediateGJS],
25
- [babelPluginEmberTemplateCompilation, {
26
- compiler
27
- }], [babel.availablePlugins['proposal-decorators'], {
28
- legacy: true
29
- }], [babel.availablePlugins['proposal-class-properties']]],
30
- presets: [[babel.availablePresets['env'], {
31
- // false -- keeps ES Modules
32
- modules: 'cjs',
33
- targets: {
34
- esmodules: true
35
- },
36
- forceAllTransforms: false,
37
- ...options
38
- }]]
39
- });
40
- }
41
-
42
- export { preprocess, transform };
43
- //# sourceMappingURL=gjs.js.map
@@ -1 +0,0 @@
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;;;;"}
@@ -1,94 +0,0 @@
1
- import { setComponentTemplate } from '@ember/component';
2
- import _TO from '@ember/component/template-only';
3
- import { array, concat, fn, get, hash } from '@ember/helper';
4
- import { on } from '@ember/modifier';
5
- import { createTemplateFactory } from '@ember/template-factory';
6
- import { importSync } from '@embroider/macros';
7
- import { nameFor } from './utils.js';
8
-
9
- /* eslint-disable @typescript-eslint/no-explicit-any */
10
- // import { precompileJSON } from '@glimmer/compiler';
11
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
- // @ts-ignore
13
- // These things are pre-bundled in the old system.
14
- // ember-template-compiler defines them in AMD/requirejs
15
- const {
16
- precompileJSON
17
- } = importSync('@glimmer/compiler');
18
- const {
19
- getTemplateLocals
20
- } = importSync('@glimmer/syntax');
21
-
22
- /**
23
- * compile a template with an empty scope
24
- * to use components, helpers, etc, you will need to compile with JS
25
- *
26
- * (templates alone do not have a way to import / define complex structures)
27
- */
28
- function compileHBS(template, options = {}) {
29
- let name = nameFor(template);
30
- let component;
31
- let error;
32
- try {
33
- component = setComponentTemplate(compileTemplate(template, {
34
- moduleName: options.moduleName || name,
35
- ...options
36
- }), _TO(options.moduleName || name));
37
- } catch (e) {
38
- error = e;
39
- }
40
- return {
41
- name,
42
- component,
43
- error
44
- };
45
- }
46
- /**
47
- * The reason why we can't use precompile directly is because of this:
48
- * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132
49
- *
50
- * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.
51
- * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,
52
- * which means that *everything* is undefined.
53
- */
54
- function compileTemplate(source, {
55
- moduleName,
56
- scope = {}
57
- }) {
58
- let localScope = {
59
- array,
60
- concat,
61
- fn,
62
- get,
63
- hash,
64
- on,
65
- ...scope
66
- };
67
- let locals = getTemplateLocals(source);
68
- let options = {
69
- strictMode: true,
70
- moduleName,
71
- locals,
72
- isProduction: false,
73
- meta: {
74
- moduleName
75
- }
76
- };
77
-
78
- // Copied from @glimmer/compiler/lib/compiler#precompile
79
- let [block, usedLocals] = precompileJSON(source, options);
80
- let usedScope = usedLocals.map(key => localScope[key]);
81
- let blockJSON = JSON.stringify(block);
82
- let templateJSONObject = {
83
- id: moduleName,
84
- block: blockJSON,
85
- moduleName: moduleName ?? '(unknown template module)',
86
- scope: () => usedScope,
87
- isStrictMode: true
88
- };
89
- let factory = createTemplateFactory(templateJSONObject);
90
- return factory;
91
- }
92
-
93
- export { compileHBS };
94
- //# sourceMappingURL=hbs.js.map