Skip to content

Commit

Permalink
WIP: update tests to match formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TylorS committed Jun 8, 2024
1 parent 1aa8bbb commit 9e94ff2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 87 deletions.
104 changes: 41 additions & 63 deletions packages/compiler/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,7 @@ export class Compiler {
remaining: Array<ParsedTemplate>,
imports: ImportDeclarationManager
): ts.Node {
const sink = ts.factory.createParameterDeclaration([], undefined, `sink`)
const ctx = new CreateNodeCtx(
parts,
remaining,
imports,
Chunk.empty(),
"dom",
Chunk.empty()
)
const ctx = new CreateNodeCtx(parts, remaining, imports, Chunk.empty(), "dom", Chunk.empty())
const setupNodes = createDomSetupStatements(ctx)
const domNodes = Array.from(consumeNestedIterable(createDomTemplateStatements(template, ctx)))
const domEffects = createDomEffectStatements(template, ctx)
Expand All @@ -179,7 +171,7 @@ export class Compiler {
undefined,
`render`,
[],
[sink],
[ts.factory.createParameterDeclaration([], undefined, `sink`)],
undefined,
ts.factory.createBlock([
ts.factory.createReturnStatement(createMethodCall(`Effect`, `gen`, [], [
Expand Down Expand Up @@ -482,20 +474,16 @@ function createDomEffectStatements(template: Template.Template, ctx: CreateNodeC
)
)
),
ts.factory.createBlock(
[
ts.factory.createExpressionStatement(
createEffectYield(
ts.factory.createPropertyAccessExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`templateContext`),
`refCounter`
),
`wait`
)
)
ts.factory.createExpressionStatement(
createEffectYield(
ts.factory.createPropertyAccessExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`templateContext`),
`refCounter`
),
`wait`
)
]
)
)
)
)
Expand Down Expand Up @@ -1136,27 +1124,22 @@ function* createStandardNodePartStatements(
ts.SyntaxKind.ExclamationEqualsEqualsToken,
ts.factory.createNull()
),
ts.factory.createBlock(
[
ts.factory.createExpressionStatement(
createEffectYield(
ts.factory.createIdentifier(varName),
createMethodCall(`Effect`, `catchAllCause`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`sink`),
`onFailure`
)
]),
createMethodCall(`Effect`, `forkIn`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`templateContext`),
`scope`
)
])
ts.factory.createExpressionStatement(
createEffectYield(
ts.factory.createIdentifier(varName),
createMethodCall(`Effect`, `catchAllCause`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`sink`),
`onFailure`
)
)
],
true
]),
createMethodCall(`Effect`, `forkIn`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`templateContext`),
`scope`
)
])
)
)
)
}
Expand All @@ -1170,27 +1153,22 @@ function runPartIfNotNull(varName: string, ctx: CreateNodeCtx) {
ts.SyntaxKind.ExclamationEqualsEqualsToken,
ts.factory.createNull()
),
ts.factory.createBlock(
[
ts.factory.createExpressionStatement(
createEffectYield(
ts.factory.createIdentifier(varName),
createMethodCall(`Effect`, `catchAllCause`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`sink`),
`onFailure`
)
]),
createMethodCall(`Effect`, `forkIn`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`templateContext`),
`scope`
)
])
ts.factory.createExpressionStatement(
createEffectYield(
ts.factory.createIdentifier(varName),
createMethodCall(`Effect`, `catchAllCause`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`sink`),
`onFailure`
)
)
],
true
]),
createMethodCall(`Effect`, `forkIn`, [], [
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(`templateContext`),
`scope`
)
])
)
)
)
}
Expand Down
41 changes: 17 additions & 24 deletions packages/compiler/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ import * as RenderEvent from "@typed/template/RenderEvent";
import * as Effect from "effect/Effect";
import * as Scope from "effect/Scope";
import * as Fx from "@typed/fx";
export const render = Fx.make(sink => Effect.gen(function* (_) {
export const render = Fx.make(function render(sink) { return Effect.gen(function* (_) {
const context = yield* _(Effect.context());
const document = Context.get(context, Document.Document);
const renderContext = Context.get(context, RenderContext.RenderContext);
Expand All @@ -225,12 +225,11 @@ export const render = Fx.make(sink => Effect.gen(function* (_) {
template0_element1.appendChild(template0_text1);
element0.appendChild(template0_element0);
element0.appendChild(template0_element1);
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected)))) {
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected))))
yield* _(templateContext.refCounter.wait);
}
yield* _(sink.onSuccess(RenderEvent.DomRenderEvent(element0)));
yield* _(Effect.never, Effect.onExit(exit => Scope.close(templateContext.scope, exit)));
}));
}); });
//# sourceMappingURL=nested-templates.js.map`

