Skip to content

Commit

Permalink
Bug in await fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlamesX-128 committed Nov 10, 2021
1 parent a44dca2 commit 739d23e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ChangeLog
`0.0.2` - Bug in await fixed:
- Fixed a bug that did not allow use of await.

`0.0.1` - First release:
+ This is the first version!
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# **Deno Tag**
A simple html preprocessor for deno.

## **Change Log:**
This is the list of changes:
- 0.0.1 - first release:
+ Deno tag:
```html
<deno>
console.log("Hello Deno!");
</deno>
```
+ write: This is a function that adds something to the html.

### **Examples:**
Example One:
## **ChangeLog**
`0.0.2` - Bug in await fixed:
- Fixed a bug that did not allow use of await.

`0.0.1` - First release:
+ This is the first version!

---

## **Examples**

`Example One:`

```ts
// main.ts
import render from "https://deno.land/x/denotag/mod.ts";
Expand All @@ -35,14 +35,18 @@ import render from "https://deno.land/x/denotag/mod.ts";
</body>
```

Result:
`Result:`

```html
<body>
Hello world
</body>
```

Example Two:
---

`Example Two:`

```ts
// main.ts
import render from "https://deno.land/x/denotag/mod.ts";
Expand All @@ -65,15 +69,18 @@ import render from "https://deno.land/x/denotag/mod.ts";
</body>
```

Result:
`Result:`

```html
<body>
orange
apple
</body>
```

#### **Information:**
---

## **Information:**
Deno tag only accepts JS, tested with:
- deno 1.14.3 (release, x86_64-unknown-linux-gnu)

Expand Down
6 changes: 3 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function render(filePath: string): Promise<string> {
return target;
}

const asyncFunction: FunctionConstructor = Object.getPrototypeOf(async function(){}).constructor;

return await (
/**
Expand Down Expand Up @@ -101,7 +102,7 @@ async function render(filePath: string): Promise<string> {
* This creates a function with the code to execute and receives the return.
* @type {string[]}
*/
const result: string[] = await new Function(`
const result: string[] = await new asyncFunction(`
/**
* This is the variable in charge of receiving and returning the changes in the html.
* @type {string[]}
Expand All @@ -122,15 +123,14 @@ async function render(filePath: string): Promise<string> {
* This function is responsible for executing the code declared in the deno tag.
* @returns {Promise<void> | void}
*/
(async function main() {
await (async function main() {
${file.slice(open+6, close)}
})();
return ${privateVar};
`)();


return await lookingDeno(
file.replace(file.slice(open, close + 7), result.join("\n"))
);
Expand Down
10 changes: 10 additions & 0 deletions test/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ <h2>Que tal lmao</h2>
}
</deno>

<deno>
let i = 0;

for (; i < 30; i++) {
await fetch("https://www.google.com/")
}

write(`${i}`)
</deno>

</body>
</html>
4 changes: 3 additions & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import render from "../mod.ts";


(async function main(): Promise<void> {
const res = await render(join(dirname(fromFileUrl(import.meta.url)), "main.html"));
const res: string = await render(
join(dirname(fromFileUrl(import.meta.url)), "main.html")
);

console.log(res);
})();

0 comments on commit 739d23e

Please sign in to comment.