@embroider/core 1.9.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +0,0 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs-deps.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-deps.ts"],"names":[],"mappings":";;;AAGA,+BAA4B;AAG5B,kEAAyE;AACzE,yDAA+C;AAE/C;;;;;;EAME;AACF,IAAI,YAA+B,CAAC;AAEpC;;;EAGE;AACF,SAAgB,UAAU,CAAC,cAAsB,EAAE,OAAgC;IACjF,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,6GAA6G,CAC9G,CAAC;KACH;IACD,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,cAAc,EAAE;QACjF,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,I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AAC,CAAC;KACxD;IACD,OAAO,KAAK,CAAC,gBAAgB,CAAC;AAChC,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { join } from 'path';\nimport type { TemplateCompiler } from './template-compiler-common';\nimport { ResolvedDep } from './resolver';\nimport { templateCompilationModules } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\n\n/*\n In order to coordinate with babel-plugin-ember-template-compilation, we need\n to give it a `precompile` function that, as a side-effect, captures the\n dependencies needed within the current file. We do this coordination via this\n module-scoped variable, which is safe given Javascript's single-threaded\n nature and babel's synchronicity.\n*/\nlet currentState: State | undefined;\n\n/*\n This is the precompile function you should pass to\n babel-plugin-ember-template-compilation.\n*/\nexport function precompile(templateSource: string, options: Record<string, unknown>) {\n if (!currentState) {\n throw new Error(\n `bug: babel-plugin-ember-template-compilation and babel-plugin-inline-hbs-deps aren't coordinating correctly`\n );\n }\n let { compiled, dependencies } = compiler(currentState).precompile(templateSource, {\n filename: currentState.file.opts.filename,\n ...options,\n });\n for (let dep of dependencies) {\n currentState.dependencies.set(dep.runtimeName, dep);\n }\n return compiled;\n}\n\ninterface State {\n opts: {};\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n dependencies: Map<string, ResolvedDep>;\n getCompiler: (opts: any) => TemplateCompiler;\n templateCompiler: TemplateCompiler | undefined;\n adder: ImportUtil;\n emittedCallExpressions: Set<t.Node>;\n}\n\nexport default function make(getCompiler: (opts: any) => TemplateCompiler) {\n function inlineHBSTransform(babel: typeof Babel): unknown {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n state.dependencies = new Map();\n state.adder = new ImportUtil(t, path);\n state.emittedCallExpressions = new Set();\n state.getCompiler = getCompiler;\n currentState = state;\n },\n exit(path: NodePath<t.Program>, state: State) {\n // we are responsible for rewriting all usages of all the\n // templateCompilationModules to standardize on\n // @ember/template-compilation, so all imports other than that one\n // need to be cleaned up here.\n for (let moduleConfig of templateCompilationModules) {\n if (moduleConfig.module !== '@ember/template-compilation') {\n state.adder.removeImport(moduleConfig.module, moduleConfig.exportedName);\n }\n }\n let counter = 0;\n for (let dep of state.dependencies.values()) {\n path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));\n path.node.body.unshift(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(`a${counter++}`))],\n t.stringLiteral(dep.path)\n )\n );\n }\n currentState = undefined;\n },\n },\n TaggedTemplateExpression(path: NodePath<t.TaggedTemplateExpression>, state: State) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('tag').referencesImport(module, exportedName)) {\n handleTagged(path, state, t);\n }\n }\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n if (state.emittedCallExpressions.has(path.node)) {\n return;\n }\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('callee').referencesImport(module, exportedName)) {\n handleCalled(path, state, t);\n }\n }\n },\n },\n };\n }\n\n inlineHBSTransform._parallelBabel = {\n requireFile: __filename,\n };\n\n inlineHBSTransform.baseDir = function () {\n return join(__dirname, '..');\n };\n\n function handleTagged(path: NodePath<t.TaggedTemplateExpression>, state: State, t: typeof Babel.types) {\n if (path.node.quasi.expressions.length) {\n throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');\n }\n let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');\n let args: t.Expression[] = [t.stringLiteral(template)];\n\n let locals: t.Identifier[] = [\n // TODO: this is where lexically scoped dependencies go\n ];\n let opts = precompileOpts(locals, t);\n if (opts) {\n args.push(opts);\n }\n\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n args\n );\n\n state.emittedCallExpressions.add(newCallExpression);\n path.replaceWith(newCallExpression);\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State, t: typeof Babel.types) {\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n path.node.arguments\n );\n state.emittedCallExpressions.add(newCallExpression);\n path.replaceWith(newCallExpression);\n }\n\n function precompileOpts(locals: t.Identifier[], t: typeof Babel.types) {\n if (locals.length > 0) {\n return t.objectExpression([\n t.objectProperty(\n t.identifier('scope'),\n t.arrowFunctionExpression(\n [],\n t.objectExpression(locals.map(name => t.objectProperty(name, name, false, true)))\n )\n ),\n ]);\n }\n }\n\n function amdDefine(runtimeName: string, importCounter: number, t: typeof Babel.types) {\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),\n ])\n );\n }\n return inlineHBSTransform;\n}\n\nfunction compiler(state: State) {\n if (!state.templateCompiler) {\n state.templateCompiler = state.getCompiler(state.opts);\n }\n return state.templateCompiler;\n}\n"]}
@@ -1,7 +0,0 @@
1
- import { NodeTemplateCompilerParams } from './template-compiler-node';
2
- import type * as Babel from '@babel/core';
3
- export interface Params {
4
- templateCompiler: NodeTemplateCompilerParams;
5
- }
6
- declare const _default: (babel: typeof Babel) => Babel.PluginObj<unknown>;
7
- export default _default;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- /*
3
- This plugin is used only for Ember < 3.27. For newer Ember's we have a
4
- different implementation that shares the standard
5
- babel-plugin-ember-template-compilation and supports passing Javascript
6
- lexically scoped names into templates.
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
- const template_compiler_node_1 = require("./template-compiler-node");
13
- const babel_plugin_inline_hbs_1 = __importDefault(require("./babel-plugin-inline-hbs"));
14
- exports.default = (0, babel_plugin_inline_hbs_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
15
- //# sourceMappingURL=babel-plugin-inline-hbs-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-node.ts"],"names":[],"mappings":";AAAA;;;;;EAKE;;;;;AAEF,qEAA4F;AAC5F,wFAA6C;AAO7C,kBAAe,IAAA,iCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAExD,CAAC","sourcesContent":["/*\n This plugin is used only for Ember < 3.27. For newer Ember's we have a\n different implementation that shares the standard\n babel-plugin-ember-template-compilation and supports passing Javascript\n lexically scoped names into templates.\n*/\n\nimport { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make from './babel-plugin-inline-hbs';\nimport type * as Babel from '@babel/core';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler)) as (\n babel: typeof Babel\n) => babel.PluginObj<unknown>;\n"]}
@@ -1,24 +0,0 @@
1
- import type * as Babel from '@babel/core';
2
- import type { TemplateCompiler } from './template-compiler-common';
3
- import { ResolvedDep } from './resolver';
4
- import { ImportUtil } from 'babel-import-util';
5
- interface State<O> {
6
- opts: O;
7
- file: {
8
- code: string;
9
- opts: {
10
- filename: string;
11
- };
12
- };
13
- dependencies: Map<string, ResolvedDep>;
14
- templateCompiler: TemplateCompiler | undefined;
15
- adder: ImportUtil;
16
- }
17
- export default function make<O>(getCompiler: (opts: O) => TemplateCompiler): {
18
- (babel: typeof Babel): Babel.PluginObj<State<O>>;
19
- _parallelBabel: {
20
- requireFile: string;
21
- };
22
- baseDir(): string;
23
- };
24
- export {};
@@ -1,142 +0,0 @@
1
- "use strict";
2
- /*
3
- This plugin is used only for Ember < 3.27. For newer Ember's we have a
4
- different implementation that shares the standard
5
- babel-plugin-ember-template-compilation and supports passing Javascript
6
- lexically scoped names into templates.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const path_1 = require("path");
10
- const core_1 = require("@babel/core");
11
- const babel_import_util_1 = require("babel-import-util");
12
- const shared_internals_1 = require("@embroider/shared-internals");
13
- function make(getCompiler) {
14
- function inlineHBSTransform(babel) {
15
- let t = babel.types;
16
- return {
17
- visitor: {
18
- Program: {
19
- enter(path, state) {
20
- state.dependencies = new Map();
21
- state.adder = new babel_import_util_1.ImportUtil(t, path);
22
- },
23
- exit(path, state) {
24
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
25
- state.adder.removeImport(module, exportedName);
26
- }
27
- let counter = 0;
28
- for (let dep of state.dependencies.values()) {
29
- path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));
30
- path.node.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(dep.path)));
31
- }
32
- },
33
- },
34
- TaggedTemplateExpression(path, state) {
35
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
36
- if (path.get('tag').referencesImport(module, exportedName)) {
37
- handleTagged(path, state, t);
38
- }
39
- }
40
- },
41
- CallExpression(path, state) {
42
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
43
- if (path.get('callee').referencesImport(module, exportedName)) {
44
- handleCalled(path, state, t);
45
- }
46
- }
47
- },
48
- },
49
- };
50
- }
51
- inlineHBSTransform._parallelBabel = {
52
- requireFile: __filename,
53
- };
54
- inlineHBSTransform.baseDir = function () {
55
- return (0, path_1.join)(__dirname, '..');
56
- };
57
- function handleTagged(path, state, t) {
58
- if (path.node.quasi.expressions.length) {
59
- throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
60
- }
61
- let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
62
- let { compiled, dependencies } = compiler(state).precompile(template, { filename: state.file.opts.filename });
63
- for (let dep of dependencies) {
64
- state.dependencies.set(dep.runtimeName, dep);
65
- }
66
- path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
67
- jsonLiteral(compiled, t),
68
- ]));
69
- }
70
- function handleCalled(path, state, t) {
71
- let { template, insertRuntimeErrors } = getCallArguments(path);
72
- let compilerInstance = compiler(state);
73
- let result;
74
- try {
75
- result = compilerInstance.precompile(template, { filename: state.file.opts.filename, insertRuntimeErrors });
76
- }
77
- catch (err) {
78
- if (insertRuntimeErrors) {
79
- path.replaceWith(t.callExpression(t.functionExpression(null, [], t.blockStatement([
80
- t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral(err.message)])),
81
- ])), []));
82
- return;
83
- }
84
- throw err;
85
- }
86
- let { compiled, dependencies } = result;
87
- for (let dep of dependencies) {
88
- state.dependencies.set(dep.runtimeName, dep);
89
- }
90
- path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
91
- jsonLiteral(compiled, t),
92
- ]));
93
- }
94
- function jsonLiteral(value, t) {
95
- if (typeof value === 'undefined') {
96
- return t.identifier('undefined');
97
- }
98
- let ast = (0, core_1.parse)(`a(${value})`, {});
99
- let statement = ast.program.body[0];
100
- let expression = statement.expression;
101
- return expression.arguments[0];
102
- }
103
- function compiler(state) {
104
- if (!state.templateCompiler) {
105
- state.templateCompiler = getCompiler(state.opts);
106
- }
107
- return state.templateCompiler;
108
- }
109
- function amdDefine(runtimeName, importCounter, t) {
110
- return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
111
- t.stringLiteral(runtimeName),
112
- t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),
113
- ]));
114
- }
115
- function getTemplateString(template, path) {
116
- if ((template === null || template === void 0 ? void 0 : template.type) === 'StringLiteral') {
117
- return template.value;
118
- }
119
- // treat inert TemplateLiteral (without subexpressions) like a StringLiteral
120
- if ((template === null || template === void 0 ? void 0 : template.type) === 'TemplateLiteral' && !template.expressions.length) {
121
- return template.quasis[0].value.cooked;
122
- }
123
- throw path.buildCodeFrameError('hbs accepts only a string literal argument');
124
- }
125
- function getCallArguments(path) {
126
- let [template, options] = path.node.arguments;
127
- let insertRuntimeErrors = (options === null || options === void 0 ? void 0 : options.type) === 'ObjectExpression' &&
128
- options.properties.some(prop => prop.type === 'ObjectProperty' &&
129
- prop.computed === false &&
130
- prop.key.type === 'Identifier' &&
131
- prop.key.name === 'insertRuntimeErrors' &&
132
- prop.value.type === 'BooleanLiteral' &&
133
- prop.value.value);
134
- return {
135
- template: getTemplateString(template, path),
136
- insertRuntimeErrors,
137
- };
138
- }
139
- return inlineHBSTransform;
140
- }
141
- exports.default = make;
142
- //# sourceMappingURL=babel-plugin-inline-hbs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs.js","sourceRoot":"","sources":["babel-plugin-inline-hbs.ts"],"names":[],"mappings":";AAAA;;;;;EAKE;;AAKF,+BAA4B;AAE5B,sCAAoC;AAEpC,yDAA+C;AAC/C,kEAAyE;AAiBzE,SAAwB,IAAI,CAAI,WAA0C;IACxE,SAAS,kBAAkB,CAAC,KAAmB;QAC7C,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,KAAK,CAAC,IAAyB,EAAE,KAAe;wBAC9C,KAAK,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;wBAC/B,KAAK,CAAC,KAAK,GAAG,IAAI,8BAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;oBACxC,CAAC;oBACD,IAAI,CAAC,IAAyB,EAAE,KAAe;wBAC7C,KAAK,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,6CAA0B,EAAE;4BAC/D,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;yBAChD;wBACD,IAAI,OAAO,GAAG,CAAC,CAAC;wBAChB,KAAK,IAAI,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE;4BAC3C,IAAI,CAAC,IAAI,CA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C/E,CAAC;IAED,SAAS,gBAAgB,CAAC,IAAgC;QACxD,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;QAE9C,IAAI,mBAAmB,GACrB,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,kBAAkB;YACpC,OAAO,CAAC,UAAU,CAAC,IAAI,CACrB,IAAI,CAAC,EAAE,CACL,IAAI,CAAC,IAAI,KAAK,gBAAgB;gBAC9B,IAAI,CAAC,QAAQ,KAAK,KAAK;gBACvB,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;gBAC9B,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,qBAAqB;gBACvC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,gBAAgB;gBACpC,IAAI,CAAC,KAAK,CAAC,KAAK,CACnB,CAAC;QAEJ,OAAO;YACL,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC;YAC3C,mBAAmB;SACpB,CAAC;IACJ,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AApKD,uBAoKC","sourcesContent":["/*\n This plugin is used only for Ember < 3.27. For newer Ember's we have a\n different implementation that shares the standard\n babel-plugin-ember-template-compilation and supports passing Javascript\n lexically scoped names into templates.\n*/\n\nimport type { types as t } from '@babel/core';\nimport type * as Babel from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport { join } from 'path';\nimport type { TemplateCompiler } from './template-compiler-common';\nimport { parse } from '@babel/core';\nimport { ResolvedDep } from './resolver';\nimport { ImportUtil } from 'babel-import-util';\nimport { templateCompilationModules } from '@embroider/shared-internals';\n\ntype BabelTypes = typeof t;\n\ninterface State<O> {\n opts: O;\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n dependencies: Map<string, ResolvedDep>;\n templateCompiler: TemplateCompiler | undefined;\n adder: ImportUtil;\n}\n\nexport default function make<O>(getCompiler: (opts: O) => TemplateCompiler) {\n function inlineHBSTransform(babel: typeof Babel): Babel.PluginObj<State<O>> {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State<O>) {\n state.dependencies = new Map();\n state.adder = new ImportUtil(t, path);\n },\n exit(path: NodePath<t.Program>, state: State<O>) {\n for (let { module, exportedName } of templateCompilationModules) {\n state.adder.removeImport(module, exportedName);\n }\n let counter = 0;\n for (let dep of state.dependencies.values()) {\n path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));\n path.node.body.unshift(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(`a${counter++}`))],\n t.stringLiteral(dep.path)\n )\n );\n }\n },\n },\n TaggedTemplateExpression(path: NodePath<t.TaggedTemplateExpression>, state: State<O>) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('tag').referencesImport(module, exportedName)) {\n handleTagged(path, state, t);\n }\n }\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State<O>) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('callee').referencesImport(module, exportedName)) {\n handleCalled(path, state, t);\n }\n }\n },\n },\n };\n }\n\n inlineHBSTransform._parallelBabel = {\n requireFile: __filename,\n };\n\n inlineHBSTransform.baseDir = function () {\n return join(__dirname, '..');\n };\n\n function handleTagged(path: NodePath<t.TaggedTemplateExpression>, state: State<O>, t: BabelTypes) {\n if (path.node.quasi.expressions.length) {\n throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');\n }\n let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');\n let { compiled, dependencies } = compiler(state).precompile(template, { filename: state.file.opts.filename });\n for (let dep of dependencies) {\n state.dependencies.set(dep.runtimeName, dep);\n }\n\n path.replaceWith(\n t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [\n jsonLiteral(compiled, t),\n ])\n );\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State<O>, t: BabelTypes) {\n let { template, insertRuntimeErrors } = getCallArguments(path);\n let compilerInstance = compiler(state);\n\n let result: ReturnType<TemplateCompiler['precompile']>;\n try {\n result = compilerInstance.precompile(template, { filename: state.file.opts.filename, insertRuntimeErrors });\n } catch (err) {\n if (insertRuntimeErrors) {\n path.replaceWith(\n t.callExpression(\n t.functionExpression(\n null,\n [],\n t.blockStatement([\n t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral(err.message)])),\n ])\n ),\n []\n )\n );\n return;\n }\n throw err;\n }\n let { compiled, dependencies } = result;\n for (let dep of dependencies) {\n state.dependencies.set(dep.runtimeName, dep);\n }\n path.replaceWith(\n t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [\n jsonLiteral(compiled, t),\n ])\n );\n }\n\n function jsonLiteral(value: unknown | undefined, t: BabelTypes) {\n if (typeof value === 'undefined') {\n return t.identifier('undefined');\n }\n let ast = parse(`a(${value})`, {}) as t.File;\n let statement = ast.program.body[0] as t.ExpressionStatement;\n let expression = statement.expression as t.CallExpression;\n return expression.arguments[0];\n }\n\n function compiler(state: State<O>) {\n if (!state.templateCompiler) {\n state.templateCompiler = getCompiler(state.opts);\n }\n return state.templateCompiler;\n }\n\n function amdDefine(runtimeName: string, importCounter: number, t: BabelTypes) {\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),\n ])\n );\n }\n\n function getTemplateString(template: any, path: NodePath<t.CallExpression>): string {\n if (template?.type === 'StringLiteral') {\n return template.value;\n }\n // treat inert TemplateLiteral (without subexpressions) like a StringLiteral\n if (template?.type === 'TemplateLiteral' && !template.expressions.length) {\n return template.quasis[0].value.cooked;\n }\n throw path.buildCodeFrameError('hbs accepts only a string literal argument');\n }\n\n function getCallArguments(path: NodePath<t.CallExpression>): { template: string; insertRuntimeErrors: boolean } {\n let [template, options] = path.node.arguments;\n\n let insertRuntimeErrors =\n options?.type === 'ObjectExpression' &&\n options.properties.some(\n prop =>\n prop.type === 'ObjectProperty' &&\n prop.computed === false &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'insertRuntimeErrors' &&\n prop.value.type === 'BooleanLiteral' &&\n prop.value.value\n );\n\n return {\n template: getTemplateString(template, path),\n insertRuntimeErrors,\n };\n }\n\n return inlineHBSTransform;\n}\n"]}
@@ -1,12 +0,0 @@
1
- import { NodeTemplateCompilerParams } from './template-compiler-node';
2
- export interface Params {
3
- templateCompiler: NodeTemplateCompilerParams;
4
- }
5
- declare const _default: {
6
- (babel: typeof import("@babel/core")): unknown;
7
- _parallelBabel: {
8
- requireFile: string;
9
- };
10
- baseDir(): string;
11
- };
12
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const template_compiler_node_1 = require("./template-compiler-node");
7
- const babel_plugin_stage1_inline_hbs_1 = __importDefault(require("./babel-plugin-stage1-inline-hbs"));
8
- exports.default = (0, babel_plugin_stage1_inline_hbs_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
9
- //# sourceMappingURL=babel-plugin-stage1-inline-hbs-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-stage1-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-stage1-inline-hbs-node.ts"],"names":[],"mappings":";;;;;AAAA,qEAA4F;AAC5F,sGAAoD;AAMpD,kBAAe,IAAA,wCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC","sourcesContent":["import { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make from './babel-plugin-stage1-inline-hbs';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler));\n"]}
@@ -1,9 +0,0 @@
1
- import type { TemplateCompiler } from './template-compiler-common';
2
- import type * as Babel from '@babel/core';
3
- export default function make<Opts>(getCompiler: (opts: Opts) => TemplateCompiler): {
4
- (babel: typeof Babel): unknown;
5
- _parallelBabel: {
6
- requireFile: string;
7
- };
8
- baseDir(): string;
9
- };
@@ -1,96 +0,0 @@
1
- "use strict";
2
- /*
3
- This babel plugins is responsible for running custom AST transform in inline
4
- templates. It doesn't compile to wire format, because it runs at stage1.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const path_1 = require("path");
8
- const shared_internals_1 = require("@embroider/shared-internals");
9
- function make(getCompiler) {
10
- function stage1InlineHBSTransform(babel) {
11
- let t = babel.types;
12
- return {
13
- visitor: {
14
- TaggedTemplateExpression(path, state) {
15
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
16
- if (path.get('tag').referencesImport(module, exportedName)) {
17
- handleTagged(path, state, t);
18
- }
19
- }
20
- },
21
- CallExpression(path, state) {
22
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
23
- if (path.get('callee').referencesImport(module, exportedName)) {
24
- handleCalled(path, state, t);
25
- }
26
- }
27
- },
28
- },
29
- };
30
- }
31
- stage1InlineHBSTransform._parallelBabel = {
32
- requireFile: __filename,
33
- };
34
- stage1InlineHBSTransform.baseDir = function () {
35
- return (0, path_1.join)(__dirname, '..');
36
- };
37
- function handleTagged(path, state, t) {
38
- if (path.node.quasi.expressions.length) {
39
- throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
40
- }
41
- let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
42
- let compiled = compiler(state).applyTransforms(state.file.opts.filename, template);
43
- path.get('quasi').replaceWith(t.templateLiteral([t.templateElement({ raw: compiled, cooked: compiled })], []));
44
- }
45
- function handleCalled(path, state, t) {
46
- let { template, insertRuntimeErrors } = getCallArguments(path);
47
- let compilerInstance = compiler(state);
48
- let compiled;
49
- try {
50
- compiled = compilerInstance.applyTransforms(state.file.opts.filename, template);
51
- }
52
- catch (err) {
53
- if (insertRuntimeErrors) {
54
- // in stage 1 we just leave the bad template in place (we were only
55
- // trying to run transforms and re-emit hbs), so that it will be handled
56
- // at stage3 instead.
57
- return;
58
- }
59
- throw err;
60
- }
61
- path.get('arguments')[0].replaceWith(t.stringLiteral(compiled));
62
- }
63
- function compiler(state) {
64
- if (!state.templateCompiler) {
65
- state.templateCompiler = getCompiler(state.opts);
66
- }
67
- return state.templateCompiler;
68
- }
69
- function getCallArguments(path) {
70
- let [template, options] = path.node.arguments;
71
- let insertRuntimeErrors = (options === null || options === void 0 ? void 0 : options.type) === 'ObjectExpression' &&
72
- options.properties.some(prop => prop.type === 'ObjectProperty' &&
73
- prop.computed === false &&
74
- prop.key.type === 'Identifier' &&
75
- prop.key.name === 'insertRuntimeErrors' &&
76
- prop.value.type === 'BooleanLiteral' &&
77
- prop.value.value);
78
- return {
79
- template: getTemplateString(template, path),
80
- insertRuntimeErrors,
81
- };
82
- }
83
- return stage1InlineHBSTransform;
84
- }
85
- exports.default = make;
86
- function getTemplateString(template, path) {
87
- if ((template === null || template === void 0 ? void 0 : template.type) === 'StringLiteral') {
88
- return template.value;
89
- }
90
- // treat inert TemplateLiteral (without subexpressions) like a StringLiteral
91
- if ((template === null || template === void 0 ? void 0 : template.type) === 'TemplateLiteral' && !template.expressions.length) {
92
- return template.quasis[0].value.cooked;
93
- }
94
- throw path.buildCodeFrameError('hbs accepts only a string literal argument');
95
- }
96
- //# sourceMappingURL=babel-plugin-stage1-inline-hbs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-stage1-inline-hbs.js","sourceRoot":"","sources":["babel-plugin-stage1-inline-hbs.ts"],"names":[],"mappings":";AAAA;;;EAGE;;AAEF,+BAA4B;AAK5B,kEAAyE;AAEzE,SAAwB,IAAI,CAAO,WAA6C;IAY9E,SAAS,wBAAwB,CAAC,K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n templates. It doesn't compile to wire format, because it runs at stage1.\n*/\n\nimport { join } from 'path';\nimport type { TemplateCompiler } from './template-compiler-common';\nimport type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { templateCompilationModules } from '@embroider/shared-internals';\n\nexport default function make<Opts>(getCompiler: (opts: Opts) => TemplateCompiler) {\n interface State {\n opts: Opts;\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n templateCompiler: TemplateCompiler | undefined;\n }\n\n function stage1InlineHBSTransform(babel: typeof Babel): unknown {\n let t = babel.types;\n return {\n visitor: {\n TaggedTemplateExpression(path: NodePath<t.TaggedTemplateExpression>, state: State) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('tag').referencesImport(module, exportedName)) {\n handleTagged(path, state, t);\n }\n }\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('callee').referencesImport(module, exportedName)) {\n handleCalled(path, state, t);\n }\n }\n },\n },\n };\n }\n\n stage1InlineHBSTransform._parallelBabel = {\n requireFile: __filename,\n };\n\n stage1InlineHBSTransform.baseDir = function () {\n return join(__dirname, '..');\n };\n\n function handleTagged(path: NodePath<t.TaggedTemplateExpression>, state: State, t: typeof Babel.types) {\n if (path.node.quasi.expressions.length) {\n throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');\n }\n let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');\n let compiled = compiler(state).applyTransforms(state.file.opts.filename, template);\n path.get('quasi').replaceWith(t.templateLiteral([t.templateElement({ raw: compiled, cooked: compiled })], []));\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State, t: typeof Babel.types) {\n let { template, insertRuntimeErrors } = getCallArguments(path);\n let compilerInstance = compiler(state);\n\n let compiled: string;\n try {\n compiled = compilerInstance.applyTransforms(state.file.opts.filename, template);\n } catch (err) {\n if (insertRuntimeErrors) {\n // in stage 1 we just leave the bad template in place (we were only\n // trying to run transforms and re-emit hbs), so that it will be handled\n // at stage3 instead.\n return;\n }\n throw err;\n }\n (path.get('arguments')[0] as NodePath).replaceWith(t.stringLiteral(compiled));\n }\n\n function compiler(state: State) {\n if (!state.templateCompiler) {\n state.templateCompiler = getCompiler(state.opts);\n }\n return state.templateCompiler;\n }\n\n function getCallArguments(path: NodePath<t.CallExpression>): { template: string; insertRuntimeErrors: boolean } {\n let [template, options] = path.node.arguments;\n\n let insertRuntimeErrors =\n options?.type === 'ObjectExpression' &&\n options.properties.some(\n prop =>\n prop.type === 'ObjectProperty' &&\n prop.computed === false &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'insertRuntimeErrors' &&\n prop.value.type === 'BooleanLiteral' &&\n prop.value.value\n );\n\n return {\n template: getTemplateString(template, path),\n insertRuntimeErrors,\n };\n }\n\n return stage1InlineHBSTransform;\n}\n\nfunction getTemplateString(template: any, path: NodePath<t.CallExpression>): string {\n if (template?.type === 'StringLiteral') {\n return template.value;\n }\n // treat inert TemplateLiteral (without subexpressions) like a StringLiteral\n if (template?.type === 'TemplateLiteral' && !template.expressions.length) {\n return template.quasis[0].value.cooked;\n }\n throw path.buildCodeFrameError('hbs accepts only a string literal argument');\n}\n"]}
@@ -1 +0,0 @@
1
- export { TemplateCompiler, TemplateCompilerParams } from './template-compiler-common';
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateCompiler = void 0;
4
- var template_compiler_common_1 = require("./template-compiler-common");
5
- Object.defineProperty(exports, "TemplateCompiler", { enumerable: true, get: function () { return template_compiler_common_1.TemplateCompiler; } });
6
- //# sourceMappingURL=browser-index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser-index.js","sourceRoot":"","sources":["browser-index.ts"],"names":[],"mappings":";;;AAAA,uEAAsF;AAA7E,4HAAA,gBAAgB,OAAA","sourcesContent":["export { TemplateCompiler, TemplateCompilerParams } from './template-compiler-common';\n"]}
@@ -1,41 +0,0 @@
1
- export interface Plugins {
2
- ast?: unknown[];
3
- }
4
- export interface AST {
5
- _deliberatelyOpaque: 'AST';
6
- }
7
- export interface PreprocessOptions {
8
- contents: string;
9
- moduleName: string;
10
- plugins?: Plugins;
11
- filename?: string;
12
- parseOptions?: {
13
- srcName?: string;
14
- ignoreStandalone?: boolean;
15
- };
16
- mode?: 'codemod' | 'precompile';
17
- strictMode?: boolean;
18
- locals?: string[];
19
- }
20
- export interface PrinterOptions {
21
- entityEncoding?: 'transformed' | 'raw';
22
- }
23
- export interface GlimmerSyntax {
24
- preprocess(html: string, options?: PreprocessOptions): AST;
25
- print(ast: AST, options?: PrinterOptions): string;
26
- defaultOptions(options: PreprocessOptions): PreprocessOptions;
27
- precompile(templateContents: string, options: {
28
- contents: string;
29
- moduleName: string;
30
- filename: string;
31
- plugins?: any;
32
- parseOptions?: {
33
- srcName?: string;
34
- };
35
- }): string;
36
- _Ember: {
37
- FEATURES: any;
38
- ENV: any;
39
- };
40
- cacheKey: string;
41
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=ember-template-compiler-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ember-template-compiler-types.js","sourceRoot":"","sources":["ember-template-compiler-types.ts"],"names":[],"mappings":"","sourcesContent":["export 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 cacheKey: string;\n}\n"]}
@@ -1,6 +0,0 @@
1
- declare type EmbersExports = {
2
- cacheKey: string;
3
- theExports: any;
4
- };
5
- export declare function getEmberExports(templateCompilerPath: string): EmbersExports;
6
- export {};
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEmberExports = void 0;
4
- const fs_1 = require("fs");
5
- const vm_1 = require("vm");
6
- const crypto_1 = require("crypto");
7
- const patch_template_compiler_1 = require("./patch-template-compiler");
8
- const CACHE = new Map();
9
- function getEmberExports(templateCompilerPath) {
10
- let entry = CACHE.get(templateCompilerPath);
11
- if (entry) {
12
- let currentStat = (0, fs_1.statSync)(templateCompilerPath);
13
- // Let's ensure the template is still what we cached
14
- if (currentStat.mode === entry.stat.mode &&
15
- currentStat.size === entry.stat.size &&
16
- currentStat.mtime.getTime() === entry.stat.mtime.getTime()) {
17
- return entry.value;
18
- }
19
- }
20
- let stat = (0, fs_1.statSync)(templateCompilerPath);
21
- let source = (0, patch_template_compiler_1.patch)((0, fs_1.readFileSync)(templateCompilerPath, 'utf8'), templateCompilerPath);
22
- let theExports = undefined;
23
- // cacheKey, theExports
24
- let cacheKey = (0, crypto_1.createHash)('md5').update(source).digest('hex');
25
- entry = Object.freeze({
26
- value: {
27
- cacheKey,
28
- get theExports() {
29
- if (theExports) {
30
- return theExports;
31
- }
32
- // matches (essentially) what ember-cli-htmlbars does in https://git.io/Jtbpj
33
- let sandbox = {
34
- module: { require, exports: {} },
35
- require,
36
- };
37
- if (typeof globalThis === 'undefined') {
38
- // for Node 10 usage with Ember 3.27+ we have to define the `global` global
39
- // in order for ember-template-compiler.js to evaluate properly
40
- // due to this code https://git.io/Jtb7
41
- sandbox.global = sandbox;
42
- }
43
- // using vm.createContext / vm.Script to ensure we evaluate in a fresh sandbox context
44
- // so that any global mutation done within ember-template-compiler.js does not leak out
45
- let context = (0, vm_1.createContext)(sandbox);
46
- let script = new vm_1.Script(source, { filename: templateCompilerPath });
47
- script.runInContext(context);
48
- return (theExports = context.module.exports);
49
- },
50
- },
51
- stat, // This is stored, so we can reload the templateCompiler if it changes mid-build.
52
- });
53
- CACHE.set(templateCompilerPath, entry);
54
- return entry.value;
55
- }
56
- exports.getEmberExports = getEmberExports;
57
- //# sourceMappingURL=load-ember-template-compiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-ember-template-compiler.js","sourceRoot":"","sources":["load-ember-template-compiler.ts"],"names":[],"mappings":";;;AAAA,2BAAgD;AAChD,2BAA2C;AAC3C,mCAAoC;AACpC,uEAAkD;AAYlD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsC,CAAC;AAE5D,SAAgB,eAAe,CAAC,oBAA4B;IAC1D,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAE5C,IAAI,KAAK,EAAE;QACT,IAAI,WAAW,GAAG,IAAA,aAAQ,EAAC,oBAAoB,CAAC,CAAC;QAEjD,oDAAoD;QACpD,IACE,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI;YACpC,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI;YACpC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAC1D;YACA,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;KACF;IAED,IAAI,IAAI,GAAG,IAAA,aAAQ,EAAC,oBAAoB,CAAC,CAAC;IAE1C,IAAI,MAAM,GAAG,IA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ext, Script } from 'vm';\nimport { createHash } from 'crypto';\nimport { patch } from './patch-template-compiler';\n\ntype TemplateCompilerCacheEntry = {\n value: EmbersExports;\n stat: fs.Stats;\n};\n\ntype EmbersExports = {\n cacheKey: string;\n theExports: any;\n};\n\nconst CACHE = new Map<string, TemplateCompilerCacheEntry>();\n\nexport function getEmberExports(templateCompilerPath: string): EmbersExports {\n let entry = CACHE.get(templateCompilerPath);\n\n if (entry) {\n let currentStat = statSync(templateCompilerPath);\n\n // Let's ensure the template is still what we cached\n if (\n currentStat.mode === entry.stat.mode &&\n currentStat.size === entry.stat.size &&\n currentStat.mtime.getTime() === entry.stat.mtime.getTime()\n ) {\n return entry.value;\n }\n }\n\n let stat = statSync(templateCompilerPath);\n\n let source = patch(readFileSync(templateCompilerPath, 'utf8'), templateCompilerPath);\n let theExports: any = undefined;\n\n // cacheKey, theExports\n let cacheKey = createHash('md5').update(source).digest('hex');\n\n entry = Object.freeze({\n value: {\n cacheKey,\n get theExports() {\n if (theExports) {\n return theExports;\n }\n\n // matches (essentially) what ember-cli-htmlbars does in https://git.io/Jtbpj\n let sandbox = {\n module: { require, exports: {} },\n require,\n };\n\n if (typeof globalThis === 'undefined') {\n // for Node 10 usage with Ember 3.27+ we have to define the `global` global\n // in order for ember-template-compiler.js to evaluate properly\n // due to this code https://git.io/Jtb7\n (sandbox as any).global = sandbox;\n }\n // using vm.createContext / vm.Script to ensure we evaluate in a fresh sandbox context\n // so that any global mutation done within ember-template-compiler.js does not leak out\n let context = createContext(sandbox);\n let script = new Script(source, { filename: templateCompilerPath });\n\n script.runInContext(context);\n return (theExports = context.module.exports);\n },\n },\n stat, // This is stored, so we can reload the templateCompiler if it changes mid-build.\n });\n\n CACHE.set(templateCompilerPath, entry);\n return entry.value;\n}\n"]}
@@ -1,12 +0,0 @@
1
- import type { types as t } from '@babel/core';
2
- import type { NodePath } from '@babel/traverse';
3
- declare type BabelTypes = typeof t;
4
- export default function miniModulesPolyfill(babel: unknown): {
5
- visitor: {
6
- Program: {
7
- exit(path: NodePath<t.Program>): void;
8
- };
9
- };
10
- };
11
- export declare function handleImportDeclaration(t: BabelTypes, path: NodePath<t.ImportDeclaration>): undefined;
12
- export {};