ember-repl 4.3.4 → 5.0.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,OAAO,CAAC,aAAa,CAAC,CAkBxB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,OAAO,CAAC,aAAa,CAAC,CAkBxB"}
@@ -19,6 +19,7 @@ import * as _service from '@ember/service';
19
19
  import * as _template from '@ember/template';
20
20
  import { createTemplateFactory } from '@ember/template-factory';
21
21
  import * as _utils from '@ember/utils';
22
+ import * as _decoratorsRuntime from 'decorator-transforms/runtime';
22
23
  export declare const modules: {
23
24
  '@ember/application': typeof _application;
24
25
  '@ember/array': typeof _array;
@@ -40,5 +41,6 @@ export declare const modules: {
40
41
  '@ember/owner': typeof _owner;
41
42
  '@glimmer/component': typeof _GlimmerComponent;
42
43
  '@glimmer/tracking': typeof _tracking;
44
+ 'decorator-transforms/runtime': typeof _decoratorsRuntime;
43
45
  };
44
46
  //# sourceMappingURL=known-modules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/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
+ {"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/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,OAAO,KAAK,kBAAkB,MAAM,8BAA8B,CAAC;AAEnE,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;CAqBnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"eval.js","sources":["../../../../src/compile/formats/gjs/eval.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { modules } from './known-modules.ts';\n\nimport type Component from '@glimmer/component';\n\nexport function evalSnippet(\n compiled: string,\n extraModules: Record<string, unknown /* imported module */> = {}\n): {\n default: Component;\n services?: { [key: string]: unknown };\n} {\n const exports = {};\n\n function require(moduleName: keyof typeof modules): unknown {\n let preConfigured = modules[moduleName] || extraModules[moduleName];\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return preConfigured || window.require(moduleName);\n }\n\n eval(compiled);\n\n return Object.assign(exports, { require }) as {\n default: Component;\n services?: { [key: string]: unknown };\n require: unknown;\n };\n}\n"],"names":["evalSnippet","compiled","extraModules","exports","require","moduleName","preConfigured","modules","window","eval","Object","assign"],"mappings":";;AAAA;AAKO,SAASA,WAAWA,CACzBC,QAAgB,EAChBC,YAA2D,GAAG,EAAE,EAIhE;EACA,MAAMC,OAAO,GAAG,EAAE,CAAA;EAElB,SAASC,OAAOA,CAACC,UAAgC,EAAW;IAC1D,IAAIC,aAAa,GAAGC,OAAO,CAACF,UAAU,CAAC,IAAIH,YAAY,CAACG,UAAU,CAAC,CAAA;;AAEnE;AACA;AACA,IAAA,OAAOC,aAAa,IAAIE,MAAM,CAACJ,OAAO,CAACC,UAAU,CAAC,CAAA;AACpD,GAAA;EAEAI,IAAI,CAACR,QAAQ,CAAC,CAAA;AAEd,EAAA,OAAOS,MAAM,CAACC,MAAM,CAACR,OAAO,EAAE;AAAEC,IAAAA,OAAAA;AAAQ,GAAC,CAAC,CAAA;AAK5C;;;;"}
1
+ {"version":3,"file":"eval.js","sources":["../../../../src/compile/formats/gjs/eval.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { modules } from './known-modules.ts';\n\nimport type Component from '@glimmer/component';\n\nexport function evalSnippet(\n compiled: string,\n extraModules: Record<string, unknown /* imported module */> = {}\n): {\n default: Component;\n services?: { [key: string]: unknown };\n} {\n const exports = {};\n\n function require(moduleName: keyof typeof modules): unknown {\n let preConfigured = modules[moduleName] || extraModules[moduleName];\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return preConfigured || window.require(moduleName);\n }\n\n eval(compiled);\n\n return Object.assign(exports, { require }) as {\n default: Component;\n services?: { [key: string]: unknown };\n require: unknown;\n };\n}\n"],"names":["evalSnippet","compiled","extraModules","exports","require","moduleName","preConfigured","modules","window","eval","Object","assign"],"mappings":";;AAAA;AAKO,SAASA,WAAWA,CACzBC,QAAgB,EAChBC,YAA2D,GAAG,EAAE,EAIhE;EACA,MAAMC,OAAO,GAAG,EAAE;EAElB,SAASC,OAAOA,CAACC,UAAgC,EAAW;IAC1D,IAAIC,aAAa,GAAGC,OAAO,CAACF,UAAU,CAAC,IAAIH,YAAY,CAACG,UAAU,CAAC;;AAEnE;AACA;AACA,IAAA,OAAOC,aAAa,IAAIE,MAAM,CAACJ,OAAO,CAACC,UAAU,CAAC;AACpD;EAEAI,IAAI,CAACR,QAAQ,CAAC;AAEd,EAAA,OAAOS,MAAM,CAACC,MAAM,CAACR,OAAO,EAAE;AAAEC,IAAAA;AAAQ,GAAC,CAAC;AAK5C;;;;"}
@@ -1,4 +1,3 @@
1
- import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';
2
1
  import * as compiler from 'ember-template-compiler';
3
2
  import { nameFor } from '../../utils.js';
4
3
  import { evalSnippet } from './eval.js';
@@ -68,35 +67,52 @@ async function preprocess(input, name) {
68
67
  } = await fetchingPromise;
69
68
  processor = new Preprocessor();
70
69
  }
71
- return processor.process(input, {
70
+ let {
71
+ code /* map */
72
+ } = processor.process(input, {
72
73
  filename: `${name}.js`,
73
74
  inline_source_map: true
74
75
  });
76
+ return code;
75
77
  }
76
- async function transform(intermediate, name, options = {}) {
77
- // @babel/standalone is a CJS module....
78
+ async function transform(intermediate, name) {
79
+ const [
80
+ // _parser, _traverse, _generator,
81
+ _decoratorTransforms, _emberTemplateCompilation] = await Promise.all([
82
+ // @babel/* doesn't have the greatest ESM compat yet
83
+ // https://github.com/babel/babel/issues/14314#issuecomment-1054505190
84
+ //
85
+ // babel-standalone is so easy...
86
+ // import('@babel/parser'),
87
+ // import('@babel/traverse'),
88
+ // import('@babel/generator'),
89
+ import('decorator-transforms'), import('babel-plugin-ember-template-compilation')]);
90
+
91
+ // These libraries are compiled incorrectly for cjs<->ESM compat
92
+ const decoratorTransforms = 'default' in _decoratorTransforms ? _decoratorTransforms.default : _decoratorTransforms;
93
+ const emberTemplateCompilation = 'default' in _emberTemplateCompilation ? _emberTemplateCompilation.default : _emberTemplateCompilation;
94
+
78
95
  // so we have to use the default export (which is all the exports)
79
96
  let maybeBabel = await import('@babel/standalone');
80
97
  // Handle difference between vite and webpack in consuming projects...
81
98
  let babel = 'availablePlugins' in maybeBabel ? maybeBabel : maybeBabel.default;
82
99
  return babel.transform(intermediate, {
83
100
  filename: `${name}.js`,
84
- plugins: [
85
- // [babelPluginIntermediateGJS],
86
- [babelPluginEmberTemplateCompilation, {
101
+ plugins: [[emberTemplateCompilation, {
87
102
  compiler
88
- }], [babel.availablePlugins['proposal-decorators'], {
89
- legacy: true
90
- }], [babel.availablePlugins['proposal-class-properties']]],
91
- presets: [[babel.availablePresets['env'], {
92
- // false -- keeps ES Modules
93
- modules: 'cjs',
94
- targets: {
95
- esmodules: true
96
- },
97
- forceAllTransforms: false,
98
- ...options
99
- }]]
103
+ }], [
104
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
+ // @ts-ignore - we don't care about types here..
106
+ decoratorTransforms, {
107
+ runtime: {
108
+ import: 'decorator-transforms/runtime'
109
+ }
110
+ }],
111
+ // Womp.
112
+ // See this exploration into true ESM:
113
+ // https://github.com/NullVoxPopuli/limber/pull/1805
114
+ [babel.availablePlugins['transform-modules-commonjs']]],
115
+ presets: []
100
116
  });
101
117
  }
102
118
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/compile/formats/gjs/index.ts"],"sourcesContent":["import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';\nimport * as compiler from 'ember-template-compiler';\n\nimport { nameFor } from '../../utils.ts';\nimport { evalSnippet } from './eval.ts';\n\nimport type { CompileResult } from '../../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\n/**\n * @public\n * Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.\n * The returned component can be invoked explicitly in the consuming project.\n *\n * SEE: README for example usage\n *\n * @param {string} code: the code to be compiled\n * @param {Object} extraModules: map of import paths to modules. This isn't needed\n * for classic ember projects, but for strict static ember projects, extraModules\n * will need to be pasesd if compileJS is intended to be used in a styleguide or\n * if there are additional modules that could be imported in the passed `code`.\n *\n * Later on, imports that are not present by default (ember/glimmer) or that\n * are not provided by extraModules will be searched on npm to see if a package\n * needs to be downloaded before running the `code` / invoking the component\n */\nexport async function compileJS(\n code: string,\n extraModules?: Record<string, unknown>\n): Promise<CompileResult> {\n let name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n let compiled = await transpile({ code: code, name });\n\n if (!compiled) {\n throw new Error(`Compiled output is missing`);\n }\n\n component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\nasync function transpile({ code: input, name }: Info) {\n let preprocessed = await preprocess(input, name);\n let result = await transform(preprocessed, name);\n\n if (!result) {\n return;\n }\n\n let { code } = result;\n\n return code;\n}\n\nimport type { Babel } from './babel.ts';\n\nlet processor: any;\nlet fetchingPromise: Promise<any>;\n\nasync 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, { filename: `${name}.js`, inline_source_map: true });\n}\n\nasync function transform(\n intermediate: string,\n name: string,\n options: any = {}\n): Promise<ReturnType<Babel['transform']>> {\n // @babel/standalone is a CJS module....\n // so we have to use the default export (which is all the exports)\n let maybeBabel = (await import('@babel/standalone')) as any;\n // Handle difference between vite and webpack in consuming projects...\n let babel: Babel = 'availablePlugins' in maybeBabel ? maybeBabel : maybeBabel.default;\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":["compileJS","code","extraModules","name","nameFor","component","error","compiled","transpile","Error","evalSnippet","default","e","input","preprocessed","preprocess","result","transform","processor","fetchingPromise","Preprocessor","process","filename","inline_source_map","intermediate","options","maybeBabel","babel","plugins","babelPluginEmberTemplateCompilation","compiler","availablePlugins","legacy","presets","availablePresets","modules","targets","esmodules","forceAllTransforms"],"mappings":";;;;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,SAASA,CAC7BC,IAAY,EACZC,YAAsC,EACd;AACxB,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,SAAS,CAAC;AAAEP,MAAAA,IAAI,EAAEA,IAAI;AAAEE,MAAAA,IAAAA;AAAK,KAAC,CAAC,CAAA;IAEpD,IAAI,CAACI,QAAQ,EAAE;AACb,MAAA,MAAM,IAAIE,KAAK,CAAC,CAAA,0BAAA,CAA4B,CAAC,CAAA;AAC/C,KAAA;IAEAJ,SAAS,GAAGK,WAAW,CAACH,QAAQ,EAAEL,YAAY,CAAC,CAACS,OAAmC,CAAA;GACpF,CAAC,OAAOC,CAAC,EAAE;AACVN,IAAAA,KAAK,GAAGM,CAAsB,CAAA;AAChC,GAAA;EAEA,OAAO;IAAET,IAAI;IAAEE,SAAS;AAAEC,IAAAA,KAAAA;GAAO,CAAA;AACnC,CAAA;AAEA,eAAeE,SAASA,CAAC;AAAEP,EAAAA,IAAI,EAAEY,KAAK;AAAEV,EAAAA,IAAAA;AAAW,CAAC,EAAE;EACpD,IAAIW,YAAY,GAAG,MAAMC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ACA,IAAA,CACEC,mCAAmC,EACnC;AACEC,MAAAA,QAAAA;KACD,CACF,EACD,CAACH,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,GAAGb,OAAAA;AACL,KAAC,CACF,CAAA;AAEL,GAAC,CAAC,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/compile/formats/gjs/index.ts"],"sourcesContent":["import * as compiler from 'ember-template-compiler';\n\nimport { nameFor } from '../../utils.ts';\nimport { evalSnippet } from './eval.ts';\n\nimport type { CompileResult } from '../../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\n/**\n * @public\n * Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.\n * The returned component can be invoked explicitly in the consuming project.\n *\n * SEE: README for example usage\n *\n * @param {string} code: the code to be compiled\n * @param {Object} extraModules: map of import paths to modules. This isn't needed\n * for classic ember projects, but for strict static ember projects, extraModules\n * will need to be pasesd if compileJS is intended to be used in a styleguide or\n * if there are additional modules that could be imported in the passed `code`.\n *\n * Later on, imports that are not present by default (ember/glimmer) or that\n * are not provided by extraModules will be searched on npm to see if a package\n * needs to be downloaded before running the `code` / invoking the component\n */\nexport async function compileJS(\n code: string,\n extraModules?: Record<string, unknown>\n): Promise<CompileResult> {\n let name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n let compiled = await transpile({ code: code, name });\n\n if (!compiled) {\n throw new Error(`Compiled output is missing`);\n }\n\n component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\nasync function transpile({ code: input, name }: Info) {\n let preprocessed = await preprocess(input, name);\n let result = await transform(preprocessed, name);\n\n if (!result) {\n return;\n }\n\n let { code } = result;\n\n return code;\n}\n\nimport type { Babel } from './babel.ts';\n\nlet processor: any;\nlet fetchingPromise: Promise<any>;\n\nasync 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 let { code /* map */ } = processor.process(input, {\n filename: `${name}.js`,\n inline_source_map: true,\n });\n\n return code;\n}\n\nasync function transform(\n intermediate: string,\n name: string\n): Promise<ReturnType<Babel['transform']>> {\n const [\n // _parser, _traverse, _generator,\n _decoratorTransforms,\n _emberTemplateCompilation,\n ] = await Promise.all([\n // @babel/* doesn't have the greatest ESM compat yet\n // https://github.com/babel/babel/issues/14314#issuecomment-1054505190\n //\n // babel-standalone is so easy...\n // import('@babel/parser'),\n // import('@babel/traverse'),\n // import('@babel/generator'),\n import('decorator-transforms'),\n import('babel-plugin-ember-template-compilation'),\n ]);\n\n // These libraries are compiled incorrectly for cjs<->ESM compat\n const decoratorTransforms =\n 'default' in _decoratorTransforms ? _decoratorTransforms.default : _decoratorTransforms;\n\n const emberTemplateCompilation =\n 'default' in _emberTemplateCompilation\n ? _emberTemplateCompilation.default\n : _emberTemplateCompilation;\n\n // so we have to use the default export (which is all the exports)\n let maybeBabel = (await import('@babel/standalone')) as any;\n // Handle difference between vite and webpack in consuming projects...\n let babel: Babel = 'availablePlugins' in maybeBabel ? maybeBabel : maybeBabel.default;\n\n return babel.transform(intermediate, {\n filename: `${name}.js`,\n plugins: [\n [\n emberTemplateCompilation,\n {\n compiler,\n },\n ],\n [\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - we don't care about types here..\n decoratorTransforms,\n {\n runtime: {\n import: 'decorator-transforms/runtime',\n },\n },\n ],\n // Womp.\n // See this exploration into true ESM:\n // https://github.com/NullVoxPopuli/limber/pull/1805\n [babel.availablePlugins['transform-modules-commonjs']],\n ],\n presets: [],\n });\n}\n"],"names":["compileJS","code","extraModules","name","nameFor","component","error","compiled","transpile","Error","evalSnippet","default","e","input","preprocessed","preprocess","result","transform","processor","fetchingPromise","Preprocessor","process","filename","inline_source_map","intermediate","_decoratorTransforms","_emberTemplateCompilation","Promise","all","decoratorTransforms","emberTemplateCompilation","maybeBabel","babel","plugins","compiler","runtime","import","availablePlugins","presets"],"mappings":";;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,SAASA,CAC7BC,IAAY,EACZC,YAAsC,EACd;AACxB,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,IAAI,CAAC;AACxB,EAAA,IAAII,SAAoC;AACxC,EAAA,IAAIC,KAAwB;EAE5B,IAAI;AACF,IAAA,IAAIC,QAAQ,GAAG,MAAMC,SAAS,CAAC;AAAEP,MAAAA,IAAI,EAAEA,IAAI;AAAEE,MAAAA;AAAK,KAAC,CAAC;IAEpD,IAAI,CAACI,QAAQ,EAAE;AACb,MAAA,MAAM,IAAIE,KAAK,CAAC,CAAA,0BAAA,CAA4B,CAAC;AAC/C;IAEAJ,SAAS,GAAGK,WAAW,CAACH,QAAQ,EAAEL,YAAY,CAAC,CAACS,OAAmC;GACpF,CAAC,OAAOC,CAAC,EAAE;AACVN,IAAAA,KAAK,GAAGM,CAAsB;AAChC;EAEA,OAAO;IAAET,IAAI;IAAEE,SAAS;AAAEC,IAAAA;GAAO;AACnC;AAEA,eAAeE,SAASA,CAAC;AAAEP,EAAAA,IAAI,EAAEY,KAAK;AAAEV,EAAAA;AAAW,CAAC,EAAE;EACpD,IAAIW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e,yBAAyB;;AAE/B;AACA,EAAA,IAAIK,UAAU,GAAI,MAAM,OAAO,mBAAmB,CAAS;AAC3D;EACA,IAAIC,KAAY,GAAG,kBAAkB,IAAID,UAAU,GAAGA,UAAU,GAAGA,UAAU,CAACpB,OAAO;AAErF,EAAA,OAAOqB,KAAK,CAACf,SAAS,CAACO,YAAY,EAAE;IACnCF,QAAQ,EAAE,CAAGnB,EAAAA,IAAI,CAAK,GAAA,CAAA;AACtB8B,IAAAA,OAAO,EAAE,CACP,CACEH,wBAAwB,EACxB;AACEI,MAAAA;AACF,KAAC,CACF,EACD;AACE;AACA;AACAL,IAAAA,mBAAmB,EACnB;AACEM,MAAAA,OAAO,EAAE;AACPC,QAAAA,MAAM,EAAE;AACV;AACF,KAAC,CACF;AACD;AACA;AACA;AACA,IAAA,CAACJ,KAAK,CAACK,gBAAgB,CAAC,4BAA4B,CAAC,CAAC,CACvD;AACDC,IAAAA,OAAO,EAAE;AACX,GAAC,CAAC;AACJ;;;;"}
@@ -16,6 +16,7 @@ import * as _service from '@ember/service';
16
16
  import * as _template from '@ember/template';
17
17
  import { createTemplateFactory } from '@ember/template-factory';
18
18
  import * as _utils from '@ember/utils';
19
+ import * as _decoratorsRuntime from 'decorator-transforms/runtime';
19
20
 
20
21
  /**
21
22
  * We need to import and hang on to these references so that they
@@ -41,7 +42,8 @@ const modules = {
41
42
  '@ember/template': _template,
42
43
  '@ember/owner': _owner,
43
44
  '@glimmer/component': _GlimmerComponent,
44
- '@glimmer/tracking': _tracking
45
+ '@glimmer/tracking': _tracking,
46
+ 'decorator-transforms/runtime': _decoratorsRuntime
45
47
  };
46
48
 
47
49
  export { modules };
@@ -1 +1 @@
1
- {"version":3,"file":"known-modules.js","sources":["../../../../src/compile/formats/gjs/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;;;;"}
1
+ {"version":3,"file":"known-modules.js","sources":["../../../../src/compile/formats/gjs/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\nimport * as _decoratorsRuntime from 'decorator-transforms/runtime';\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 'decorator-transforms/runtime': _decoratorsRuntime,\n};\n"],"names":["modules","_application","_array","_EmberComponent","_EmberComponentHelper","_TO","_debug","_destroyable","_helpers","_modifier","_object","_runloop","_service","createTemplateFactory","_utils","_template","_owner","_GlimmerComponent","_tracking","_decoratorsRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAwBO,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;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,SAAS;AAC9B,EAAA,8BAA8B,EAAEC;AAClC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"hbs.js","sources":["../../../src/compile/formats/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\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nimport { precompileJSON } from '@glimmer/compiler';\nimport { getTemplateLocals } from '@glimmer/syntax';\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';\n\nimport { nameFor } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ComponentLike } from '@glint/template';\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(\n `Attempt to use ${key} in compiled hbs, but it was not available in scope. ` +\n `Available scope includes: ${Object.keys(localScope)}`\n );\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 ?? '(dynamically compiled component)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n let factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","getTemplateLocals","strictMode","isProduction","meta","block","usedLocals","precompileJSON","usedScope","map","key","value","Error","Object","keys","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAgBA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,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;A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U,IAAI,kCAAkC;IAC5DI,KAAK,EAAEA,MAAMgB,SAAS;AACtBY,IAAAA,YAAY,EAAE,IAAA;GACf,CAAA;AAED,EAAA,IAAIC,OAAO,GAAGC,qBAAqB,CAACJ,kBAAkB,CAAC,CAAA;AAEvD,EAAA,OAAOG,OAAO,CAAA;AAChB;;;;"}
1
+ {"version":3,"file":"hbs.js","sources":["../../../src/compile/formats/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\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nimport { precompileJSON } from '@glimmer/compiler';\nimport { getTemplateLocals } from '@glimmer/syntax';\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';\n\nimport { nameFor } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ComponentLike } from '@glint/template';\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(\n `Attempt to use ${key} in compiled hbs, but it was not available in scope. ` +\n `Available scope includes: ${Object.keys(localScope)}`\n );\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 ?? '(dynamically compiled component)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n let factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","getTemplateLocals","strictMode","isProduction","meta","block","usedLocals","precompileJSON","usedScope","map","key","value","Error","Object","keys","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAgBA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAUA,CAACC,QAAgB,EAAEC,OAA+B,GAAG,EAAE,EAAiB;AAChG,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,QAAQ,CAAC;AAC5B,EAAA,IAAII,SAAoC;AACxC,EAAA,IAAIC,KAAwB;EAE5B,IAAI;AACFD,IAAAA,SAAS,GAAGE,oBAAoB,CAC9BC,eAAe,CAACP,Q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,IAAA,OAAOkB,KAAK;AACd,GAAC,CAAC;AAEF,EAAA,IAAII,SAAS,GAAGC,IAAI,CAACC,SAAS,CAACZ,KAAK,CAAC;AACrC,EAAA,IAAIa,kBAAkB,GAAG;AACvBC,IAAAA,EAAE,EAAE/B,UAAU;AACdiB,IAAAA,KAAK,EAAEU,SAAS;IAChB3B,UAAU,EAAEA,UAAU,IAAI,kCAAkC;IAC5DI,KAAK,EAAEA,MAAMgB,SAAS;AACtBY,IAAAA,YAAY,EAAE;GACf;AAED,EAAA,IAAIC,OAAO,GAAGC,qBAAqB,CAACJ,kBAAkB,CAAC;AAEvD,EAAA,OAAOG,OAAO;AAChB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","sources":["../../../src/compile/formats/markdown.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\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 sanitizeForGlimmer(/* options */) {\n return (tree: Parent) => {\n visit(tree, 'element', (node: Parent) => {\n if ('tagName' in node) {\n if (!['pre', 'code'].includes(node.tagName as string)) return;\n\n visit(node, 'text', (textNode: Text) => {\n if ('value' in textNode && textNode.value) {\n textNode.value = textNode.value.replace(/{{/g, '\\\\{{');\n }\n });\n\n return 'skip';\n }\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\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 // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\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 // .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 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 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 if (options.rehypePlugins) {\n options.rehypePlugins.forEach((plugin) => {\n // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\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 compiler = compiler.use(sanitizeForGlimmer);\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 rehypePlugins?: 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","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","node","type","lang","trim","copyNode","value","enhance","code","data","hProperties","className","children","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","sanitizeForGlimmer","tagName","textNode","replace","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","remarkPlugins","forEach","plugin","p","Array","isArray","CopyComponent","ShadowComponent","remarkRehype","allowDangerousHtml","properties","match","rehypePlugins","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,SAASC,MAAMA,CAACC,IAAY,EAAE;AAC5B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC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AA,wBAAwB,EAAE,IAAI;AAC9BV,IAAAA,kBAAkB,EAAE,IAAA;AACtB,GAAC,CAAQ,CAAA;AAET,EAAA,OAAOd,QAAQ,CAAA;AACjB,CAAA;AASA;AACA;AACA;AACO,eAAeyB,aAAaA,CACjCC,KAAa,EACbjF,OAA6B,GAAG,EAAE,EACL;AAC7B,EAAA,IAAIkF,gBAAgB,GAAG5B,aAAa,CAACtD,OAAO,CAAC,CAAA;EAC7C,IAAImF,SAAS,GAAG,MAAMD,gBAAgB,CAACE,OAAO,CAACH,KAAK,CAAC,CAAA;EACrD,IAAI7C,QAAQ,GAAI+C,SAAS,CAACnE,IAAI,CAAcoB,QAAQ,IAAI,EAAE,CAAA;AAC1D,EAAA,IAAIiD,YAAY,GAAGF,SAAS,CAACG,QAAQ,EAAE,CAAA;EAEvC,OAAO;AAAEC,IAAAA,oBAAoB,EAAEF,YAAY;AAAEG,IAAAA,MAAM,EAAEpD,QAAAA;GAAU,CAAA;AACjE;;;;"}
1
+ {"version":3,"file":"markdown.js","sources":["../../../src/compile/formats/markdown.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\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 sanitizeForGlimmer(/* options */) {\n return (tree: Parent) => {\n visit(tree, 'element', (node: Parent) => {\n if ('tagName' in node) {\n if (!['pre', 'code'].includes(node.tagName as string)) return;\n\n visit(node, 'text', (textNode: Text) => {\n if ('value' in textNode && textNode.value) {\n textNode.value = textNode.value.replace(/{{/g, '\\\\{{');\n }\n });\n\n return 'skip';\n }\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\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 // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\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 // .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 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 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 if (options.rehypePlugins) {\n options.rehypePlugins.forEach((plugin) => {\n // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\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 compiler = compiler.use(sanitizeForGlimmer);\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 rehypePlugins?: 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","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","node","type","lang","trim","copyNode","value","enhance","code","data","hProperties","className","children","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","sanitizeForGlimmer","tagName","textNode","replace","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","remarkPlugins","forEach","plugin","p","Array","isArray","CopyComponent","ShadowComponent","remarkRehype","allowDangerousHtml","properties","match","rehypePlugins","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;AACvD,MAAMC,eAAe,GAAGD,MAAM,CAAC,qBAAqB,CAA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],"sourcesContent":["import { invocationName } from './utils.ts';\n\nimport type { ExtractedCode } from './formats/markdown.ts';\nimport type { CompileResult, 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('./formats/gjs/index.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('./formats/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 rehypePlugins?: 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('./formats/markdown.ts');\n let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\n ShadowComponent: options?.ShadowComponent,\n remarkPlugins: options?.remarkPlugins,\n rehypePlugins: options?.rehypePlugins,\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","rehypePlugins","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAMA,eAAeA,eAAeA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAChF,IAAIC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC7BJ,EAAE,CAACK,GAAG,CAAC,OAAO;AAAEC,IAAAA,IAAAA;AAAK,GAAC,KAAK;AACzB,IAAA,OAAO,MAAMC,UAAU,CAACD,IAAI,EAAEL,SAAS,CAAC,CAAA;AAC1C,GAAC,CACH,CAAC,CAAA;AAED,EAAA,OAAOC,OAAO,CAAA;AAChB,CAAA;AAEO,eAAeK,UAAUA,CAC9BC,QAAgB,EAChBP,SAAyB,EACD;EACxB,IAAI;IACF,IAAI;AAAEQ,MAAAA,SAAAA;AAAU,KAAC,GAAG,MAAM,OAAO,wBAAwB,CAAC,CAAA;AAE1D,IAAA,OAAO,MAAMA,SAAS,CAACD,QAAQ,EAAEP,SAAS,CAAC,CAAA;GAC5C,CAAC,OAAOS,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACnD,GAAA;AACF,CAAA;AAEO,eAAeC,UAAUA,CAC9BC,QAAgB,EAChBC,OAGC,EACuB;EACxB,IAAI;IACF,IAAI;AAAEF,MAAAA,UAAAA;AAAW,KAAC,GAAG,MAAM,OAAO,kBAAkB,CAAC,CAAA;AAErD,IAAA,OAAOA,UAAU,CAACC,QAAQ,EAAEC,OAAO,CAAC,CAAA;GACrC,CAAC,OAAOJ,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACnD,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AAK,IAAI;IAAED,KAAK;AAAE4B,IAAAA,SAAAA;GAAW,IAAIrB,KAAK,EAAE;IACtC,IAAI,CAACqB,SAAS,EAAE;AACd,MAAA,IAAI5B,KAAK,EAAE;QACT,OAAO;UAAEA,KAAK;UAAEmB,YAAY;AAAElB,UAAAA,IAAI,EAAE,SAAA;SAAW,CAAA;AACjD,OAAA;AACF,KAAA;AACF,GAAA;;AAEA;AACF;AACA;EACE,IAAI;IACF,IAAI4B,UAAU,GAAGtB,KAAK,CAACuB,MAAM,CAC3B,CAACC,KAAK,EAAE;MAAEH,SAAS;AAAE3B,MAAAA,IAAAA;AAAK,KAAC,KAAK;AAC9B8B,MAAAA,KAAK,CAACC,cAAc,CAAC/B,IAAI,CAAC,CAAC,GAAG2B,SAAS,CAAA;AAEvC,MAAA,OAAOG,KAAK,CAAA;KACb,EACD,EACF,CAAC,CAAA;AAED,IAAA,OAAO,MAAM7B,UAAU,CAACiB,YAAY,EAAE;AACpCc,MAAAA,UAAU,EAAE,qBAAqB;AACjC1B,MAAAA,KAAK,EAAE;AACL,QAAA,GAAGS,aAAa;QAChB,GAAGa,UAAAA;AACL,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAC,OAAO7B,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;MAAEmB,YAAY;AAAElB,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACjE,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"formats.js","sources":["../../src/compile/formats.ts"],"sourcesContent":["import { invocationName } from './utils.ts';\n\nimport type { ExtractedCode } from './formats/markdown.ts';\nimport type { CompileResult, 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('./formats/gjs/index.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('./formats/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 rehypePlugins?: 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('./formats/markdown.ts');\n let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\n ShadowComponent: options?.ShadowComponent,\n remarkPlugins: options?.remarkPlugins,\n rehypePlugins: options?.rehypePlugins,\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","rehypePlugins","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAMA,eAAeA,eAAeA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAChF,IAAIC,OAAO,GAAG,MAAMC,OAAO,C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AACL;AACF,KAAC,CAAC;GACH,CAAC,OAAO7B,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;MAAEmB,YAAY;AAAElB,MAAAA,IAAI,EAAE;KAAW;AACjE;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\nimport { nameFor } from './utils.ts';\n\nimport type { CompileResult, 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 rehypePlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\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(`${options.format}:${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 rehypePlugins?: 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","format","existing","get","includes","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","markdownText","maybeOptions","resource","maybeObject","input","ready","cell","current","e","isReady","resourceFactory"],"mappings":";;;;MAcaA,KAAK,GAAG,IAAIC,GAAG,GAAyB;AAYrD,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;;AA+BpD;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,eAAeC,OAAOA,CAC3B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,GAAGkB,IAAI,EAAiB,CAAA;AAElC,IAAA,IAAIF,KAAK,EAAE;MACT5B,OAAO,CAAC4B,KAAK,EAAE;AACb;AACApB,QAAAA,MAAM,EAAEA,MAAa;QACrBL,SAAS,EAAE,MAAOmB,SAAS,IAAK;UAC9BV,MAAM,CAACmB,OAAO,GAAGT,SAAS,CAAA;AAC1BO,UAAAA,KAAK,CAACR,GAAG,CAAC,IAAI,CAAC,CAAA;AACfF,UAAAA,KAAK,CAACE,GAAG,CAAC,IAAI,CAAC,CAAA;SAChB;QACDjB,OAAO,EAAE,MAAO4B,CAAC,IAAK;AACpBb,UAAAA,KAAK,CAACE,GAAG,CAACW,CAAC,CAAC,CAAA;SACb;QACD3B,cAAc,EAAE,YAAY;AAC1BwB,UAAAA,KAAK,CAACR,GAAG,CAAC,KAAK,CAAC,CAAA;SACjB;QACD,GAAGnB,OAAAA;AACL,OAAC,CAAC,CAAA;AACJ,KAAA;AAEA,IAAA,OAAO,OAAO;MACZ+B,OAAO,EAAEJ,KAAK,CAACE,OAAO;MACtBZ,KAAK,EAAEA,KAAK,CAACY,OAAO;MACpBT,SAAS,EAAEV,MAAM,CAACmB,OAAAA;AACpB,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AACJ,CAAA;AAEAG,eAAe,CAACX,QAAQ,CAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\nimport { nameFor } from './utils.ts';\n\nimport type { CompileResult, 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 rehypePlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\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(`${options.format}:${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 rehypePlugins?: 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","format","existing","get","includes","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","markdownText","maybeOptions","resource","maybeObject","input","ready","cell","current","e","isReady","resourceFactory"],"mappings":";;;;MAcaA,KAAK,GAAG,IAAIC,GAAG;AAY5B,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC;;AA+BpD;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;AAAe,GAAC,GAAGH,OAAO;EACpD,IAAII,EAAE,GAAGC,OAAO,CAAC,CAAA,EAAGL,OAAO,CAACM,MAAM,CAAA,CAAA,EAAIP,IAAI,CAAA,CAAE,CAAC;AAE7C,EAAA,IAAIQ,QAAQ,GAAGZ,KAAK,CAACa,GAAG,CAACJ,EAAE,CAAC;AAE5B,EAAA,IAAIG,QAAQ,EAAE;IACZN,SAAS,CAACM,QAAQ,CAAC;AAEnB,IAAA;AACF;EAEA,IAAI,CAACV,iBAAiB,CAACY,QAAQ,CAACT,OAAO,CAACM,MAAM,CAAC,EAAE;IAC/C,MAAMJ,OAAO,CAAC,CAAuBF,oBAAAA,EAAAA,OAAO,CAACM,MAAM,CAAA,qBAAA,EAAwBT,iBAAiB,CAAA,CAAE,CAAC;AAE/F,IAAA;AACF;EAEA,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ils.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { pascalCase } from 'change-case';\nimport { v5 as uuidv5 } from 'uuid';\n\n/**\n * a namespace is required for uuid v5\n *\n * it helps generate stable outputs for for any given input.\n */\nconst NAMESPACE = '926f034a-f480-4112-a363-321244f4e5de';\nconst DEFAULT_PREFIX = 'ember-repl';\n\n/**\n * For any given code block, a reasonably stable name can be\n * generated.\n * This can help with cacheing previously compiled components,\n * and generally allowing a consumer to derive \"known references\" to user-input\n */\nexport function nameFor(code: string, prefix = DEFAULT_PREFIX) {\n let id = uuidv5(code, NAMESPACE);\n\n return `${prefix ? `${prefix}-` : ''}${id}`;\n}\n\n/**\n * Returns the text for invoking a component with a given name.\n * It is assumed the component takes no arguments, as would be the\n * case in REPLs / Playgrounds for the \"root\" component.\n */\nexport function invocationOf(name: string) {\n assert(\n `You must pass a name to invocationOf. Received: \\`${name}\\``,\n typeof name === 'string' && name.length > 0\n );\n\n if (name.length === 0) {\n throw new Error(`name passed to invocationOf must have non-0 length`);\n }\n\n return `<${invocationName(name)} />`;\n}\n\n/**\n * Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)\n * inflection does not support hyphens\n */\nexport function invocationName(name: string) {\n return pascalCase(name).replaceAll('_', '');\n}\n"],"names":["NAMESPACE","DEFAULT_PREFIX","nameFor","code","prefix","id","uuidv5","invocationOf","name","assert","length","Error","invocationName","pascalCase","replaceAll"],"mappings":";;;;AAKA;AACA;AACA;AACA;AACA;AACA,MAAMA,SAAS,GAAG,sCAAsC,CAAA;AACxD,MAAMC,cAAc,GAAG,YAAY,CAAA;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAACC,IAAY,EAAEC,MAAM,GAAGH,cAAc,EAAE;AAC7D,EAAA,IAAII,EAAE,GAAGC,EAAM,CAACH,IAAI,EAAEH,SAAS,CAAC,CAAA;EAEhC,OAAO,CAAA,EAAGI,MAAM,GAAG,CAAGA,EAAAA,MAAM,GAAG,GAAG,EAAE,CAAGC,EAAAA,EAAE,CAAE,CAAA,CAAA;AAC7C,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,IAAY,EAAE;AACzCC,EAAAA,MAAM,CACJ,CAAA,kDAAA,EAAqDD,IAAI,CAAA,EAAA,CAAI,EAC7D,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,CAACE,MAAM,GAAG,CAC5C,CAAC,CAAA;AAED,EAAA,IAAIF,IAAI,CAACE,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,MAAM,IAAIC,KAAK,CAAC,CAAA,kDAAA,CAAoD,CAAC,CAAA;AACvE,GAAA;AAEA,EAAA,OAAO,CAAIC,CAAAA,EAAAA,cAAc,CAACJ,IAAI,CAAC,CAAK,GAAA,CAAA,CAAA;AACtC,CAAA;;AAEA;AACA;AACA;AACA;AACO,SAASI,cAAcA,CAACJ,IAAY,EAAE;EAC3C,OAAOK,UAAU,CAACL,IAAI,CAAC,CAACM,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAC7C;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/compile/utils.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { pascalCase } from 'change-case';\nimport { v5 as uuidv5 } from 'uuid';\n\n/**\n * a namespace is required for uuid v5\n *\n * it helps generate stable outputs for for any given input.\n */\nconst NAMESPACE = '926f034a-f480-4112-a363-321244f4e5de';\nconst DEFAULT_PREFIX = 'ember-repl';\n\n/**\n * For any given code block, a reasonably stable name can be\n * generated.\n * This can help with cacheing previously compiled components,\n * and generally allowing a consumer to derive \"known references\" to user-input\n */\nexport function nameFor(code: string, prefix = DEFAULT_PREFIX) {\n let id = uuidv5(code, NAMESPACE);\n\n return `${prefix ? `${prefix}-` : ''}${id}`;\n}\n\n/**\n * Returns the text for invoking a component with a given name.\n * It is assumed the component takes no arguments, as would be the\n * case in REPLs / Playgrounds for the \"root\" component.\n */\nexport function invocationOf(name: string) {\n assert(\n `You must pass a name to invocationOf. Received: \\`${name}\\``,\n typeof name === 'string' && name.length > 0\n );\n\n if (name.length === 0) {\n throw new Error(`name passed to invocationOf must have non-0 length`);\n }\n\n return `<${invocationName(name)} />`;\n}\n\n/**\n * Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)\n * inflection does not support hyphens\n */\nexport function invocationName(name: string) {\n return pascalCase(name).replaceAll('_', '');\n}\n"],"names":["NAMESPACE","DEFAULT_PREFIX","nameFor","code","prefix","id","uuidv5","invocationOf","name","assert","length","Error","invocationName","pascalCase","replaceAll"],"mappings":";;;;AAKA;AACA;AACA;AACA;AACA;AACA,MAAMA,SAAS,GAAG,sCAAsC;AACxD,MAAMC,cAAc,GAAG,YAAY;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAACC,IAAY,EAAEC,MAAM,GAAGH,cAAc,EAAE;AAC7D,EAAA,IAAII,EAAE,GAAGC,EAAM,CAACH,IAAI,EAAEH,SAAS,CAAC;EAEhC,OAAO,CAAA,EAAGI,MAAM,GAAG,CAAGA,EAAAA,MAAM,GAAG,GAAG,EAAE,CAAGC,EAAAA,EAAE,CAAE,CAAA;AAC7C;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,IAAY,EAAE;AACzCC,EAAAA,MAAM,CACJ,CAAA,kDAAA,EAAqDD,IAAI,CAAA,EAAA,CAAI,EAC7D,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,CAACE,MAAM,GAAG,CAC5C,CAAC;AAED,EAAA,IAAIF,IAAI,CAACE,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,MAAM,IAAIC,KAAK,CAAC,CAAA,kDAAA,CAAoD,CAAC;AACvE;AAEA,EAAA,OAAO,CAAIC,CAAAA,EAAAA,cAAc,CAACJ,IAAI,CAAC,CAAK,GAAA,CAAA;AACtC;;AAEA;AACA;AACA;AACA;AACO,SAASI,cAAcA,CAACJ,IAAY,EAAE;EAC3C,OAAOK,UAAU,CAACL,IAAI,CAAC,CAACM,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;AAC7C;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { CACHE } from '../compile/index.ts';\n\nexport function clearCompileCache() {\n CACHE.clear();\n}\n"],"names":["clearCompileCache","CACHE","clear"],"mappings":";;AAEO,SAASA,iBAAiBA,GAAG;EAClCC,KAAK,CAACC,KAAK,EAAE,CAAA;AACf;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { CACHE } from '../compile/index.ts';\n\nexport function clearCompileCache() {\n CACHE.clear();\n}\n"],"names":["clearCompileCache","CACHE","clear"],"mappings":";;AAEO,SAASA,iBAAiBA,GAAG;EAClCC,KAAK,CAACC,KAAK,EAAE;AACf;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-repl",
3
- "version": "4.3.4",
3
+ "version": "5.0.1",
4
4
  "description": "Addon for enabling REPL and Playground creation with Ember/Glimmer",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -69,8 +69,8 @@
69
69
  "broccoli-file-creator": "^2.1.1",
70
70
  "change-case": "^5.4.4",
71
71
  "common-tags": "^1.8.2",
72
- "content-tag": "^2.0.2",
73
- "decorator-transforms": "^2.2.2",
72
+ "content-tag": "^3.0.0",
73
+ "decorator-transforms": "^2.3.0",
74
74
  "ember-resources": "^7.0.1",
75
75
  "line-column": "^1.0.2",
76
76
  "magic-string": "^0.30.6",
@@ -1,4 +1,3 @@
1
- import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';
2
1
  import * as compiler from 'ember-template-compiler';
3
2
 
4
3
  import { nameFor } from '../../utils.ts';
@@ -81,15 +80,43 @@ async function preprocess(input: string, name: string): Promise<string> {
81
80
  processor = new Preprocessor();
82
81
  }
83
82
 
84
- return processor.process(input, { filename: `${name}.js`, inline_source_map: true });
83
+ let { code /* map */ } = processor.process(input, {
84
+ filename: `${name}.js`,
85
+ inline_source_map: true,
86
+ });
87
+
88
+ return code;
85
89
  }
86
90
 
87
91
  async function transform(
88
92
  intermediate: string,
89
- name: string,
90
- options: any = {}
93
+ name: string
91
94
  ): Promise<ReturnType<Babel['transform']>> {
92
- // @babel/standalone is a CJS module....
95
+ const [
96
+ // _parser, _traverse, _generator,
97
+ _decoratorTransforms,
98
+ _emberTemplateCompilation,
99
+ ] = await Promise.all([
100
+ // @babel/* doesn't have the greatest ESM compat yet
101
+ // https://github.com/babel/babel/issues/14314#issuecomment-1054505190
102
+ //
103
+ // babel-standalone is so easy...
104
+ // import('@babel/parser'),
105
+ // import('@babel/traverse'),
106
+ // import('@babel/generator'),
107
+ import('decorator-transforms'),
108
+ import('babel-plugin-ember-template-compilation'),
109
+ ]);
110
+
111
+ // These libraries are compiled incorrectly for cjs<->ESM compat
112
+ const decoratorTransforms =
113
+ 'default' in _decoratorTransforms ? _decoratorTransforms.default : _decoratorTransforms;
114
+
115
+ const emberTemplateCompilation =
116
+ 'default' in _emberTemplateCompilation
117
+ ? _emberTemplateCompilation.default
118
+ : _emberTemplateCompilation;
119
+
93
120
  // so we have to use the default export (which is all the exports)
94
121
  let maybeBabel = (await import('@babel/standalone')) as any;
95
122
  // Handle difference between vite and webpack in consuming projects...
@@ -98,27 +125,27 @@ async function transform(
98
125
  return babel.transform(intermediate, {
99
126
  filename: `${name}.js`,
100
127
  plugins: [
101
- // [babelPluginIntermediateGJS],
102
128
  [
103
- babelPluginEmberTemplateCompilation,
129
+ emberTemplateCompilation,
104
130
  {
105
131
  compiler,
106
132
  },
107
133
  ],
108
- [babel.availablePlugins['proposal-decorators'], { legacy: true }],
109
- [babel.availablePlugins['proposal-class-properties']],
110
- ],
111
- presets: [
112
134
  [
113
- babel.availablePresets['env'],
135
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
136
+ // @ts-ignore - we don't care about types here..
137
+ decoratorTransforms,
114
138
  {
115
- // false -- keeps ES Modules
116
- modules: 'cjs',
117
- targets: { esmodules: true },
118
- forceAllTransforms: false,
119
- ...options,
139
+ runtime: {
140
+ import: 'decorator-transforms/runtime',
141
+ },
120
142
  },
121
143
  ],
144
+ // Womp.
145
+ // See this exploration into true ESM:
146
+ // https://github.com/NullVoxPopuli/limber/pull/1805
147
+ [babel.availablePlugins['transform-modules-commonjs']],
122
148
  ],
149
+ presets: [],
123
150
  });
124
151
  }
@@ -23,6 +23,8 @@ import * as _template from '@ember/template';
23
23
  import { createTemplateFactory } from '@ember/template-factory';
24
24
  import * as _utils from '@ember/utils';
25
25
 
26
+ import * as _decoratorsRuntime from 'decorator-transforms/runtime';
27
+
26
28
  export const modules = {
27
29
  '@ember/application': _application,
28
30
  '@ember/array': _array,
@@ -43,4 +45,5 @@ export const modules = {
43
45
 
44
46
  '@glimmer/component': _GlimmerComponent,
45
47
  '@glimmer/tracking': _tracking,
48
+ 'decorator-transforms/runtime': _decoratorsRuntime,
46
49
  };