Skip to content

Commit

Permalink
Added failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Aug 23, 2024
1 parent 230f8bc commit 76af48c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/core/XNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ export default class XNode {

async execute() {
const a = this.attributes ?? {};
a.throwOnFail ??= true;
const { then, failed, throwOnFail} = a;
const { then, failed, throwOnFail = true} = a;
let result;
if (this.log) {
console.log(`Executing ${this.name.name}`);
console.log(this.attributes);
console.log(a);
}
try {
result = await this.___invoke(a);
await then?.(result);
} catch (error) {
failed?.(error);
if (throwOnFail) {
throw new (Error as any)("Failed", { cause: error });
throw new (Error as any)(`Failed on ${this.attributes?.location}`, { cause: error });
}
}
return result;
Expand Down
14 changes: 12 additions & 2 deletions src/core/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const presets = {
}
return node;
},
JSXElement(node) {
JSXElement(node, state) {
if (node.node.children?.length) {
const copy = [... node.node.children];
const transformed = node.node.children = [];
Expand All @@ -46,6 +46,16 @@ const presets = {
case "JSXEmptyExpression":
continue;
}

// lets add location...
if (element.loc?.start) {
(element.openingElement.attributes ??= []).push(
babel.types.jsxAttribute(
babel.types.jsxIdentifier("location"),
babel.types.stringLiteral( `${state.filename} ${element.loc.start.line},${element.loc.start.column}`))
);
}

transformed.push(babel.types.arrowFunctionExpression([], element));
}
}
Expand Down Expand Up @@ -75,7 +85,7 @@ export class Babel {
static async transformJSX(file: string, outputFile?: string) {
let code = await readFile(file, "utf8");
const finalCode = `${inject};${code}`;
const p = { ... presets };
const p = { ... presets, filename: file };
if (outputFile) {
p.sourceMaps = true;
}
Expand Down

0 comments on commit 76af48c

Please sign in to comment.