ember-repl 3.0.0-beta.5 → 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/__PRIVATE__.d.ts +2 -0
- package/declarations/browser/__PRIVATE__.d.ts.map +1 -0
- package/declarations/browser/compile/formats.d.ts +2 -0
- package/declarations/browser/compile/formats.d.ts.map +1 -1
- package/declarations/browser/compile/index.d.ts +31 -7
- package/declarations/browser/compile/index.d.ts.map +1 -1
- package/declarations/browser/compile/markdown-to-ember.d.ts +2 -0
- package/declarations/browser/compile/markdown-to-ember.d.ts.map +1 -1
- package/declarations/browser/compile/types.d.ts +2 -0
- package/declarations/browser/compile/types.d.ts.map +1 -1
- 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/__PRIVATE__.js +2 -0
- package/dist/browser/__PRIVATE__.js.map +1 -0
- package/dist/browser/cjs/index.js +1 -1
- package/dist/browser/cjs/index.js.map +1 -1
- package/dist/browser/compile/formats.js +2 -1
- package/dist/browser/compile/formats.js.map +1 -1
- package/dist/browser/compile/index.js +28 -14
- package/dist/browser/compile/index.js.map +1 -1
- package/dist/browser/compile/markdown-to-ember.js +26 -8
- package/dist/browser/compile/markdown-to-ember.js.map +1 -1
- package/dist/browser/compile/types.js +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 +59 -54
- package/src/browser/__PRIVATE__.ts +1 -0
- package/src/browser/cjs/index.ts +1 -1
- package/src/browser/compile/formats.ts +3 -0
- package/src/browser/compile/index.ts +58 -24
- package/src/browser/compile/markdown-to-ember.ts +91 -76
- package/src/browser/compile/types.ts +4 -0
- 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,187 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { getTemplateLocals } from '@glimmer/syntax';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import lineColumn from 'line-column';
|
|
8
|
-
import MagicString from 'magic-string';
|
|
9
|
-
|
|
10
|
-
import { expect } from './debug.ts';
|
|
11
|
-
import { parseTemplates } from './parse-templates.ts';
|
|
12
|
-
|
|
13
|
-
import type { ParseTemplatesOptions, TemplateMatch } from './parse-templates.ts';
|
|
14
|
-
|
|
15
|
-
interface PreprocessOptionsEager {
|
|
16
|
-
importIdentifier?: string;
|
|
17
|
-
importPath?: string;
|
|
18
|
-
templateTag?: string;
|
|
19
|
-
templateTagReplacement?: string;
|
|
20
|
-
|
|
21
|
-
relativePath: string;
|
|
22
|
-
includeSourceMaps: boolean;
|
|
23
|
-
includeTemplateTokens: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface PreprocessOptionsLazy {
|
|
27
|
-
importIdentifier?: string;
|
|
28
|
-
importPath?: string;
|
|
29
|
-
templateTag?: string;
|
|
30
|
-
templateTagReplacement?: string;
|
|
31
|
-
|
|
32
|
-
relativePath: string;
|
|
33
|
-
includeSourceMaps: boolean;
|
|
34
|
-
includeTemplateTokens: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type PreprocessOptions = PreprocessOptionsLazy | PreprocessOptionsEager;
|
|
38
|
-
|
|
39
|
-
interface PreprocessedOutput {
|
|
40
|
-
output: string;
|
|
41
|
-
replacements: Replacement[];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface Replacement {
|
|
45
|
-
type: 'start' | 'end';
|
|
46
|
-
index: number;
|
|
47
|
-
oldLength: number;
|
|
48
|
-
newLength: number;
|
|
49
|
-
originalLine: number;
|
|
50
|
-
originalCol: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getMatchStartAndEnd(match: RegExpMatchArray) {
|
|
54
|
-
return {
|
|
55
|
-
start: expect(match.index, 'Expected regular expression match to have an index'),
|
|
56
|
-
end:
|
|
57
|
-
expect(match.index, 'Expected regular expression match to have an index') + match[0].length,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function replacementFrom(
|
|
62
|
-
template: string,
|
|
63
|
-
index: number,
|
|
64
|
-
oldLength: number,
|
|
65
|
-
newLength: number,
|
|
66
|
-
type: 'start' | 'end'
|
|
67
|
-
): Replacement {
|
|
68
|
-
const loc = expect(
|
|
69
|
-
lineColumn(template).fromIndex(index),
|
|
70
|
-
'BUG: expected to find a line/column based on index'
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
type,
|
|
75
|
-
index,
|
|
76
|
-
oldLength,
|
|
77
|
-
newLength,
|
|
78
|
-
originalCol: loc.col,
|
|
79
|
-
originalLine: loc.line,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function replaceMatch(
|
|
84
|
-
s: MagicString,
|
|
85
|
-
match: TemplateMatch,
|
|
86
|
-
startReplacement: string,
|
|
87
|
-
endReplacement: string,
|
|
88
|
-
template: string,
|
|
89
|
-
includeTemplateTokens: boolean
|
|
90
|
-
): Replacement[] {
|
|
91
|
-
const { start: openStart, end: openEnd } = getMatchStartAndEnd(match.start);
|
|
92
|
-
const { start: closeStart, end: closeEnd } = getMatchStartAndEnd(match.end);
|
|
93
|
-
|
|
94
|
-
let options = '';
|
|
95
|
-
|
|
96
|
-
if (includeTemplateTokens) {
|
|
97
|
-
const tokensString = getTemplateLocals(template.slice(openEnd, closeStart))
|
|
98
|
-
.filter((local: string) => local.match(/^[$A-Z_][0-9A-Z_$]*$/i))
|
|
99
|
-
.join(',');
|
|
100
|
-
|
|
101
|
-
if (tokensString.length > 0) {
|
|
102
|
-
options = `, scope: () => ({${tokensString}})`;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const newStart = `${startReplacement}\``;
|
|
107
|
-
const newEnd = `\`, { strictMode: true${options} }${endReplacement}`;
|
|
108
|
-
|
|
109
|
-
s.overwrite(openStart, openEnd, newStart);
|
|
110
|
-
s.overwrite(closeStart, closeEnd, newEnd);
|
|
111
|
-
ensureBackticksEscaped(s, openEnd + 1, closeStart - 1);
|
|
112
|
-
|
|
113
|
-
return [
|
|
114
|
-
replacementFrom(template, openStart, openEnd - openStart, newStart.length, 'start'),
|
|
115
|
-
replacementFrom(template, closeStart, closeEnd - closeStart, newEnd.length, 'end'),
|
|
116
|
-
];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Preprocesses all embedded templates within a JavaScript or TypeScript file.
|
|
121
|
-
* This function replaces all embedded templates that match our template syntax
|
|
122
|
-
* with valid, parseable JS. Optionally, it can also include a source map, and
|
|
123
|
-
* it can also include all possible values used within the template.
|
|
124
|
-
*
|
|
125
|
-
* Input:
|
|
126
|
-
*
|
|
127
|
-
* <template><MyComponent/><template>
|
|
128
|
-
*
|
|
129
|
-
* Output:
|
|
130
|
-
*
|
|
131
|
-
* [GLIMMER_TEMPLATE(`<MyComponent/>`, { scope() { return {MyComponent}; } })];
|
|
132
|
-
*
|
|
133
|
-
* It can also be used with template literals to provide the in scope values:
|
|
134
|
-
*
|
|
135
|
-
* Input:
|
|
136
|
-
*
|
|
137
|
-
* hbs`<MyComponent/>`;
|
|
138
|
-
*
|
|
139
|
-
* Output
|
|
140
|
-
*
|
|
141
|
-
* hbs(`<MyComponent/>`, { scope() { return {MyComponent}; } });
|
|
142
|
-
*/
|
|
143
|
-
export function preprocessEmbeddedTemplates(
|
|
144
|
-
template: string,
|
|
145
|
-
options: PreprocessOptions
|
|
146
|
-
): PreprocessedOutput {
|
|
147
|
-
const { templateTag, templateTagReplacement, includeTemplateTokens, relativePath } = options;
|
|
148
|
-
|
|
149
|
-
const parseTemplatesOptions: ParseTemplatesOptions = {
|
|
150
|
-
templateTag,
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const matches = parseTemplates(template, relativePath, parseTemplatesOptions);
|
|
154
|
-
const replacements: Replacement[] = [];
|
|
155
|
-
const s = new MagicString(template);
|
|
156
|
-
|
|
157
|
-
for (const match of matches) {
|
|
158
|
-
if (match.type === 'template-tag') {
|
|
159
|
-
replacements.push(
|
|
160
|
-
...replaceMatch(
|
|
161
|
-
s,
|
|
162
|
-
match,
|
|
163
|
-
`[${templateTagReplacement}(`,
|
|
164
|
-
')]',
|
|
165
|
-
template,
|
|
166
|
-
includeTemplateTokens
|
|
167
|
-
)
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let output = s.toString();
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
output,
|
|
176
|
-
replacements,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function ensureBackticksEscaped(s: MagicString, start: number, end: number) {
|
|
181
|
-
if (start >= end) return;
|
|
182
|
-
|
|
183
|
-
let content = s.slice(start, end);
|
|
184
|
-
|
|
185
|
-
content = content.replace(/(?<!\\)`/g, '\\`');
|
|
186
|
-
s.overwrite(start, end, content, false);
|
|
187
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { buildPrecompileTemplateCall, registerRefs, TEMPLATE_TAG_NAME } from './util.ts';
|
|
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
|
-
export const transformTemplateTag = function (t: any, templatePath: any, state: any) {
|
|
17
|
-
let compiled = buildPrecompileTemplateCall(t, templatePath, state);
|
|
18
|
-
let path = templatePath.parentPath;
|
|
19
|
-
|
|
20
|
-
if (path.type === 'ArrayExpression') {
|
|
21
|
-
let arrayParentPath = path.parentPath;
|
|
22
|
-
let varId = arrayParentPath.node.id || path.scope.generateUidIdentifier(templatePath);
|
|
23
|
-
|
|
24
|
-
const templateOnlyComponentExpression = t.callExpression(
|
|
25
|
-
buildSetComponentTemplate(path, state),
|
|
26
|
-
[
|
|
27
|
-
compiled,
|
|
28
|
-
t.callExpression(
|
|
29
|
-
state.importUtil.import(
|
|
30
|
-
templatePath,
|
|
31
|
-
'@ember/component/template-only',
|
|
32
|
-
'default',
|
|
33
|
-
'templateOnly'
|
|
34
|
-
),
|
|
35
|
-
[t.stringLiteral('dynamic-runtime-file.js'), t.stringLiteral(varId.name)]
|
|
36
|
-
),
|
|
37
|
-
]
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
arrayParentPath.type === 'ExpressionStatement' &&
|
|
42
|
-
arrayParentPath.parentPath.type === 'Program'
|
|
43
|
-
) {
|
|
44
|
-
registerRefs(
|
|
45
|
-
arrayParentPath.replaceWith(t.exportDefaultDeclaration(templateOnlyComponentExpression)),
|
|
46
|
-
(newPath: any) => [
|
|
47
|
-
newPath.get('declaration.callee'),
|
|
48
|
-
newPath.get('declaration.arguments.0.callee'),
|
|
49
|
-
newPath.get('declaration.arguments.1.callee'),
|
|
50
|
-
]
|
|
51
|
-
);
|
|
52
|
-
} else {
|
|
53
|
-
registerRefs(path.replaceWith(templateOnlyComponentExpression), (newPath: any) => [
|
|
54
|
-
newPath.get('callee'),
|
|
55
|
-
newPath.get('arguments.0.callee'),
|
|
56
|
-
newPath.get('arguments.1.callee'),
|
|
57
|
-
]);
|
|
58
|
-
}
|
|
59
|
-
} else if (path.type === 'ClassProperty') {
|
|
60
|
-
let classPath = path.parentPath.parentPath;
|
|
61
|
-
|
|
62
|
-
if (classPath.node.type === 'ClassDeclaration') {
|
|
63
|
-
registerRefs(
|
|
64
|
-
classPath.insertAfter(
|
|
65
|
-
t.expressionStatement(
|
|
66
|
-
t.callExpression(buildSetComponentTemplate(path, state), [compiled, classPath.node.id])
|
|
67
|
-
)
|
|
68
|
-
),
|
|
69
|
-
(newPath: any) => [
|
|
70
|
-
newPath.get('expression.callee'),
|
|
71
|
-
newPath.get('expression.arguments.0.callee'),
|
|
72
|
-
]
|
|
73
|
-
);
|
|
74
|
-
} else {
|
|
75
|
-
registerRefs(
|
|
76
|
-
classPath.replaceWith(
|
|
77
|
-
t.expressionStatement(
|
|
78
|
-
t.callExpression(buildSetComponentTemplate(path, state), [compiled, classPath.node])
|
|
79
|
-
)
|
|
80
|
-
),
|
|
81
|
-
(newPath: any) => [
|
|
82
|
-
newPath.parentPath.get('callee'),
|
|
83
|
-
newPath.parentPath.get('arguments.0.callee'),
|
|
84
|
-
]
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
path.remove();
|
|
89
|
-
|
|
90
|
-
return;
|
|
91
|
-
} else {
|
|
92
|
-
throw path.buildCodeFrameError(
|
|
93
|
-
`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`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
function buildSetComponentTemplate(path: any, state: any) {
|
|
99
|
-
return state.importUtil.import(path, '@ember/component', 'setComponentTemplate');
|
|
100
|
-
}
|
package/src/browser/eti/util.ts
DELETED
|
@@ -1,72 +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
|
-
|
|
6
|
-
// const Greeting = <template>Hello</template>
|
|
7
|
-
export const TEMPLATE_TAG_NAME = 'template';
|
|
8
|
-
export const TEMPLATE_TAG_PLACEHOLDER = '__GLIMMER_TEMPLATE';
|
|
9
|
-
|
|
10
|
-
export function isTemplateTag(callExpressionPath: NodePath<CallExpression>) {
|
|
11
|
-
const callee = callExpressionPath.get('callee');
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
!Array.isArray(callee) && callee.isIdentifier() && callee.node.name === TEMPLATE_TAG_PLACEHOLDER
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function buildPrecompileTemplateCall(
|
|
19
|
-
t: any,
|
|
20
|
-
callExpressionPath: NodePath<CallExpression>,
|
|
21
|
-
state: {
|
|
22
|
-
importUtil: ImportUtil;
|
|
23
|
-
}
|
|
24
|
-
): CallExpression {
|
|
25
|
-
const callee = callExpressionPath.get('callee');
|
|
26
|
-
|
|
27
|
-
return t.callExpression(
|
|
28
|
-
state.importUtil.import(callee, '@ember/template-compilation', 'precompileTemplate'),
|
|
29
|
-
callExpressionPath.node.arguments
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function registerRefs(
|
|
34
|
-
newPath: string | string[],
|
|
35
|
-
getRefPaths: (path: string) => NodePath[]
|
|
36
|
-
) {
|
|
37
|
-
if (Array.isArray(newPath)) {
|
|
38
|
-
if (newPath.length > 1) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
'registerRefs is only meant to handle single node transformations. Received more than one path node.'
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
newPath = newPath[0] as string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const refPaths = getRefPaths(newPath);
|
|
48
|
-
|
|
49
|
-
for (const ref of refPaths) {
|
|
50
|
-
if (!ref.isIdentifier()) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
'ember-template-imports internal assumption that refPath should of type identifier. Please open an issue.'
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const binding = ref.scope.getBinding(ref.node.name);
|
|
57
|
-
|
|
58
|
-
if (binding !== undefined) {
|
|
59
|
-
binding.reference(ref);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const SUPPORTED_EXTENSIONS = ['.js', '.ts', '.gjs', '.gts'];
|
|
65
|
-
|
|
66
|
-
export function isSupportedScriptFileExtension(filePath: string) {
|
|
67
|
-
return SUPPORTED_EXTENSIONS.some((ext) => filePath.endsWith(ext));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function isStrictMode(templateInfo: TemplateMatch): boolean {
|
|
71
|
-
return templateInfo.type === 'template-tag';
|
|
72
|
-
}
|