From 1a7ef56c094afbb62cbd25a59da487fee0be1f6f Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 22 Feb 2024 09:13:52 +0100 Subject: [PATCH] support embroider static --- lib/import-processor.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/import-processor.ts b/lib/import-processor.ts index b0b91eb..c9745aa 100644 --- a/lib/import-processor.ts +++ b/lib/import-processor.ts @@ -87,6 +87,7 @@ const importProcessors = { useHelperWrapper: true, useSafeImports: true, extendImportPathForNamedImports: true, + embroiderStatic: true, messageFormat: 'json' }, glimmer, @@ -188,8 +189,11 @@ const importProcessors = { const components = imported.info.components; const helpers = imported.info.helpers; const modifiers = imported.info.modifiers; + const options = this.options; + function findImport(name: string) { return imports.find((imp) => { + if (options.embroiderStatic && imp.shouldLookInFile) return false; if (imp.isStyle) { return name.split('.')[0] === imp.localName; } @@ -355,11 +359,13 @@ const importProcessors = { } const createComponentLetBlockExpr = (comp: [key: string, info: {path: string}]) => { - return importProcessors.glimmer.preprocess(`{{#let (component "${comp[1].path}") as |${comp[0]}|}}{{/let}}`).body[0] as glimmer.AST.BlockStatement; + const path = '__hbs__import_:' + comp[1].path.replace(/\\/g, '/'); + return importProcessors.glimmer.preprocess(`{{#let (component "${path}") as |${comp[0]}|}}{{/let}}`).body[0] as glimmer.AST.BlockStatement; }; const handleHelper = (helper: { nodes: PathExpression[], resolvedPath: string }) => { + const path = '__hbs__import_:' + helper.resolvedPath.replace(/\\/g, '/'); if (this.options.useModifierHelperHelpers) { - let lookup = `"${helper.resolvedPath}"`; + let lookup = `"${path}"`; if (this.options.useHelperWrapper) { lookup = `(ember-hbs-imports/helpers/lookup-helper this "${helper.resolvedPath}")`; } @@ -371,8 +377,9 @@ const importProcessors = { } }; const handleModifier = (modifier: { nodes: PathExpression[], resolvedPath: string }) => { + const path = '__hbs__import_:' + modifier.resolvedPath.replace(/\\/g, '/'); if (this.options.useModifierHelperHelpers) { - let lookup = `"${modifier.resolvedPath}"`; + let lookup = `"${path}"`; if (this.options.useHelperWrapper) { lookup = `(ember-hbs-imports/helpers/lookup-modifier this "${modifier.resolvedPath}")`; }