@embroider/core 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/package.json +1 -1
  2. package/src/babel-plugin-adjust-imports.d.ts +3 -34
  3. package/src/babel-plugin-adjust-imports.js +94 -318
  4. package/src/babel-plugin-adjust-imports.js.map +1 -1
  5. package/src/babel-plugin-inline-hbs-deps-node.d.ts +14 -0
  6. package/src/babel-plugin-inline-hbs-deps-node.js +27 -0
  7. package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -0
  8. package/src/babel-plugin-inline-hbs-deps.d.ts +10 -0
  9. package/src/babel-plugin-inline-hbs-deps.js +134 -0
  10. package/src/babel-plugin-inline-hbs-deps.js.map +1 -0
  11. package/src/babel-plugin-inline-hbs-node.d.ts +7 -0
  12. package/src/babel-plugin-inline-hbs-node.js +15 -0
  13. package/src/babel-plugin-inline-hbs-node.js.map +1 -0
  14. package/src/babel-plugin-inline-hbs.d.ts +24 -0
  15. package/src/babel-plugin-inline-hbs.js +142 -0
  16. package/src/babel-plugin-inline-hbs.js.map +1 -0
  17. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +12 -0
  18. package/src/babel-plugin-stage1-inline-hbs-node.js +9 -0
  19. package/src/babel-plugin-stage1-inline-hbs-node.js.map +1 -0
  20. package/src/babel-plugin-stage1-inline-hbs.d.ts +9 -0
  21. package/src/babel-plugin-stage1-inline-hbs.js +96 -0
  22. package/src/babel-plugin-stage1-inline-hbs.js.map +1 -0
  23. package/src/browser-index.d.ts +1 -0
  24. package/src/browser-index.js +6 -0
  25. package/src/browser-index.js.map +1 -0
  26. package/src/ember-template-compiler-types.d.ts +41 -0
  27. package/src/ember-template-compiler-types.js +3 -0
  28. package/src/ember-template-compiler-types.js.map +1 -0
  29. package/src/load-ember-template-compiler.d.ts +6 -0
  30. package/src/load-ember-template-compiler.js +57 -0
  31. package/src/load-ember-template-compiler.js.map +1 -0
  32. package/src/messages.d.ts +0 -1
  33. package/src/mini-modules-polyfill.d.ts +12 -0
  34. package/src/mini-modules-polyfill.js +80 -0
  35. package/src/mini-modules-polyfill.js.map +1 -0
  36. package/src/module-resolver.d.ts +46 -0
  37. package/src/module-resolver.js +260 -0
  38. package/src/module-resolver.js.map +1 -0
  39. package/src/patch-template-compiler.d.ts +1 -0
  40. package/src/patch-template-compiler.js +176 -0
  41. package/src/patch-template-compiler.js.map +1 -0
  42. package/src/resolver-plugin.d.ts +3 -0
  43. package/src/resolver-plugin.js +53 -0
  44. package/src/resolver-plugin.js.map +1 -0
  45. package/src/resolver.d.ts +14 -0
  46. package/src/resolver.js +3 -0
  47. package/src/resolver.js.map +1 -0
  48. package/src/template-compiler-common.d.ts +70 -0
  49. package/src/template-compiler-common.js +176 -0
  50. package/src/template-compiler-common.js.map +1 -0
  51. package/src/template-compiler-node.d.ts +17 -0
  52. package/src/template-compiler-node.js +32 -0
  53. package/src/template-compiler-node.js.map +1 -0
