@embroider/core 1.9.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/package.json +6 -20
  2. package/src/app.d.ts +4 -5
  3. package/src/app.js +43 -52
  4. package/src/app.js.map +1 -1
  5. package/src/babel-plugin-adjust-imports.d.ts +0 -1
  6. package/src/babel-plugin-adjust-imports.js +10 -17
  7. package/src/babel-plugin-adjust-imports.js.map +1 -1
  8. package/src/index.d.ts +0 -4
  9. package/src/index.js +2 -6
  10. package/src/index.js.map +1 -1
  11. package/src/messages.d.ts +3 -1
  12. package/src/messages.js +15 -4
  13. package/src/messages.js.map +1 -1
  14. package/src/packager.d.ts +4 -1
  15. package/src/packager.js +2 -1
  16. package/src/packager.js.map +1 -1
  17. package/src/portable-babel-config.js +1 -1
  18. package/src/portable-babel-config.js.map +1 -1
  19. package/src/babel-plugin-inline-hbs-deps-node.d.ts +0 -14
  20. package/src/babel-plugin-inline-hbs-deps-node.js +0 -27
  21. package/src/babel-plugin-inline-hbs-deps-node.js.map +0 -1
  22. package/src/babel-plugin-inline-hbs-deps.d.ts +0 -10
  23. package/src/babel-plugin-inline-hbs-deps.js +0 -134
  24. package/src/babel-plugin-inline-hbs-deps.js.map +0 -1
  25. package/src/babel-plugin-inline-hbs-node.d.ts +0 -7
  26. package/src/babel-plugin-inline-hbs-node.js +0 -15
  27. package/src/babel-plugin-inline-hbs-node.js.map +0 -1
  28. package/src/babel-plugin-inline-hbs.d.ts +0 -24
  29. package/src/babel-plugin-inline-hbs.js +0 -142
  30. package/src/babel-plugin-inline-hbs.js.map +0 -1
  31. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +0 -12
  32. package/src/babel-plugin-stage1-inline-hbs-node.js +0 -9
  33. package/src/babel-plugin-stage1-inline-hbs-node.js.map +0 -1
  34. package/src/babel-plugin-stage1-inline-hbs.d.ts +0 -9
  35. package/src/babel-plugin-stage1-inline-hbs.js +0 -96
  36. package/src/babel-plugin-stage1-inline-hbs.js.map +0 -1
  37. package/src/browser-index.d.ts +0 -1
  38. package/src/browser-index.js +0 -6
  39. package/src/browser-index.js.map +0 -1
  40. package/src/ember-template-compiler-types.d.ts +0 -41
  41. package/src/ember-template-compiler-types.js +0 -3
  42. package/src/ember-template-compiler-types.js.map +0 -1
  43. package/src/load-ember-template-compiler.d.ts +0 -6
  44. package/src/load-ember-template-compiler.js +0 -57
  45. package/src/load-ember-template-compiler.js.map +0 -1
  46. package/src/mini-modules-polyfill.d.ts +0 -12
  47. package/src/mini-modules-polyfill.js +0 -80
  48. package/src/mini-modules-polyfill.js.map +0 -1
  49. package/src/patch-template-compiler.d.ts +0 -1
  50. package/src/patch-template-compiler.js +0 -176
  51. package/src/patch-template-compiler.js.map +0 -1
  52. package/src/resolver.d.ts +0 -14
  53. package/src/resolver.js +0 -3
  54. package/src/resolver.js.map +0 -1
  55. package/src/template-compiler-common.d.ts +0 -70
  56. package/src/template-compiler-common.js +0 -176
  57. package/src/template-compiler-common.js.map +0 -1
  58. package/src/template-compiler-node.d.ts +0 -17
  59. package/src/template-compiler-node.js +0 -32
  60. package/src/template-compiler-node.js.map +0 -1
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleImportDeclaration = void 0;
4
- // this is intentionally not the whole babel-plugin-ember-modules-api-polyfill.
5
- // That runs very early, so any usage of polyfilled imports that gets emitted by
6
- // our other babel plugins can't take advantage of it.
7
- //
8
- // If I was going to try to do this properly, I would change
9
- // babel-plugin-ember-modules-api-polyfill to run very late in the game, like
10
- // this code does, so that other plugins could always not worry about it. But
11
- // seeing as modules-api-polyfill is already on the way out, it's simpler to
12
- // just handle the small piece of its functionality that matter to us:
13
- //
14
- // - all our usage (emitted by our babel plugins) is static imports, not dynamic
15
- // ones, so it's OK to just walk the top level, saving us the cost of a full
16
- // traverse
17
- // - we only emit a handful of specific imports that are easy to just list here
18
- //
19
- //
20
- let replacements = {
21
- '@ember/component/template-only': {
22
- default(t) {
23
- return t.memberExpression(t.identifier('Ember'), t.identifier('_templateOnlyComponent'));
24
- },
25
- },
26
- '@ember/template-factory': {
27
- createTemplateFactory(t) {
28
- return t.memberExpression(t.memberExpression(t.identifier('Ember'), t.identifier('HTMLBars')), t.identifier('template'));
29
- },
30
- },
31
- '@ember/component': {
32
- default(t) {
33
- return t.memberExpression(t.identifier('Ember'), t.identifier('Component'));
34
- },
35
- setComponentTemplate(t) {
36
- return t.memberExpression(t.identifier('Ember'), t.identifier('_setComponentTemplate'));
37
- },
38
- },
39
- };
40
- function miniModulesPolyfill(babel) {
41
- let t = babel.types;
42
- return {
43
- visitor: {
44
- Program: {
45
- exit(path) {
46
- for (let child of path.get('body')) {
47
- if (child.isImportDeclaration()) {
48
- let replacement = handleImportDeclaration(t, child);
49
- if (replacement) {
50
- path.replaceWith(replacement);
51
- }
52
- }
53
- }
54
- },
55
- },
56
- },
57
- };
58
- }
59
- exports.default = miniModulesPolyfill;
60
- function handleImportDeclaration(t, path) {
61
- let match = replacements[path.node.source.value];
62
- if (match) {
63
- let specifiers = path.get('specifiers');
64
- let replacers = specifiers.map(specifier => ({ replacer: match[specifier.node.local.name], specifier }));
65
- if (replacers.every(r => Boolean(r.replacer))) {
66
- path.replaceWith(t.variableDeclaration('const', replacers.map(r => t.variableDeclarator(r.specifier.node.local, r.replacer(t)))));
67
- }
68
- else {
69
- for (let { specifier, replacer } of replacers) {
70
- if (replacer) {
71
- path.insertAfter(t.variableDeclaration('const', [t.variableDeclarator(specifier.node.local, replacer(t))]));
72
- specifier.remove();
73
- }
74
- }
75
- }
76
- }
77
- return undefined;
78
- }
79
- exports.handleImportDeclaration = handleImportDeclaration;
80
- //# sourceMappingURL=mini-modules-polyfill.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mini-modules-polyfill.js","sourceRoot":"","sources":["mini-modules-polyfill.ts"],"names":[],"mappings":";;;AAKA,+EAA+E;AAC/E,gFAAgF;AAChF,sDAAsD;AACtD,EAAE;AACF,4DAA4D;AAC5D,6EAA6E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AAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC5G,SAAS,CAAC,MAAM,EAAE,CAAC;iBACpB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAtBD,0DAsBC","sourcesContent":["import type { types as t } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\n\ntype BabelTypes = typeof t;\n\n// this is intentionally not the whole babel-plugin-ember-modules-api-polyfill.\n// That runs very early, so any usage of polyfilled imports that gets emitted by\n// our other babel plugins can't take advantage of it.\n//\n// If I was going to try to do this properly, I would change\n// babel-plugin-ember-modules-api-polyfill to run very late in the game, like\n// this code does, so that other plugins could always not worry about it. But\n// seeing as modules-api-polyfill is already on the way out, it's simpler to\n// just handle the small piece of its functionality that matter to us:\n//\n// - all our usage (emitted by our babel plugins) is static imports, not dynamic\n// ones, so it's OK to just walk the top level, saving us the cost of a full\n// traverse\n// - we only emit a handful of specific imports that are easy to just list here\n//\n//\nlet replacements: { [moduleSpecifier: string]: { [name: string]: ((t: BabelTypes) => t.Expression) | undefined } } = {\n '@ember/component/template-only': {\n default(t: BabelTypes) {\n return t.memberExpression(t.identifier('Ember'), t.identifier('_templateOnlyComponent'));\n },\n },\n '@ember/template-factory': {\n createTemplateFactory(t) {\n return t.memberExpression(\n t.memberExpression(t.identifier('Ember'), t.identifier('HTMLBars')),\n t.identifier('template')\n );\n },\n },\n '@ember/component': {\n default(t: BabelTypes) {\n return t.memberExpression(t.identifier('Ember'), t.identifier('Component'));\n },\n setComponentTemplate(t: BabelTypes) {\n return t.memberExpression(t.identifier('Ember'), t.identifier('_setComponentTemplate'));\n },\n },\n};\n\nexport default function miniModulesPolyfill(babel: unknown) {\n let t = (babel as any).types as BabelTypes;\n return {\n visitor: {\n Program: {\n exit(path: NodePath<t.Program>) {\n for (let child of path.get('body')) {\n if (child.isImportDeclaration()) {\n let replacement = handleImportDeclaration(t, child);\n if (replacement) {\n path.replaceWith(replacement);\n }\n }\n }\n },\n },\n },\n };\n}\n\nexport function handleImportDeclaration(t: BabelTypes, path: NodePath<t.ImportDeclaration>) {\n let match = replacements[path.node.source.value];\n if (match) {\n let specifiers = path.get('specifiers');\n let replacers = specifiers.map(specifier => ({ replacer: match[specifier.node.local.name], specifier }));\n if (replacers.every(r => Boolean(r.replacer))) {\n path.replaceWith(\n t.variableDeclaration(\n 'const',\n replacers.map(r => t.variableDeclarator(r.specifier.node.local, r.replacer!(t)))\n )\n );\n } else {\n for (let { specifier, replacer } of replacers) {\n if (replacer) {\n path.insertAfter(t.variableDeclaration('const', [t.variableDeclarator(specifier.node.local, replacer(t))]));\n specifier.remove();\n }\n }\n }\n }\n return undefined;\n}\n"]}
@@ -1 +0,0 @@
1
- export declare function patch(source: string, templateCompilerPath: string): string;
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patch = void 0;
4
- const core_1 = require("@babel/core");
5
- function parseVersion(templateCompilerPath, source) {
6
- // ember-template-compiler.js contains a comment that indicates what version it is for
7
- // that looks like:
8
- /*!
9
- * @overview Ember - JavaScript Application Framework
10
- * @copyright Copyright 2011-2020 Tilde Inc. and contributors
11
- * Portions Copyright 2006-2011 Strobe Inc.
12
- * Portions Copyright 2008-2011 Apple Inc. All rights reserved.
13
- * @license Licensed under MIT license
14
- * See https://raw.github.com/emberjs/ember.js/master/LICENSE
15
- * @version 3.25.1
16
- */
17
- let version = source.match(/@version\s+([\d\.]+)/);
18
- if (!version || !version[1]) {
19
- throw new Error(`Could not find version string in \`${templateCompilerPath}\`. Maybe we don't support your ember-source version?`);
20
- }
21
- let numbers = version[1].split('.');
22
- let major = parseInt(numbers[0], 10);
23
- let minor = parseInt(numbers[1], 10);
24
- let patch = parseInt(numbers[2], 10);
25
- return { major, minor, patch };
26
- }
27
- function emberVersionGte(templateCompilerPath, source, major, minor) {
28
- let actual = parseVersion(templateCompilerPath, source);
29
- return actual.major > major || (actual.major === major && actual.minor >= minor);
30
- }
31
- function patch(source, templateCompilerPath) {
32
- let version = parseVersion(templateCompilerPath, source);
33
- if (emberVersionGte(templateCompilerPath, source, 3, 26) ||
34
- (version.major === 3 && version.minor === 25 && version.patch >= 2) ||
35
- (version.major === 3 && version.minor === 24 && version.patch >= 3)) {
36
- // no modifications are needed after
37
- // https://github.com/emberjs/ember.js/pull/19426 and backported to
38
- // 3.26.0-beta.3, 3.25.2, 3.24.3
39
- return source;
40
- }
41
- let replacedVar = false;
42
- let patchedSource;
43
- let needsAngleBracketPrinterFix = emberVersionGte(templateCompilerPath, source, 3, 12) && !emberVersionGte(templateCompilerPath, source, 3, 17);
44
- if (needsAngleBracketPrinterFix) {
45
- // here we are stripping off the first `var Ember;`. That one small change
46
- // lets us crack open the file and get access to its internal loader, because
47
- // we can give it our own predefined `Ember` variable instead, which it will
48
- // use and put `Ember.__loader` onto.
49
- //
50
- // on ember 3.12 through 3.16 (which use variants of glimmer-vm 0.38.5) we
51
- // also apply a patch to the printer in @glimmer/syntax to fix
52
- // https://github.com/glimmerjs/glimmer-vm/pull/941/files because it can
53
- // really bork apps under embroider, and we'd like to support at least all
54
- // active LTS versions of ember.
55
- patchedSource = (0, core_1.transform)(source, {
56
- plugins: [
57
- function () {
58
- return {
59
- visitor: {
60
- VariableDeclarator(path) {
61
- let id = path.node.id;
62
- if (id.type === 'Identifier' && id.name === 'Ember' && !replacedVar) {
63
- replacedVar = true;
64
- path.remove();
65
- }
66
- },
67
- CallExpression: {
68
- enter(path, state) {
69
- let callee = path.get('callee');
70
- if (!callee.isIdentifier() || callee.node.name !== 'define') {
71
- return;
72
- }
73
- let firstArg = path.get('arguments')[0];
74
- if (!firstArg.isStringLiteral() || firstArg.node.value !== '@glimmer/syntax') {
75
- return;
76
- }
77
- state.definingGlimmerSyntax = path;
78
- },
79
- exit(path, state) {
80
- if (state.definingGlimmerSyntax === path) {
81
- state.definingGlimmerSyntax = false;
82
- }
83
- },
84
- },
85
- FunctionDeclaration: {
86
- enter(path, state) {
87
- if (!state.definingGlimmerSyntax) {
88
- return;
89
- }
90
- let id = path.get('id');
91
- if (id.isIdentifier() && id.node.name === 'build') {
92
- state.declaringBuildFunction = path;
93
- }
94
- },
95
- exit(path, state) {
96
- if (state.declaringBuildFunction === path) {
97
- state.declaringBuildFunction = false;
98
- }
99
- },
100
- },
101
- SwitchCase: {
102
- enter(path, state) {
103
- if (!state.definingGlimmerSyntax) {
104
- return;
105
- }
106
- let test = path.get('test');
107
- if (test.isStringLiteral() && test.node.value === 'ElementNode') {
108
- state.caseElementNode = path;
109
- }
110
- },
111
- exit(path, state) {
112
- if (state.caseElementNode === path) {
113
- state.caseElementNode = false;
114
- }
115
- },
116
- },
117
- IfStatement(path, state) {
118
- if (!state.caseElementNode) {
119
- return;
120
- }
121
- let test = path.get('test');
122
- // the place we want is the only if with a computed member
123
- // expression predicate.
124
- if (test.isMemberExpression() && test.node.computed) {
125
- path.node.alternate = core_1.types.ifStatement(core_1.types.memberExpression(core_1.types.identifier('ast'), core_1.types.identifier('selfClosing')), core_1.types.blockStatement([
126
- core_1.types.expressionStatement(core_1.types.callExpression(core_1.types.memberExpression(core_1.types.identifier('output'), core_1.types.identifier('push')), [
127
- core_1.types.stringLiteral(' />'),
128
- ])),
129
- ]), path.node.alternate);
130
- }
131
- },
132
- },
133
- };
134
- },
135
- ],
136
- }).code;
137
- }
138
- else {
139
- // applies to < 3.12 and >= 3.17
140
- //
141
- // here we are stripping off the first `var Ember;`. That one small change
142
- // lets us crack open the file and get access to its internal loader, because
143
- // we can give it our own predefined `Ember` variable instead, which it will
144
- // use and put `Ember.__loader` onto.
145
- patchedSource = (0, core_1.transform)(source, {
146
- generatorOpts: {
147
- compact: true,
148
- },
149
- plugins: [
150
- function () {
151
- return {
152
- visitor: {
153
- VariableDeclarator(path) {
154
- let id = path.node.id;
155
- if (id.type === 'Identifier' && id.name === 'Ember' && !replacedVar) {
156
- replacedVar = true;
157
- path.remove();
158
- }
159
- },
160
- },
161
- };
162
- },
163
- ],
164
- }).code;
165
- }
166
- if (!replacedVar) {
167
- throw new Error(`didn't find expected source in ${templateCompilerPath}. Maybe we don't support your ember-source version?`);
168
- }
169
- return `
170
- let Ember = {};
171
- ${patchedSource};
172
- module.exports.Ember = Ember;
173
- `;
174
- }
175
- exports.patch = patch;
176
- //# sourceMappingURL=patch-template-compiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"patch-template-compiler.js","sourceRoot":"","sources":["patch-template-compiler.ts"],"names":[],"mappings":";;;AACA,sCAAoD;AAEpD,SAAS,YAAY,CAAC,oBAA4B,EAAE,MAAc;IAChE,sFAAsF;IACtF,mBAAmB;IAEnB;;;;;;;;OAQG;IAEH,IAAI,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACnD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,sCAAsC,oBAAoB,uDAAuD,CAClH,CAAC;KACH;IAED,IAAI,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAErC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,eAAe,CAAC,oBAA4B,EAAE,MAAc,EAAE,KAAa,EAAE,KAAa;IACjG,IAAI,MAAM,GAAG,YAAY,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IAExD,OAAO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,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,YAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;4CACjF,YAAC,CAAC,aAAa,CAAC,KAAK,CAAC;yCACvB,CAAC,CACH;qCACF,CAAC,EACF,IAAI,CAAC,IAAI,CAAC,SAAS,CACpB,CAAC;iCACH;4BACH,CAAC;yBACF;qBACF,CAAC;gBACJ,CAAC;aACF;SACF,CAAE,CAAC,IAAK,CAAC;KACX;SAAM;QACL,gCAAgC;QAChC,EAAE;QACF,0EAA0E;QAC1E,6EAA6E;QAC7E,4EAA4E;QAC5E,qCAAqC;QACrC,aAAa,GAAG,IAAA,gBAAS,EAAC,MAAM,EAAE;YAChC,aAAa,EAAE;gBACb,OAAO,EAAE,IAAI;aACd;YACD,OAAO,EAAE;gBACP;oBACE,OAAO;wBACL,OAAO,EAAE;4BACP,kBAAkB,CAAC,IAAoC;gCACrD,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gCACtB,IAAI,EAAE,CAAC,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,WAAW,EAAE;oCACnE,WAAW,GAAG,IAAI,CAAC;oCACnB,IAAI,CAAC,MAAM,EAAE,CAAC;iCACf;4BACH,CAAC;yBACF;qBACF,CAAC;gBACJ,CAAC;aACF;SACF,CAAE,CAAC,IAAK,CAAC;KACX;IAED,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,kCAAkC,oBAAoB,qDAAqD,CAC5G,CAAC;KACH;IAED,OAAO;;QAED,aAAa;;GAElB,CAAC;AACJ,CAAC;AA/JD,sBA+JC","sourcesContent":["import { NodePath } from '@babel/traverse';\nimport { transform, types as t } from '@babel/core';\n\nfunction parseVersion(templateCompilerPath: string, source: string): { major: number; minor: number; patch: number } {\n // ember-template-compiler.js contains a comment that indicates what version it is for\n // that looks like:\n\n /*!\n * @overview Ember - JavaScript Application Framework\n * @copyright Copyright 2011-2020 Tilde Inc. and contributors\n * Portions Copyright 2006-2011 Strobe Inc.\n * Portions Copyright 2008-2011 Apple Inc. All rights reserved.\n * @license Licensed under MIT license\n * See https://raw.github.com/emberjs/ember.js/master/LICENSE\n * @version 3.25.1\n */\n\n let version = source.match(/@version\\s+([\\d\\.]+)/);\n if (!version || !version[1]) {\n throw new Error(\n `Could not find version string in \\`${templateCompilerPath}\\`. Maybe we don't support your ember-source version?`\n );\n }\n\n let numbers = version[1].split('.');\n let major = parseInt(numbers[0], 10);\n let minor = parseInt(numbers[1], 10);\n let patch = parseInt(numbers[2], 10);\n\n return { major, minor, patch };\n}\n\nfunction emberVersionGte(templateCompilerPath: string, source: string, major: number, minor: number): boolean {\n let actual = parseVersion(templateCompilerPath, source);\n\n return actual.major > major || (actual.major === major && actual.minor >= minor);\n}\n\nexport function patch(source: string, templateCompilerPath: string): string {\n let version = parseVersion(templateCompilerPath, source);\n\n if (\n emberVersionGte(templateCompilerPath, source, 3, 26) ||\n (version.major === 3 && version.minor === 25 && version.patch >= 2) ||\n (version.major === 3 && version.minor === 24 && version.patch >= 3)\n ) {\n // no modifications are needed after\n // https://github.com/emberjs/ember.js/pull/19426 and backported to\n // 3.26.0-beta.3, 3.25.2, 3.24.3\n return source;\n }\n\n let replacedVar = false;\n let patchedSource;\n\n let needsAngleBracketPrinterFix =\n emberVersionGte(templateCompilerPath, source, 3, 12) && !emberVersionGte(templateCompilerPath, source, 3, 17);\n\n if (needsAngleBracketPrinterFix) {\n // here we are stripping off the first `var Ember;`. That one small change\n // lets us crack open the file and get access to its internal loader, because\n // we can give it our own predefined `Ember` variable instead, which it will\n // use and put `Ember.__loader` onto.\n //\n // on ember 3.12 through 3.16 (which use variants of glimmer-vm 0.38.5) we\n // also apply a patch to the printer in @glimmer/syntax to fix\n // https://github.com/glimmerjs/glimmer-vm/pull/941/files because it can\n // really bork apps under embroider, and we'd like to support at least all\n // active LTS versions of ember.\n patchedSource = transform(source, {\n plugins: [\n function () {\n return {\n visitor: {\n VariableDeclarator(path: NodePath<t.VariableDeclarator>) {\n let id = path.node.id;\n if (id.type === 'Identifier' && id.name === 'Ember' && !replacedVar) {\n replacedVar = true;\n path.remove();\n }\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: BabelState) {\n let callee = path.get('callee');\n if (!callee.isIdentifier() || callee.node.name !== 'define') {\n return;\n }\n let firstArg = path.get('arguments')[0];\n if (!firstArg.isStringLiteral() || firstArg.node.value !== '@glimmer/syntax') {\n return;\n }\n state.definingGlimmerSyntax = path;\n },\n exit(path: NodePath<t.CallExpression>, state: BabelState) {\n if (state.definingGlimmerSyntax === path) {\n state.definingGlimmerSyntax = false;\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: BabelState) {\n if (!state.definingGlimmerSyntax) {\n return;\n }\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'build') {\n state.declaringBuildFunction = path;\n }\n },\n exit(path: NodePath<t.FunctionDeclaration>, state: BabelState) {\n if (state.declaringBuildFunction === path) {\n state.declaringBuildFunction = false;\n }\n },\n },\n SwitchCase: {\n enter(path: NodePath<t.SwitchCase>, state: BabelState) {\n if (!state.definingGlimmerSyntax) {\n return;\n }\n let test = path.get('test');\n if (test.isStringLiteral() && test.node.value === 'ElementNode') {\n state.caseElementNode = path;\n }\n },\n exit(path: NodePath<t.SwitchCase>, state: BabelState) {\n if (state.caseElementNode === path) {\n state.caseElementNode = false;\n }\n },\n },\n IfStatement(path: NodePath<t.IfStatement>, state: BabelState) {\n if (!state.caseElementNode) {\n return;\n }\n let test = path.get('test');\n // the place we want is the only if with a computed member\n // expression predicate.\n if (test.isMemberExpression() && test.node.computed) {\n path.node.alternate = t.ifStatement(\n t.memberExpression(t.identifier('ast'), t.identifier('selfClosing')),\n t.blockStatement([\n t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('output'), t.identifier('push')), [\n t.stringLiteral(' />'),\n ])\n ),\n ]),\n path.node.alternate\n );\n }\n },\n },\n };\n },\n ],\n })!.code!;\n } else {\n // applies to < 3.12 and >= 3.17\n //\n // here we are stripping off the first `var Ember;`. That one small change\n // lets us crack open the file and get access to its internal loader, because\n // we can give it our own predefined `Ember` variable instead, which it will\n // use and put `Ember.__loader` onto.\n patchedSource = transform(source, {\n generatorOpts: {\n compact: true,\n },\n plugins: [\n function () {\n return {\n visitor: {\n VariableDeclarator(path: NodePath<t.VariableDeclarator>) {\n let id = path.node.id;\n if (id.type === 'Identifier' && id.name === 'Ember' && !replacedVar) {\n replacedVar = true;\n path.remove();\n }\n },\n },\n };\n },\n ],\n })!.code!;\n }\n\n if (!replacedVar) {\n throw new Error(\n `didn't find expected source in ${templateCompilerPath}. Maybe we don't support your ember-source version?`\n );\n }\n\n return `\n let Ember = {};\n ${patchedSource};\n module.exports.Ember = Ember;\n `;\n}\n\ninterface BabelState {\n definingGlimmerSyntax: NodePath | false;\n declaringBuildFunction: NodePath | false;\n caseElementNode: NodePath | false;\n}\n"]}
package/src/resolver.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { TemplateCompiler } from './template-compiler-common';
2
- import { Options } from './babel-plugin-adjust-imports';
3
- export interface ResolvedDep {
4
- runtimeName: string;
5
- path: string;
6
- absPath: string;
7
- }
8
- export interface Resolver {
9
- astTransformer(templateCompiler: TemplateCompiler): unknown;
10
- dependenciesOf(moduleName: string): ResolvedDep[];
11
- absPathToRuntimePath(absPath: string): string;
12
- absPathToRuntimeName(absPath: string): string;
13
- adjustImportsOptions: Options;
14
- }
package/src/resolver.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":"","sourcesContent":["import type { TemplateCompiler } from './template-compiler-common';\nimport { Options } from './babel-plugin-adjust-imports';\n\nexport interface ResolvedDep {\n runtimeName: string;\n path: string;\n absPath: string;\n}\n\nexport interface Resolver {\n astTransformer(templateCompiler: TemplateCompiler): unknown;\n dependenciesOf(moduleName: string): ResolvedDep[];\n\n // this takes an absolute path to a file and gives back a path like\n // \"the-package-name/path/to/the-file.js\", while taking into account any\n // backward-compatible runtime name of the package. It's used by the template\n // compiler, because this is the kind of path AST plugins expect to see.\n absPathToRuntimePath(absPath: string): string;\n\n // this takes an absolute path to a file and gives back the runtime name of\n // that module, as it would tradtionally be named within loader.js.\n absPathToRuntimeName(absPath: string): string;\n\n adjustImportsOptions: Options;\n}\n"]}
@@ -1,70 +0,0 @@
1
- import { Resolver, ResolvedDep } from './resolver';
2
- export interface Plugins {
3
- ast?: unknown[];
4
- }
5
- export interface AST {
6
- _deliberatelyOpaque: 'AST';
7
- }
8
- export interface PreprocessOptions {
9
- contents: string;
10
- moduleName: string;
11
- plugins?: Plugins;
12
- filename?: string;
13
- parseOptions?: {
14
- srcName?: string;
15
- ignoreStandalone?: boolean;
16
- };
17
- mode?: 'codemod' | 'precompile';
18
- strictMode?: boolean;
19
- locals?: string[];
20
- }
21
- export interface PrinterOptions {
22
- entityEncoding?: 'transformed' | 'raw';
23
- }
24
- export interface GlimmerSyntax {
25
- preprocess(html: string, options?: PreprocessOptions): AST;
26
- print(ast: AST, options?: PrinterOptions): string;
27
- defaultOptions(options: PreprocessOptions): PreprocessOptions;
28
- precompile(templateContents: string, options: {
29
- contents: string;
30
- moduleName: string;
31
- filename: string;
32
- plugins?: any;
33
- parseOptions?: {
34
- srcName?: string;
35
- };
36
- }): string;
37
- _Ember: {
38
- FEATURES: any;
39
- ENV: any;
40
- };
41
- }
42
- export interface TemplateCompilerParams {
43
- loadEmberTemplateCompiler: () => {
44
- theExports: unknown;
45
- cacheKey: string;
46
- };
47
- resolver?: Resolver;
48
- EmberENV: unknown;
49
- plugins: Plugins;
50
- }
51
- export declare class TemplateCompiler {
52
- private loadEmberTemplateCompiler;
53
- private resolver?;
54
- private EmberENV;
55
- private plugins;
56
- constructor(params: TemplateCompilerParams);
57
- private get syntax();
58
- get cacheKey(): string;
59
- private setup;
60
- private getReversedASTPlugins;
61
- precompile(templateSource: string, options: Record<string, unknown> & {
62
- filename: string;
63
- }): {
64
- compiled: string;
65
- dependencies: ResolvedDep[];
66
- };
67
- applyTransforms(moduleName: string, contents: string): string;
68
- parse(moduleName: string, contents: string): AST;
69
- baseDir(): string;
70
- }
@@ -1,176 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TemplateCompiler = void 0;
13
- const strip_bom_1 = __importDefault(require("strip-bom"));
14
- const path_1 = require("path");
15
- const typescript_memoize_1 = require("typescript-memoize");
16
- const wrap_legacy_hbs_plugin_if_needed_1 = __importDefault(require("wrap-legacy-hbs-plugin-if-needed"));
17
- class TemplateCompiler {
18
- constructor(params) {
19
- this.loadEmberTemplateCompiler = params.loadEmberTemplateCompiler;
20
- this.resolver = params.resolver;
21
- this.EmberENV = params.EmberENV;
22
- this.plugins = params.plugins;
23
- }
24
- get syntax() {
25
- return this.setup().syntax;
26
- }
27
- get cacheKey() {
28
- return this.setup().cacheKey;
29
- }
30
- setup() {
31
- let { theExports, cacheKey } = this.loadEmberTemplateCompiler();
32
- let syntax = loadGlimmerSyntax(theExports);
33
- initializeEmberENV(syntax, this.EmberENV);
34
- // todo: get resolver reflected in cacheKey
35
- return { syntax, cacheKey };
36
- }
37
- getReversedASTPlugins(ast) {
38
- return ast.slice().reverse();
39
- }
40
- // Compiles to the wire format plus dependency list.
41
- precompile(templateSource, options) {
42
- var _a, _b;
43
- let dependencies;
44
- let runtimeName;
45
- let filename = options.filename;
46
- if (this.resolver) {
47
- runtimeName = this.resolver.absPathToRuntimePath(filename);
48
- }
49
- else {
50
- runtimeName = filename;
51
- }
52
- let opts = this.syntax.defaultOptions({ contents: templateSource, moduleName: filename });
53
- let plugins = {
54
- ...opts === null || opts === void 0 ? void 0 : opts.plugins,
55
- ast: [
56
- ...this.getReversedASTPlugins(this.plugins.ast),
57
- this.resolver && this.resolver.astTransformer(this),
58
- // Ember 3.27+ uses _buildCompileOptions will not add AST plugins to its result
59
- ...((_b = (_a = opts === null || opts === void 0 ? void 0 : opts.plugins) === null || _a === void 0 ? void 0 : _a.ast) !== null && _b !== void 0 ? _b : []),
60
- ].filter(Boolean),
61
- };
62
- let compiled = this.syntax.precompile((0, strip_bom_1.default)(templateSource), {
63
- contents: templateSource,
64
- moduleName: runtimeName,
65
- plugins,
66
- ...options,
67
- });
68
- if (this.resolver) {
69
- dependencies = this.resolver.dependenciesOf(filename);
70
- }
71
- else {
72
- dependencies = [];
73
- }
74
- return { compiled, dependencies };
75
- }
76
- // Applies all custom AST transforms and emits the results still as
77
- // handlebars.
78
- applyTransforms(moduleName, contents) {
79
- let opts = this.syntax.defaultOptions({ contents, moduleName });
80
- // the user-provided plugins come first in the list, and those are the
81
- // only ones we want to run. The built-in plugins don't need to run here
82
- // in stage1, it's better that they run in stage3 when the appropriate
83
- // ember version is in charge.
84
- //
85
- // rather than slicing them off, we could choose instead to not call
86
- // syntax.defaultOptions, but then we lose some of the compatibility
87
- // normalization that it does on the user-provided plugins.
88
- opts.plugins = opts.plugins || {}; // Ember 3.27+ won't add opts.plugins
89
- opts.plugins.ast = this.getReversedASTPlugins(this.plugins.ast).map(plugin => {
90
- // Although the precompile API does, this direct glimmer syntax api
91
- // does not support these legacy plugins, so we must wrap them.
92
- return (0, wrap_legacy_hbs_plugin_if_needed_1.default)(plugin);
93
- });
94
- // instructs glimmer-vm to preserve entity encodings (e.g. don't parse &nbsp; -> ' ')
95
- opts.mode = 'codemod';
96
- opts.filename = moduleName;
97
- opts.moduleName = this.resolver ? this.resolver.absPathToRuntimePath(moduleName) || moduleName : moduleName;
98
- let ast = this.syntax.preprocess(contents, opts);
99
- return this.syntax.print(ast, { entityEncoding: 'raw' });
100
- }
101
- parse(moduleName, contents) {
102
- // this is just a parse, so we deliberately don't run any plugins.
103
- let opts = { contents, moduleName, plugins: {} };
104
- return this.syntax.preprocess(contents, opts);
105
- }
106
- baseDir() {
107
- return (0, path_1.join)(__dirname, '..');
108
- }
109
- }
110
- __decorate([
111
- (0, typescript_memoize_1.Memoize)()
112
- ], TemplateCompiler.prototype, "setup", null);
113
- __decorate([
114
- (0, typescript_memoize_1.Memoize)()
115
- ], TemplateCompiler.prototype, "getReversedASTPlugins", null);
116
- exports.TemplateCompiler = TemplateCompiler;
117
- // this matches the setup done by ember-cli-htmlbars: https://git.io/JtbN6
118
- function initializeEmberENV(syntax, EmberENV) {
119
- if (!EmberENV) {
120
- return;
121
- }
122
- let props;
123
- if (EmberENV.FEATURES) {
124
- props = Object.keys(EmberENV.FEATURES);
125
- props.forEach(prop => {
126
- syntax._Ember.FEATURES[prop] = EmberENV.FEATURES[prop];
127
- });
128
- }
129
- if (EmberENV) {
130
- props = Object.keys(EmberENV);
131
- props.forEach(prop => {
132
- if (prop === 'FEATURES') {
133
- return;
134
- }
135
- syntax._Ember.ENV[prop] = EmberENV[prop];
136
- });
137
- }
138
- }
139
- // we could directly depend on @glimmer/syntax and have nice types and
140
- // everything. But the problem is, we really want to use the exact version that
141
- // the app itself is using, and its copy is bundled away inside
142
- // ember-template-compiler.js.
143
- function loadGlimmerSyntax(emberTemplateCompilerExports) {
144
- var _a, _b;
145
- // detect if we are using an Ember version with the exports we need
146
- // (from https://github.com/emberjs/ember.js/pull/19426)
147
- if (emberTemplateCompilerExports._preprocess !== undefined) {
148
- return {
149
- print: emberTemplateCompilerExports._print,
150
- preprocess: emberTemplateCompilerExports._preprocess,
151
- defaultOptions: emberTemplateCompilerExports._buildCompileOptions,
152
- precompile: emberTemplateCompilerExports.precompile,
153
- _Ember: emberTemplateCompilerExports._Ember,
154
- };
155
- }
156
- else {
157
- // Older Ember versions (prior to 3.27) do not expose a public way to to source 2 source compilation of templates.
158
- // because of this, we must resort to some hackery.
159
- //
160
- // We use the following API's (that we grab from Ember.__loader):
161
- //
162
- // * glimmer/syntax's preprocess
163
- // * glimmer/syntax's print
164
- // * ember-template-compiler/lib/system/compile-options's defaultOptions
165
- let syntax = ((_a = emberTemplateCompilerExports.Ember) !== null && _a !== void 0 ? _a : emberTemplateCompilerExports._Ember).__loader.require('@glimmer/syntax');
166
- let compilerOptions = ((_b = emberTemplateCompilerExports.Ember) !== null && _b !== void 0 ? _b : emberTemplateCompilerExports._Ember).__loader.require('ember-template-compiler/lib/system/compile-options');
167
- return {
168
- print: syntax.print,
169
- preprocess: syntax.preprocess,
170
- defaultOptions: compilerOptions.default,
171
- precompile: emberTemplateCompilerExports.precompile,
172
- _Ember: emberTemplateCompilerExports._Ember,
173
- };
174
- }
175
- }
176
- //# sourceMappingURL=template-compiler-common.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template-compiler-common.js","sourceRoot":"","sources":["template-compiler-common.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAiC;AAEjC,+BAA4B;AAC5B,2DAA6C;AAC7C,wGAA2E;AAiE3E,MAAa,gBAAgB;IAM3B,YAAY,MAA8B;QACxC,IAAI,CAAC,yBAAyB,GAAG,MAAM,CAAC,yBAAyB,CAAC;QAClE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,OAAO,GA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ACrD,CAAC;QAEF,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,cAAc,EAAE,eAAe,CAAC,OAAO;YACvC,UAAU,EAAE,4BAA4B,CAAC,UAAU;YACnD,MAAM,EAAE,4BAA4B,CAAC,MAAM;SAC5C,CAAC;KACH;AACH,CAAC","sourcesContent":["import stripBom from 'strip-bom';\nimport { Resolver, ResolvedDep } from './resolver';\nimport { join } from 'path';\nimport { Memoize } from 'typescript-memoize';\nimport wrapLegacyHbsPluginIfNeeded from 'wrap-legacy-hbs-plugin-if-needed';\n\nexport interface Plugins {\n ast?: unknown[];\n}\n\nexport interface AST {\n _deliberatelyOpaque: 'AST';\n}\n\nexport interface PreprocessOptions {\n contents: string;\n moduleName: string;\n plugins?: Plugins;\n filename?: string;\n\n parseOptions?: {\n srcName?: string;\n ignoreStandalone?: boolean;\n };\n\n // added in Ember 3.17 (@glimmer/syntax@0.40.2)\n mode?: 'codemod' | 'precompile';\n\n // added in Ember 3.25\n strictMode?: boolean;\n locals?: string[];\n}\n\nexport interface PrinterOptions {\n entityEncoding?: 'transformed' | 'raw';\n}\n\n// This just reflects the API we're extracting from ember-template-compiler.js,\n// plus a cache key that lets us know when the underlying source has remained\n// stable.\nexport interface GlimmerSyntax {\n preprocess(html: string, options?: PreprocessOptions): AST;\n print(ast: AST, options?: PrinterOptions): string;\n defaultOptions(options: PreprocessOptions): PreprocessOptions;\n precompile(\n templateContents: string,\n options: {\n contents: string;\n moduleName: string;\n filename: string;\n plugins?: any;\n parseOptions?: {\n srcName?: string;\n };\n }\n ): string;\n _Ember: { FEATURES: any; ENV: any };\n}\n\nexport interface TemplateCompilerParams {\n // this should be the exports object from ember-template-compiler.js. It's\n // \"unknown\" here because it changes shape in different ember versions, we\n // will do our best to consume it.\n loadEmberTemplateCompiler: () => { theExports: unknown; cacheKey: string };\n resolver?: Resolver;\n EmberENV: unknown;\n plugins: Plugins;\n}\n\nexport class TemplateCompiler {\n private loadEmberTemplateCompiler: () => { theExports: unknown; cacheKey: string };\n private resolver?: Resolver;\n private EmberENV: unknown;\n private plugins: Plugins;\n\n constructor(params: TemplateCompilerParams) {\n this.loadEmberTemplateCompiler = params.loadEmberTemplateCompiler;\n this.resolver = params.resolver;\n this.EmberENV = params.EmberENV;\n this.plugins = params.plugins;\n }\n\n private get syntax(): GlimmerSyntax {\n return this.setup().syntax;\n }\n\n get cacheKey(): string {\n return this.setup().cacheKey;\n }\n\n @Memoize()\n private setup() {\n let { theExports, cacheKey } = this.loadEmberTemplateCompiler();\n let syntax = loadGlimmerSyntax(theExports);\n initializeEmberENV(syntax, this.EmberENV);\n // todo: get resolver reflected in cacheKey\n return { syntax, cacheKey };\n }\n\n @Memoize()\n private getReversedASTPlugins(ast: unknown[]): unknown[] {\n return ast.slice().reverse();\n }\n\n // Compiles to the wire format plus dependency list.\n precompile(\n templateSource: string,\n options: Record<string, unknown> & { filename: string }\n ): { compiled: string; dependencies: ResolvedDep[] } {\n let dependencies: ResolvedDep[];\n let runtimeName: string;\n let filename: string = options.filename;\n\n if (this.resolver) {\n runtimeName = this.resolver.absPathToRuntimePath(filename);\n } else {\n runtimeName = filename;\n }\n\n let opts = this.syntax.defaultOptions({ contents: templateSource, moduleName: filename });\n let plugins: Plugins = {\n ...opts?.plugins,\n\n ast: [\n ...this.getReversedASTPlugins(this.plugins.ast!),\n this.resolver && this.resolver.astTransformer(this),\n\n // Ember 3.27+ uses _buildCompileOptions will not add AST plugins to its result\n ...(opts?.plugins?.ast ?? []),\n ].filter(Boolean),\n };\n\n let compiled = this.syntax.precompile(stripBom(templateSource), {\n contents: templateSource,\n moduleName: runtimeName,\n plugins,\n ...options,\n });\n\n if (this.resolver) {\n dependencies = this.resolver.dependenciesOf(filename);\n } else {\n dependencies = [];\n }\n\n return { compiled, dependencies };\n }\n\n // Applies all custom AST transforms and emits the results still as\n // handlebars.\n applyTransforms(moduleName: string, contents: string): string {\n let opts = this.syntax.defaultOptions({ contents, moduleName });\n\n // the user-provided plugins come first in the list, and those are the\n // only ones we want to run. The built-in plugins don't need to run here\n // in stage1, it's better that they run in stage3 when the appropriate\n // ember version is in charge.\n //\n // rather than slicing them off, we could choose instead to not call\n // syntax.defaultOptions, but then we lose some of the compatibility\n // normalization that it does on the user-provided plugins.\n opts.plugins = opts.plugins || {}; // Ember 3.27+ won't add opts.plugins\n opts.plugins.ast = this.getReversedASTPlugins(this.plugins.ast!).map(plugin => {\n // Although the precompile API does, this direct glimmer syntax api\n // does not support these legacy plugins, so we must wrap them.\n return wrapLegacyHbsPluginIfNeeded(plugin as any);\n });\n\n // instructs glimmer-vm to preserve entity encodings (e.g. don't parse &nbsp; -> ' ')\n opts.mode = 'codemod';\n\n opts.filename = moduleName;\n opts.moduleName = this.resolver ? this.resolver.absPathToRuntimePath(moduleName) || moduleName : moduleName;\n let ast = this.syntax.preprocess(contents, opts);\n\n return this.syntax.print(ast, { entityEncoding: 'raw' });\n }\n\n parse(moduleName: string, contents: string): AST {\n // this is just a parse, so we deliberately don't run any plugins.\n let opts = { contents, moduleName, plugins: {} };\n return this.syntax.preprocess(contents, opts);\n }\n\n baseDir() {\n return join(__dirname, '..');\n }\n}\n\n// this matches the setup done by ember-cli-htmlbars: https://git.io/JtbN6\nfunction initializeEmberENV(syntax: GlimmerSyntax, EmberENV: any) {\n if (!EmberENV) {\n return;\n }\n\n let props;\n\n if (EmberENV.FEATURES) {\n props = Object.keys(EmberENV.FEATURES);\n props.forEach(prop => {\n syntax._Ember.FEATURES[prop] = EmberENV.FEATURES[prop];\n });\n }\n\n if (EmberENV) {\n props = Object.keys(EmberENV);\n props.forEach(prop => {\n if (prop === 'FEATURES') {\n return;\n }\n syntax._Ember.ENV[prop] = EmberENV[prop];\n });\n }\n}\n\n// we could directly depend on @glimmer/syntax and have nice types and\n// everything. But the problem is, we really want to use the exact version that\n// the app itself is using, and its copy is bundled away inside\n// ember-template-compiler.js.\nfunction loadGlimmerSyntax(emberTemplateCompilerExports: any): GlimmerSyntax {\n // detect if we are using an Ember version with the exports we need\n // (from https://github.com/emberjs/ember.js/pull/19426)\n if (emberTemplateCompilerExports._preprocess !== undefined) {\n return {\n print: emberTemplateCompilerExports._print,\n preprocess: emberTemplateCompilerExports._preprocess,\n defaultOptions: emberTemplateCompilerExports._buildCompileOptions,\n precompile: emberTemplateCompilerExports.precompile,\n _Ember: emberTemplateCompilerExports._Ember,\n };\n } else {\n // Older Ember versions (prior to 3.27) do not expose a public way to to source 2 source compilation of templates.\n // because of this, we must resort to some hackery.\n //\n // We use the following API's (that we grab from Ember.__loader):\n //\n // * glimmer/syntax's preprocess\n // * glimmer/syntax's print\n // * ember-template-compiler/lib/system/compile-options's defaultOptions\n let syntax = (emberTemplateCompilerExports.Ember ?? emberTemplateCompilerExports._Ember).__loader.require(\n '@glimmer/syntax'\n );\n let compilerOptions = (emberTemplateCompilerExports.Ember ?? emberTemplateCompilerExports._Ember).__loader.require(\n 'ember-template-compiler/lib/system/compile-options'\n );\n\n return {\n print: syntax.print,\n preprocess: syntax.preprocess,\n defaultOptions: compilerOptions.default,\n precompile: emberTemplateCompilerExports.precompile,\n _Ember: emberTemplateCompilerExports._Ember,\n };\n }\n}\n"]}
@@ -1,17 +0,0 @@
1
- import { Resolver } from './resolver';
2
- import { PluginItem } from '@babel/core';
3
- import { Plugins } from './ember-template-compiler-types';
4
- import { TemplateCompiler } from './template-compiler-common';
5
- export interface NodeTemplateCompilerParams {
6
- compilerPath: string;
7
- compilerChecksum: string;
8
- resolver?: Resolver;
9
- EmberENV: unknown;
10
- plugins: Plugins;
11
- }
12
- export declare class NodeTemplateCompiler extends TemplateCompiler {
13
- params: NodeTemplateCompilerParams;
14
- constructor(params: NodeTemplateCompilerParams);
15
- inlineTransformsBabelPlugin(): PluginItem;
16
- baseDir(): string;
17
- }