@embroider/core 0.46.1 → 0.47.2

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 (42) hide show
  1. package/package.json +4 -4
  2. package/src/app-files.js +5 -3
  3. package/src/app-files.js.map +1 -1
  4. package/src/app.js +27 -8
  5. package/src/app.js.map +1 -1
  6. package/src/babel-plugin-adjust-imports.d.ts +6 -5
  7. package/src/babel-plugin-adjust-imports.js.map +1 -1
  8. package/src/babel-plugin-inline-hbs-deps-node.d.ts +14 -0
  9. package/src/babel-plugin-inline-hbs-deps-node.js +27 -0
  10. package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -0
  11. package/src/babel-plugin-inline-hbs-deps.d.ts +10 -0
  12. package/src/babel-plugin-inline-hbs-deps.js +119 -0
  13. package/src/babel-plugin-inline-hbs-deps.js.map +1 -0
  14. package/src/babel-plugin-inline-hbs-node.d.ts +3 -9
  15. package/src/babel-plugin-inline-hbs-node.js.map +1 -1
  16. package/src/babel-plugin-inline-hbs.d.ts +5 -7
  17. package/src/babel-plugin-inline-hbs.js +35 -73
  18. package/src/babel-plugin-inline-hbs.js.map +1 -1
  19. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +12 -0
  20. package/src/babel-plugin-stage1-inline-hbs-node.js +9 -0
  21. package/src/babel-plugin-stage1-inline-hbs-node.js.map +1 -0
  22. package/src/babel-plugin-stage1-inline-hbs.d.ts +9 -0
  23. package/src/babel-plugin-stage1-inline-hbs.js +96 -0
  24. package/src/babel-plugin-stage1-inline-hbs.js.map +1 -0
  25. package/src/describe-exports.js +3 -3
  26. package/src/describe-exports.js.map +1 -1
  27. package/src/mini-modules-polyfill.d.ts +1 -1
  28. package/src/mini-modules-polyfill.js.map +1 -1
  29. package/src/patch-template-compiler.js +3 -4
  30. package/src/patch-template-compiler.js.map +1 -1
  31. package/src/rename-require-plugin.js.map +1 -1
  32. package/src/template-compiler-common.d.ts +3 -1
  33. package/src/template-compiler-common.js +8 -12
  34. package/src/template-compiler-common.js.map +1 -1
  35. package/src/template-compiler-node.js +3 -3
  36. package/src/template-compiler-node.js.map +1 -1
  37. package/src/babel-import-adder.d.ts +0 -11
  38. package/src/babel-import-adder.js +0 -75
  39. package/src/babel-import-adder.js.map +0 -1
  40. package/src/template-colocation-plugin.d.ts +0 -22
  41. package/src/template-colocation-plugin.js +0 -113
  42. package/src/template-colocation-plugin.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs.js","sourceRoot":"","sources":["babel-plugin-inline-hbs.ts"],"names":[],"mappings":";;AAEA,+BAA4B;AAE5B,sCAAoC;AAEpC,yDAA+C;AAI/C,4EAA4E;AAC5E,6EAA6E;AAC7E,2BAA2B;AAC3B,MAAM,WAAW,GAAG;IAClB,CAAC,4BAA4B,EAAE,SAAS,CAAC;IACzC,CAAC,sCAAsC,EAAE,SAAS,CAAC;IACnD,CAAC,oBAAoB,EAAE,KAAK,CAAC;CAC9B,CAAC;AAwBF,SAAwB,IAAI,CAAC,WAA4C;IACvE,SAAS,kBAAkB,CAAC,KAAc;QACxC,IAAI,CAAC,GAAI,KAAa,CAAC,KAAmB,CAAC;QAC3C,OAAO;YACL,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,KAAK,CAAC,IAAyB,EAAE,KAAY;wBAC3C,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,KAAY;wBAC1C,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE;4BAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;yBACpB;wBACD,IAAI,OAAO,GAAG,CAAC,CAAC;wBAChB,KAAK,IAAI,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE;4BAC3C,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AO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;SACxC;QACD,MAAM,IAAI,CAAC,mBAAmB,CAAC,4CAA4C,CAAC,CAAC;IAC/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;AAvMD,uBAuMC","sourcesContent":["import type * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { join } from 'path';\nimport { TemplateCompiler } from './template-compiler-common';\nimport { parse } from '@babel/core';\nimport { ResolvedDep } from './resolver';\nimport { ImportUtil } from 'babel-import-util';\n\ntype BabelTypes = typeof t;\n\n// These are the known names that people are using to import the `hbs` macro\n// from. In theory the original plugin lets people customize these names, but\n// that is a terrible idea.\nconst modulePaths = [\n ['htmlbars-inline-precompile', 'default'],\n ['ember-cli-htmlbars-inline-precompile', 'default'],\n ['ember-cli-htmlbars', 'hbs'],\n];\n\ninterface State {\n opts: {\n // the stages here correspond to the two places in the overall Embroider\n // architecture that this transform applies. In stage1 HBS stays as HBS, but\n // we still need to run any custom AST transforms inside that HBS. In\n // stage3, we are running more like the traditional\n // ember-cli-htmlbars-inline-precompile by compiling the HBS to Javascript.\n stage: 1 | 3;\n };\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 type Params = State['opts'];\n\nexport default function make(getCompiler: (opts: any) => TemplateCompiler) {\n function inlineHBSTransform(babel: unknown): unknown {\n let t = (babel as any).types as BabelTypes;\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 },\n exit(path: NodePath<t.Program>, state: State) {\n if (state.opts.stage === 3) {\n pruneImports(path);\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) {\n for (let [modulePath, identifier] of modulePaths) {\n if (path.get('tag').referencesImport(modulePath, identifier)) {\n handleTagged(path, state, t);\n }\n }\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n for (let [modulePath, identifier] of modulePaths) {\n if (path.get('callee').referencesImport(modulePath, identifier)) {\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: 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 if (state.opts.stage === 1) {\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 } else {\n let { compiled, dependencies } = compiler(state).precompile(state.file.opts.filename, template);\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\n function handleCalled(path: NodePath<t.CallExpression>, state: State, t: BabelTypes) {\n let { template, insertRuntimeErrors } = getCallArguments(path);\n let compilerInstance = compiler(state);\n\n if (state.opts.stage === 1) {\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 } else {\n let result: ReturnType<TemplateCompiler['precompile']>;\n try {\n result = compilerInstance.precompile(state.file.opts.filename, template);\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\n function pruneImports(path: NodePath) {\n if (!path.isProgram()) {\n return;\n }\n for (let topLevelPath of path.get('body')) {\n if (topLevelPath.isImportDeclaration()) {\n let modulePath = topLevelPath.get('source').node.value;\n if (modulePaths.find(p => p[0] === modulePath)) {\n topLevelPath.remove();\n }\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) {\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