@@ -0,0 +1,70 @@
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
+ }
@@ -0,0 +1,176 @@
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
@@ -0,0 +1 @@
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,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,IAAY,MAAM;QAChB,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAGO,KAAK;QACX,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAChE,IAAI,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAC3C,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,2CAA2C;QAC3C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAGO,qBAAqB,CAAC,GAAc;QAC1C,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,oDAAoD;IACpD,UAAU,CACR,cAAsB,EACtB,OAAuD;;QAEvD,IAAI,YAA2B,CAAC;QAChC,IAA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AA4B,CAAC,WAAW;YACpD,cAAc,EAAE,4BAA4B,CAAC,oBAAoB;YACjE,UAAU,EAAE,4BAA4B,CAAC,UAAU;YACnD,MAAM,EAAE,4BAA4B,CAAC,MAAM;SAC5C,CAAC;KACH;SAAM;QACL,kHAAkH;QAClH,mDAAmD;QACnD,EAAE;QACF,iEAAiE;QACjE,EAAE;QACF,gCAAgC;QAChC,2BAA2B;QAC3B,wEAAwE;QACxE,IAAI,MAAM,GAAG,CAAC,MAAA,4BAA4B,CAAC,KAAK,mCAAI,4BAA4B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CACvG,iBAAiB,CAClB,CAAC;QACF,IAAI,eAAe,GAAG,CAAC,MAAA,4BAA4B,CAAC,KAAK,mCAAI,4BAA4B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAChH,oDAAoD,CACrD,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"]}
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeTemplateCompiler = void 0;
4
+ const path_1 = require("path");
5
+ const load_ember_template_compiler_1 = require("./load-ember-template-compiler");
6
+ const template_compiler_common_1 = require("./template-compiler-common");
7
+ class NodeTemplateCompiler extends template_compiler_common_1.TemplateCompiler {
8
+ constructor(params) {
9
+ super({
10
+ loadEmberTemplateCompiler: () => (0, load_ember_template_compiler_1.getEmberExports)(params.compilerPath),
11
+ resolver: params.resolver,
12
+ EmberENV: params.EmberENV,
13
+ plugins: params.plugins,
14
+ });
15
+ this.params = params;
16
+ }
17
+ // Use applyTransforms on the contents of inline hbs template strings inside
18
+ // Javascript.
19
+ inlineTransformsBabelPlugin() {
20
+ return [
21
+ (0, path_1.join)(__dirname, 'babel-plugin-stage1-inline-hbs-node.js'),
22
+ {
23
+ templateCompiler: this.params,
24
+ },
25
+ ];
26
+ }
27
+ baseDir() {
28
+ return (0, path_1.join)(__dirname, '..');
29
+ }
30
+ }
31
+ exports.NodeTemplateCompiler = NodeTemplateCompiler;
32
+ //# sourceMappingURL=template-compiler-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-compiler-node.js","sourceRoot":"","sources":["template-compiler-node.ts"],"names":[],"mappings":";;;AACA,+BAA4B;AAI5B,iFAAiE;AACjE,yEAA8D;AAU9D,MAAa,oBAAqB,SAAQ,2CAAgB;IACxD,YAAmB,MAAkC;QACnD,KAAK,CAAC;YACJ,yBAAyB,EAAE,GAAG,EAAE,CAAC,IAAA,8CAAe,EAAC,MAAM,CAAC,YAAY,CAAC;YACrE,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;QANc,WAAM,GAAN,MAAM,CAA4B;IAOrD,CAAC;IAED,4EAA4E;IAC5E,cAAc;IACd,2BAA2B;QACzB,OAAO;YACL,IAAA,WAAI,EAAC,SAAS,EAAE,wCAAwC,CAAC;YACzD;gBACE,gBAAgB,EAAE,IAAI,CAAC,MAAM;aACT;SACvB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF;AAxBD,oDAwBC","sourcesContent":["import { Resolver } from './resolver';\nimport { join } from 'path';\nimport { PluginItem } from '@babel/core';\nimport type { Params as InlineBabelParams } from './babel-plugin-stage1-inline-hbs-node';\nimport { Plugins } from './ember-template-compiler-types';\nimport { getEmberExports } from './load-ember-template-compiler';\nimport { TemplateCompiler } from './template-compiler-common';\n\nexport interface NodeTemplateCompilerParams {\n compilerPath: string;\n compilerChecksum: string;\n resolver?: Resolver;\n EmberENV: unknown;\n plugins: Plugins;\n}\n\nexport class NodeTemplateCompiler extends TemplateCompiler {\n constructor(public params: NodeTemplateCompilerParams) {\n super({\n loadEmberTemplateCompiler: () => getEmberExports(params.compilerPath),\n resolver: params.resolver,\n EmberENV: params.EmberENV,\n plugins: params.plugins,\n });\n }\n\n // Use applyTransforms on the contents of inline hbs template strings inside\n // Javascript.\n inlineTransformsBabelPlugin(): PluginItem {\n return [\n join(__dirname, 'babel-plugin-stage1-inline-hbs-node.js'),\n {\n templateCompiler: this.params,\n } as InlineBabelParams,\n ];\n }\n\n baseDir() {\n return join(__dirname, '..');\n }\n}\n"]}