-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
822 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { Config } from '$compiler/parser/interfaces' | ||
import { Config as ConfigNode } from '$compiler/parser/interfaces' | ||
|
||
import { CompileNodeContext } from '../types' | ||
|
||
export async function compile(_: CompileNodeContext<Config>) { | ||
/* do nothing */ | ||
export async function compile({ | ||
node, | ||
setConfig, | ||
}: CompileNodeContext<ConfigNode>): Promise<void> { | ||
setConfig(node.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/compiler/src/compiler/base/nodes/tags/chainStep.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { tagAttributeIsLiteral } from '$compiler/compiler/utils' | ||
import errors from '$compiler/error/errors' | ||
import { ChainStepTag } from '$compiler/parser/interfaces' | ||
import { Config, ContentType } from '$compiler/types' | ||
|
||
import { CompileNodeContext } from '../../types' | ||
|
||
function isValidConfig(value: unknown): value is Config | undefined { | ||
if (value === undefined) return true | ||
if (Array.isArray(value)) return false | ||
return typeof value === 'object' | ||
} | ||
|
||
export async function compile( | ||
{ | ||
node, | ||
scope, | ||
popStepResponse, | ||
addMessage, | ||
groupContent, | ||
baseNodeError, | ||
stop, | ||
}: CompileNodeContext<ChainStepTag>, | ||
attributes: Record<string, unknown>, | ||
) { | ||
const stepResponse = popStepResponse() | ||
|
||
const { as: varName, ...config } = attributes | ||
|
||
if (stepResponse === undefined) { | ||
if (!isValidConfig(config)) { | ||
baseNodeError(errors.invalidStepConfig, node) | ||
} | ||
|
||
stop(config as Config) | ||
} | ||
|
||
if ('as' in attributes) { | ||
if (!tagAttributeIsLiteral(node, 'as')) { | ||
baseNodeError(errors.invalidStaticAttribute('as'), node) | ||
} | ||
|
||
const responseText = stepResponse?.content | ||
.filter((c) => c.type === ContentType.text) | ||
.map((c) => c.value) | ||
.join(' ') | ||
|
||
scope.set(String(varName), responseText) | ||
} | ||
|
||
groupContent() | ||
addMessage(stepResponse!) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.