+ {"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;A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nB,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-htmlbars-inline-precompile 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 { 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"]}
@@ -0,0 +1,12 @@
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;
@@ -0,0 +1,9 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,9 @@
1
+ import { 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
+ };
@@ -0,0 +1,96 @@
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
@@ -0,0 +1 @@
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,KAAmB;QACnD,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,wBAAwB,CAAC,IAA0C,EAAE,KAAY;oBAC/E,KAAK,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,6CAA0B,EAAE;wBAC/D,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE;4BAC1D,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;yBAC9B;qBACF;gBACH,CAAC;gBACD,cAAc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K,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,wBAAwB,CAAC;AAClC,CAAC;AAnGD,uBAmGC;AAED,SAAS,iBAAiB,CAAC,QAAa,EAAE,IAAgC;IACxE,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,eAAe,EAAE;QACtC,OAAO,QAAQ,CAAC,KAAK,CAAC;KACvB;IACD,4EAA4E;IAC5E,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,iBAAiB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE;QACxE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;KACxC;IACD,MAAM,IAAI,CAAC,mBAAmB,CAAC,4CAA4C,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/*\n This babel plugins is responsible for running custom AST transform in inline\n templates. It doesn't compile to wire format, because it runs at stage1.\n*/\n\nimport { join } from 'path';\nimport { 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"]}
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.describeExports = void 0;
7
7
  const core_1 = require("@babel/core");
8
8
  const traverse_1 = __importDefault(require("@babel/traverse"));
9
- const types_1 = require("@babel/types");
9
+ const core_2 = require("@babel/core");
10
10
  const assert_never_1 = __importDefault(require("assert-never"));
11
11
  function describeExports(code, babelParserConfig) {
12
12
  let ast = (0, core_1.parse)(code, babelParserConfig);
@@ -36,9 +36,9 @@ function describeExports(code, babelParserConfig) {
36
36
  (0, assert_never_1.default)(spec);
37
37
  }
38
38
  }
39
- if ((0, types_1.isVariableDeclaration)(path.node.declaration)) {
39
+ if (core_2.types.isVariableDeclaration(path.node.declaration)) {
40
40
  for (let dec of path.node.declaration.declarations) {
41
- if ((0, types_1.isIdentifier)(dec.id)) {
41
+ if (core_2.types.isIdentifier(dec.id)) {
42
42
  names.add(dec.id.name);
43
43
  }
44
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"describe-exports.js","sourceRoot":"","sources":["describe-exports.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAsD;AACtD,+DAAqD;AACrD,wCAAqH;AACrH,gEAAuC;AAEvC,SAAgB,eAAe,CAC7B,IAAY,EACZ,iBAAmC;IAEnC,IAAI,GAAG,GAAG,IAAA,YAAK,EAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACzC,IAAI,CAAC,GAA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C1B,CAAC;KACF,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC;AACrC,CAAC;AA7CD,0CA6CC","sourcesContent":["import { parse, TransformOptions } from '@babel/core';\nimport traverse, { NodePath } from '@babel/traverse';\nimport { ExportNamedDeclaration, ExportDefaultDeclaration, isVariableDeclaration, isIdentifier } from '@babel/types';\nimport assertNever from 'assert-never';\n\nexport function describeExports(\n code: string,\n babelParserConfig: TransformOptions\n): { names: Set<string>; hasDefaultExport: boolean } {\n let ast = parse(code, babelParserConfig);\n if (!ast || ast.type !== 'File') {\n throw new Error(`bug in embroider/core describe-exports`);\n }\n let names: Set<string> = new Set();\n let hasDefaultExport = false;\n\n traverse(ast, {\n ExportNamedDeclaration(path: NodePath<ExportNamedDeclaration>) {\n for (let spec of path.node.specifiers) {\n switch (spec.type) {\n case 'ExportSpecifier':\n case 'ExportNamespaceSpecifier':\n const name = spec.exported.type === 'Identifier' ? spec.exported.name : spec.exported.value;\n\n if (name === 'default') {\n hasDefaultExport = true;\n } else {\n names.add(name);\n }\n break;\n case 'ExportDefaultSpecifier':\n // this is in the types but was never standardized\n break;\n default:\n assertNever(spec);\n }\n }\n if (isVariableDeclaration(path.node.declaration)) {\n for (let dec of path.node.declaration.declarations) {\n if (isIdentifier(dec.id)) {\n names.add(dec.id.name);\n }\n }\n }\n },\n ExportDefaultDeclaration(_path: NodePath<ExportDefaultDeclaration>) {\n hasDefaultExport = true;\n },\n });\n return { names, hasDefaultExport };\n}\n"]}
1
+ {"version":3,"file":"describe-exports.js","sourceRoot":"","sources":["describe-exports.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAsD;AACtD,+DAAqD;AACrD,sCAAyC;AACzC,gEAAuC;AAEvC,SAAgB,eAAe,CAC7B,IAAY,EACZ,iBAAmC;IAEnC,IAAI,GAAG,GAAG,IAAA,YAAK,EAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACzC,IAAI,CAAC,GAAG,IAAI,GAAG,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B,CAAC;KACF,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC;AACrC,CAAC;AA7CD,0CA6CC","sourcesContent":["import { parse, TransformOptions } from '@babel/core';\nimport traverse, { NodePath } from '@babel/traverse';\nimport { types as t } from '@babel/core';\nimport assertNever from 'assert-never';\n\nexport function describeExports(\n code: string,\n babelParserConfig: TransformOptions\n): { names: Set<string>; hasDefaultExport: boolean } {\n let ast = parse(code, babelParserConfig);\n if (!ast || ast.type !== 'File') {\n throw new Error(`bug in embroider/core describe-exports`);\n }\n let names: Set<string> = new Set();\n let hasDefaultExport = false;\n\n traverse(ast, {\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\n for (let spec of path.node.specifiers) {\n switch (spec.type) {\n case 'ExportSpecifier':\n case 'ExportNamespaceSpecifier':\n const name = spec.exported.type === 'Identifier' ? spec.exported.name : spec.exported.value;\n\n if (name === 'default') {\n hasDefaultExport = true;\n } else {\n names.add(name);\n }\n break;\n case 'ExportDefaultSpecifier':\n // this is in the types but was never standardized\n break;\n default:\n assertNever(spec);\n }\n }\n if (t.isVariableDeclaration(path.node.declaration)) {\n for (let dec of path.node.declaration.declarations) {\n if (t.isIdentifier(dec.id)) {\n names.add(dec.id.name);\n }\n }\n }\n },\n ExportDefaultDeclaration(_path: NodePath<t.ExportDefaultDeclaration>) {\n hasDefaultExport = true;\n },\n });\n return { names, hasDefaultExport };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type * as t from '@babel/types';
1
+ import type { types as t } from '@babel/core';
2
2
  import type { NodePath } from '@babel/traverse';
3
3
  declare type BabelTypes = typeof t;
4
4
  export default function miniModulesPolyfill(babel: unknown): {
@@ -1 +1 @@
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,6EAA6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CAAC,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 * as t from '@babel/types';\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
+ {"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;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,aAAa;AACb,+EAA+E;AAC/E,EAAE;AACF,EAAE;AACF,IAAI,YAAY,GAAqG;IACnH,gCAAgC,EAAE;QAChC,OAAO,CAAC,CAAa;YACnB,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC;QAC3F,CAAC;KACF;IACD,yBAAyB,EAAE;QACzB,qBAAqB,CAAC,CAAC;YACrB,OAAO,CAAC,CAAC,gBAAgB,CACvB,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,EACnE,CAAC,CAAC,UAAU,CAAC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AE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QACzG,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE;YAC7C,IAAI,CAAC,WAAW,CACd,CAAC,CAAC,mBAAmB,CACnB,OAAO,EACP,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,QAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CACjF,CACF,CAAC;SACH;aAAM;YACL,KAAK,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE;gBAC7C,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patch = void 0;
4
- const types_1 = require("@babel/types");
5
4
  const core_1 = require("@babel/core");
6
5
  function parseVersion(templateCompilerPath, source) {
7
6
  // ember-template-compiler.js contains a comment that indicates what version it is for
@@ -123,9 +122,9 @@ function patch(source, templateCompilerPath) {
123
122
  // the place we want is the only if with a computed member
124
123
  // expression predicate.
125
124
  if (test.isMemberExpression() && test.node.computed) {
126
- path.node.alternate = (0, types_1.ifStatement)((0, types_1.memberExpression)((0, types_1.identifier)('ast'), (0, types_1.identifier)('selfClosing')), (0, types_1.blockStatement)([
127
- (0, types_1.expressionStatement)((0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.identifier)('output'), (0, types_1.identifier)('push')), [
128
- (0, types_1.stringLiteral)(' />'),
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(' />'),
129
128
  ])),
130
129
  ]), path.node.alternate);
131
130
  }
@@ -1 +1 @@
1
- {"version":3,"file":"patch-template-compiler.js","sourceRoot":"","sources":["patch-template-compiler.ts"],"names":[],"mappings":";;;AAAA,wCAasB;AAEtB,sCAAwC;AAExC,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,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AAE,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 {\n CallExpression,\n FunctionDeclaration,\n VariableDeclarator,\n SwitchCase,\n IfStatement,\n ifStatement,\n memberExpression,\n identifier,\n blockStatement,\n callExpression,\n expressionStatement,\n stringLiteral,\n} from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport { transform } 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<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<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<CallExpression>, state: BabelState) {\n if (state.definingGlimmerSyntax === path) {\n state.definingGlimmerSyntax = false;\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<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<FunctionDeclaration>, state: BabelState) {\n if (state.declaringBuildFunction === path) {\n state.declaringBuildFunction = false;\n }\n },\n },\n SwitchCase: {\n enter(path: NodePath<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<SwitchCase>, state: BabelState) {\n if (state.caseElementNode === path) {\n state.caseElementNode = false;\n }\n },\n },\n IfStatement(path: NodePath<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 = ifStatement(\n memberExpression(identifier('ast'), identifier('selfClosing')),\n blockStatement([\n expressionStatement(\n callExpression(memberExpression(identifier('output'), identifier('push')), [\n 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<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"]}
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;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,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rename-require-plugin.js","sourceRoot":"","sources":["rename-require-plugin.ts"],"names":[],"mappings":";;AAGA,SAAwB,kBAAkB;IACxC,OAAO;QACL,OAAO,EAAE;YACP,sBAAsB,CAAC,IAAwC;gBAC7D,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;oBACtC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;iBAC9B;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAVD,qCAUC","sourcesContent":["import type * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\n\nexport default function inlineHBSTransform(): unknown {\n return {\n visitor: {\n ImportDefaultSpecifier(path: NodePath<t.ImportDefaultSpecifier>) {\n if (path.node.local.name === 'require') {\n path.scope.rename('require');\n }\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"rename-require-plugin.js","sourceRoot":"","sources":["rename-require-plugin.ts"],"names":[],"mappings":";;AAGA,SAAwB,kBAAkB;IACxC,OAAO;QACL,OAAO,EAAE;YACP,sBAAsB,CAAC,IAAwC;gBAC7D,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;oBACtC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;iBAC9B;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAVD,qCAUC","sourcesContent":["import type { types as t } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\n\nexport default function inlineHBSTransform(): unknown {\n return {\n visitor: {\n ImportDefaultSpecifier(path: NodePath<t.ImportDefaultSpecifier>) {\n if (path.node.local.name === 'require') {\n path.scope.rename('require');\n }\n },\n },\n };\n}\n"]}
@@ -59,7 +59,9 @@ export declare class TemplateCompiler {
59
59
  get cacheKey(): string;
60
60
  private setup;
61
61
  private getReversedASTPlugins;
62
- precompile(moduleName: string, contents: string): {
62
+ precompile(templateSource: string, options: Record<string, unknown> & {
63
+ filename: string;
64
+ }): {
63
65
  compiled: string;
64
66
  dependencies: ResolvedDep[];
65
67
  };
@@ -51,31 +51,27 @@ class TemplateCompiler {
51
51
  return ast.slice().reverse();
52
52
  }
53
53
  // Compiles to the wire format plus dependency list.
54
- precompile(moduleName, contents) {
54
+ precompile(templateSource, options) {
55
55
  var _a, _b;
56
56
  let dependencies;
57
57
  let runtimeName;
58
+ let filename = options.filename;
58
59
  if (this.resolver) {
59
- runtimeName = this.resolver.absPathToRuntimePath(moduleName);
60
+ runtimeName = this.resolver.absPathToRuntimePath(filename);
60
61
  }
61
62
  else {
62
- runtimeName = moduleName;
63
+ runtimeName = filename;
63
64
  }
64
- let opts = this.syntax.defaultOptions({ contents, moduleName });
65
+ let opts = this.syntax.defaultOptions({ contents: templateSource, moduleName: filename });
65
66
  let plugins = Object.assign(Object.assign({}, opts === null || opts === void 0 ? void 0 : opts.plugins), { ast: [
66
67
  ...this.getReversedASTPlugins(this.plugins.ast),
67
68
  this.resolver && this.resolver.astTransformer(this),
68
69
  // Ember 3.27+ uses _buildCompileOptions will not add AST plugins to its result
69
70
  ...((_b = (_a = opts === null || opts === void 0 ? void 0 : opts.plugins) === null || _a === void 0 ? void 0 : _a.ast) !== null && _b !== void 0 ? _b : []),
70
71
  ].filter(Boolean) });
71
- let compiled = this.syntax.precompile((0, strip_bom_1.default)(contents), {
72
- contents,
73
- moduleName: runtimeName,
74
- filename: moduleName,
75
- plugins,
76
- });
72
+ let compiled = this.syntax.precompile((0, strip_bom_1.default)(templateSource), Object.assign({ contents: templateSource, moduleName: runtimeName, plugins }, options));
77
73
  if (this.resolver) {
78
- dependencies = this.resolver.dependenciesOf(moduleName);
74
+ dependencies = this.resolver.dependenciesOf(filename);
79
75
  }
80
76
  else {
81
77
  dependencies = [];
@@ -84,7 +80,7 @@ class TemplateCompiler {
84
80
  }
85
81
  // Compiles all the way from a template string to a javascript module string.
86
82
  compile(moduleName, contents) {
87
- let { compiled, dependencies } = this.precompile(moduleName, contents);
83
+ let { compiled, dependencies } = this.precompile(contents, { filename: moduleName });
88
84
  let lines = [];
89
85
  let counter = 0;
90
86
  for (let { runtimeName, path } of dependencies) {
@@ -1 +1 @@
1
- {"version":3,"file":"template-compiler-common.js","sourceRoot":"","sources":["template-compiler-common.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAiC;AAEjC,+BAAiC;AAEjC,2DAA6C;AAC7C,wGAA2E;AAuD3E,MAAM,kBAAkB,GAAG;IACzB,CAAC,4BAA4B,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACpD,CAAC,4BAA4B,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACzE,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACjD,CAAC,4BAA4B,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACtE,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IAC5C,CAAC,oBAAoB,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACjE,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACzC,CAAC,oBAAoB,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;CAC/D,CAAC;AAYF,MAAa,gBAAgB;IAM3B,YAAY,MAA8B;QACxC,IAAI,CAAC,yBAAyB,GAAG,MA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AAC9B,SAAS,iBAAiB,CAAC,4BAAiC;;IAC1D,mEAAmE;IACnE,wDAAwD;IACxD,IAAI,4BAA4B,CAAC,WAAW,KAAK,SAAS,EAAE;QAC1D,OAAO;YACL,KAAK,EAAE,4BAA4B,CAAC,MAAM;YAC1C,UAAU,EAAE,4BAA4B,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, sep } from 'path';\nimport type { PluginItem } from '@babel/core';\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\nconst htmlbarPathMatches = [\n ['htmlbars-inline-precompile', 'index.js'].join(sep),\n ['htmlbars-inline-precompile', 'lib', 'require-from-worker.js'].join(sep),\n ['htmlbars-inline-precompile', 'index'].join(sep),\n ['htmlbars-inline-precompile', 'lib', 'require-from-worker'].join(sep),\n ['ember-cli-htmlbars', 'index.js'].join(sep),\n ['ember-cli-htmlbars', 'lib', 'require-from-worker.js'].join(sep),\n ['ember-cli-htmlbars', 'index'].join(sep),\n ['ember-cli-htmlbars', 'lib', 'require-from-worker'].join(sep),\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 // stage3 packagers don't need to know about our instance, they can just\n // grab the compile function and use it.\n this.compile = this.compile.bind(this);\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(moduleName: string, contents: string): { compiled: string; dependencies: ResolvedDep[] } {\n let dependencies: ResolvedDep[];\n let runtimeName: string;\n\n if (this.resolver) {\n runtimeName = this.resolver.absPathToRuntimePath(moduleName);\n } else {\n runtimeName = moduleName;\n }\n\n let opts = this.syntax.defaultOptions({ contents, moduleName });\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(contents), {\n contents,\n moduleName: runtimeName,\n filename: moduleName,\n plugins,\n });\n\n if (this.resolver) {\n dependencies = this.resolver.dependenciesOf(moduleName);\n } else {\n dependencies = [];\n }\n\n return { compiled, dependencies };\n }\n\n // Compiles all the way from a template string to a javascript module string.\n compile(moduleName: string, contents: string) {\n let { compiled, dependencies } = this.precompile(moduleName, contents);\n let lines = [];\n let counter = 0;\n for (let { runtimeName, path } of dependencies) {\n lines.push(`import a${counter} from \"${path.split(sep).join('/')}\";`);\n lines.push(`window.define('${runtimeName}', function(){ return a${counter++}});`);\n }\n\n lines.push(`import { createTemplateFactory } from '@ember/template-factory';`);\n lines.push(`export default createTemplateFactory(${compiled});`);\n\n return lines.join('\\n');\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 // tests for the classic ember-cli-htmlbars-inline-precompile babel plugin\n static isInlinePrecompilePlugin(item: PluginItem) {\n if (typeof item === 'string') {\n return matchesSourceFile(item);\n }\n if (hasProperties(item) && (item as any)._parallelBabel) {\n return matchesSourceFile((item as any)._parallelBabel.requireFile);\n }\n if (Array.isArray(item) && item.length > 0) {\n if (typeof item[0] === 'string') {\n return matchesSourceFile(item[0]);\n }\n if (hasProperties(item[0]) && (item[0] as any)._parallelBabel) {\n return matchesSourceFile((item[0] as any)._parallelBabel.requireFile);\n }\n }\n return false;\n }\n}\n\nexport function matchesSourceFile(filename: string) {\n return Boolean(htmlbarPathMatches.find(match => filename.endsWith(match)));\n}\n\nfunction hasProperties(item: any) {\n return item && (typeof item === 'object' || typeof item === 'function');\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
+ {"version":3,"file":"template-compiler-common.js","sourceRoot":"","sources":["template-compiler-common.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAiC;AAEjC,+BAAiC;AAEjC,2DAA6C;AAC7C,wGAA2E;AAuD3E,MAAM,kBAAkB,GAAG;IACzB,CAAC,4BAA4B,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACpD,CAAC,4BAA4B,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACzE,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACjD,CAAC,4BAA4B,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACtE,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IAC5C,CAAC,oBAAoB,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACjE,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;IACzC,CAAC,oBAAoB,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,UAAG,CAAC;CAC/D,CAAC;AAYF,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,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AAI,4BAA4B,CAAC,WAAW,KAAK,SAAS,EAAE;QAC1D,OAAO;YACL,KAAK,EAAE,4BAA4B,CAAC,MAAM;YAC1C,UAAU,EAAE,4BAA4B,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, sep } from 'path';\nimport type { PluginItem } from '@babel/core';\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\nconst htmlbarPathMatches = [\n ['htmlbars-inline-precompile', 'index.js'].join(sep),\n ['htmlbars-inline-precompile', 'lib', 'require-from-worker.js'].join(sep),\n ['htmlbars-inline-precompile', 'index'].join(sep),\n ['htmlbars-inline-precompile', 'lib', 'require-from-worker'].join(sep),\n ['ember-cli-htmlbars', 'index.js'].join(sep),\n ['ember-cli-htmlbars', 'lib', 'require-from-worker.js'].join(sep),\n ['ember-cli-htmlbars', 'index'].join(sep),\n ['ember-cli-htmlbars', 'lib', 'require-from-worker'].join(sep),\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 // stage3 packagers don't need to know about our instance, they can just\n // grab the compile function and use it.\n this.compile = this.compile.bind(this);\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 // Compiles all the way from a template string to a javascript module string.\n compile(moduleName: string, contents: string) {\n let { compiled, dependencies } = this.precompile(contents, { filename: moduleName });\n let lines = [];\n let counter = 0;\n for (let { runtimeName, path } of dependencies) {\n lines.push(`import a${counter} from \"${path.split(sep).join('/')}\";`);\n lines.push(`window.define('${runtimeName}', function(){ return a${counter++}});`);\n }\n\n lines.push(`import { createTemplateFactory } from '@ember/template-factory';`);\n lines.push(`export default createTemplateFactory(${compiled});`);\n\n return lines.join('\\n');\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 // tests for the classic ember-cli-htmlbars-inline-precompile babel plugin\n static isInlinePrecompilePlugin(item: PluginItem) {\n if (typeof item === 'string') {\n return matchesSourceFile(item);\n }\n if (hasProperties(item) && (item as any)._parallelBabel) {\n return matchesSourceFile((item as any)._parallelBabel.requireFile);\n }\n if (Array.isArray(item) && item.length > 0) {\n if (typeof item[0] === 'string') {\n return matchesSourceFile(item[0]);\n }\n if (hasProperties(item[0]) && (item[0] as any)._parallelBabel) {\n return matchesSourceFile((item[0] as any)._parallelBabel.requireFile);\n }\n }\n return false;\n }\n}\n\nexport function matchesSourceFile(filename: string) {\n return Boolean(htmlbarPathMatches.find(match => filename.endsWith(match)));\n}\n\nfunction hasProperties(item: any) {\n return item && (typeof item === 'object' || typeof item === 'function');\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"]}
@@ -23,12 +23,13 @@ class NodeTemplateCompiler extends template_compiler_common_1.TemplateCompiler {
23
23
  let src = super.compile(moduleName, contents);
24
24
  let resolver = this.params.resolver;
25
25
  if (resolver) {
26
+ let opts = resolver.adjustImportsOptions;
26
27
  return (0, core_1.transform)(src, {
27
28
  filename: moduleName,
28
29
  generatorOpts: {
29
30
  compact: false,
30
31
  },
31
- plugins: [[babel_plugin_adjust_imports_1.default, resolver.adjustImportsOptions]],
32
+ plugins: [[babel_plugin_adjust_imports_1.default, opts]],
32
33
  }).code;
33
34
  }
34
35
  else {
@@ -39,10 +40,9 @@ class NodeTemplateCompiler extends template_compiler_common_1.TemplateCompiler {
39
40
  // Javascript.
40
41
  inlineTransformsBabelPlugin() {
41
42
  return [
42
- (0, path_1.join)(__dirname, 'babel-plugin-inline-hbs-node.js'),
43
+ (0, path_1.join)(__dirname, 'babel-plugin-stage1-inline-hbs-node.js'),
43
44
  {
44
45
  templateCompiler: this.params,
45
- stage: 1,
46
46
  },
47
47
  ];
48
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"template-compiler-node.js","sourceRoot":"","sources":["template-compiler-node.ts"],"names":[],"mappings":";;;;;;AACA,+BAA4B;AAC5B,sCAAoD;AAGpD,iFAAiE;AACjE,yEAAiF;AACjF,gGAAgE;AAUhE,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,CAA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C1C,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;gBAC/B,OAAO,IAAA,4CAAiB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;aACnC;YACD,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAK,IAAI,CAAC,CAAC,CAAS,CAAC,cAAc,EAAE;gBAC7D,OAAO,IAAA,4CAAiB,EAAE,IAAI,CAAC,CAAC,CAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;aACvE;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5DD,oDA4DC;AAED,SAAS,aAAa,CAAC,IAAS;IAC9B,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import { Resolver } from './resolver';\nimport { join } from 'path';\nimport { PluginItem, transform } from '@babel/core';\nimport type { Params as InlineBabelParams } from './babel-plugin-inline-hbs';\nimport { Plugins } from './ember-template-compiler-types';\nimport { getEmberExports } from './load-ember-template-compiler';\nimport { TemplateCompiler, matchesSourceFile } from './template-compiler-common';\nimport adjustImportsPlugin from './babel-plugin-adjust-imports';\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 compile(moduleName: string, contents: string) {\n let src = super.compile(moduleName, contents);\n let resolver = this.params.resolver;\n if (resolver) {\n return transform(src, {\n filename: moduleName,\n generatorOpts: {\n compact: false,\n },\n plugins: [[adjustImportsPlugin, resolver.adjustImportsOptions]],\n })!.code!;\n } else {\n return src;\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-inline-hbs-node.js'),\n {\n templateCompiler: this.params,\n stage: 1,\n } as InlineBabelParams,\n ];\n }\n\n baseDir() {\n return join(__dirname, '..');\n }\n\n // tests for the classic ember-cli-htmlbars-inline-precompile babel plugin\n static isInlinePrecompilePlugin(item: PluginItem) {\n if (typeof item === 'string') {\n return matchesSourceFile(item);\n }\n if (hasProperties(item) && (item as any)._parallelBabel) {\n return matchesSourceFile((item as any)._parallelBabel.requireFile);\n }\n if (Array.isArray(item) && item.length > 0) {\n if (typeof item[0] === 'string') {\n return matchesSourceFile(item[0]);\n }\n if (hasProperties(item[0]) && (item[0] as any)._parallelBabel) {\n return matchesSourceFile((item[0] as any)._parallelBabel.requireFile);\n }\n }\n return false;\n }\n}\n\nfunction hasProperties(item: any) {\n return item && (typeof item === 'object' || typeof item === 'function');\n}\n"]}
1
+ {"version":3,"file":"template-compiler-node.js","sourceRoot":"","sources":["template-compiler-node.ts"],"names":[],"mappings":";;;;;;AACA,+BAA4B;AAC5B,sCAAoD;AAGpD,iFAAiE;AACjE,yEAAiF;AACjF,gGAAqG;AAUrG,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,OAAO,CAAC,UAAkB,EAAE,QAAgB;QAC1C,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC9C,IAAI,QAAQ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,IAAI,CAAC,CAAC,CAAS,CAAC,cAAc,EAAE;gBAC7D,OAAO,IAAA,4CAAiB,EAAE,IAAI,CAAC,CAAC,CAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;aACvE;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5DD,oDA4DC;AAED,SAAS,aAAa,CAAC,IAAS;IAC9B,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import { Resolver } from './resolver';\nimport { join } from 'path';\nimport { PluginItem, transform } 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, matchesSourceFile } from './template-compiler-common';\nimport adjustImportsPlugin, { Options as AdjustImportsOptions } from './babel-plugin-adjust-imports';\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 compile(moduleName: string, contents: string) {\n let src = super.compile(moduleName, contents);\n let resolver = this.params.resolver;\n if (resolver) {\n let opts: AdjustImportsOptions = resolver.adjustImportsOptions;\n return transform(src, {\n filename: moduleName,\n generatorOpts: {\n compact: false,\n },\n plugins: [[adjustImportsPlugin, opts]],\n })!.code!;\n } else {\n return src;\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 // tests for the classic ember-cli-htmlbars-inline-precompile babel plugin\n static isInlinePrecompilePlugin(item: PluginItem) {\n if (typeof item === 'string') {\n return matchesSourceFile(item);\n }\n if (hasProperties(item) && (item as any)._parallelBabel) {\n return matchesSourceFile((item as any)._parallelBabel.requireFile);\n }\n if (Array.isArray(item) && item.length > 0) {\n if (typeof item[0] === 'string') {\n return matchesSourceFile(item[0]);\n }\n if (hasProperties(item[0]) && (item[0] as any)._parallelBabel) {\n return matchesSourceFile((item[0] as any)._parallelBabel.requireFile);\n }\n }\n return false;\n }\n}\n\nfunction hasProperties(item: any) {\n return item && (typeof item === 'object' || typeof item === 'function');\n}\n"]}