@embroider/core 0.46.2 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/package.json +4 -4
  2. package/src/app-files.d.ts +1 -0
  3. package/src/app-files.js +11 -3
  4. package/src/app-files.js.map +1 -1
  5. package/src/app.js +30 -8
  6. package/src/app.js.map +1 -1
  7. package/src/babel-plugin-adjust-imports.d.ts +6 -5
  8. package/src/babel-plugin-adjust-imports.js.map +1 -1
  9. package/src/babel-plugin-inline-hbs-deps-node.d.ts +14 -0
  10. package/src/babel-plugin-inline-hbs-deps-node.js +27 -0
  11. package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -0
  12. package/src/babel-plugin-inline-hbs-deps.d.ts +10 -0
  13. package/src/babel-plugin-inline-hbs-deps.js +119 -0
  14. package/src/babel-plugin-inline-hbs-deps.js.map +1 -0
  15. package/src/babel-plugin-inline-hbs-node.d.ts +3 -9
  16. package/src/babel-plugin-inline-hbs-node.js.map +1 -1
  17. package/src/babel-plugin-inline-hbs.d.ts +5 -7
  18. package/src/babel-plugin-inline-hbs.js +35 -73
  19. package/src/babel-plugin-inline-hbs.js.map +1 -1
  20. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +12 -0
  21. package/src/babel-plugin-stage1-inline-hbs-node.js +9 -0
  22. package/src/babel-plugin-stage1-inline-hbs-node.js.map +1 -0
  23. package/src/babel-plugin-stage1-inline-hbs.d.ts +9 -0
  24. package/src/babel-plugin-stage1-inline-hbs.js +96 -0
  25. package/src/babel-plugin-stage1-inline-hbs.js.map +1 -0
  26. package/src/describe-exports.js +3 -3
  27. package/src/describe-exports.js.map +1 -1
  28. package/src/mini-modules-polyfill.d.ts +1 -1
  29. package/src/mini-modules-polyfill.js.map +1 -1
  30. package/src/options.d.ts +1 -0
  31. package/src/options.js +1 -0
  32. package/src/options.js.map +1 -1
  33. package/src/patch-template-compiler.js +3 -4
  34. package/src/patch-template-compiler.js.map +1 -1
  35. package/src/rename-require-plugin.js.map +1 -1
  36. package/src/template-compiler-common.d.ts +3 -1
  37. package/src/template-compiler-common.js +8 -12
  38. package/src/template-compiler-common.js.map +1 -1
  39. package/src/template-compiler-node.js +3 -3
  40. package/src/template-compiler-node.js.map +1 -1
  41. package/src/babel-import-adder.d.ts +0 -11
  42. package/src/babel-import-adder.js +0 -75
  43. package/src/babel-import-adder.js.map +0 -1
  44. package/src/template-colocation-plugin.d.ts +0 -22
  45. package/src/template-colocation-plugin.js +0 -113
  46. package/src/template-colocation-plugin.js.map +0 -1
