Skip to content

Commit

Permalink
support embroider static
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Feb 22, 2024
1 parent e72479c commit 1a7ef56
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/import-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const importProcessors = {
useHelperWrapper: true,
useSafeImports: true,
extendImportPathForNamedImports: true,
embroiderStatic: true,
messageFormat: 'json'
},
glimmer,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}")`;
}
Expand All @@ -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}")`;
}
Expand Down

0 comments on commit 1a7ef56

Please sign in to comment.