ember-repl 3.0.0-beta.6 → 3.0.0-beta.7
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/declarations/browser/gjs.d.ts +1 -1
- package/declarations/browser/gjs.d.ts.map +1 -1
- package/declarations/browser/known-modules.d.ts +4 -0
- package/declarations/browser/known-modules.d.ts.map +1 -1
- package/dist/browser/cjs/index.js +1 -1
- package/dist/browser/cjs/index.js.map +1 -1
- package/dist/browser/esm/index.js +1 -1
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/gjs.js +12 -13
- package/dist/browser/gjs.js.map +1 -1
- package/dist/browser/known-modules.js +4 -4
- package/dist/browser/known-modules.js.map +1 -1
- package/package.json +52 -51
- package/src/browser/cjs/index.ts +1 -1
- package/src/browser/esm/index.ts +1 -1
- package/src/browser/gjs.ts +13 -15
- package/src/browser/known-modules.ts +4 -2
- package/declarations/browser/eti/babel-plugin.d.ts +0 -54
- package/declarations/browser/eti/babel-plugin.d.ts.map +0 -1
- package/declarations/browser/eti/debug.d.ts +0 -2
- package/declarations/browser/eti/debug.d.ts.map +0 -1
- package/declarations/browser/eti/parse-templates.d.ts +0 -56
- package/declarations/browser/eti/parse-templates.d.ts.map +0 -1
- package/declarations/browser/eti/preprocess.d.ts +0 -58
- package/declarations/browser/eti/preprocess.d.ts.map +0 -1
- package/declarations/browser/eti/template-tag-transform.d.ts +0 -15
- package/declarations/browser/eti/template-tag-transform.d.ts.map +0 -1
- package/declarations/browser/eti/util.d.ts +0 -14
- package/declarations/browser/eti/util.d.ts.map +0 -1
- package/dist/browser/eti/babel-plugin.js +0 -95
- package/dist/browser/eti/babel-plugin.js.map +0 -1
- package/dist/browser/eti/debug.js +0 -9
- package/dist/browser/eti/debug.js.map +0 -1
- package/dist/browser/eti/parse-templates.js +0 -181
- package/dist/browser/eti/parse-templates.js.map +0 -1
- package/dist/browser/eti/preprocess.js +0 -106
- package/dist/browser/eti/preprocess.js.map +0 -1
- package/dist/browser/eti/template-tag-transform.js +0 -46
- package/dist/browser/eti/template-tag-transform.js.map +0 -1
- package/dist/browser/eti/util.js +0 -39
- package/dist/browser/eti/util.js.map +0 -1
- package/src/browser/eti/babel-plugin.ts +0 -105
- package/src/browser/eti/debug.ts +0 -7
- package/src/browser/eti/parse-templates.ts +0 -284
- package/src/browser/eti/preprocess.ts +0 -187
- package/src/browser/eti/template-tag-transform.ts +0 -100
- package/src/browser/eti/util.ts +0 -72
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
export declare function preprocessEmbeddedTemplates(template: string, options: PreprocessOptions): PreprocessedOutput;
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=preprocess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preprocess.d.ts","sourceRoot":"","sources":["../../../src/browser/eti/preprocess.ts"],"names":[],"mappings":"AAcA,UAAU,sBAAsB;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,UAAU,qBAAqB;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,KAAK,iBAAiB,GAAG,qBAAqB,GAAG,sBAAsB,CAAC;AAExE,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,WAAW,EAAE,CAAC;CAC7B;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,OAAO,GAAG,KAAK,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAoED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,GACzB,kBAAkB,CAgCpB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
export declare const transformTemplateTag: (t: any, templatePath: any, state: any) => void;
|
|
15
|
-
//# sourceMappingURL=template-tag-transform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template-tag-transform.d.ts","sourceRoot":"","sources":["../../../src/browser/eti/template-tag-transform.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,MAAgB,GAAG,gBAAgB,GAAG,SAAS,GAAG,SAgFlF,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { TemplateMatch } from './parse-templates.ts';
|
|
2
|
-
import type { NodePath } from '@babel/traverse';
|
|
3
|
-
import type { CallExpression } from '@babel/types';
|
|
4
|
-
import type { ImportUtil } from 'babel-import-util';
|
|
5
|
-
export declare const TEMPLATE_TAG_NAME = "template";
|
|
6
|
-
export declare const TEMPLATE_TAG_PLACEHOLDER = "__GLIMMER_TEMPLATE";
|
|
7
|
-
export declare function isTemplateTag(callExpressionPath: NodePath<CallExpression>): boolean;
|
|
8
|
-
export declare function buildPrecompileTemplateCall(t: any, callExpressionPath: NodePath<CallExpression>, state: {
|
|
9
|
-
importUtil: ImportUtil;
|
|
10
|
-
}): CallExpression;
|
|
11
|
-
export declare function registerRefs(newPath: string | string[], getRefPaths: (path: string) => NodePath[]): void;
|
|
12
|
-
export declare function isSupportedScriptFileExtension(filePath: string): boolean;
|
|
13
|
-
export declare function isStrictMode(templateInfo: TemplateMatch): boolean;
|
|
14
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/browser/eti/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D,wBAAgB,aAAa,CAAC,kBAAkB,EAAE,QAAQ,CAAC,cAAc,CAAC,WAMzE;AAED,wBAAgB,2BAA2B,CACzC,CAAC,EAAE,GAAG,EACN,kBAAkB,EAAE,QAAQ,CAAC,cAAc,CAAC,EAC5C,KAAK,EAAE;IACL,UAAU,EAAE,UAAU,CAAC;CACxB,GACA,cAAc,CAOhB;AAED,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,EAAE,QA2B1C;AAID,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,WAE9D;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,aAAa,GAAG,OAAO,CAEjE"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { ImportUtil } from 'babel-import-util';
|
|
2
|
-
import { transformTemplateTag } from './template-tag-transform.js';
|
|
3
|
-
import { isTemplateTag } from './util.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This Babel plugin takes parseable code emitted by the string-based
|
|
7
|
-
* preprocessor plugin in this package and converts it into calls to
|
|
8
|
-
* the standardized `precompileTemplate` macro from `@ember/template-compilation`.
|
|
9
|
-
*
|
|
10
|
-
* Its goal is to convert code like this:
|
|
11
|
-
*
|
|
12
|
-
* ```js
|
|
13
|
-
* import { hbs } from 'ember-template-imports';
|
|
14
|
-
*
|
|
15
|
-
* const A = hbs(`A`, {...});
|
|
16
|
-
* const B = [__GLIMMER_TEMPLATE(`B`, {...})];
|
|
17
|
-
* class C {
|
|
18
|
-
* template = hbs(`C`, {...});
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* [__GLIMMER_TEMPLATE(`default`, {...})];
|
|
22
|
-
*
|
|
23
|
-
* class D {
|
|
24
|
-
* [__GLIMMER_TEMPLATE(`D`, {...})]
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* Into this:
|
|
29
|
-
*
|
|
30
|
-
* ```js
|
|
31
|
-
* import { precompileTemplate } from '@ember/template-compilation';
|
|
32
|
-
* import { setComponentTemplate } from '@ember/component';
|
|
33
|
-
* import templateOnlyComponent from '@ember/component/template-only';
|
|
34
|
-
*
|
|
35
|
-
* const A = setComponentTemplate(
|
|
36
|
-
* precompileTemplate(`A`, {...}),
|
|
37
|
-
* templateOnlyComponent('this-module.js', 'A')
|
|
38
|
-
* );
|
|
39
|
-
* const B = setComponentTemplate(
|
|
40
|
-
* precompileTemplate(`B`, {...}),
|
|
41
|
-
* templateOnlyComponent('this-module.js', 'B')
|
|
42
|
-
* );
|
|
43
|
-
* class C {}
|
|
44
|
-
* setComponentTemplate(precompileTemplate(`C`, {...}), C);
|
|
45
|
-
*
|
|
46
|
-
* export default setComponentTemplate(
|
|
47
|
-
* precompileTemplate(`default`, {...}),
|
|
48
|
-
* templateOnlyComponent('this-module.js', '_thisModule')
|
|
49
|
-
* );
|
|
50
|
-
*
|
|
51
|
-
* class D {}
|
|
52
|
-
* setComponentTemplate(precompileTemplate(`D`, {...}), D);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
function babelPluginIntermediateGJS (babel) {
|
|
56
|
-
let t = babel.types;
|
|
57
|
-
let visitor = {
|
|
58
|
-
Program: {
|
|
59
|
-
enter(path, state) {
|
|
60
|
-
state.importUtil = new ImportUtil(t, path);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
// Process class bodies before things like class properties get transformed
|
|
64
|
-
// into imperative constructor code that we can't recognize. Taken directly
|
|
65
|
-
// from babel-plugin-htmlbars-inline-precompile https://git.io/JMi1G
|
|
66
|
-
Class(path, state) {
|
|
67
|
-
let bodyPath = path.get('body.body');
|
|
68
|
-
if (!Array.isArray(bodyPath)) return;
|
|
69
|
-
bodyPath.forEach(path => {
|
|
70
|
-
if (path.type !== 'ClassProperty') return;
|
|
71
|
-
let keyPath = path.get('key');
|
|
72
|
-
let valuePath = path.get('value');
|
|
73
|
-
if (Array.isArray(keyPath)) return;
|
|
74
|
-
if (keyPath && visitor[keyPath.type]) {
|
|
75
|
-
visitor[keyPath.type](keyPath, state);
|
|
76
|
-
}
|
|
77
|
-
if (Array.isArray(valuePath)) return;
|
|
78
|
-
if (valuePath && visitor[valuePath.type]) {
|
|
79
|
-
visitor[valuePath.type](valuePath, state);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
CallExpression(path, state) {
|
|
84
|
-
if (isTemplateTag(path)) {
|
|
85
|
-
transformTemplateTag(t, path, state);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
visitor
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { babelPluginIntermediateGJS as default };
|
|
95
|
-
//# sourceMappingURL=babel-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin.js","sources":["../../../src/browser/eti/babel-plugin.ts"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\n\nimport { transformTemplateTag } from './template-tag-transform.ts';\nimport * as util from './util.ts';\n\nimport type { NodePath } from '@babel/traverse';\nimport type { CallExpression, Class, Program } from '@babel/types';\n\n/**\n * This Babel plugin takes parseable code emitted by the string-based\n * preprocessor plugin in this package and converts it into calls to\n * the standardized `precompileTemplate` macro from `@ember/template-compilation`.\n *\n * Its goal is to convert code like this:\n *\n * ```js\n * import { hbs } from 'ember-template-imports';\n *\n * const A = hbs(`A`, {...});\n * const B = [__GLIMMER_TEMPLATE(`B`, {...})];\n * class C {\n * template = hbs(`C`, {...});\n * }\n *\n * [__GLIMMER_TEMPLATE(`default`, {...})];\n *\n * class D {\n * [__GLIMMER_TEMPLATE(`D`, {...})]\n * }\n * ```\n *\n * Into this:\n *\n * ```js\n * import { precompileTemplate } from '@ember/template-compilation';\n * import { setComponentTemplate } from '@ember/component';\n * import templateOnlyComponent from '@ember/component/template-only';\n *\n * const A = setComponentTemplate(\n * precompileTemplate(`A`, {...}),\n * templateOnlyComponent('this-module.js', 'A')\n * );\n * const B = setComponentTemplate(\n * precompileTemplate(`B`, {...}),\n * templateOnlyComponent('this-module.js', 'B')\n * );\n * class C {}\n * setComponentTemplate(precompileTemplate(`C`, {...}), C);\n *\n * export default setComponentTemplate(\n * precompileTemplate(`default`, {...}),\n * templateOnlyComponent('this-module.js', '_thisModule')\n * );\n *\n * class D {}\n * setComponentTemplate(precompileTemplate(`D`, {...}), D);\n * ```\n */\nexport default function (babel: any) {\n let t = babel.types;\n\n let visitor: any = {\n Program: {\n enter(path: NodePath<Program>, state: any) {\n state.importUtil = new ImportUtil(t, path);\n },\n },\n\n // Process class bodies before things like class properties get transformed\n // into imperative constructor code that we can't recognize. Taken directly\n // from babel-plugin-htmlbars-inline-precompile https://git.io/JMi1G\n Class(path: NodePath<Class>, state: any) {\n let bodyPath = path.get('body.body');\n\n if (!Array.isArray(bodyPath)) return;\n\n bodyPath.forEach((path) => {\n if (path.type !== 'ClassProperty') return;\n\n let keyPath = path.get('key');\n let valuePath = path.get('value');\n\n if (Array.isArray(keyPath)) return;\n\n if (keyPath && visitor[keyPath.type]) {\n visitor[keyPath.type](keyPath, state);\n }\n\n if (Array.isArray(valuePath)) return;\n\n if (valuePath && visitor[valuePath.type]) {\n visitor[valuePath.type](valuePath, state);\n }\n });\n },\n\n CallExpression(path: NodePath<CallExpression>, state: any) {\n if (util.isTemplateTag(path)) {\n transformTemplateTag(t, path, state);\n }\n },\n };\n\n return { visitor };\n}\n"],"names":["babel","t","types","visitor","Program","enter","path","state","importUtil","ImportUtil","Class","bodyPath","get","Array","isArray","forEach","type","keyPath","valuePath","CallExpression","util","transformTemplateTag"],"mappings":";;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,mCAAA,EAAUA,KAAU,EAAE;AACnC,EAAA,IAAIC,CAAC,GAAGD,KAAK,CAACE,KAAK,CAAA;AAEnB,EAAA,IAAIC,OAAY,GAAG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B,CAACd,IAAI,CAAC,EAAE;AAC5Be,QAAAA,oBAAoB,CAACpB,CAAC,EAAEK,IAAI,EAAEC,KAAK,CAAC,CAAA;AACtC,OAAA;AACF,KAAA;GACD,CAAA;EAED,OAAO;AAAEJ,IAAAA,OAAAA;GAAS,CAAA;AACpB;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sources":["../../../src/browser/eti/debug.ts"],"sourcesContent":["export function expect<T>(value: T | null | undefined, message: string): T {\n if (value === undefined || value === null) {\n throw new Error(`LIBRARY BUG: ${message}`);\n }\n\n return value;\n}\n"],"names":["expect","value","message","undefined","Error"],"mappings":"AAAO,SAASA,MAAMA,CAAIC,KAA2B,EAAEC,OAAe,EAAK;AACzE,EAAA,IAAID,KAAK,KAAKE,SAAS,IAAIF,KAAK,KAAK,IAAI,EAAE;AACzC,IAAA,MAAM,IAAIG,KAAK,CAAE,CAAeF,aAAAA,EAAAA,OAAQ,EAAC,CAAC,CAAA;AAC5C,GAAA;AAEA,EAAA,OAAOD,KAAK,CAAA;AACd;;;;"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { expect } from './debug.js';
|
|
2
|
-
import { TEMPLATE_TAG_NAME } from './util.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents a static import of a template literal.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The input options to instruct parseTemplates on how to parse the input.
|
|
10
|
-
*
|
|
11
|
-
* @param templateTag
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const escapeChar = '\\';
|
|
15
|
-
const stringDelimiter = /['"]/;
|
|
16
|
-
const singleLineCommentStart = /\/\//;
|
|
17
|
-
const newLine = /\n/;
|
|
18
|
-
const multiLineCommentStart = /\/\*/;
|
|
19
|
-
const multiLineCommentEnd = /\*\//;
|
|
20
|
-
const templateLiteralStart = /([$a-zA-Z_][0-9a-zA-Z_$]*)?`/;
|
|
21
|
-
const templateLiteralEnd = /`/;
|
|
22
|
-
const dynamicSegmentStart = /\${/;
|
|
23
|
-
const blockStart = /{/;
|
|
24
|
-
const dynamicSegmentEnd = /}/;
|
|
25
|
-
function isEscaped(template, _offset) {
|
|
26
|
-
let offset = expect(_offset, 'Expected an index to check escaping');
|
|
27
|
-
let count = 0;
|
|
28
|
-
while (template[offset - 1] === escapeChar) {
|
|
29
|
-
count++;
|
|
30
|
-
offset--;
|
|
31
|
-
}
|
|
32
|
-
return count % 2 === 1;
|
|
33
|
-
}
|
|
34
|
-
const DEFAULT_PARSE_TEMPLATES_OPTIONS = {
|
|
35
|
-
templateTag: TEMPLATE_TAG_NAME
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Parses a template to find all possible valid matches for an embedded template.
|
|
40
|
-
* Supported syntaxes are template literals:
|
|
41
|
-
*
|
|
42
|
-
* hbs`Hello, world!`
|
|
43
|
-
*
|
|
44
|
-
* And template tags
|
|
45
|
-
*
|
|
46
|
-
* <template></template>
|
|
47
|
-
*
|
|
48
|
-
* The parser excludes any values found within strings recursively, and also
|
|
49
|
-
* excludes any string literals with dynamic segments (e.g `${}`) since these
|
|
50
|
-
* cannot be valid templates.
|
|
51
|
-
*
|
|
52
|
-
* @param template The template to parse
|
|
53
|
-
* @param relativePath Relative file path for the template (for errors)
|
|
54
|
-
* @param options optional configuration options for how to parse templates
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
function parseTemplates(template, relativePath, options = DEFAULT_PARSE_TEMPLATES_OPTIONS) {
|
|
58
|
-
const results = [];
|
|
59
|
-
const templateTag = options?.templateTag;
|
|
60
|
-
const templateTagStart = new RegExp(`<${templateTag}[^<]*>`);
|
|
61
|
-
const templateTagEnd = new RegExp(`</${templateTag}>`);
|
|
62
|
-
const argumentsMatchRegex = new RegExp(`<${templateTag}[^<]*\\S[^<]*>`);
|
|
63
|
-
const allTokens = new RegExp([singleLineCommentStart.source, newLine.source, multiLineCommentStart.source, multiLineCommentEnd.source, stringDelimiter.source, templateLiteralStart.source, templateLiteralEnd.source, dynamicSegmentStart.source, dynamicSegmentEnd.source, blockStart.source, templateTagStart.source, templateTagEnd.source].join('|'), 'g');
|
|
64
|
-
const tokens = Array.from(template.matchAll(allTokens));
|
|
65
|
-
while (tokens.length > 0) {
|
|
66
|
-
const currentToken = tokens.shift(); // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
67
|
-
|
|
68
|
-
parseToken(results, template, currentToken, tokens, true);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Parse the current token. If top level, then template tags can be parsed.
|
|
73
|
-
* Else, we are nested within a dynamic segment, which is currently unsupported.
|
|
74
|
-
*/
|
|
75
|
-
function parseToken(results, template, token, tokens, isTopLevel = false) {
|
|
76
|
-
if (token[0].match(multiLineCommentStart)) {
|
|
77
|
-
parseMultiLineComment(results, template, token, tokens);
|
|
78
|
-
} else if (token[0].match(singleLineCommentStart)) {
|
|
79
|
-
parseSingleLineComment(results, template, token, tokens);
|
|
80
|
-
} else if (token[0].match(templateLiteralStart)) {
|
|
81
|
-
parseTemplateLiteral(template, tokens);
|
|
82
|
-
} else if (isTopLevel && templateTag !== undefined && templateTagStart && token[0].match(templateTagStart)) {
|
|
83
|
-
parseTemplateTag(results, template, token, tokens, templateTag);
|
|
84
|
-
} else if (token[0].match(stringDelimiter)) {
|
|
85
|
-
parseString(results, template, token, tokens);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Parse a template literal. If a dynamic segment is found, enters the dynamic
|
|
91
|
-
* segment and parses it recursively. If no dynamic segments are found and the
|
|
92
|
-
* literal is top level (e.g. not nested within a dynamic segment) and has a
|
|
93
|
-
* tag, pushes it into the list of results.
|
|
94
|
-
*/
|
|
95
|
-
function parseTemplateLiteral(template, tokens) {
|
|
96
|
-
while (tokens.length > 0) {
|
|
97
|
-
let currentToken = expect(tokens.shift(), 'expected token');
|
|
98
|
-
if (isEscaped(template, currentToken.index)) continue;
|
|
99
|
-
if (currentToken[0].match(templateLiteralEnd)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Parse a string. All tokens within a string are ignored
|
|
107
|
-
* since there are no dynamic segments within these.
|
|
108
|
-
*/
|
|
109
|
-
function parseString(_results, template, startToken, tokens) {
|
|
110
|
-
while (tokens.length > 0) {
|
|
111
|
-
const currentToken = expect(tokens.shift(), 'expected token');
|
|
112
|
-
if (currentToken[0] === startToken[0] && !isEscaped(template, currentToken.index)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Parse a single-line comment. All tokens within a single-line comment are ignored
|
|
120
|
-
* since there are no dynamic segments within them.
|
|
121
|
-
*/
|
|
122
|
-
function parseSingleLineComment(_results, _template, _startToken, tokens) {
|
|
123
|
-
while (tokens.length > 0) {
|
|
124
|
-
const currentToken = expect(tokens.shift(), 'expected token');
|
|
125
|
-
if (currentToken[0] === '\n') {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Parse a multi-line comment. All tokens within a multi-line comment are ignored
|
|
133
|
-
* since there are no dynamic segments within them.
|
|
134
|
-
*/
|
|
135
|
-
function parseMultiLineComment(_results, _template, _startToken, tokens) {
|
|
136
|
-
while (tokens.length > 0) {
|
|
137
|
-
const currentToken = expect(tokens.shift(), 'expected token');
|
|
138
|
-
if (currentToken[0] === '*/') {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Parses a template tag. Continues parsing until the template tag has closed,
|
|
146
|
-
* accounting for nested template tags.
|
|
147
|
-
*/
|
|
148
|
-
function parseTemplateTag(results, _template, startToken, tokens, templateTag) {
|
|
149
|
-
let stack = 1;
|
|
150
|
-
if (argumentsMatchRegex && startToken[0].match(argumentsMatchRegex)) {
|
|
151
|
-
throw new Error(`embedded template preprocessing currently does not support passing arguments, found args in: ${relativePath}`);
|
|
152
|
-
}
|
|
153
|
-
while (tokens.length > 0) {
|
|
154
|
-
const currentToken = expect(tokens.shift(), 'expected token');
|
|
155
|
-
if (currentToken[0].match(templateTagStart)) {
|
|
156
|
-
stack++;
|
|
157
|
-
} else if (currentToken[0].match(templateTagEnd)) {
|
|
158
|
-
stack--;
|
|
159
|
-
}
|
|
160
|
-
if (stack === 0) {
|
|
161
|
-
let contents = '';
|
|
162
|
-
if (startToken.index !== undefined) {
|
|
163
|
-
const templateStart = startToken.index + startToken[0].length;
|
|
164
|
-
contents = template.slice(templateStart, currentToken.index);
|
|
165
|
-
}
|
|
166
|
-
results.push({
|
|
167
|
-
type: 'template-tag',
|
|
168
|
-
tagName: templateTag,
|
|
169
|
-
contents: contents,
|
|
170
|
-
start: startToken,
|
|
171
|
-
end: currentToken
|
|
172
|
-
});
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return results;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export { DEFAULT_PARSE_TEMPLATES_OPTIONS, parseTemplates };
|
|
181
|
-
//# sourceMappingURL=parse-templates.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-templates.js","sources":["../../../src/browser/eti/parse-templates.ts"],"sourcesContent":["import { expect } from './debug.ts';\nimport { TEMPLATE_TAG_NAME } from './util.ts';\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,MAAMC,UAAU,GAAG,GAAG,CAAA;AACtB,MAAMC,iBAAiB,GAAG,GAAG,CAAA;AAE7B,SAASC,SAASA,CAACC,QAAgB,EAAEC,OAA2B,EAAE;AAChE,EAAA,IAAIC,MAAM,GAAGC,MAAM,CAACF,OAAO,EAAE,qCAAqC,CAAC,CAAA;EAEnE,IAAIG,KAAK,GAAG,CAAC,CAAA;EAEb,OAAOJ,QAAQ,CAACE,MAAM,GAAG,CAAC,CAAC,KAAKd,UAAU,EAAE;AAC1CgB,IAAAA,KAAK,EAAE,CAAA;AACPF,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E,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;;;;"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { getTemplateLocals } from '@glimmer/syntax';
|
|
2
|
-
import lineColumn from 'line-column';
|
|
3
|
-
import MagicString from 'magic-string';
|
|
4
|
-
import { expect } from './debug.js';
|
|
5
|
-
import { parseTemplates } from './parse-templates.js';
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
function getMatchStartAndEnd(match) {
|
|
10
|
-
return {
|
|
11
|
-
start: expect(match.index, 'Expected regular expression match to have an index'),
|
|
12
|
-
end: expect(match.index, 'Expected regular expression match to have an index') + match[0].length
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function replacementFrom(template, index, oldLength, newLength, type) {
|
|
16
|
-
const loc = expect(lineColumn(template).fromIndex(index), 'BUG: expected to find a line/column based on index');
|
|
17
|
-
return {
|
|
18
|
-
type,
|
|
19
|
-
index,
|
|
20
|
-
oldLength,
|
|
21
|
-
newLength,
|
|
22
|
-
originalCol: loc.col,
|
|
23
|
-
originalLine: loc.line
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function replaceMatch(s, match, startReplacement, endReplacement, template, includeTemplateTokens) {
|
|
27
|
-
const {
|
|
28
|
-
start: openStart,
|
|
29
|
-
end: openEnd
|
|
30
|
-
} = getMatchStartAndEnd(match.start);
|
|
31
|
-
const {
|
|
32
|
-
start: closeStart,
|
|
33
|
-
end: closeEnd
|
|
34
|
-
} = getMatchStartAndEnd(match.end);
|
|
35
|
-
let options = '';
|
|
36
|
-
if (includeTemplateTokens) {
|
|
37
|
-
const tokensString = getTemplateLocals(template.slice(openEnd, closeStart)).filter(local => local.match(/^[$A-Z_][0-9A-Z_$]*$/i)).join(',');
|
|
38
|
-
if (tokensString.length > 0) {
|
|
39
|
-
options = `, scope: () => ({${tokensString}})`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const newStart = `${startReplacement}\``;
|
|
43
|
-
const newEnd = `\`, { strictMode: true${options} }${endReplacement}`;
|
|
44
|
-
s.overwrite(openStart, openEnd, newStart);
|
|
45
|
-
s.overwrite(closeStart, closeEnd, newEnd);
|
|
46
|
-
ensureBackticksEscaped(s, openEnd + 1, closeStart - 1);
|
|
47
|
-
return [replacementFrom(template, openStart, openEnd - openStart, newStart.length, 'start'), replacementFrom(template, closeStart, closeEnd - closeStart, newEnd.length, 'end')];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Preprocesses all embedded templates within a JavaScript or TypeScript file.
|
|
52
|
-
* This function replaces all embedded templates that match our template syntax
|
|
53
|
-
* with valid, parseable JS. Optionally, it can also include a source map, and
|
|
54
|
-
* it can also include all possible values used within the template.
|
|
55
|
-
*
|
|
56
|
-
* Input:
|
|
57
|
-
*
|
|
58
|
-
* <template><MyComponent/><template>
|
|
59
|
-
*
|
|
60
|
-
* Output:
|
|
61
|
-
*
|
|
62
|
-
* [GLIMMER_TEMPLATE(`<MyComponent/>`, { scope() { return {MyComponent}; } })];
|
|
63
|
-
*
|
|
64
|
-
* It can also be used with template literals to provide the in scope values:
|
|
65
|
-
*
|
|
66
|
-
* Input:
|
|
67
|
-
*
|
|
68
|
-
* hbs`<MyComponent/>`;
|
|
69
|
-
*
|
|
70
|
-
* Output
|
|
71
|
-
*
|
|
72
|
-
* hbs(`<MyComponent/>`, { scope() { return {MyComponent}; } });
|
|
73
|
-
*/
|
|
74
|
-
function preprocessEmbeddedTemplates(template, options) {
|
|
75
|
-
const {
|
|
76
|
-
templateTag,
|
|
77
|
-
templateTagReplacement,
|
|
78
|
-
includeTemplateTokens,
|
|
79
|
-
relativePath
|
|
80
|
-
} = options;
|
|
81
|
-
const parseTemplatesOptions = {
|
|
82
|
-
templateTag
|
|
83
|
-
};
|
|
84
|
-
const matches = parseTemplates(template, relativePath, parseTemplatesOptions);
|
|
85
|
-
const replacements = [];
|
|
86
|
-
const s = new MagicString(template);
|
|
87
|
-
for (const match of matches) {
|
|
88
|
-
if (match.type === 'template-tag') {
|
|
89
|
-
replacements.push(...replaceMatch(s, match, `[${templateTagReplacement}(`, ')]', template, includeTemplateTokens));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
let output = s.toString();
|
|
93
|
-
return {
|
|
94
|
-
output,
|
|
95
|
-
replacements
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function ensureBackticksEscaped(s, start, end) {
|
|
99
|
-
if (start >= end) return;
|
|
100
|
-
let content = s.slice(start, end);
|
|
101
|
-
content = content.replace(/(?<!\\)`/g, '\\`');
|
|
102
|
-
s.overwrite(start, end, content, false);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { preprocessEmbeddedTemplates };
|
|
106
|
-
//# sourceMappingURL=preprocess.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preprocess.js","sources":["../../../src/browser/eti/preprocess.ts"],"sourcesContent":["// 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.ts';\nimport { parseTemplates } from './parse-templates.ts';\n\nimport type { ParseTemplatesOptions, TemplateMatch } from './parse-templates.ts';\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":["getMatchStartAndEnd","match","start","expect","index","end","length","replacementFrom","template","oldLength","newLength","type","loc","lineColumn","fromIndex","originalCol","col","originalLine","line","replaceMatch","s","startReplacement","endReplacement","includeTemplateTokens","openStart","openEnd","closeStart","closeEnd","options","tokensString","getTemplateLocals","slice","filter","local","join","newStart","newEnd","overwrite","ensureBackticksEscaped","preprocessEmbeddedTemplates","templateTag","templateTagReplacement","relativePath","parseTemplatesOptions","matches","parseTemplates","replacements","MagicString","push","output","toString","content","replace"],"mappings":";;;;;;AAAA;AACA;AAmDA,SAASA,mBAAmBA,CAACC,KAAuB,EAAE;EACpD,OAAO;IACLC,KAAK,EAAEC,MAAM,CAACF,KAAK,CAACG,KAAK,EAAE,oDAAoD,CAAC;AAChFC,IAAAA,GAAG,EACDF,MAAM,CAACF,KAAK,CAACG,KAAK,EAAE,oDAAoD,CAAC,GAAGH,KAAK,CAAC,CAAC,CAAC,CAACK,MAAAA;GACxF,CAAA;AACH,CAAA;AAEA,SAASC,eAAeA,CACtBC,QAAgB,EAChBJ,KAAa,EACbK,SAAiB,EACjBC,SAAiB,EACjBC,IAAqB,EACR;AACb,EAAA,MAAMC,GAAG,GAAGT,MAAM,CAChBU,UAAU,CAACL,QAAQ,CAAC,CAACM,SAAS,CAACV,KAAK,CAAC,EACrC,oDACF,CAAC,CAAA;EAED,OAAO;IACLO,IAAI;IACJP,KAAK;IACLK,SAAS;IACTC,SAAS;IACTK,WAAW,EAAEH,GAAG,CAACI,GAAG;IACpBC,YAAY,EAAEL,GAAG,CAACM,IAAAA;GACnB,CAAA;AACH,CAAA;AAEA,SAASC,YAAYA,CACnBC,CAAc,EACdnB,KAAoB,EACpBoB,gBAAwB,EACxBC,cAAsB,EACtBd,QAAgB,EAChBe,qBAA8B,EACf;EACf,MAAM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B,CAAc,EAAElB,KAAa,EAAEG,GAAW,EAAE;EAC1E,IAAIH,KAAK,IAAIG,GAAG,EAAE,OAAA;EAElB,IAAI8C,OAAO,GAAG/B,CAAC,CAACW,KAAK,CAAC7B,KAAK,EAAEG,GAAG,CAAC,CAAA;EAEjC8C,OAAO,GAAGA,OAAO,CAACC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;EAC7ChC,CAAC,CAACiB,SAAS,CAACnC,KAAK,EAAEG,GAAG,EAAE8C,OAAO,EAAE,KAAK,CAAC,CAAA;AACzC;;;;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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.ts';\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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