ember-repl 2.0.62 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- 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/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 +271 -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} +3 -6
- package/dist/browser/hbs.js +94 -0
- package/dist/browser/hbs.js.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.js +5 -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 -3
- package/dist/browser/known-modules.js +48 -0
- package/dist/browser/known-modules.js.map +1 -0
- package/dist/browser/types.d.ts +17 -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/package.json +98 -125
- package/{addon → src/browser}/cjs/eval.ts +9 -5
- package/src/browser/cjs/index.ts +44 -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 +18 -6
- package/{addon → src/browser}/js.ts +6 -2
- package/{addon → src/browser}/known-modules.ts +4 -0
- package/{addon → src/browser}/types.ts +2 -1
- package/{addon → src/browser}/utils.ts +6 -2
- package/src/build/ember-cli.cjs +36 -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 -738
- 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
- /package/{addon → src/browser}/index.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-templates.js","sources":["../../../src/browser/eti/parse-templates.ts"],"sourcesContent":["import { expect } from './debug';\nimport { TEMPLATE_TAG_NAME } from './util';\n\nexport type TemplateMatch = TemplateTagMatch;\n\nexport interface TemplateTagMatch {\n type: 'template-tag';\n tagName: string;\n start: RegExpMatchArray;\n end: RegExpMatchArray;\n contents: string;\n}\n\n/**\n * Represents a static import of a template literal.\n */\nexport interface StaticImportConfig {\n /**\n * The path to the package from which we want to import the template literal\n * (e.g.: 'ember-cli-htmlbars')\n */\n importPath: string;\n /**\n * The name of the template literal (e.g.: 'hbs') or 'default' if this package\n * exports a default function\n */\n importIdentifier: string;\n}\n\n/**\n * The input options to instruct parseTemplates on how to parse the input.\n *\n * @param templateTag\n */\nexport interface ParseTemplatesOptions {\n /** Tag to use, if parsing template tags is enabled. */\n templateTag?: string;\n}\n\nconst escapeChar = '\\\\';\nconst stringDelimiter = /['\"]/;\n\nconst singleLineCommentStart = /\\/\\//;\nconst newLine = /\\n/;\nconst multiLineCommentStart = /\\/\\*/;\nconst multiLineCommentEnd = /\\*\\//;\n\nconst templateLiteralStart = /([$a-zA-Z_][0-9a-zA-Z_$]*)?`/;\nconst templateLiteralEnd = /`/;\n\nconst dynamicSegmentStart = /\\${/;\nconst blockStart = /{/;\nconst dynamicSegmentEnd = /}/;\n\nfunction isEscaped(template: string, _offset: number | undefined) {\n let offset = expect(_offset, 'Expected an index to check escaping');\n\n let count = 0;\n\n while (template[offset - 1] === escapeChar) {\n count++;\n offset--;\n }\n\n return count % 2 === 1;\n}\n\nexport const DEFAULT_PARSE_TEMPLATES_OPTIONS = {\n templateTag: TEMPLATE_TAG_NAME,\n};\n\n/**\n * Parses a template to find all possible valid matches for an embedded template.\n * Supported syntaxes are template literals:\n *\n * hbs`Hello, world!`\n *\n * And template tags\n *\n * <template></template>\n *\n * The parser excludes any values found within strings recursively, and also\n * excludes any string literals with dynamic segments (e.g `${}`) since these\n * cannot be valid templates.\n *\n * @param template The template to parse\n * @param relativePath Relative file path for the template (for errors)\n * @param options optional configuration options for how to parse templates\n * @returns\n */\nexport function parseTemplates(\n template: string,\n relativePath: string,\n options: ParseTemplatesOptions = DEFAULT_PARSE_TEMPLATES_OPTIONS\n): TemplateMatch[] {\n const results: TemplateMatch[] = [];\n const templateTag = options?.templateTag;\n\n const templateTagStart = new RegExp(`<${templateTag}[^<]*>`);\n const templateTagEnd = new RegExp(`</${templateTag}>`);\n const argumentsMatchRegex = new RegExp(`<${templateTag}[^<]*\\\\S[^<]*>`);\n\n const allTokens = new RegExp(\n [\n singleLineCommentStart.source,\n newLine.source,\n multiLineCommentStart.source,\n multiLineCommentEnd.source,\n stringDelimiter.source,\n templateLiteralStart.source,\n templateLiteralEnd.source,\n dynamicSegmentStart.source,\n dynamicSegmentEnd.source,\n blockStart.source,\n templateTagStart.source,\n templateTagEnd.source,\n ].join('|'),\n 'g'\n );\n\n const tokens = Array.from(template.matchAll(allTokens));\n\n while (tokens.length > 0) {\n const currentToken = tokens.shift()!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n\n parseToken(results, template, currentToken, tokens, true);\n }\n\n /**\n * Parse the current token. If top level, then template tags can be parsed.\n * Else, we are nested within a dynamic segment, which is currently unsupported.\n */\n function parseToken(\n results: TemplateMatch[],\n template: string,\n token: RegExpMatchArray,\n tokens: RegExpMatchArray[],\n isTopLevel = false\n ) {\n if (token[0].match(multiLineCommentStart)) {\n parseMultiLineComment(results, template, token, tokens);\n } else if (token[0].match(singleLineCommentStart)) {\n parseSingleLineComment(results, template, token, tokens);\n } else if (token[0].match(templateLiteralStart)) {\n parseTemplateLiteral(template, tokens);\n } else if (\n isTopLevel &&\n templateTag !== undefined &&\n templateTagStart &&\n token[0].match(templateTagStart)\n ) {\n parseTemplateTag(results, template, token, tokens, templateTag);\n } else if (token[0].match(stringDelimiter)) {\n parseString(results, template, token, tokens);\n }\n }\n\n /**\n * Parse a template literal. If a dynamic segment is found, enters the dynamic\n * segment and parses it recursively. If no dynamic segments are found and the\n * literal is top level (e.g. not nested within a dynamic segment) and has a\n * tag, pushes it into the list of results.\n */\n function parseTemplateLiteral(template: string, tokens: RegExpMatchArray[]) {\n while (tokens.length > 0) {\n let currentToken = expect(tokens.shift(), 'expected token');\n\n if (isEscaped(template, currentToken.index)) continue;\n\n if (currentToken[0].match(templateLiteralEnd)) {\n return;\n }\n }\n }\n\n /**\n * Parse a string. All tokens within a string are ignored\n * since there are no dynamic segments within these.\n */\n function parseString(\n _results: TemplateMatch[],\n template: string,\n startToken: RegExpMatchArray,\n tokens: RegExpMatchArray[]\n ) {\n while (tokens.length > 0) {\n const currentToken = expect(tokens.shift(), 'expected token');\n\n if (currentToken[0] === startToken[0] && !isEscaped(template, currentToken.index)) {\n return;\n }\n }\n }\n\n /**\n * Parse a single-line comment. All tokens within a single-line comment are ignored\n * since there are no dynamic segments within them.\n */\n function parseSingleLineComment(\n _results: TemplateMatch[],\n _template: string,\n _startToken: RegExpMatchArray,\n tokens: RegExpMatchArray[]\n ) {\n while (tokens.length > 0) {\n const currentToken = expect(tokens.shift(), 'expected token');\n\n if (currentToken[0] === '\\n') {\n return;\n }\n }\n }\n\n /**\n * Parse a multi-line comment. All tokens within a multi-line comment are ignored\n * since there are no dynamic segments within them.\n */\n function parseMultiLineComment(\n _results: TemplateMatch[],\n _template: string,\n _startToken: RegExpMatchArray,\n tokens: RegExpMatchArray[]\n ) {\n while (tokens.length > 0) {\n const currentToken = expect(tokens.shift(), 'expected token');\n\n if (currentToken[0] === '*/') {\n return;\n }\n }\n }\n\n /**\n * Parses a template tag. Continues parsing until the template tag has closed,\n * accounting for nested template tags.\n */\n function parseTemplateTag(\n results: TemplateMatch[],\n _template: string,\n startToken: RegExpMatchArray,\n tokens: RegExpMatchArray[],\n templateTag: string\n ) {\n let stack = 1;\n\n if (argumentsMatchRegex && startToken[0].match(argumentsMatchRegex)) {\n throw new Error(\n `embedded template preprocessing currently does not support passing arguments, found args in: ${relativePath}`\n );\n }\n\n while (tokens.length > 0) {\n const currentToken = expect(tokens.shift(), 'expected token');\n\n if (currentToken[0].match(templateTagStart)) {\n stack++;\n } else if (currentToken[0].match(templateTagEnd)) {\n stack--;\n }\n\n if (stack === 0) {\n let contents = '';\n\n if (startToken.index !== undefined) {\n const templateStart = startToken.index + startToken[0].length;\n\n contents = template.slice(templateStart, currentToken.index);\n }\n\n results.push({\n type: 'template-tag',\n tagName: templateTag,\n contents: contents,\n start: startToken,\n end: currentToken,\n });\n\n return;\n }\n }\n }\n\n return results;\n}\n"],"names":["escapeChar","stringDelimiter","singleLineCommentStart","newLine","multiLineCommentStart","multiLineCommentEnd","templateLiteralStart","templateLiteralEnd","dynamicSegmentStart","blockStart","dynamicSegmentEnd","isEscaped","template","_offset","offset","expect","count","DEFAULT_PARSE_TEMPLATES_OPTIONS","templateTag","TEMPLATE_TAG_NAME","parseTemplates","relativePath","options","results","templateTagStart","RegExp","templateTagEnd","argumentsMatchRegex","allTokens","source","join","tokens","Array","from","matchAll","length","currentToken","shift","parseToken","token","isTopLevel","match","parseMultiLineComment","parseSingleLineComment","parseTemplateLiteral","undefined","parseTemplateTag","parseString","index","_results","startToken","_template","_startToken","stack","Error","contents","templateStart","slice","push","type","tagName","start","end"],"mappings":";;;AAaA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;;AAMA,MAAMA,UAAU,GAAG,IAAI,CAAA;AACvB,MAAMC,eAAe,GAAG,MAAM,CAAA;AAE9B,MAAMC,sBAAsB,GAAG,MAAM,CAAA;AACrC,MAAMC,OAAO,GAAG,IAAI,CAAA;AACpB,MAAMC,qBAAqB,GAAG,MAAM,CAAA;AACpC,MAAMC,mBAAmB,GAAG,MAAM,CAAA;AAElC,MAAMC,oBAAoB,GAAG,8BAA8B,CAAA;AAC3D,MAAMC,kBAAkB,GAAG,GAAG,CAAA;AAE9B,MAAMC,mBAAmB,GAAG,KAAK,CAAA;AACjC,MAA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OU,MAAM,CAACI,MAAM,GAAG,CAAC,EAAE;MACxB,MAAMC,YAAY,GAAGrB,MAAM,CAACgB,MAAM,CAACM,KAAK,EAAE,EAAE,gBAAgB,CAAC,CAAA;MAE7D,IAAID,YAAY,CAAC,CAAC,CAAC,CAACK,KAAK,CAACjB,gBAAgB,CAAC,EAAE;AAC3C6B,QAAAA,KAAK,EAAE,CAAA;OACR,MAAM,IAAIjB,YAAY,CAAC,CAAC,CAAC,CAACK,KAAK,CAACf,cAAc,CAAC,EAAE;AAChD2B,QAAAA,KAAK,EAAE,CAAA;AACT,OAAA;MAEA,IAAIA,KAAK,KAAK,CAAC,EAAE;QACf,IAAIE,QAAQ,GAAG,EAAE,CAAA;AAEjB,QAAA,IAAIL,UAAU,CAACF,KAAK,KAAKH,SAAS,EAAE;UAClC,MAAMW,aAAa,GAAGN,UAAU,CAACF,KAAK,GAAGE,UAAU,CAAC,CAAC,CAAC,CAACf,MAAM,CAAA;UAE7DoB,QAAQ,GAAG3C,QAAQ,CAAC6C,KAAK,CAACD,aAAa,EAAEpB,YAAY,CAACY,KAAK,CAAC,CAAA;AAC9D,SAAA;QAEAzB,OAAO,CAACmC,IAAI,CAAC;AACXC,UAAAA,IAAI,EAAE,cAAc;AACpBC,UAAAA,OAAO,EAAE1C,WAAW;AACpBqC,UAAAA,QAAQ,EAAEA,QAAQ;AAClBM,UAAAA,KAAK,EAAEX,UAAU;AACjBY,UAAAA,GAAG,EAAE1B,YAAAA;AACP,SAAC,CAAC,CAAA;AAEF,QAAA,OAAA;AACF,OAAA;AACF,KAAA;AACF,GAAA;AAEA,EAAA,OAAOb,OAAO,CAAA;AAChB;;;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface PreprocessOptionsEager {
|
|
2
|
+
importIdentifier?: string;
|
|
3
|
+
importPath?: string;
|
|
4
|
+
templateTag?: string;
|
|
5
|
+
templateTagReplacement?: string;
|
|
6
|
+
relativePath: string;
|
|
7
|
+
includeSourceMaps: boolean;
|
|
8
|
+
includeTemplateTokens: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface PreprocessOptionsLazy {
|
|
11
|
+
importIdentifier?: string;
|
|
12
|
+
importPath?: string;
|
|
13
|
+
templateTag?: string;
|
|
14
|
+
templateTagReplacement?: string;
|
|
15
|
+
relativePath: string;
|
|
16
|
+
includeSourceMaps: boolean;
|
|
17
|
+
includeTemplateTokens: boolean;
|
|
18
|
+
}
|
|
19
|
+
type PreprocessOptions = PreprocessOptionsLazy | PreprocessOptionsEager;
|
|
20
|
+
interface PreprocessedOutput {
|
|
21
|
+
output: string;
|
|
22
|
+
replacements: Replacement[];
|
|
23
|
+
}
|
|
24
|
+
interface Replacement {
|
|
25
|
+
type: 'start' | 'end';
|
|
26
|
+
index: number;
|
|
27
|
+
oldLength: number;
|
|
28
|
+
newLength: number;
|
|
29
|
+
originalLine: number;
|
|
30
|
+
originalCol: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Preprocesses all embedded templates within a JavaScript or TypeScript file.
|
|
34
|
+
* This function replaces all embedded templates that match our template syntax
|
|
35
|
+
* with valid, parseable JS. Optionally, it can also include a source map, and
|
|
36
|
+
* it can also include all possible values used within the template.
|
|
37
|
+
*
|
|
38
|
+
* Input:
|
|
39
|
+
*
|
|
40
|
+
* <template><MyComponent/><template>
|
|
41
|
+
*
|
|
42
|
+
* Output:
|
|
43
|
+
*
|
|
44
|
+
* [GLIMMER_TEMPLATE(`<MyComponent/>`, { scope() { return {MyComponent}; } })];
|
|
45
|
+
*
|
|
46
|
+
* It can also be used with template literals to provide the in scope values:
|
|
47
|
+
*
|
|
48
|
+
* Input:
|
|
49
|
+
*
|
|
50
|
+
* hbs`<MyComponent/>`;
|
|
51
|
+
*
|
|
52
|
+
* Output
|
|
53
|
+
*
|
|
54
|
+
* hbs(`<MyComponent/>`, { scope() { return {MyComponent}; } });
|
|
55
|
+
*/
|
|
56
|
+
declare function preprocessEmbeddedTemplates(template: string, options: PreprocessOptions): PreprocessedOutput;
|
|
57
|
+
export { preprocessEmbeddedTemplates };
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { getTemplateLocals } from '@glimmer/syntax';
|
|
2
|
+
import MagicString from 'magic-string';
|
|
3
|
+
import { expect } from './debug.js';
|
|
4
|
+
import { parseTemplates } from './parse-templates.js';
|
|
5
|
+
|
|
6
|
+
function getDefaultExportFromCjs (x) {
|
|
7
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
var toString = {}.toString;
|
|
11
|
+
var isarray = Array.isArray || function (arr) {
|
|
12
|
+
return toString.call(arr) == '[object Array]';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/*!
|
|
16
|
+
* isobject <https://github.com/jonschlinkert/isobject>
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2014-2015, Jon Schlinkert.
|
|
19
|
+
* Licensed under the MIT License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var isArray$1 = isarray;
|
|
23
|
+
var isobject = function isObject(val) {
|
|
24
|
+
return val != null && typeof val === 'object' && isArray$1(val) === false;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* line-column - Convert efficiently index to/from line-column in a string
|
|
29
|
+
* @module lineColumn
|
|
30
|
+
* @license MIT
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
var isArray = isarray;
|
|
34
|
+
var isObject = isobject;
|
|
35
|
+
var lineColumn = LineColumnFinder;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Finder for index and line-column from given string.
|
|
39
|
+
*
|
|
40
|
+
* You can call this without `new` operator as it returns an instance anyway.
|
|
41
|
+
*
|
|
42
|
+
* @class
|
|
43
|
+
* @param {string} str - A string to be parsed.
|
|
44
|
+
* @param {Object|number} [options] - Options.
|
|
45
|
+
* This can be an index in the string for shorthand of `lineColumn(str, index)`.
|
|
46
|
+
* @param {number} [options.origin=1] - The origin value of line and column.
|
|
47
|
+
*/
|
|
48
|
+
function LineColumnFinder(str, options) {
|
|
49
|
+
if (!(this instanceof LineColumnFinder)) {
|
|
50
|
+
if (typeof options === "number") {
|
|
51
|
+
return new LineColumnFinder(str).fromIndex(options);
|
|
52
|
+
}
|
|
53
|
+
return new LineColumnFinder(str, options);
|
|
54
|
+
}
|
|
55
|
+
this.str = str || "";
|
|
56
|
+
this.lineToIndex = buildLineToIndex(this.str);
|
|
57
|
+
options = options || {};
|
|
58
|
+
this.origin = typeof options.origin === "undefined" ? 1 : options.origin;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Find line and column from index in the string.
|
|
63
|
+
*
|
|
64
|
+
* @param {number} index - Index in the string. (0-origin)
|
|
65
|
+
* @return {Object|null}
|
|
66
|
+
* Found line number and column number in object `{ line: X, col: Y }`.
|
|
67
|
+
* If the given index is out of range, it returns `null`.
|
|
68
|
+
*/
|
|
69
|
+
LineColumnFinder.prototype.fromIndex = function (index) {
|
|
70
|
+
if (index < 0 || index >= this.str.length || isNaN(index)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
var line = findLowerIndexInRangeArray(index, this.lineToIndex);
|
|
74
|
+
return {
|
|
75
|
+
line: line + this.origin,
|
|
76
|
+
col: index - this.lineToIndex[line] + this.origin
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Find index from line and column in the string.
|
|
82
|
+
*
|
|
83
|
+
* @param {number|Object|Array} line - Line number in the string.
|
|
84
|
+
* This can be an Object of `{ line: X, col: Y }`, or
|
|
85
|
+
* an Array of `[line, col]`.
|
|
86
|
+
* @param {number} [column] - Column number in the string.
|
|
87
|
+
* This must be omitted or undefined when Object or Array is given
|
|
88
|
+
* to the first argument.
|
|
89
|
+
* @return {number}
|
|
90
|
+
* Found index in the string. (always 0-origin)
|
|
91
|
+
* If the given line or column is out of range, it returns `-1`.
|
|
92
|
+
*/
|
|
93
|
+
LineColumnFinder.prototype.toIndex = function (line, column) {
|
|
94
|
+
if (typeof column === "undefined") {
|
|
95
|
+
if (isArray(line) && line.length >= 2) {
|
|
96
|
+
return this.toIndex(line[0], line[1]);
|
|
97
|
+
}
|
|
98
|
+
if (isObject(line) && "line" in line && ("col" in line || "column" in line)) {
|
|
99
|
+
return this.toIndex(line.line, "col" in line ? line.col : line.column);
|
|
100
|
+
}
|
|
101
|
+
return -1;
|
|
102
|
+
}
|
|
103
|
+
if (isNaN(line) || isNaN(column)) {
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
line -= this.origin;
|
|
107
|
+
column -= this.origin;
|
|
108
|
+
if (line >= 0 && column >= 0 && line < this.lineToIndex.length) {
|
|
109
|
+
var lineIndex = this.lineToIndex[line];
|
|
110
|
+
var nextIndex = line === this.lineToIndex.length - 1 ? this.str.length : this.lineToIndex[line + 1];
|
|
111
|
+
if (column < nextIndex - lineIndex) {
|
|
112
|
+
return lineIndex + column;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return -1;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Build an array of indexes of each line from a string.
|
|
120
|
+
*
|
|
121
|
+
* @private
|
|
122
|
+
* @param str {string} An input string.
|
|
123
|
+
* @return {number[]} Built array of indexes. The key is line number.
|
|
124
|
+
*/
|
|
125
|
+
function buildLineToIndex(str) {
|
|
126
|
+
var lines = str.split("\n"),
|
|
127
|
+
lineToIndex = new Array(lines.length),
|
|
128
|
+
index = 0;
|
|
129
|
+
for (var i = 0, l = lines.length; i < l; i++) {
|
|
130
|
+
lineToIndex[i] = index;
|
|
131
|
+
index += lines[i].length + /* "\n".length */1;
|
|
132
|
+
}
|
|
133
|
+
return lineToIndex;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Find a lower-bound index of a value in a sorted array of ranges.
|
|
138
|
+
*
|
|
139
|
+
* Assume `arr = [0, 5, 10, 15, 20]` and
|
|
140
|
+
* this returns `1` for `value = 7` (5 <= value < 10),
|
|
141
|
+
* and returns `3` for `value = 18` (15 <= value < 20).
|
|
142
|
+
*
|
|
143
|
+
* @private
|
|
144
|
+
* @param arr {number[]} An array of values representing ranges.
|
|
145
|
+
* @param value {number} A value to be searched.
|
|
146
|
+
* @return {number} Found index. If not found `-1`.
|
|
147
|
+
*/
|
|
148
|
+
function findLowerIndexInRangeArray(value, arr) {
|
|
149
|
+
if (value >= arr[arr.length - 1]) {
|
|
150
|
+
return arr.length - 1;
|
|
151
|
+
}
|
|
152
|
+
var min = 0,
|
|
153
|
+
max = arr.length - 2,
|
|
154
|
+
mid;
|
|
155
|
+
while (min < max) {
|
|
156
|
+
mid = min + (max - min >> 1);
|
|
157
|
+
if (value < arr[mid]) {
|
|
158
|
+
max = mid - 1;
|
|
159
|
+
} else if (value >= arr[mid + 1]) {
|
|
160
|
+
min = mid + 1;
|
|
161
|
+
} else {
|
|
162
|
+
// value >= arr[mid] && value < arr[mid + 1]
|
|
163
|
+
min = mid;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return min;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var lineColumn$1 = /*@__PURE__*/getDefaultExportFromCjs(lineColumn);
|
|
171
|
+
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
function getMatchStartAndEnd(match) {
|
|
175
|
+
return {
|
|
176
|
+
start: expect(match.index, 'Expected regular expression match to have an index'),
|
|
177
|
+
end: expect(match.index, 'Expected regular expression match to have an index') + match[0].length
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function replacementFrom(template, index, oldLength, newLength, type) {
|
|
181
|
+
const loc = expect(lineColumn$1(template).fromIndex(index), 'BUG: expected to find a line/column based on index');
|
|
182
|
+
return {
|
|
183
|
+
type,
|
|
184
|
+
index,
|
|
185
|
+
oldLength,
|
|
186
|
+
newLength,
|
|
187
|
+
originalCol: loc.col,
|
|
188
|
+
originalLine: loc.line
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function replaceMatch(s, match, startReplacement, endReplacement, template, includeTemplateTokens) {
|
|
192
|
+
const {
|
|
193
|
+
start: openStart,
|
|
194
|
+
end: openEnd
|
|
195
|
+
} = getMatchStartAndEnd(match.start);
|
|
196
|
+
const {
|
|
197
|
+
start: closeStart,
|
|
198
|
+
end: closeEnd
|
|
199
|
+
} = getMatchStartAndEnd(match.end);
|
|
200
|
+
let options = '';
|
|
201
|
+
if (includeTemplateTokens) {
|
|
202
|
+
const tokensString = getTemplateLocals(template.slice(openEnd, closeStart)).filter(local => local.match(/^[$A-Z_][0-9A-Z_$]*$/i)).join(',');
|
|
203
|
+
if (tokensString.length > 0) {
|
|
204
|
+
options = `, scope: () => ({${tokensString}})`;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const newStart = `${startReplacement}\``;
|
|
208
|
+
const newEnd = `\`, { strictMode: true${options} }${endReplacement}`;
|
|
209
|
+
s.overwrite(openStart, openEnd, newStart);
|
|
210
|
+
s.overwrite(closeStart, closeEnd, newEnd);
|
|
211
|
+
ensureBackticksEscaped(s, openEnd + 1, closeStart - 1);
|
|
212
|
+
return [replacementFrom(template, openStart, openEnd - openStart, newStart.length, 'start'), replacementFrom(template, closeStart, closeEnd - closeStart, newEnd.length, 'end')];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Preprocesses all embedded templates within a JavaScript or TypeScript file.
|
|
217
|
+
* This function replaces all embedded templates that match our template syntax
|
|
218
|
+
* with valid, parseable JS. Optionally, it can also include a source map, and
|
|
219
|
+
* it can also include all possible values used within the template.
|
|
220
|
+
*
|
|
221
|
+
* Input:
|
|
222
|
+
*
|
|
223
|
+
* <template><MyComponent/><template>
|
|
224
|
+
*
|
|
225
|
+
* Output:
|
|
226
|
+
*
|
|
227
|
+
* [GLIMMER_TEMPLATE(`<MyComponent/>`, { scope() { return {MyComponent}; } })];
|
|
228
|
+
*
|
|
229
|
+
* It can also be used with template literals to provide the in scope values:
|
|
230
|
+
*
|
|
231
|
+
* Input:
|
|
232
|
+
*
|
|
233
|
+
* hbs`<MyComponent/>`;
|
|
234
|
+
*
|
|
235
|
+
* Output
|
|
236
|
+
*
|
|
237
|
+
* hbs(`<MyComponent/>`, { scope() { return {MyComponent}; } });
|
|
238
|
+
*/
|
|
239
|
+
function preprocessEmbeddedTemplates(template, options) {
|
|
240
|
+
const {
|
|
241
|
+
templateTag,
|
|
242
|
+
templateTagReplacement,
|
|
243
|
+
includeTemplateTokens,
|
|
244
|
+
relativePath
|
|
245
|
+
} = options;
|
|
246
|
+
const parseTemplatesOptions = {
|
|
247
|
+
templateTag
|
|
248
|
+
};
|
|
249
|
+
const matches = parseTemplates(template, relativePath, parseTemplatesOptions);
|
|
250
|
+
const replacements = [];
|
|
251
|
+
const s = new MagicString(template);
|
|
252
|
+
for (const match of matches) {
|
|
253
|
+
if (match.type === 'template-tag') {
|
|
254
|
+
replacements.push(...replaceMatch(s, match, `[${templateTagReplacement}(`, ')]', template, includeTemplateTokens));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let output = s.toString();
|
|
258
|
+
return {
|
|
259
|
+
output,
|
|
260
|
+
replacements
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function ensureBackticksEscaped(s, start, end) {
|
|
264
|
+
if (start >= end) return;
|
|
265
|
+
let content = s.slice(start, end);
|
|
266
|
+
content = content.replace(/(?<!\\)`/g, '\\`');
|
|
267
|
+
s.overwrite(start, end, content, false);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { preprocessEmbeddedTemplates };
|
|
271
|
+
//# sourceMappingURL=preprocess.js.map
|
|
@@ -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,IA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F,CACF,CAAC,CAAA;AACH,KAAA;AACF,GAAA;AAEA,EAAA,IAAIyB,MAAM,GAAG5B,CAAC,CAAClD,QAAQ,EAAE,CAAA;EAEzB,OAAO;IACL8E,MAAM;AACNH,IAAAA,YAAAA;GACD,CAAA;AACH,CAAA;AAEA,SAASR,sBAAsBA,CAACjB,CAAc,EAAEb,KAAa,EAAEE,GAAW,EAAE;EAC1E,IAAIF,KAAK,IAAIE,GAAG,EAAE,OAAA;EAElB,IAAIwC,OAAO,GAAG7B,CAAC,CAACU,KAAK,CAACvB,KAAK,EAAEE,GAAG,CAAC,CAAA;EAEjCwC,OAAO,GAAGA,OAAO,CAACC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;EAC7C9B,CAAC,CAACgB,SAAS,CAAC7B,KAAK,EAAEE,GAAG,EAAEwC,OAAO,EAAE,KAAK,CAAC,CAAA;AACzC;;;;","x_google_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,eAAe,CAACE,IAAI,CAACC,EAAE,IAAIN,IAAI,CAACO,KAAK,CAACC,qBAAqB,CAACZ,YAAY,CAAC,CAAA;IAErF,MAAMa,+BAA+B,GAAGd,CAAC,CAACe,cAAc,CACtDC,yBAAyB,CAACX,IAAI,EAAEH,KAAK,CAAC,EACtC,CACEC,QAAQ,EACRH,CAAC,CAACe,cAAc,CACdb,KAAK,CAACe,UAAU,CAACC,MAAM,CACrBjB,YAAY,EACZ,gCAAgC,EAChC,SAAS,EACT,cACF,CAAC,EACD,CAACD,CAAC,CAACmB,aAAa,CAAC,yBAAyB,CAAC,EAAEnB,CAAC,CAACmB,aAAa,CAACV,KAAK,CAACW,IAAI,CAAC,CAC1E,CAAC,CAEL,CAAC,CAAA;AAED,IAAA,IACEZ,eAAe,CAACD,IAAI,KAAK,qBAAqB,IAC9CC,eAAe,CAACF,UAAU,CAACC,IAAI,KAAK,SAAS,EAC7C;AACAc,MAAAA,YAAY,CACVb,eAAe,CAACc,WAAW,CAACtB,CAAC,CAACuB,wBAAwB,CAACT,+BAA+B,CAAC,CAAC,EAC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ACAc,OAAY,IAAK,CAChBA,OAAO,CAAClB,UAAU,CAACmB,GAAG,CAAC,QAAQ,CAAC,EAChCD,OAAO,CAAClB,UAAU,CAACmB,GAAG,CAAC,oBAAoB,CAAC,CAEhD,CAAC,CAAA;AACH,KAAA;IAEApB,IAAI,CAACwB,MAAM,EAAE,CAAA;AAEb,IAAA,OAAA;AACF,GAAC,MAAM;AACL,IAAA,MAAMxB,IAAI,CAACyB,mBAAmB,CAC3B,CAAsBC,oBAAAA,EAAAA,iBAAkB,0SAC3C,CAAC,CAAA;AACH,GAAA;AACF,EAAC;AAED,SAASf,yBAAyBA,CAACX,IAAS,EAAEH,KAAU,EAAE;EACxD,OAAOA,KAAK,CAACe,UAAU,CAACC,MAAM,CAACb,IAAI,EAAE,kBAAkB,EAAE,sBAAsB,CAAC,CAAA;AAClF;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
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;AAC1E,EAAA,MAAMC,MAAM,GAAGD,kBAAkB,CAACE,GAAG,CAAC,QAAQ,CAAC,CAAA;EAE/C,OACE,CAACC,KAAK,CAACC,OAAO,CAACH,MAAM,CAAC,IAAIA,MAAM,CAACI,YAAY,EAAE,IAAIJ,MAAM,CAACK,IAAI,CAACC,IAAI,KAAKT,wBAAwB,CAAA;AAEpG,CAAA;AAEO,SAASU,2BAA2BA,CACzCC,CAAM,EACNT,kBAA4C,EAC5CU,KAEC,EACe;AAChB,EAAA,MAAMT,MAAM,GAAGD,kBAAkB,CAACE,GAAG,CAAC,QAAQ,CAAC,CAAA;EAE/C,OAAOO,CAAC,CAACE,cAAc,CACrBD,KAAK,CAACE,UAAU,CAACC,MAAM,CAACZ,MAAM,EAAE,6BAA6B,EAAE,oBAAoB,CAAC,EACpFD,kBAAkB,CAACM,IAAI,CAACQ,SAC1B,CAAC,CAAA;AACH,CAAA;AAEO,SAASC,YAAYA,CAC1BC,OAA0B,EAC1BC,WAAyC,EACzC;AACA,EAAA,IAAId,KAAK,CAACC,OAAO,CAACY,OAAO,CAAC,EAAE;AAC1B,IAAA,IAAIA,OAAO,CAACE,MAAM,GAAG,CAAC,EAAE;AACtB,MAAA,MAAM,IAAIC,KAAK,CACb,qGACF,CAAC,CAAA;AACH,KAAA;AAEAH,IAAAA,OAAO,GAAGA,OAAO,CAAC,CAAC,CAAW,CAAA;AAChC,GAAA;AAEA,EAAA,MAAMI,QAAQ,GAAGH,WAAW,CAACD,OAAO,CAAC,CAAA;AAErC,EAAA,KAAK,MAAMK,GAAG,IAAID,QAAQ,EAAE;AAC1B,IAAA,IAAI,CAACC,GAAG,CAAChB,YAAY,EAAE,EAAE;AACvB,MAAA,MAAM,IAAIc,KAAK,CACb,0GACF,CAAC,CAAA;AACH,KAAA;AAEA,IAAA,MAAMG,OAAO,GAAGD,GAAG,CAACE,KAAK,CAACC,UAAU,CAACH,GAAG,CAACf,IAAI,CAACC,IAAI,CAAC,CAAA;IAEnD,IAAIe,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,13 @@
|
|
|
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?: Omit<CompileTemplateOptions, 'moduleName'>): CompileResult;
|
|
12
9
|
interface CompileTemplateOptions {
|
|
13
10
|
moduleName: string;
|
|
14
11
|
scope?: Record<string, unknown>;
|
|
15
12
|
}
|
|
16
|
-
export {};
|
|
13
|
+
export { compileHBS };
|