expect(text).toEqual(expected)
Expand All @@ -248,7 +247,7 @@ import * as RenderEvent from "@typed/template/RenderEvent";
import * as Scope from "effect/Scope";
import * as Fx from "@typed/fx";
import * as Effect from "effect/Effect";
export const render = Fx.make(sink => Effect.gen(function* (_) {
export const render = Fx.make(function render(sink) { return Effect.gen(function* (_) {
const context = yield* _(Effect.context());
const document = Context.get(context, Document.Document);
const renderContext = Context.get(context, RenderContext.RenderContext);
Expand All @@ -257,28 +256,26 @@ export const render = Fx.make(sink => Effect.gen(function* (_) {
const nodePart0_comment = document.createComment("hole0");
element0.appendChild(nodePart0_comment);
const nodePart0 = CompilerTools.setupNodePart({ index: 0 }, nodePart0_comment, templateContext, null, []);
if (nodePart0 !== null) {
if (nodePart0 !== null)
yield* _(nodePart0, Effect.catchAllCause(sink.onFailure), Effect.forkIn(templateContext.scope));
}
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected)))) {
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected))))
yield* _(templateContext.refCounter.wait);
}
yield* _(sink.onSuccess(RenderEvent.DomRenderEvent(element0)));
yield* _(Effect.never, Effect.onExit(exit => Scope.close(templateContext.scope, exit)));
}));
}); });
//# sourceMappingURL=div-with-interpolated-effect.js.map`)

expect(getSnapshotText(divWithRefSubject.js)).toEqual(`import * as Document from "@typed/dom/Document";
import * as RenderContext from "@typed/template/RenderContext";
import * as Context from "@typed/context";
import * as CompilerTools from "@typed/template/compiler-tools";
import * as RenderEvent from "@typed/template/RenderEvent";
import * as Effect from "effect/Effect";
import * as RenderEvent from "@typed/template/RenderEvent";
import * as Scope from "effect/Scope";
import * as Fx from "@typed/fx";
import { RefSubject } from "@typed/core";
const ref = RefSubject.tagged()("ref");
export const render = Fx.make(sink => Effect.gen(function* (_) {
export const render = Fx.make(function render(sink) { return Effect.gen(function* (_) {
const context = yield* _(Effect.context());
const document = Context.get(context, Document.Document);
const renderContext = Context.get(context, RenderContext.RenderContext);
Expand All @@ -287,15 +284,13 @@ export const render = Fx.make(sink => Effect.gen(function* (_) {
const nodePart0_comment = document.createComment("hole0");
element0.appendChild(nodePart0_comment);
const nodePart0 = CompilerTools.setupNodePart({ index: 0 }, nodePart0_comment, templateContext, null, []);
if (nodePart0 !== null) {
if (nodePart0 !== null)
yield* _(nodePart0, Effect.catchAllCause(sink.onFailure), Effect.forkIn(templateContext.scope));
}
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected)))) {
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected))))
yield* _(templateContext.refCounter.wait);
}
yield* _(sink.onSuccess(RenderEvent.DomRenderEvent(element0)));
yield* _(Effect.never, Effect.onExit(exit => Scope.close(templateContext.scope, exit)));
}));
}); });
//# sourceMappingURL=div-with-interpolated-refsubject.js.map`)
})

Expand All @@ -306,30 +301,28 @@ export const render = Fx.make(sink => Effect.gen(function* (_) {
import * as RenderContext from "@typed/template/RenderContext";
import * as Context from "@typed/context";
import * as CompilerTools from "@typed/template/compiler-tools";
import * as RenderEvent from "@typed/template/RenderEvent";
import * as Effect from "effect/Effect";
import * as RenderEvent from "@typed/template/RenderEvent";
import * as Scope from "effect/Scope";
import * as Fx from "@typed/fx";
export const render = Fx.make(sink => Effect.gen(function* (_) {
export const render = Fx.make(function render(sink) { return Effect.gen(function* (_) {
const context = yield* _(Effect.context());
const document = Context.get(context, Document.Document);
const renderContext = Context.get(context, RenderContext.RenderContext);
const templateContext = yield* _(CompilerTools.makeTemplateContext(document, renderContext, [["foo", "bar"]], sink.onFailure));
const element0 = document.createElement("div");
const template0_element0 = document.createElement("div");
const template0_element0_class = CompilerTools.setupSparseClassNamePart({ nodes: [{ _tag: "className-part", index: 0 }, { _tag: "text", value: " " }, { _tag: "className-part", index: 1 }] }, template0_element0, { ...templateContext, values: templateContext.values[0] });
if (template0_element0_class !== null) {
if (template0_element0_class !== null)
yield* _(template0_element0_class, Effect.catchAllCause(sink.onFailure), Effect.forkIn(templateContext.scope));
}
const template0_text0 = document.createTextNode("Hello World");
template0_element0.appendChild(template0_text0);
element0.appendChild(template0_element0);
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected)))) {
if (templateContext.expected > 0 && (yield* _(templateContext.refCounter.expect(templateContext.expected))))
yield* _(templateContext.refCounter.wait);
}
yield* _(sink.onSuccess(RenderEvent.DomRenderEvent(element0)));
yield* _(Effect.never, Effect.onExit(exit => Scope.close(templateContext.scope, exit)));
}));
}); });
//# sourceMappingURL=div-with-sparse-class.js.map`)
})
})
Expand Down

0 comments on commit 9e94ff2

Please sign in to comment.