ember-repl 2.0.63 → 3.0.0-beta.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.
- package/README.md +200 -35
- package/addon-main.cjs +5 -0
- package/dist/browser/cjs/eval.d.ts +10 -0
- package/dist/browser/cjs/eval.d.ts.map +1 -0
- package/dist/browser/cjs/eval.js +22 -0
- package/dist/browser/cjs/eval.js.map +1 -0
- package/dist/browser/cjs/index.d.ts +7 -0
- package/dist/browser/cjs/index.js +43 -0
- package/dist/browser/cjs/index.js.map +1 -0
- package/dist/browser/compile/formats.d.ts +15 -0
- package/dist/browser/compile/formats.js +169 -0
- package/dist/browser/compile/formats.js.map +1 -0
- package/dist/browser/compile/index.d.ts +32 -0
- package/dist/browser/compile/index.js +90 -0
- package/dist/browser/compile/index.js.map +1 -0
- package/dist/browser/compile/markdown-to-ember.d.ts +18 -0
- package/dist/browser/compile/markdown-to-ember.js +237 -0
- package/dist/browser/compile/markdown-to-ember.js.map +1 -0
- package/dist/browser/compile/types.d.ts +7 -0
- package/dist/browser/compile/types.js +2 -0
- package/dist/browser/compile/types.js.map +1 -0
- package/dist/browser/esm/index.d.ts +8 -0
- package/dist/browser/esm/index.js +67 -0
- package/dist/browser/esm/index.js.map +1 -0
- package/dist/browser/eti/babel-plugin.d.ts +54 -0
- package/dist/browser/eti/babel-plugin.js +95 -0
- package/dist/browser/eti/babel-plugin.js.map +1 -0
- package/dist/browser/eti/debug.d.ts +2 -0
- package/dist/browser/eti/debug.js +9 -0
- package/dist/browser/eti/debug.js.map +1 -0
- package/dist/browser/eti/parse-templates.d.ts +56 -0
- package/dist/browser/eti/parse-templates.js +181 -0
- package/dist/browser/eti/parse-templates.js.map +1 -0
- package/dist/browser/eti/preprocess.d.ts +57 -0
- package/dist/browser/eti/preprocess.js +270 -0
- package/dist/browser/eti/preprocess.js.map +1 -0
- package/dist/browser/eti/template-tag-transform.d.ts +15 -0
- package/dist/browser/eti/template-tag-transform.js +46 -0
- package/dist/browser/eti/template-tag-transform.js.map +1 -0
- package/dist/browser/eti/util.d.ts +14 -0
- package/dist/browser/eti/util.js +39 -0
- package/dist/browser/eti/util.js.map +1 -0
- package/dist/browser/gjs.d.ts +4 -0
- package/dist/browser/gjs.js +40 -0
- package/dist/browser/gjs.js.map +1 -0
- package/{hbs.d.ts → dist/browser/hbs.d.ts} +7 -7
- package/dist/browser/hbs.js +91 -0
- package/dist/browser/hbs.js.map +1 -0
- package/dist/browser/index.d.ts +6 -0
- package/dist/browser/index.js +6 -0
- package/dist/browser/index.js.map +1 -0
- package/{js.d.ts → dist/browser/js.d.ts} +3 -6
- package/dist/browser/js.js +38 -0
- package/dist/browser/js.js.map +1 -0
- package/{known-modules.d.ts → dist/browser/known-modules.d.ts} +6 -5
- package/dist/browser/known-modules.js +46 -0
- package/dist/browser/known-modules.js.map +1 -0
- package/dist/browser/types.d.ts +21 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/{utils.d.ts → dist/browser/utils.d.ts} +8 -3
- package/dist/browser/utils.js +46 -0
- package/dist/browser/utils.js.map +1 -0
- package/dist/build/ember-cli.cjs +36 -0
- package/dist/test-support/index.d.ts +2 -0
- package/dist/test-support/index.js +8 -0
- package/dist/test-support/index.js.map +1 -0
- package/package.json +122 -125
- package/{addon → src/browser}/cjs/eval.ts +9 -5
- package/src/browser/cjs/index.ts +44 -0
- package/src/browser/compile/formats.ts +168 -0
- package/src/browser/compile/index.ts +131 -0
- package/src/browser/compile/markdown-to-ember.ts +318 -0
- package/src/browser/compile/types.ts +7 -0
- package/src/browser/esm/index.ts +80 -0
- package/src/browser/eti/babel-plugin.ts +105 -0
- package/src/browser/eti/debug.ts +7 -0
- package/src/browser/eti/parse-templates.ts +284 -0
- package/src/browser/eti/preprocess.ts +187 -0
- package/src/browser/eti/template-tag-transform.ts +100 -0
- package/src/browser/eti/util.ts +72 -0
- package/src/browser/gjs.ts +59 -0
- package/{addon → src/browser}/hbs.ts +24 -12
- package/{addon → src/browser}/index.ts +1 -0
- package/{addon → src/browser}/js.ts +6 -2
- package/{addon → src/browser}/known-modules.ts +4 -2
- package/{addon → src/browser}/types.ts +6 -1
- package/{addon → src/browser}/utils.ts +6 -2
- package/src/build/ember-cli.cjs +36 -0
- package/src/test-support/index.ts +5 -0
- package/.github/renovate.json5 +0 -93
- package/.github/workflows/ci.yml +0 -120
- package/.github/workflows/lint.yml +0 -88
- package/.github/workflows/types.yml +0 -30
- package/CHANGELOG.md +0 -745
- package/addon/cjs/index.ts +0 -100
- package/addon/esm/index.ts +0 -131
- package/cjs/eval.d.ts +0 -8
- package/cjs/index.d.ts +0 -10
- package/config/environment.js +0 -5
- package/esm/index.d.ts +0 -11
- package/index.d.ts +0 -5
- package/index.js +0 -105
- package/tsconfig.json +0 -56
- package/types/dummy/index.d.ts +0 -1
- package/types/global.d.ts +0 -43
- package/types/overrides.d.ts +0 -18
- package/types.d.ts +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preprocess.js","sources":["../../../../../../node_modules/.pnpm/isarray@1.0.0/node_modules/isarray/index.js","../../../../../../node_modules/.pnpm/isobject@2.1.0/node_modules/isobject/index.js","../../../../../../node_modules/.pnpm/line-column@1.0.2/node_modules/line-column/lib/line-column.js","../../../src/browser/eti/preprocess.ts"],"sourcesContent":["var toString = {}.toString;\n\nmodule.exports = Array.isArray || function (arr) {\n return toString.call(arr) == '[object Array]';\n};\n","/*!\n * isobject <https://github.com/jonschlinkert/isobject>\n *\n * Copyright (c) 2014-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nvar isArray = require('isarray');\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && isArray(val) === false;\n};\n","/**\n * line-column - Convert efficiently index to/from line-column in a string\n * @module lineColumn\n * @license MIT\n */\n\"use strict\";\n\nvar isArray = require(\"isarray\");\nvar isObject = require(\"isobject\");\nvar slice = Array.prototype.slice;\n\nmodule.exports = LineColumnFinder;\n\n/**\n * Finder for index and line-column from given string.\n *\n * You can call this without `new` operator as it returns an instance anyway.\n *\n * @class\n * @param {string} str - A string to be parsed.\n * @param {Object|number} [options] - Options.\n * This can be an index in the string for shorthand of `lineColumn(str, index)`.\n * @param {number} [options.origin=1] - The origin value of line and column.\n */\nfunction LineColumnFinder(str, options) {\n if (!(this instanceof LineColumnFinder)) {\n if (typeof options === \"number\") {\n return (new LineColumnFinder(str)).fromIndex(options);\n }\n return new LineColumnFinder(str, options);\n }\n\n this.str = str || \"\";\n this.lineToIndex = buildLineToIndex(this.str);\n\n options = options || {};\n this.origin = typeof options.origin === \"undefined\" ? 1 : options.origin;\n}\n\n/**\n * Find line and column from index in the string.\n *\n * @param {number} index - Index in the string. (0-origin)\n * @return {Object|null}\n * Found line number and column number in object `{ line: X, col: Y }`.\n * If the given index is out of range, it returns `null`.\n */\nLineColumnFinder.prototype.fromIndex = function (index) {\n if (index < 0 || index >= this.str.length || isNaN(index)) {\n return null;\n }\n\n var line = findLowerIndexInRangeArray(index, this.lineToIndex);\n return {\n line: line + this.origin,\n col: index - this.lineToIndex[line] + this.origin\n };\n}\n\n/**\n * Find index from line and column in the string.\n *\n * @param {number|Object|Array} line - Line number in the string.\n * This can be an Object of `{ line: X, col: Y }`, or\n * an Array of `[line, col]`.\n * @param {number} [column] - Column number in the string.\n * This must be omitted or undefined when Object or Array is given\n * to the first argument.\n * @return {number}\n * Found index in the string. (always 0-origin)\n * If the given line or column is out of range, it returns `-1`.\n */\nLineColumnFinder.prototype.toIndex = function (line, column) {\n if (typeof column === \"undefined\") {\n if (isArray(line) && line.length >= 2) {\n return this.toIndex(line[0], line[1]);\n }\n if (isObject(line) && \"line\" in line && (\"col\" in line || \"column\" in line)) {\n return this.toIndex(line.line, (\"col\" in line ? line.col : line.column));\n }\n return -1;\n }\n if (isNaN(line) || isNaN(column)) {\n return -1;\n }\n\n line -= this.origin;\n column -= this.origin;\n\n if (line >= 0 && column >= 0 && line < this.lineToIndex.length) {\n var lineIndex = this.lineToIndex[line];\n var nextIndex = (\n line === this.lineToIndex.length - 1\n ? this.str.length\n : this.lineToIndex[line + 1]\n );\n\n if (column < nextIndex - lineIndex) {\n return lineIndex + column;\n }\n }\n return -1;\n}\n\n/**\n * Build an array of indexes of each line from a string.\n *\n * @private\n * @param str {string} An input string.\n * @return {number[]} Built array of indexes. The key is line number.\n */\nfunction buildLineToIndex(str) {\n var lines = str.split(\"\\n\"),\n lineToIndex = new Array(lines.length),\n index = 0;\n\n for (var i = 0, l = lines.length; i < l; i++) {\n lineToIndex[i] = index;\n index += lines[i].length + /* \"\\n\".length */ 1;\n }\n return lineToIndex;\n}\n\n/**\n * Find a lower-bound index of a value in a sorted array of ranges.\n *\n * Assume `arr = [0, 5, 10, 15, 20]` and\n * this returns `1` for `value = 7` (5 <= value < 10),\n * and returns `3` for `value = 18` (15 <= value < 20).\n *\n * @private\n * @param arr {number[]} An array of values representing ranges.\n * @param value {number} A value to be searched.\n * @return {number} Found index. If not found `-1`.\n */\nfunction findLowerIndexInRangeArray(value, arr) {\n if (value >= arr[arr.length - 1]) {\n return arr.length - 1;\n }\n\n var min = 0, max = arr.length - 2, mid;\n while (min < max) {\n mid = min + ((max - min) >> 1);\n\n if (value < arr[mid]) {\n max = mid - 1;\n } else if (value >= arr[mid + 1]) {\n min = mid + 1;\n } else { // value >= arr[mid] && value < arr[mid + 1]\n min = mid;\n break;\n }\n }\n return min;\n}\n","// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { getTemplateLocals } from '@glimmer/syntax';\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport lineColumn from 'line-column';\nimport MagicString from 'magic-string';\n\nimport { expect } from './debug';\nimport { parseTemplates } from './parse-templates';\n\nimport type { ParseTemplatesOptions, TemplateMatch } from './parse-templates';\n\ninterface PreprocessOptionsEager {\n importIdentifier?: string;\n importPath?: string;\n templateTag?: string;\n templateTagReplacement?: string;\n\n relativePath: string;\n includeSourceMaps: boolean;\n includeTemplateTokens: boolean;\n}\n\ninterface PreprocessOptionsLazy {\n importIdentifier?: string;\n importPath?: string;\n templateTag?: string;\n templateTagReplacement?: string;\n\n relativePath: string;\n includeSourceMaps: boolean;\n includeTemplateTokens: boolean;\n}\n\ntype PreprocessOptions = PreprocessOptionsLazy | PreprocessOptionsEager;\n\ninterface PreprocessedOutput {\n output: string;\n replacements: Replacement[];\n}\n\ninterface Replacement {\n type: 'start' | 'end';\n index: number;\n oldLength: number;\n newLength: number;\n originalLine: number;\n originalCol: number;\n}\n\nfunction getMatchStartAndEnd(match: RegExpMatchArray) {\n return {\n start: expect(match.index, 'Expected regular expression match to have an index'),\n end:\n expect(match.index, 'Expected regular expression match to have an index') + match[0].length,\n };\n}\n\nfunction replacementFrom(\n template: string,\n index: number,\n oldLength: number,\n newLength: number,\n type: 'start' | 'end'\n): Replacement {\n const loc = expect(\n lineColumn(template).fromIndex(index),\n 'BUG: expected to find a line/column based on index'\n );\n\n return {\n type,\n index,\n oldLength,\n newLength,\n originalCol: loc.col,\n originalLine: loc.line,\n };\n}\n\nfunction replaceMatch(\n s: MagicString,\n match: TemplateMatch,\n startReplacement: string,\n endReplacement: string,\n template: string,\n includeTemplateTokens: boolean\n): Replacement[] {\n const { start: openStart, end: openEnd } = getMatchStartAndEnd(match.start);\n const { start: closeStart, end: closeEnd } = getMatchStartAndEnd(match.end);\n\n let options = '';\n\n if (includeTemplateTokens) {\n const tokensString = getTemplateLocals(template.slice(openEnd, closeStart))\n .filter((local: string) => local.match(/^[$A-Z_][0-9A-Z_$]*$/i))\n .join(',');\n\n if (tokensString.length > 0) {\n options = `, scope: () => ({${tokensString}})`;\n }\n }\n\n const newStart = `${startReplacement}\\``;\n const newEnd = `\\`, { strictMode: true${options} }${endReplacement}`;\n\n s.overwrite(openStart, openEnd, newStart);\n s.overwrite(closeStart, closeEnd, newEnd);\n ensureBackticksEscaped(s, openEnd + 1, closeStart - 1);\n\n return [\n replacementFrom(template, openStart, openEnd - openStart, newStart.length, 'start'),\n replacementFrom(template, closeStart, closeEnd - closeStart, newEnd.length, 'end'),\n ];\n}\n\n/**\n * Preprocesses all embedded templates within a JavaScript or TypeScript file.\n * This function replaces all embedded templates that match our template syntax\n * with valid, parseable JS. Optionally, it can also include a source map, and\n * it can also include all possible values used within the template.\n *\n * Input:\n *\n * <template><MyComponent/><template>\n *\n * Output:\n *\n * [GLIMMER_TEMPLATE(`<MyComponent/>`, { scope() { return {MyComponent}; } })];\n *\n * It can also be used with template literals to provide the in scope values:\n *\n * Input:\n *\n * hbs`<MyComponent/>`;\n *\n * Output\n *\n * hbs(`<MyComponent/>`, { scope() { return {MyComponent}; } });\n */\nexport function preprocessEmbeddedTemplates(\n template: string,\n options: PreprocessOptions\n): PreprocessedOutput {\n const { templateTag, templateTagReplacement, includeTemplateTokens, relativePath } = options;\n\n const parseTemplatesOptions: ParseTemplatesOptions = {\n templateTag,\n };\n\n const matches = parseTemplates(template, relativePath, parseTemplatesOptions);\n const replacements: Replacement[] = [];\n const s = new MagicString(template);\n\n for (const match of matches) {\n if (match.type === 'template-tag') {\n replacements.push(\n ...replaceMatch(\n s,\n match,\n `[${templateTagReplacement}(`,\n ')]',\n template,\n includeTemplateTokens\n )\n );\n }\n }\n\n let output = s.toString();\n\n return {\n output,\n replacements,\n };\n}\n\nfunction ensureBackticksEscaped(s: MagicString, start: number, end: number) {\n if (start >= end) return;\n\n let content = s.slice(start, end);\n\n content = content.replace(/(?<!\\\\)`/g, '\\\\`');\n s.overwrite(start, end, content, false);\n}\n"],"names":["toString","module","Array","isArray","arr","call","require","isObject","val","LineColumnFinder","str","options","fromIndex","lineToIndex","buildLineToIndex","origin","prototype","index","length","isNaN","line","findLowerIndexInRangeArray","col","toIndex","column","lineIndex","nextIndex","lines","split","i","l","value","min","max","mid","getMatchStartAndEnd","match","start","expect","end","replacementFrom","template","oldLength","newLength","type","loc","lineColumn","originalCol","originalLine","replaceMatch","s","startReplacement","endReplacement","includeTemplateTokens","openStart","openEnd","closeStart","closeEnd","tokensString","getTemplateLocals","slice","filter","local","join","newStart","newEnd","overwrite","ensureBackticksEscaped","preprocessEmbeddedTemplates","templateTag","templateTagReplacement","relativePath","parseTemplatesOptions","matches","parseTemplates","replacements","MagicString","push","output","content","replace"],"mappings":";;;;;;;;;AAAA,IAAIA,QAAQ,GAAG,EAAE,CAACA,QAAQ,CAAA;AAE1BC,IAAAA,OAAc,GAAGC,KAAK,CAACC,OAAO,IAAI,UAAUC,GAAG,EAAE;AAC/C,EAAA,OAAOJ,QAAQ,CAACK,IAAI,CAACD,GAAG,CAAC,IAAI,gBAAgB,CAAA;AAC/C,CAAC;;;;;;;;;ACKD,IAAID,SAAO,GAAGG,OAAkB,CAAA;AAEhCL,IAAAA,QAAc,GAAG,SAASM,QAAQA,CAACC,GAAG,EAAE;AACtC,EAAA,OAAOA,GAAG,IAAI,IAAI,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAIL,SAAO,CAACK,GAAG,CAAC,KAAK,KAAK,CAAA;AACzE,CAAC;;;;;;;;ACND,IAAIL,OAAO,GAAIG,OAAkB,CAAA;AACjC,IAAIC,QAAQ,GAAGD,QAAmB,CAAA;IAGlCL,UAAc,GAAGQ,gBAAgB,CAAA;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAgBA,CAACC,GAAG,EAAEC,OAAO,EAAE;AACtC,EAAA,IAAI,EAAE,IAAI,YAAYF,gBAAgB,CAAC,EAAE;AACvC,IAAA,IAAI,OAAOE,OAAO,KAAK,QAAQ,EAAE;MAC/B,OAAQ,IAAIF,gBAAgB,CAACC,GAAG,CAAC,CAAEE,SAAS,CAACD,OAAO,CAAC,CAAA;AACvD,KAAA;AACA,IAAA,OAAO,IAAIF,gBAAgB,CAACC,GAAG,EAAEC,OAAO,CAAC,CAAA;AAC3C,GAAA;AAEA,EAAA,IAAI,CAACD,GAAG,GAAGA,GAAG,IAAI,E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_ignoreList":[0,1,2]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supports the following syntaxes:
|
|
3
|
+
*
|
|
4
|
+
* const Foo = [GLIMMER_TEMPLATE('hello')];
|
|
5
|
+
*
|
|
6
|
+
* export const Foo = [GLIMMER_TEMPLATE('hello')];
|
|
7
|
+
*
|
|
8
|
+
* export default [GLIMMER_TEMPLATE('hello')];
|
|
9
|
+
*
|
|
10
|
+
* class Foo {
|
|
11
|
+
* [GLIMMER_TEMPLATE('hello')];
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
declare const transformTemplateTag: (t: any, templatePath: any, state: any) => void;
|
|
15
|
+
export { transformTemplateTag };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { buildPrecompileTemplateCall, registerRefs, TEMPLATE_TAG_NAME } from './util.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supports the following syntaxes:
|
|
5
|
+
*
|
|
6
|
+
* const Foo = [GLIMMER_TEMPLATE('hello')];
|
|
7
|
+
*
|
|
8
|
+
* export const Foo = [GLIMMER_TEMPLATE('hello')];
|
|
9
|
+
*
|
|
10
|
+
* export default [GLIMMER_TEMPLATE('hello')];
|
|
11
|
+
*
|
|
12
|
+
* class Foo {
|
|
13
|
+
* [GLIMMER_TEMPLATE('hello')];
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
const transformTemplateTag = function (t, templatePath, state) {
|
|
17
|
+
let compiled = buildPrecompileTemplateCall(t, templatePath, state);
|
|
18
|
+
let path = templatePath.parentPath;
|
|
19
|
+
if (path.type === 'ArrayExpression') {
|
|
20
|
+
let arrayParentPath = path.parentPath;
|
|
21
|
+
let varId = arrayParentPath.node.id || path.scope.generateUidIdentifier(templatePath);
|
|
22
|
+
const templateOnlyComponentExpression = t.callExpression(buildSetComponentTemplate(path, state), [compiled, t.callExpression(state.importUtil.import(templatePath, '@ember/component/template-only', 'default', 'templateOnly'), [t.stringLiteral('dynamic-runtime-file.js'), t.stringLiteral(varId.name)])]);
|
|
23
|
+
if (arrayParentPath.type === 'ExpressionStatement' && arrayParentPath.parentPath.type === 'Program') {
|
|
24
|
+
registerRefs(arrayParentPath.replaceWith(t.exportDefaultDeclaration(templateOnlyComponentExpression)), newPath => [newPath.get('declaration.callee'), newPath.get('declaration.arguments.0.callee'), newPath.get('declaration.arguments.1.callee')]);
|
|
25
|
+
} else {
|
|
26
|
+
registerRefs(path.replaceWith(templateOnlyComponentExpression), newPath => [newPath.get('callee'), newPath.get('arguments.0.callee'), newPath.get('arguments.1.callee')]);
|
|
27
|
+
}
|
|
28
|
+
} else if (path.type === 'ClassProperty') {
|
|
29
|
+
let classPath = path.parentPath.parentPath;
|
|
30
|
+
if (classPath.node.type === 'ClassDeclaration') {
|
|
31
|
+
registerRefs(classPath.insertAfter(t.expressionStatement(t.callExpression(buildSetComponentTemplate(path, state), [compiled, classPath.node.id]))), newPath => [newPath.get('expression.callee'), newPath.get('expression.arguments.0.callee')]);
|
|
32
|
+
} else {
|
|
33
|
+
registerRefs(classPath.replaceWith(t.expressionStatement(t.callExpression(buildSetComponentTemplate(path, state), [compiled, classPath.node]))), newPath => [newPath.parentPath.get('callee'), newPath.parentPath.get('arguments.0.callee')]);
|
|
34
|
+
}
|
|
35
|
+
path.remove();
|
|
36
|
+
return;
|
|
37
|
+
} else {
|
|
38
|
+
throw path.buildCodeFrameError(`Attempted to use \`<${TEMPLATE_TAG_NAME}>\` to define a template in an unsupported way. Templates defined using this syntax must be:\n\n1. Assigned to a variable declaration OR\n2. The default export of a file OR\n2. In the top level of the file on their own (sugar for \`export default\`) OR\n4. Used directly within a named class body`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function buildSetComponentTemplate(path, state) {
|
|
42
|
+
return state.importUtil.import(path, '@ember/component', 'setComponentTemplate');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { transformTemplateTag };
|
|
46
|
+
//# sourceMappingURL=template-tag-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-tag-transform.js","sources":["../../../src/browser/eti/template-tag-transform.ts"],"sourcesContent":["import { buildPrecompileTemplateCall, registerRefs, TEMPLATE_TAG_NAME } from './util';\n\n/**\n * Supports the following syntaxes:\n *\n * const Foo = [GLIMMER_TEMPLATE('hello')];\n *\n * export const Foo = [GLIMMER_TEMPLATE('hello')];\n *\n * export default [GLIMMER_TEMPLATE('hello')];\n *\n * class Foo {\n * [GLIMMER_TEMPLATE('hello')];\n * }\n */\nexport const transformTemplateTag = function (t: any, templatePath: any, state: any) {\n let compiled = buildPrecompileTemplateCall(t, templatePath, state);\n let path = templatePath.parentPath;\n\n if (path.type === 'ArrayExpression') {\n let arrayParentPath = path.parentPath;\n let varId = arrayParentPath.node.id || path.scope.generateUidIdentifier(templatePath);\n\n const templateOnlyComponentExpression = t.callExpression(\n buildSetComponentTemplate(path, state),\n [\n compiled,\n t.callExpression(\n state.importUtil.import(\n templatePath,\n '@ember/component/template-only',\n 'default',\n 'templateOnly'\n ),\n [t.stringLiteral('dynamic-runtime-file.js'), t.stringLiteral(varId.name)]\n ),\n ]\n );\n\n if (\n arrayParentPath.type === 'ExpressionStatement' &&\n arrayParentPath.parentPath.type === 'Program'\n ) {\n registerRefs(\n arrayParentPath.replaceWith(t.exportDefaultDeclaration(templateOnlyComponentExpression)),\n (newPath: any) => [\n newPath.get('declaration.callee'),\n newPath.get('declaration.arguments.0.callee'),\n newPath.get('declaration.arguments.1.callee'),\n ]\n );\n } else {\n registerRefs(path.replaceWith(templateOnlyComponentExpression), (newPath: any) => [\n newPath.get('callee'),\n newPath.get('arguments.0.callee'),\n newPath.get('arguments.1.callee'),\n ]);\n }\n } else if (path.type === 'ClassProperty') {\n let classPath = path.parentPath.parentPath;\n\n if (classPath.node.type === 'ClassDeclaration') {\n registerRefs(\n classPath.insertAfter(\n t.expressionStatement(\n t.callExpression(buildSetComponentTemplate(path, state), [compiled, classPath.node.id])\n )\n ),\n (newPath: any) => [\n newPath.get('expression.callee'),\n newPath.get('expression.arguments.0.callee'),\n ]\n );\n } else {\n registerRefs(\n classPath.replaceWith(\n t.expressionStatement(\n t.callExpression(buildSetComponentTemplate(path, state), [compiled, classPath.node])\n )\n ),\n (newPath: any) => [\n newPath.parentPath.get('callee'),\n newPath.parentPath.get('arguments.0.callee'),\n ]\n );\n }\n\n path.remove();\n\n return;\n } else {\n throw path.buildCodeFrameError(\n `Attempted to use \\`<${TEMPLATE_TAG_NAME}>\\` to define a template in an unsupported way. Templates defined using this syntax must be:\\n\\n1. Assigned to a variable declaration OR\\n2. The default export of a file OR\\n2. In the top level of the file on their own (sugar for \\`export default\\`) OR\\n4. Used directly within a named class body`\n );\n }\n};\n\nfunction buildSetComponentTemplate(path: any, state: any) {\n return state.importUtil.import(path, '@ember/component', 'setComponentTemplate');\n}\n"],"names":["transformTemplateTag","t","templatePath","state","compiled","buildPrecompileTemplateCall","path","parentPath","type","arrayParentPath","varId","node","id","scope","generateUidIdentifier","templateOnlyComponentExpression","callExpression","buildSetComponentTemplate","importUtil","import","stringLiteral","name","registerRefs","replaceWith","exportDefaultDeclaration","newPath","get","classPath","insertAfter","expressionStatement","remove","buildCodeFrameError","TEMPLATE_TAG_NAME"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAG,UAAUC,CAAM,EAAEC,YAAiB,EAAEC,KAAU,EAAE;EACnF,IAAIC,QAAQ,GAAGC,2BAA2B,CAACJ,CAAC,EAAEC,YAAY,EAAEC,KAAK,CAAC,CAAA;AAClE,EAAA,IAAIG,IAAI,GAAGJ,YAAY,CAACK,UAAU,CAAA;AAElC,EAAA,IAAID,IAAI,CAACE,IAAI,KAAK,iBAAiB,EAAE;AACnC,IAAA,IAAIC,eAAe,GAAGH,IAAI,CAACC,UAAU,CAAA;AACrC,IAAA,IAAIG,KAAK,GAAGD,eAA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import { TemplateMatch } from "./parse-templates.js";
|
|
2
|
+
import { NodePath } from '@babel/traverse';
|
|
3
|
+
import { CallExpression } from '@babel/types';
|
|
4
|
+
import { ImportUtil } from 'babel-import-util';
|
|
5
|
+
declare const TEMPLATE_TAG_NAME = "template";
|
|
6
|
+
declare const TEMPLATE_TAG_PLACEHOLDER = "__GLIMMER_TEMPLATE";
|
|
7
|
+
declare function isTemplateTag(callExpressionPath: NodePath<CallExpression>): boolean;
|
|
8
|
+
declare function buildPrecompileTemplateCall(t: any, callExpressionPath: NodePath<CallExpression>, state: {
|
|
9
|
+
importUtil: ImportUtil;
|
|
10
|
+
}): CallExpression;
|
|
11
|
+
declare function registerRefs(newPath: string | string[], getRefPaths: (path: string) => NodePath[]): void;
|
|
12
|
+
declare function isSupportedScriptFileExtension(filePath: string): boolean;
|
|
13
|
+
declare function isStrictMode(templateInfo: TemplateMatch): boolean;
|
|
14
|
+
export { TEMPLATE_TAG_NAME, TEMPLATE_TAG_PLACEHOLDER, isTemplateTag, buildPrecompileTemplateCall, registerRefs, isSupportedScriptFileExtension, isStrictMode };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// const Greeting = <template>Hello</template>
|
|
2
|
+
const TEMPLATE_TAG_NAME = 'template';
|
|
3
|
+
const TEMPLATE_TAG_PLACEHOLDER = '__GLIMMER_TEMPLATE';
|
|
4
|
+
function isTemplateTag(callExpressionPath) {
|
|
5
|
+
const callee = callExpressionPath.get('callee');
|
|
6
|
+
return !Array.isArray(callee) && callee.isIdentifier() && callee.node.name === TEMPLATE_TAG_PLACEHOLDER;
|
|
7
|
+
}
|
|
8
|
+
function buildPrecompileTemplateCall(t, callExpressionPath, state) {
|
|
9
|
+
const callee = callExpressionPath.get('callee');
|
|
10
|
+
return t.callExpression(state.importUtil.import(callee, '@ember/template-compilation', 'precompileTemplate'), callExpressionPath.node.arguments);
|
|
11
|
+
}
|
|
12
|
+
function registerRefs(newPath, getRefPaths) {
|
|
13
|
+
if (Array.isArray(newPath)) {
|
|
14
|
+
if (newPath.length > 1) {
|
|
15
|
+
throw new Error('registerRefs is only meant to handle single node transformations. Received more than one path node.');
|
|
16
|
+
}
|
|
17
|
+
newPath = newPath[0];
|
|
18
|
+
}
|
|
19
|
+
const refPaths = getRefPaths(newPath);
|
|
20
|
+
for (const ref of refPaths) {
|
|
21
|
+
if (!ref.isIdentifier()) {
|
|
22
|
+
throw new Error('ember-template-imports internal assumption that refPath should of type identifier. Please open an issue.');
|
|
23
|
+
}
|
|
24
|
+
const binding = ref.scope.getBinding(ref.node.name);
|
|
25
|
+
if (binding !== undefined) {
|
|
26
|
+
binding.reference(ref);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const SUPPORTED_EXTENSIONS = ['.js', '.ts', '.gjs', '.gts'];
|
|
31
|
+
function isSupportedScriptFileExtension(filePath) {
|
|
32
|
+
return SUPPORTED_EXTENSIONS.some(ext => filePath.endsWith(ext));
|
|
33
|
+
}
|
|
34
|
+
function isStrictMode(templateInfo) {
|
|
35
|
+
return templateInfo.type === 'template-tag';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { TEMPLATE_TAG_NAME, TEMPLATE_TAG_PLACEHOLDER, buildPrecompileTemplateCall, isStrictMode, isSupportedScriptFileExtension, isTemplateTag, registerRefs };
|
|
39
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../../../src/browser/eti/util.ts"],"sourcesContent":["import type { TemplateMatch } from './parse-templates';\nimport type { NodePath } from '@babel/traverse';\nimport type { CallExpression } from '@babel/types';\nimport type { ImportUtil } from 'babel-import-util';\n\n// const Greeting = <template>Hello</template>\nexport const TEMPLATE_TAG_NAME = 'template';\nexport const TEMPLATE_TAG_PLACEHOLDER = '__GLIMMER_TEMPLATE';\n\nexport function isTemplateTag(callExpressionPath: NodePath<CallExpression>) {\n const callee = callExpressionPath.get('callee');\n\n return (\n !Array.isArray(callee) && callee.isIdentifier() && callee.node.name === TEMPLATE_TAG_PLACEHOLDER\n );\n}\n\nexport function buildPrecompileTemplateCall(\n t: any,\n callExpressionPath: NodePath<CallExpression>,\n state: {\n importUtil: ImportUtil;\n }\n): CallExpression {\n const callee = callExpressionPath.get('callee');\n\n return t.callExpression(\n state.importUtil.import(callee, '@ember/template-compilation', 'precompileTemplate'),\n callExpressionPath.node.arguments\n );\n}\n\nexport function registerRefs(\n newPath: string | string[],\n getRefPaths: (path: string) => NodePath[]\n) {\n if (Array.isArray(newPath)) {\n if (newPath.length > 1) {\n throw new Error(\n 'registerRefs is only meant to handle single node transformations. Received more than one path node.'\n );\n }\n\n newPath = newPath[0] as string;\n }\n\n const refPaths = getRefPaths(newPath);\n\n for (const ref of refPaths) {\n if (!ref.isIdentifier()) {\n throw new Error(\n 'ember-template-imports internal assumption that refPath should of type identifier. Please open an issue.'\n );\n }\n\n const binding = ref.scope.getBinding(ref.node.name);\n\n if (binding !== undefined) {\n binding.reference(ref);\n }\n }\n}\n\nconst SUPPORTED_EXTENSIONS = ['.js', '.ts', '.gjs', '.gts'];\n\nexport function isSupportedScriptFileExtension(filePath: string) {\n return SUPPORTED_EXTENSIONS.some((ext) => filePath.endsWith(ext));\n}\n\nexport function isStrictMode(templateInfo: TemplateMatch): boolean {\n return templateInfo.type === 'template-tag';\n}\n"],"names":["TEMPLATE_TAG_NAME","TEMPLATE_TAG_PLACEHOLDER","isTemplateTag","callExpressionPath","callee","get","Array","isArray","isIdentifier","node","name","buildPrecompileTemplateCall","t","state","callExpression","importUtil","import","arguments","registerRefs","newPath","getRefPaths","length","Error","refPaths","ref","binding","scope","getBinding","undefined","reference","SUPPORTED_EXTENSIONS","isSupportedScriptFileExtension","filePath","some","ext","endsWith","isStrictMode","templateInfo","type"],"mappings":"AAKA;AACO,MAAMA,iBAAiB,GAAG,WAAU;AACpC,MAAMC,wBAAwB,GAAG,qBAAoB;AAErD,SAASC,aAAaA,CAACC,kBAA4C,EAAE;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Ie,OAAO,KAAKG,SAAS,EAAE;AACzBH,MAAAA,OAAO,CAACI,SAAS,CAACL,GAAG,CAAC,CAAA;AACxB,KAAA;AACF,GAAA;AACF,CAAA;AAEA,MAAMM,oBAAoB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAEpD,SAASC,8BAA8BA,CAACC,QAAgB,EAAE;AAC/D,EAAA,OAAOF,oBAAoB,CAACG,IAAI,CAAEC,GAAG,IAAKF,QAAQ,CAACG,QAAQ,CAACD,GAAG,CAAC,CAAC,CAAA;AACnE,CAAA;AAEO,SAASE,YAAYA,CAACC,YAA2B,EAAW;AACjE,EAAA,OAAOA,YAAY,CAACC,IAAI,KAAK,cAAc,CAAA;AAC7C;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { importSync } from '@embroider/macros';
|
|
2
|
+
import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';
|
|
3
|
+
import babelPluginIntermediateGJS from './eti/babel-plugin.js';
|
|
4
|
+
import { preprocessEmbeddedTemplates } from './eti/preprocess.js';
|
|
5
|
+
import { TEMPLATE_TAG_NAME, TEMPLATE_TAG_PLACEHOLDER } from './eti/util.js';
|
|
6
|
+
|
|
7
|
+
const compiler = importSync('ember-source/dist/ember-template-compiler.js');
|
|
8
|
+
function preprocess(input, name) {
|
|
9
|
+
let preprocessed = preprocessEmbeddedTemplates(input, {
|
|
10
|
+
relativePath: `${name}.js`,
|
|
11
|
+
includeSourceMaps: false,
|
|
12
|
+
includeTemplateTokens: true,
|
|
13
|
+
templateTag: TEMPLATE_TAG_NAME,
|
|
14
|
+
templateTagReplacement: TEMPLATE_TAG_PLACEHOLDER
|
|
15
|
+
});
|
|
16
|
+
return preprocessed.output;
|
|
17
|
+
}
|
|
18
|
+
async function transform(intermediate, name, options = {}) {
|
|
19
|
+
let babel = await import('@babel/standalone');
|
|
20
|
+
return babel.transform(intermediate, {
|
|
21
|
+
filename: `${name}.js`,
|
|
22
|
+
plugins: [[babelPluginIntermediateGJS], [babelPluginEmberTemplateCompilation, {
|
|
23
|
+
compiler
|
|
24
|
+
}], [babel.availablePlugins['proposal-decorators'], {
|
|
25
|
+
legacy: true
|
|
26
|
+
}], [babel.availablePlugins['proposal-class-properties']]],
|
|
27
|
+
presets: [[babel.availablePresets['env'], {
|
|
28
|
+
// false -- keeps ES Modules
|
|
29
|
+
modules: 'cjs',
|
|
30
|
+
targets: {
|
|
31
|
+
esmodules: true
|
|
32
|
+
},
|
|
33
|
+
forceAllTransforms: false,
|
|
34
|
+
...options
|
|
35
|
+
}]]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { preprocess, transform };
|
|
40
|
+
//# sourceMappingURL=gjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gjs.js","sources":["../../src/browser/gjs.ts"],"sourcesContent":["import { importSync } from '@embroider/macros';\n\nimport babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';\n\n// TODO: use real packages, and not these copied files from ember-template-imports\nimport babelPluginIntermediateGJS from './eti/babel-plugin';\nimport { preprocessEmbeddedTemplates } from './eti/preprocess';\nimport { TEMPLATE_TAG_NAME, TEMPLATE_TAG_PLACEHOLDER } from './eti/util';\n\nimport type { Babel } from './types';\n\nconst compiler = importSync('ember-source/dist/ember-template-compiler.js');\n\nexport function preprocess(input: string, name: string) {\n let preprocessed = preprocessEmbeddedTemplates(input, {\n relativePath: `${name}.js`,\n includeSourceMaps: false,\n includeTemplateTokens: true,\n templateTag: TEMPLATE_TAG_NAME,\n templateTagReplacement: TEMPLATE_TAG_PLACEHOLDER,\n });\n\n return preprocessed.output;\n}\n\nexport async function transform(\n intermediate: string,\n name: string,\n options: any = {}\n): Promise<ReturnType<Babel['transform']>> {\n let babel = (await import('@babel/standalone')) as Babel;\n\n return babel.transform(intermediate, {\n filename: `${name}.js`,\n plugins: [\n [babelPluginIntermediateGJS],\n [\n babelPluginEmberTemplateCompilation,\n {\n compiler,\n },\n ],\n [babel.availablePlugins['proposal-decorators'], { legacy: true }],\n [babel.availablePlugins['proposal-class-properties']],\n ],\n presets: [\n [\n babel.availablePresets['env'],\n {\n // false -- keeps ES Modules\n modules: 'cjs',\n targets: { esmodules: true },\n forceAllTransforms: false,\n ...options,\n },\n ],\n ],\n });\n}\n"],"names":["compiler","importSync","preprocess","input","name","preprocessed","preprocessEmbeddedTemplates","relativePath","includeSourceMaps","includeTemplateTokens","templateTag","TEMPLATE_TAG_NAME","templateTagReplacement","TEMPLATE_TAG_PLACEHOLDER","output","transform","intermediate","options","babel","filename","plugins","babelPluginIntermediateGJS","babelPluginEmberTemplateCompilation","availablePlugins","legacy","presets","availablePresets","modules","targets","esmodules","forceAllTransforms"],"mappings":";;;;;;AAWA,MAAMA,QAAQ,GAAGC,UAAU,CAAC,8CAA8C,CAAC,CAAA;AAEpE,SAASC,UAAUA,CAACC,KAAa,EAAEC,IAAY,EAAE;AACtD,EAAA,IAAIC,YAAY,GAAGC,2BAA2B,CAACH,KAAK,EAAE;IACpDI,YAAY,EAAG,CAAEH,EAAAA,IAAK,CAAI,GAAA,CAAA;AAC1BI,IAAAA,iBAAiB,EAAE,KAAK;AACxBC,IAAAA,qBAAqB,EAAE,IAAI;AAC3BC,IAAAA,WAAW,EAAEC,iBAAiB;AAC9BC,IAAAA,sBAAsB,EAAEC,wBAAAA;AAC1B,GAAC,CAAC,CAAA;EAEF,OAAOR,YAAY,CAACS,MAAM,CAAA;AAC5B,CAAA;AAEO,eAAeC,SAASA,CAC7BC,YAAoB,EACpBZ,IAAY,EACZa,OAAY,GAAG,EAAE,EACwB;AACzC,EAAA,IAAIC,KAAK,GAAI,MAAM,OAAO,mBAAmB,CAAW,CAAA;AAExD,EAAA,OAAOA,KAAK,CAACH,SAAS,CAACC,YAAY,EAAE;IACnCG,QAAQ,EAAG,CAAEf,EAAAA,IAAK,CAAI,GAAA,CAAA;IACtBgB,OAAO,EAAE,CACP,CAACC,0BAA0B,CAAC,EAC5B,CACEC,mCAAmC,EACnC;AACEtB,MAAAA,QAAAA;KACD,CACF,EACD,CAACkB,KAAK,CAACK,gBAAgB,CAAC,qBAAqB,CAAC,EAAE;AAAEC,MAAAA,MAAM,EAAE,IAAA;KAAM,CAAC,EACjE,CAACN,KAAK,CAACK,gBAAgB,CAAC,2BAA2B,CAAC,CAAC,CACtD;IACDE,OAAO,EAAE,CACP,CACEP,KAAK,CAACQ,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,16 +1,16 @@
|
|
|
1
|
+
import { CompileResult } from "./types.js";
|
|
1
2
|
/**
|
|
2
3
|
* compile a template with an empty scope
|
|
3
4
|
* to use components, helpers, etc, you will need to compile with JS
|
|
4
5
|
*
|
|
5
6
|
* (templates alone do not have a way to import / define complex structures)
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
name: string;
|
|
9
|
-
component: unknown;
|
|
10
|
-
error: Error | undefined;
|
|
11
|
-
};
|
|
8
|
+
declare function compileHBS(template: string, options?: CompileTemplateOptions): CompileResult;
|
|
12
9
|
interface CompileTemplateOptions {
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Used for debug viewing
|
|
12
|
+
*/
|
|
13
|
+
moduleName?: string;
|
|
14
14
|
scope?: Record<string, unknown>;
|
|
15
15
|
}
|
|
16
|
-
export {};
|
|
16
|
+
export { compileHBS };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { setComponentTemplate } from '@ember/component';
|
|
2
|
+
import _TO from '@ember/component/template-only';
|
|
3
|
+
import { array, concat, fn, get, hash } from '@ember/helper';
|
|
4
|
+
import { on } from '@ember/modifier';
|
|
5
|
+
import { createTemplateFactory } from '@ember/template-factory';
|
|
6
|
+
import { importSync } from '@embroider/macros';
|
|
7
|
+
import { nameFor } from './utils.js';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
+
// These things are pre-bundled in the old system.
|
|
11
|
+
// ember-template-compiler defines them in AMD/requirejs
|
|
12
|
+
const {
|
|
13
|
+
precompileJSON
|
|
14
|
+
} = importSync('@glimmer/compiler');
|
|
15
|
+
const {
|
|
16
|
+
getTemplateLocals
|
|
17
|
+
} = importSync('@glimmer/syntax');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* compile a template with an empty scope
|
|
21
|
+
* to use components, helpers, etc, you will need to compile with JS
|
|
22
|
+
*
|
|
23
|
+
* (templates alone do not have a way to import / define complex structures)
|
|
24
|
+
*/
|
|
25
|
+
function compileHBS(template, options = {}) {
|
|
26
|
+
let name = nameFor(template);
|
|
27
|
+
let component;
|
|
28
|
+
let error;
|
|
29
|
+
try {
|
|
30
|
+
component = setComponentTemplate(compileTemplate(template, {
|
|
31
|
+
moduleName: options.moduleName || name,
|
|
32
|
+
...options
|
|
33
|
+
}), _TO(options.moduleName || name));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
error = e;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
component,
|
|
40
|
+
error
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The reason why we can't use precompile directly is because of this:
|
|
45
|
+
* https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132
|
|
46
|
+
*
|
|
47
|
+
* Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.
|
|
48
|
+
* That JSON.stringify (and the lines after) prevent us from easily setting the scope function,
|
|
49
|
+
* which means that *everything* is undefined.
|
|
50
|
+
*/
|
|
51
|
+
function compileTemplate(source, {
|
|
52
|
+
moduleName,
|
|
53
|
+
scope = {}
|
|
54
|
+
}) {
|
|
55
|
+
let localScope = {
|
|
56
|
+
array,
|
|
57
|
+
concat,
|
|
58
|
+
fn,
|
|
59
|
+
get,
|
|
60
|
+
hash,
|
|
61
|
+
on,
|
|
62
|
+
...scope
|
|
63
|
+
};
|
|
64
|
+
let locals = getTemplateLocals(source);
|
|
65
|
+
let options = {
|
|
66
|
+
strictMode: true,
|
|
67
|
+
moduleName,
|
|
68
|
+
locals,
|
|
69
|
+
isProduction: false,
|
|
70
|
+
meta: {
|
|
71
|
+
moduleName
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Copied from @glimmer/compiler/lib/compiler#precompile
|
|
76
|
+
let [block, usedLocals] = precompileJSON(source, options);
|
|
77
|
+
let usedScope = usedLocals.map(key => localScope[key]);
|
|
78
|
+
let blockJSON = JSON.stringify(block);
|
|
79
|
+
let templateJSONObject = {
|
|
80
|
+
id: moduleName,
|
|
81
|
+
block: blockJSON,
|
|
82
|
+
moduleName: moduleName ?? '(unknown template module)',
|
|
83
|
+
scope: () => usedScope,
|
|
84
|
+
isStrictMode: true
|
|
85
|
+
};
|
|
86
|
+
let factory = createTemplateFactory(templateJSONObject);
|
|
87
|
+
return factory;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { compileHBS };
|
|
91
|
+
//# sourceMappingURL=hbs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hbs.js","sources":["../../src/browser/hbs.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// import { precompileJSON } from '@glimmer/compiler';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { setComponentTemplate } from '@ember/component';\nimport templateOnlyComponent from '@ember/component/template-only';\nimport { array, concat, fn, get, hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport { importSync } from '@embroider/macros';\n\nimport { nameFor } from './utils';\n\nimport type { CompileResult } from './types';\nimport type { ComponentLike } from '@glint/template';\n\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nconst { precompileJSON } = importSync('@glimmer/compiler') as any;\nconst { getTemplateLocals } = importSync('@glimmer/syntax') as any;\n\n/**\n * compile a template with an empty scope\n * to use components, helpers, etc, you will need to compile with JS\n *\n * (templates alone do not have a way to import / define complex structures)\n */\nexport function compileHBS(template: string, options: CompileTemplateOptions = {}): CompileResult {\n let name = nameFor(template);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n component = setComponentTemplate(\n compileTemplate(template, { moduleName: options.moduleName || name, ...options }),\n templateOnlyComponent(options.moduleName || name)\n ) as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\ninterface CompileTemplateOptions {\n /**\n * Used for debug viewing\n */\n moduleName?: string;\n scope?: Record<string, unknown>;\n}\n\n/**\n * The reason why we can't use precompile directly is because of this:\n * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132\n *\n * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.\n * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,\n * which means that *everything* is undefined.\n */\nfunction compileTemplate(source: string, { moduleName, scope = {} }: CompileTemplateOptions) {\n let localScope = { array, concat, fn, get, hash, on, ...scope } as any;\n let locals = getTemplateLocals(source);\n\n let options = {\n strictMode: true,\n moduleName,\n locals,\n isProduction: false,\n meta: { moduleName },\n };\n\n // Copied from @glimmer/compiler/lib/compiler#precompile\n let [block, usedLocals] = precompileJSON(source, options);\n\n let usedScope = usedLocals.map((key: string) => localScope[key]);\n\n let blockJSON = JSON.stringify(block);\n let templateJSONObject = {\n id: moduleName,\n block: blockJSON,\n moduleName: moduleName ?? '(unknown template module)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n let factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["precompileJSON","importSync","getTemplateLocals","compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","strictMode","isProduction","meta","block","usedLocals","usedScope","map","key","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;AAAA;AAkBA;AACA;AACA,MAAM;AAAEA,EAAAA,cAAAA;AAAe,CAAC,GAAGC,UAAU,CAAC,mBAAmB,CAAQ,CAAA;AACjE,MAAM;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,GAAGD,UAAU,CAAC,iBAAiB,CAAQ,CAAA;;AAElE;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,UAAUA,CAACC,QAAgB,EAAEC,OAA+B,GAAG,EAAE,EAAiB;AAChG,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,QAAQ,CAAC,CAAA;AAC5B,EAAA,IAAII,SAAoC,CAAA;AACxC,EAAA,IAAIC,KAAwB,CAAA;EAE5B,IAAI;AACFD,IAAAA,SAAS,GAAGE,oBAAoB,CAC9BC,eAAe,CAACP,QAAQ,EAAE;AAAEQ,MAAAA,UAAU,EAAEP,OAAO,CAACO,UAAU,IAAIN,IAAI;MAAE,GAAGD,OAAAA;KAAS,CAAC,EACjFQ,GAAqB,CAACR,OAAO,CAACO,UAAU,IAAIN,IAAI,CAClD,CAAkB,CAAA;GACnB,CAAC,OAAOQ,CAAC,EAAE;AACVL,IAAAA,KAAK,GAAGK,CAAsB,CAAA;AAChC,GAAA;EAEA,OAAO;IAAER,IAAI;IAAEE,SAAS;AAAEC,IAAAA,KAAAA;GAAO,CAAA;AACnC,CAAA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAeA,CAACI,MAAc,EAAE;EAAEH,UAAU;AAAEI,EAAAA,KAAK,GAAG,EAAC;AAA0B,CAAC,EAAE;AAC3F,EAAA,IAAIC,UAAU,GAAG;IAAEC,KAAK;IAAEC,MAAM;IAAEC,EAAE;IAAEC,GAAG;IAAEC,IAAI;IAAEC,EAAE;IAAE,GAAGP,KAAAA;GAAc,CAAA;AACtE,EAAA,IAAIQ,MAAM,GAAGtB,iBAAiB,CAACa,MAAM,CAAC,CAAA;AAEtC,EAAA,IAAIV,OAAO,GAAG;AACZoB,IAAAA,UAAU,EAAE,IAAI;IAChBb,UAAU;IACVY,MAAM;AACNE,IAAAA,YAAY,EAAE,KAAK;AACnBC,IAAAA,IAAI,EAAE;AAAEf,MAAAA,UAAAA;AAAW,KAAA;GACpB,CAAA;;AAED;EACA,IAAI,CAACgB,KAAK,EAAEC,UAAU,CAAC,GAAG7B,cAAc,CAACe,MAAM,EAAEV,OAAO,CAAC,CAAA;AAEzD,EAAA,IAAIyB,SAAS,GAAGD,UAAU,CAACE,GAAG,CAAEC,GAAW,IAAKf,UAAU,CAACe,GAAG,CAAC,CAAC,CAAA;AAEhE,EAAA,IAAIC,SAAS,GAAGC,IAAI,CAACC,SAAS,CAACP,KAAK,CAAC,CAAA;AACrC,EAAA,IAAIQ,kBAAkB,GAAG;AACvBC,IAAAA,EAAE,EAAEzB,UAAU;AACdgB,IAAAA,KAAK,EAAEK,SAAS;IAChBrB,UAAU,EAAEA,UAAU,IAAI,2BAA2B;IACrDI,KAAK,EAAEA,MAAMc,SAAS;AACtBQ,IAAAA,YAAY,EAAE,IAAA;GACf,CAAA;AAED,EAAA,IAAIC,OAAO,GAAGC,qBAAqB,CAACJ,kBAAkB,CAAC,CAAA;AAEvD,EAAA,OAAOG,OAAO,CAAA;AAChB;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { compile, Compiled } from "./compile/index.js";
|
|
2
|
+
export { compileHBS } from "./hbs.js";
|
|
3
|
+
export { compileJS } from "./js.js";
|
|
4
|
+
export { modules as frameworkModules } from "./known-modules.js";
|
|
5
|
+
export { invocationName, invocationOf, nameFor } from "./utils.js";
|
|
6
|
+
export type { CompileResult } from "./types.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Compiled, compile } from './compile/index.js';
|
|
2
|
+
export { compileHBS } from './hbs.js';
|
|
3
|
+
export { compileJS } from './js.js';
|
|
4
|
+
export { modules as frameworkModules } from './known-modules.js';
|
|
5
|
+
export { invocationName, invocationOf, nameFor } from './utils.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CompileResult, ExtraModules, Options } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
* Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.
|
|
@@ -16,8 +16,5 @@ import type { ExtraModules, Options } from './types';
|
|
|
16
16
|
* are not provided by extraModules will be searched on npm to see if a package
|
|
17
17
|
* needs to be downloaded before running the `code` / invoking the component
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
component: unknown;
|
|
22
|
-
error: Error | undefined;
|
|
23
|
-
}>;
|
|
19
|
+
declare function compileJS(code: string, extraModules?: ExtraModules, options?: Options): Promise<CompileResult>;
|
|
20
|
+
export { compileJS };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { compileJS as compileJS$2 } from './cjs/index.js';
|
|
2
|
+
import { compileJS as compileJS$1 } from './esm/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
* Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.
|
|
7
|
+
* The returned component can be invoked explicitly in the consuming project.
|
|
8
|
+
*
|
|
9
|
+
* SEE: README for example usage
|
|
10
|
+
*
|
|
11
|
+
* @param {string} code: the code to be compiled
|
|
12
|
+
* @param {Object} extraModules: map of import paths to modules. This isn't needed
|
|
13
|
+
* for classic ember projects, but for strict static ember projects, extraModules
|
|
14
|
+
* will need to be pasesd if compileJS is intended to be used in a styleguide or
|
|
15
|
+
* if there are additional modules that could be imported in the passed `code`.
|
|
16
|
+
*
|
|
17
|
+
* Later on, imports that are not present by default (ember/glimmer) or that
|
|
18
|
+
* are not provided by extraModules will be searched on npm to see if a package
|
|
19
|
+
* needs to be downloaded before running the `code` / invoking the component
|
|
20
|
+
*/
|
|
21
|
+
function compileJS(code, extraModules, options) {
|
|
22
|
+
if (options?.skypack) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
// if (!(window as any).webpackChunkDummy) {
|
|
25
|
+
// return {
|
|
26
|
+
// component: undefined,
|
|
27
|
+
// name: undefined,
|
|
28
|
+
// error: `Your environment is using AMD utilities -- using native ESM is not allowed unless the environment is also ESM`,
|
|
29
|
+
// };
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
return compileJS$1(code, extraModules);
|
|
33
|
+
}
|
|
34
|
+
return compileJS$2(code, extraModules);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { compileJS };
|
|
38
|
+
//# sourceMappingURL=js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js.js","sources":["../../src/browser/js.ts"],"sourcesContent":["import { compileJS as compileAMD } from './cjs';\nimport { compileJS as compileESM } from './esm';\n\nimport type { CompileResult, ExtraModules, Options } from './types';\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 function compileJS(\n code: string,\n extraModules?: ExtraModules,\n options?: Options\n): Promise<CompileResult> {\n if (options?.skypack) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n // if (!(window as any).webpackChunkDummy) {\n // return {\n // component: undefined,\n // name: undefined,\n // error: `Your environment is using AMD utilities -- using native ESM is not allowed unless the environment is also ESM`,\n // };\n // }\n\n return compileESM(code, extraModules);\n }\n\n return compileAMD(code, extraModules);\n}\n"],"names":["compileJS","code","extraModules","options","skypack","compileESM","compileAMD"],"mappings":";;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,SAASA,CACvBC,IAAY,EACZC,YAA2B,EAC3BC,OAAiB,EACO;EACxB,IAAIA,OAAO,EAAEC,OAAO,EAAE;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAA,OAAOC,WAAU,CAACJ,IAAI,EAAEC,YAAY,CAAC,CAAA;AACvC,GAAA;AAEA,EAAA,OAAOI,WAAU,CAACL,IAAI,EAAEC,YAAY,CAAC,CAAA;AACvC;;;;"}
|
|
@@ -10,24 +10,24 @@ import * as _EmberComponent from '@ember/component';
|
|
|
10
10
|
import _TO from '@ember/component/template-only';
|
|
11
11
|
import * as _debug from '@ember/debug';
|
|
12
12
|
import * as _destroyable from '@ember/destroyable';
|
|
13
|
+
import * as _helpers from '@ember/helper';
|
|
14
|
+
import * as _modifier from '@ember/modifier';
|
|
13
15
|
import * as _object from '@ember/object';
|
|
14
16
|
import * as _runloop from '@ember/runloop';
|
|
15
17
|
import * as _service from '@ember/service';
|
|
16
|
-
import * as _string from '@ember/string';
|
|
17
18
|
import * as _utils from '@ember/utils';
|
|
18
|
-
|
|
19
|
+
declare const modules: {
|
|
19
20
|
'@ember/application': typeof _application;
|
|
20
21
|
'@ember/array': typeof _array;
|
|
21
22
|
'@ember/component': typeof _EmberComponent;
|
|
22
23
|
'@ember/component/template-only': typeof _TO;
|
|
23
24
|
'@ember/debug': typeof _debug;
|
|
24
25
|
'@ember/destroyable': typeof _destroyable;
|
|
25
|
-
'@ember/helper':
|
|
26
|
-
'@ember/modifier':
|
|
26
|
+
'@ember/helper': typeof _helpers;
|
|
27
|
+
'@ember/modifier': typeof _modifier;
|
|
27
28
|
'@ember/object': typeof _object;
|
|
28
29
|
'@ember/runloop': typeof _runloop;
|
|
29
30
|
'@ember/service': typeof _service;
|
|
30
|
-
'@ember/string': typeof _string;
|
|
31
31
|
'@ember/template-factory': {
|
|
32
32
|
createTemplateFactory: any;
|
|
33
33
|
};
|
|
@@ -35,3 +35,4 @@ export declare const modules: {
|
|
|
35
35
|
'@glimmer/component': typeof _GlimmerComponent;
|
|
36
36
|
'@glimmer/tracking': typeof _tracking;
|
|
37
37
|
};
|
|
38
|
+
export { modules };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _GlimmerComponent from '@glimmer/component';
|
|
2
|
+
import * as _tracking from '@glimmer/tracking';
|
|
3
|
+
import * as _application from '@ember/application';
|
|
4
|
+
import * as _array from '@ember/array';
|
|
5
|
+
import * as _EmberComponent from '@ember/component';
|
|
6
|
+
import _TO from '@ember/component/template-only';
|
|
7
|
+
import * as _debug from '@ember/debug';
|
|
8
|
+
import * as _destroyable from '@ember/destroyable';
|
|
9
|
+
import * as _helpers from '@ember/helper';
|
|
10
|
+
import * as _modifier from '@ember/modifier';
|
|
11
|
+
import * as _object from '@ember/object';
|
|
12
|
+
import * as _runloop from '@ember/runloop';
|
|
13
|
+
import * as _service from '@ember/service';
|
|
14
|
+
import { createTemplateFactory } from '@ember/template-factory';
|
|
15
|
+
import * as _utils from '@ember/utils';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* We need to import and hang on to these references so that they
|
|
19
|
+
* don't get optimized away during deploy
|
|
20
|
+
*/
|
|
21
|
+
// import * as _owner from '@ember/owner';
|
|
22
|
+
|
|
23
|
+
const modules = {
|
|
24
|
+
'@ember/application': _application,
|
|
25
|
+
'@ember/array': _array,
|
|
26
|
+
'@ember/component': _EmberComponent,
|
|
27
|
+
'@ember/component/template-only': _TO,
|
|
28
|
+
'@ember/debug': _debug,
|
|
29
|
+
'@ember/destroyable': _destroyable,
|
|
30
|
+
'@ember/helper': _helpers,
|
|
31
|
+
'@ember/modifier': _modifier,
|
|
32
|
+
'@ember/object': _object,
|
|
33
|
+
'@ember/runloop': _runloop,
|
|
34
|
+
'@ember/service': _service,
|
|
35
|
+
'@ember/template-factory': {
|
|
36
|
+
createTemplateFactory
|
|
37
|
+
},
|
|
38
|
+
'@ember/utils': _utils,
|
|
39
|
+
// '@ember/owner': _owner,
|
|
40
|
+
|
|
41
|
+
'@glimmer/component': _GlimmerComponent,
|
|
42
|
+
'@glimmer/tracking': _tracking
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { modules };
|
|
46
|
+
//# sourceMappingURL=known-modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-modules.js","sources":["../../src/browser/known-modules.ts"],"sourcesContent":["/**\n * We need to import and hang on to these references so that they\n * don't get optimized away during deploy\n */\nimport _GlimmerComponent from '@glimmer/component';\nimport * as _tracking from '@glimmer/tracking';\nimport * as _application from '@ember/application';\nimport * as _array from '@ember/array';\nimport * as _EmberComponent from '@ember/component';\nimport _TO from '@ember/component/template-only';\nimport * as _debug from '@ember/debug';\nimport * as _destroyable from '@ember/destroyable';\nimport * as _helpers from '@ember/helper';\nimport * as _modifier from '@ember/modifier';\nimport * as _object from '@ember/object';\nimport * as _runloop from '@ember/runloop';\nimport * as _service from '@ember/service';\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// import * as _owner from '@ember/owner';\n\nexport const modules = {\n '@ember/application': _application,\n '@ember/array': _array,\n '@ember/component': _EmberComponent,\n '@ember/component/template-only': _TO,\n '@ember/debug': _debug,\n '@ember/destroyable': _destroyable,\n '@ember/helper': _helpers,\n '@ember/modifier': _modifier,\n '@ember/object': _object,\n '@ember/runloop': _runloop,\n '@ember/service': _service,\n '@ember/template-factory': { createTemplateFactory },\n '@ember/utils': _utils,\n // '@ember/owner': _owner,\n\n '@glimmer/component': _GlimmerComponent,\n '@glimmer/tracking': _tracking,\n};\n"],"names":["modules","_application","_array","_EmberComponent","_TO","_debug","_destroyable","_helpers","_modifier","_object","_runloop","_service","createTemplateFactory","_utils","_GlimmerComponent","_tracking"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAkBA;;AAEO,MAAMA,OAAO,GAAG;AACrB,EAAA,oBAAoB,EAAEC,YAAY;AAClC,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,kBAAkB,EAAEC,eAAe;AACnC,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;;AAEA,EAAA,oBAAoB,EAAEC,iBAAiB;AACvC,EAAA,mBAAmB,EAAEC,SAAAA;AACvB;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { availablePlugins, availablePresets, transform } from '@babel/standalone';
|
|
2
|
+
import { ComponentLike } from '@glint/template';
|
|
3
|
+
interface CompileResult {
|
|
4
|
+
component?: ComponentLike;
|
|
5
|
+
error?: Error;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
interface Babel {
|
|
9
|
+
availablePlugins: typeof availablePlugins;
|
|
10
|
+
availablePresets: typeof availablePresets;
|
|
11
|
+
transform: typeof transform;
|
|
12
|
+
}
|
|
13
|
+
type Options = {
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
* @deprecated do not use - not under semver
|
|
17
|
+
*/
|
|
18
|
+
skypack?: boolean;
|
|
19
|
+
};
|
|
20
|
+
type ExtraModules = Record<string, unknown>;
|
|
21
|
+
export { CompileResult, Babel, Options, ExtraModules };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
* This can help with cacheing previously compiled components,
|
|
5
5
|
* and generally allowing a consumer to derive "known references" to user-input
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
declare function nameFor(code: string, prefix?: string): string;
|
|
8
8
|
/**
|
|
9
9
|
* Returns the text for invoking a component with a given name.
|
|
10
10
|
* It is assumed the component takes no arguments, as would be the
|
|
11
11
|
* case in REPLs / Playgrounds for the "root" component.
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
declare function invocationOf(name: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)
|
|
16
|
+
* inflection does not support hyphens
|
|
17
|
+
*/
|
|
18
|
+
declare function invocationName(name: string): string;
|
|
19
|
+
export { nameFor, invocationOf, invocationName };
|