Skip to content

Commit 0a907a8

Browse files
committed
feat(): support DeferredBlock
1 parent 2a29a94 commit 0a907a8

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

packages/cli/src/angular/migrations/standalone/0002-generate-use-icons.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,35 @@ describe("migrateComponents", () => {
125125
dedent(`export { imageOutline, closeOutline } from "ionicons/icons";`),
126126
);
127127
});
128+
129+
it("@defer", async () => {
130+
const project = new Project({ useInMemoryFileSystem: true });
131+
132+
const html = `
133+
@defer (when loaded) {
134+
<ion-icon name="image-outline" color="medium"></ion-icon>
135+
} @loading {
136+
<ion-icon name="accessibility-outline"></ion-icon>
137+
} @placeholder {
138+
}
139+
`;
140+
141+
project.createSourceFile("foo.component.html", dedent(html));
142+
143+
const useIconFile = project.createSourceFile("use-icons.ts", dedent(``));
144+
145+
await generateUseIcons(project, {
146+
dryRun: false,
147+
iconPath: "src/use-icons.ts",
148+
projectPath: cwd(),
149+
interactive: false,
150+
initialize: false,
151+
});
152+
153+
expect(dedent(useIconFile.getText())).toBe(
154+
dedent(`export { imageOutline, accessibilityOutline } from "ionicons/icons";`),
155+
);
156+
});
128157
});
129158

130159
describe("get binding name", () => {

packages/cli/src/angular/migrations/standalone/0002-generate-use-icons.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,24 @@ function detectIonicComponentsAndIcons(htmlAsString: string, filePath: string) {
201201
recursivelyFindIonicComponents(childNode);
202202
}
203203
}
204+
} else if (node.type === "DeferredBlock") {
205+
if (node.children) {
206+
for (const childNode of node.children) {
207+
recursivelyFindIonicComponents(childNode);
208+
}
209+
}
210+
211+
for (const childKey of Object.keys(node)) {
212+
if (node[childKey]?.children) {
213+
for (const childNode of node[childKey].children) {
214+
recursivelyFindIonicComponents(Object.assign(childNode, {
215+
type: childNode.constructor.name
216+
}));
217+
}
218+
}
219+
}
204220
} else {
205-
console.log(node.type);
221+
// console.log(node.type);
206222
}
207223
};
208224

0 commit comments

Comments
 (0)