@@ -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,yBAAy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D,8BAA8B;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   -> ' ')\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,G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xD,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(\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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E;YAC1C,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,Q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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-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"]}
@@ -1,11 +0,0 @@
1
- import type { NodePath } from '@babel/traverse';
2
- import type * as t from '@babel/types';
3
- declare type BabelTypes = typeof t;
4
- export declare class ImportAdder {
5
- private t;
6
- private program;
7
- constructor(t: BabelTypes, program: NodePath<t.Program>);
8
- import(target: NodePath<t.Node>, moduleSpecifier: string, exportedName: string, nameHint?: string): t.Identifier;
9
- private addSpecifier;
10
- }
11
- export {};
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImportAdder = void 0;
4
- class ImportAdder {
5
- constructor(t, program) {
6
- this.t = t;
7
- this.program = program;
8
- }
9
- import(target, moduleSpecifier, exportedName, nameHint) {
10
- var _a;
11
- let declaration = this.program
12
- .get('body')
13
- .find(elt => elt.isImportDeclaration() && elt.node.source.value === moduleSpecifier);
14
- if (declaration) {
15
- let specifier = declaration
16
- .get('specifiers')
17
- .find(spec => exportedName === 'default'
18
- ? spec.isImportDefaultSpecifier()
19
- : spec.isImportSpecifier() && name(spec.node.imported) === exportedName);
20
- if (specifier && ((_a = target.scope.getBinding(specifier.node.local.name)) === null || _a === void 0 ? void 0 : _a.kind) === 'module') {
21
- return specifier.node.local;
22
- }
23
- else {
24
- return this.addSpecifier(target, declaration, exportedName, nameHint);
25
- }
26
- }
27
- else {
28
- this.program.node.body.unshift(this.t.importDeclaration([], this.t.stringLiteral(moduleSpecifier)));
29
- return this.addSpecifier(target, this.program.get(`body.0`), exportedName, nameHint);
30
- }
31
- }
32
- addSpecifier(target, declaration, exportedName, nameHint) {
33
- let local = this.t.identifier(unusedNameLike(target, desiredName(nameHint, exportedName, target)));
34
- let specifier = exportedName === 'default'
35
- ? this.t.importDefaultSpecifier(local)
36
- : this.t.importSpecifier(local, this.t.identifier(exportedName));
37
- declaration.node.specifiers.push(specifier);
38
- declaration.scope.registerBinding('module', declaration.get(`specifiers.${declaration.node.specifiers.length - 1}`));
39
- return local;
40
- }
41
- }
42
- exports.ImportAdder = ImportAdder;
43
- function unusedNameLike(path, name) {
44
- let candidate = name;
45
- let counter = 0;
46
- while (path.scope.hasBinding(candidate)) {
47
- candidate = `${name}${counter++}`;
48
- }
49
- return candidate;
50
- }
51
- function name(node) {
52
- if (node.type === 'StringLiteral') {
53
- return node.value;
54
- }
55
- else {
56
- return node.name;
57
- }
58
- }
59
- function desiredName(nameHint, exportedName, target) {
60
- if (nameHint) {
61
- return nameHint;
62
- }
63
- if (exportedName === 'default') {
64
- if (target.isIdentifier()) {
65
- return target.node.name;
66
- }
67
- else {
68
- return target.scope.generateUidIdentifierBasedOnNode(target.node).name;
69
- }
70
- }
71
- else {
72
- return exportedName;
73
- }
74
- }
75
- //# sourceMappingURL=babel-import-adder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-import-adder.js","sourceRoot":"","sources":["babel-import-adder.ts"],"names":[],"mappings":";;;AAKA,MAAa,WAAW;IACtB,YAAoB,CAAa,EAAU,OAA4B;QAAnD,MAAC,GAAD,CAAC,CAAY;QAAU,YAAO,GAAP,OAAO,CAAqB;IAAG,CAAC;IAE3E,MAAM,CAAC,MAAwB,EAAE,eAAuB,EAAE,YAAoB,EAAE,QAAiB;;QAC/F,IAAI,WAAW,GAAG,IAAI,CAAC,OAA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B;IACD,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE;YACzB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;SACzB;aAAM;YACL,OAAO,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;SACxE;KACF;SAAM;QACL,OAAO,YAAY,CAAC;KACrB;AACH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type * as t from '@babel/types';\n\ntype BabelTypes = typeof t;\n\nexport class ImportAdder {\n constructor(private t: BabelTypes, private program: NodePath<t.Program>) {}\n\n import(target: NodePath<t.Node>, moduleSpecifier: string, exportedName: string, nameHint?: string): t.Identifier {\n let declaration = this.program\n .get('body')\n .find(elt => elt.isImportDeclaration() && elt.node.source.value === moduleSpecifier) as\n | undefined\n | NodePath<t.ImportDeclaration>;\n if (declaration) {\n let specifier = declaration\n .get('specifiers')\n .find(spec =>\n exportedName === 'default'\n ? spec.isImportDefaultSpecifier()\n : spec.isImportSpecifier() && name(spec.node.imported) === exportedName\n ) as undefined | NodePath<t.ImportSpecifier> | NodePath<t.ImportDefaultSpecifier>;\n if (specifier && target.scope.getBinding(specifier.node.local.name)?.kind === 'module') {\n return specifier.node.local;\n } else {\n return this.addSpecifier(target, declaration, exportedName, nameHint);\n }\n } else {\n this.program.node.body.unshift(this.t.importDeclaration([], this.t.stringLiteral(moduleSpecifier)));\n return this.addSpecifier(\n target,\n this.program.get(`body.0`) as NodePath<t.ImportDeclaration>,\n exportedName,\n nameHint\n );\n }\n }\n\n private addSpecifier(\n target: NodePath<t.Node>,\n declaration: NodePath<t.ImportDeclaration>,\n exportedName: string,\n nameHint: string | undefined\n ): t.Identifier {\n let local = this.t.identifier(unusedNameLike(target, desiredName(nameHint, exportedName, target)));\n let specifier =\n exportedName === 'default'\n ? this.t.importDefaultSpecifier(local)\n : this.t.importSpecifier(local, this.t.identifier(exportedName));\n declaration.node.specifiers.push(specifier);\n declaration.scope.registerBinding(\n 'module',\n declaration.get(`specifiers.${declaration.node.specifiers.length - 1}`) as NodePath\n );\n return local;\n }\n}\n\nfunction unusedNameLike(path: NodePath<unknown>, name: string): string {\n let candidate = name;\n let counter = 0;\n while (path.scope.hasBinding(candidate)) {\n candidate = `${name}${counter++}`;\n }\n return candidate;\n}\n\nfunction name(node: t.StringLiteral | t.Identifier): string {\n if (node.type === 'StringLiteral') {\n return node.value;\n } else {\n return node.name;\n }\n}\n\nfunction desiredName(nameHint: string | undefined, exportedName: string, target: NodePath<t.Node>) {\n if (nameHint) {\n return nameHint;\n }\n if (exportedName === 'default') {\n if (target.isIdentifier()) {\n return target.node.name;\n } else {\n return target.scope.generateUidIdentifierBasedOnNode(target.node).name;\n }\n } else {\n return exportedName;\n }\n}\n"]}
@@ -1,22 +0,0 @@
1
- import type { NodePath } from '@babel/traverse';
2
- import type * as t from '@babel/types';
3
- import { ImportUtil } from 'babel-import-util';
4
- interface State {
5
- colocatedTemplate: string | undefined;
6
- associate: {
7
- component: t.Identifier;
8
- template: t.Identifier;
9
- } | undefined;
10
- adder: ImportUtil;
11
- }
12
- export default function main(babel: unknown): {
13
- visitor: {
14
- Program: {
15
- enter(path: NodePath<t.Program>, state: State): void;
16
- exit(path: NodePath<t.Program>, state: State): void;
17
- };
18
- ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>, state: State): void;
19
- ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>, state: State): void;
20
- };
21
- };
22
- export {};
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
- const path_1 = require("path");
5
- const shared_internals_1 = require("@embroider/shared-internals");
6
- const shared_internals_2 = require("@embroider/shared-internals");
7
- const babel_import_util_1 = require("babel-import-util");
8
- const packageCache = shared_internals_2.PackageCache.shared('embroider-stage3');
9
- function setComponentTemplate(target, state) {
10
- return state.adder.import(target, '@ember/component', 'setComponentTemplate');
11
- }
12
- function main(babel) {
13
- let t = babel.types;
14
- return {
15
- visitor: {
16
- Program: {
17
- enter(path, state) {
18
- state.adder = new babel_import_util_1.ImportUtil(t, path);
19
- let filename = path.hub.file.opts.filename;
20
- let owningPackage = packageCache.ownerOfFile(filename);
21
- if (!owningPackage || !owningPackage.isV2Ember() || !owningPackage.meta['auto-upgraded']) {
22
- return;
23
- }
24
- let hbsFilename = filename.replace(/\.\w{1,3}$/, '') + '.hbs';
25
- if ((0, fs_1.existsSync)(hbsFilename)) {
26
- state.colocatedTemplate = hbsFilename;
27
- }
28
- },
29
- exit(path, state) {
30
- if (!state.colocatedTemplate) {
31
- return;
32
- }
33
- if (state.associate) {
34
- path.node.body.push(t.expressionStatement(t.callExpression(setComponentTemplate(path, state), [
35
- state.associate.template,
36
- state.associate.component,
37
- ])));
38
- }
39
- },
40
- },
41
- ExportDefaultDeclaration(path, state) {
42
- var _a;
43
- if (!state.colocatedTemplate) {
44
- return;
45
- }
46
- let declaration = path.get('declaration').node;
47
- if (t.isClassDeclaration(declaration)) {
48
- let template = importTemplate(path, state.adder, state.colocatedTemplate);
49
- if (declaration.id != null) {
50
- state.associate = { template, component: declaration.id };
51
- }
52
- else {
53
- path.node.declaration = t.callExpression(setComponentTemplate(path, state), [
54
- template,
55
- t.classExpression(null, declaration.superClass, declaration.body, (_a = declaration.decorators) !== null && _a !== void 0 ? _a : []),
56
- ]);
57
- }
58
- }
59
- else if (t.isFunctionDeclaration(declaration)) {
60
- let template = importTemplate(path, state.adder, state.colocatedTemplate);
61
- if (declaration.id != null) {
62
- state.associate = { template, component: declaration.id };
63
- }
64
- else {
65
- path.node.declaration = t.callExpression(setComponentTemplate(path, state), [
66
- template,
67
- t.functionExpression(null, declaration.params, declaration.body, declaration.generator, declaration.async),
68
- ]);
69
- }
70
- }
71
- else if (t.isTSDeclareFunction(declaration)) {
72
- // we don't rewrite this
73
- }
74
- else {
75
- let local = importTemplate(path, state.adder, state.colocatedTemplate);
76
- path.node.declaration = t.callExpression(setComponentTemplate(path, state), [local, declaration]);
77
- }
78
- },
79
- ExportNamedDeclaration(path, state) {
80
- if (!state.colocatedTemplate) {
81
- return;
82
- }
83
- let { node } = path;
84
- for (let specifier of path.node.specifiers) {
85
- if (t.isExportDefaultSpecifier(specifier)) {
86
- }
87
- else if (t.isExportSpecifier(specifier)) {
88
- const name = specifier.exported.type === 'Identifier' ? specifier.exported.name : specifier.exported.value;
89
- if (name === 'default') {
90
- let template = importTemplate(path, state.adder, state.colocatedTemplate);
91
- if (node.source) {
92
- // our default export is a reexport from elsewhere. We will
93
- // synthesize a new import for it so we can get a local handle
94
- // on it
95
- let component = state.adder.import(path, node.source.value, specifier.local.name, 'COMPONENT');
96
- state.associate = { template, component };
97
- }
98
- else {
99
- // our default export is one of our local names
100
- state.associate = { template, component: t.identifier(specifier.local.name) };
101
- }
102
- }
103
- }
104
- }
105
- },
106
- },
107
- };
108
- }
109
- exports.default = main;
110
- function importTemplate(target, adder, colocatedTemplate) {
111
- return adder.import(target, (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(colocatedTemplate), colocatedTemplate), 'default', 'TEMPLATE');
112
- }
113
- //# sourceMappingURL=template-colocation-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template-colocation-plugin.js","sourceRoot":"","sources":["template-colocation-plugin.ts"],"names":[],"mappings":";;AACA,2BAAgC;AAEhC,+BAA+B;AAC/B,kEAA+D;AAC/D,kEAA2D;AAC3D,yDAA+C;AAI/C,MAAM,YAAY,GAAG,+BAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAQ7D,SAAS,oBAAoB,CAAC,MAAwB,EAAE,KAAY;IAClE,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,sBAAsB,CAAC,CAAC;AAChF,CAAC;AAED,SAAwB,IAAI,CAAC,KAAc;IACzC,IAAI,CAAC,GAAI,KAAa,CAAC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AM,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;gCAC/F,KAAK,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;6BAC3C;iCAAM;gCACL,+CAA+C;gCAC/C,KAAK,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;6BAC/E;yBACF;qBACF;iBACF;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAzGD,uBAyGC;AAED,SAAS,cAAc,CAAC,MAAwB,EAAE,KAAiB,EAAE,iBAAyB;IAC5F,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAA,mCAAgB,EAAC,IAAA,cAAO,EAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACtH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport { existsSync } from 'fs';\nimport type * as t from '@babel/types';\nimport { dirname } from 'path';\nimport { explicitRelative } from '@embroider/shared-internals';\nimport { PackageCache } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\n\ntype BabelTypes = typeof t;\n\nconst packageCache = PackageCache.shared('embroider-stage3');\n\ninterface State {\n colocatedTemplate: string | undefined;\n associate: { component: t.Identifier; template: t.Identifier } | undefined;\n adder: ImportUtil;\n}\n\nfunction setComponentTemplate(target: NodePath<t.Node>, state: State) {\n return state.adder.import(target, '@ember/component', 'setComponentTemplate');\n}\n\nexport default function main(babel: 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.adder = new ImportUtil(t, path);\n let filename = path.hub.file.opts.filename;\n\n let owningPackage = packageCache.ownerOfFile(filename);\n if (!owningPackage || !owningPackage.isV2Ember() || !owningPackage.meta['auto-upgraded']) {\n return;\n }\n\n let hbsFilename = filename.replace(/\\.\\w{1,3}$/, '') + '.hbs';\n if (existsSync(hbsFilename)) {\n state.colocatedTemplate = hbsFilename;\n }\n },\n exit(path: NodePath<t.Program>, state: State) {\n if (!state.colocatedTemplate) {\n return;\n }\n if (state.associate) {\n path.node.body.push(\n t.expressionStatement(\n t.callExpression(setComponentTemplate(path, state), [\n state.associate.template,\n state.associate.component,\n ])\n )\n );\n }\n },\n },\n\n ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>, state: State) {\n if (!state.colocatedTemplate) {\n return;\n }\n\n let declaration = path.get('declaration').node;\n\n if (t.isClassDeclaration(declaration)) {\n let template = importTemplate(path, state.adder, state.colocatedTemplate);\n if (declaration.id != null) {\n state.associate = { template, component: declaration.id };\n } else {\n path.node.declaration = t.callExpression(setComponentTemplate(path, state), [\n template,\n t.classExpression(null, declaration.superClass, declaration.body, declaration.decorators ?? []),\n ]);\n }\n } else if (t.isFunctionDeclaration(declaration)) {\n let template = importTemplate(path, state.adder, state.colocatedTemplate);\n\n if (declaration.id != null) {\n state.associate = { template, component: declaration.id };\n } else {\n path.node.declaration = t.callExpression(setComponentTemplate(path, state), [\n template,\n t.functionExpression(\n null,\n declaration.params,\n declaration.body,\n declaration.generator,\n declaration.async\n ),\n ]);\n }\n } else if (t.isTSDeclareFunction(declaration)) {\n // we don't rewrite this\n } else {\n let local = importTemplate(path, state.adder, state.colocatedTemplate);\n path.node.declaration = t.callExpression(setComponentTemplate(path, state), [local, declaration]);\n }\n },\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>, state: State) {\n if (!state.colocatedTemplate) {\n return;\n }\n let { node } = path;\n for (let specifier of path.node.specifiers) {\n if (t.isExportDefaultSpecifier(specifier)) {\n } else if (t.isExportSpecifier(specifier)) {\n const name = specifier.exported.type === 'Identifier' ? specifier.exported.name : specifier.exported.value;\n\n if (name === 'default') {\n let template = importTemplate(path, state.adder, state.colocatedTemplate);\n if (node.source) {\n // our default export is a reexport from elsewhere. We will\n // synthesize a new import for it so we can get a local handle\n // on it\n let component = state.adder.import(path, node.source.value, specifier.local.name, 'COMPONENT');\n state.associate = { template, component };\n } else {\n // our default export is one of our local names\n state.associate = { template, component: t.identifier(specifier.local.name) };\n }\n }\n }\n }\n },\n },\n };\n}\n\nfunction importTemplate(target: NodePath<t.Node>, adder: ImportUtil, colocatedTemplate: string) {\n return adder.import(target, explicitRelative(dirname(colocatedTemplate), colocatedTemplate), 'default', 'TEMPLATE');\n}\n"]}