From 739d23edd6ab602433bfb4b24778ea77e51e44e0 Mon Sep 17 00:00:00 2001 From: FlamesX128 Date: Tue, 9 Nov 2021 22:56:09 -0600 Subject: [PATCH] Bug in await fixed. --- CHANGELOG.md | 6 ++++++ README.md | 41 ++++++++++++++++++++++++----------------- mod.ts | 6 +++--- test/main.html | 10 ++++++++++ test/main.test.ts | 4 +++- 5 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..18e2c46 --- /dev/null +++ b/CHANGELOG.md @@ -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! \ No newline at end of file diff --git a/README.md b/README.md index 10666fc..8bf1aa8 100644 --- a/README.md +++ b/README.md @@ -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 - - console.log("Hello 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"; @@ -35,14 +35,18 @@ import render from "https://deno.land/x/denotag/mod.ts"; ``` -Result: +`Result:` + ```html Hello world ``` -Example Two: +--- + +`Example Two:` + ```ts // main.ts import render from "https://deno.land/x/denotag/mod.ts"; @@ -65,7 +69,8 @@ import render from "https://deno.land/x/denotag/mod.ts"; ``` -Result: +`Result:` + ```html orange @@ -73,7 +78,9 @@ Result: ``` -#### **Information:** +--- + +## **Information:** Deno tag only accepts JS, tested with: - deno 1.14.3 (release, x86_64-unknown-linux-gnu) diff --git a/mod.ts b/mod.ts index 55ce34d..f042b46 100644 --- a/mod.ts +++ b/mod.ts @@ -53,6 +53,7 @@ async function render(filePath: string): Promise { return target; } + const asyncFunction: FunctionConstructor = Object.getPrototypeOf(async function(){}).constructor; return await ( /** @@ -101,7 +102,7 @@ async function render(filePath: string): Promise { * 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[]} @@ -122,7 +123,7 @@ async function render(filePath: string): Promise { * This function is responsible for executing the code declared in the deno tag. * @returns {Promise | void} */ - (async function main() { + await (async function main() { ${file.slice(open+6, close)} })(); @@ -130,7 +131,6 @@ async function render(filePath: string): Promise { return ${privateVar}; `)(); - return await lookingDeno( file.replace(file.slice(open, close + 7), result.join("\n")) ); diff --git a/test/main.html b/test/main.html index 7caa625..463445f 100644 --- a/test/main.html +++ b/test/main.html @@ -27,5 +27,15 @@

Que tal lmao

} + + let i = 0; + + for (; i < 30; i++) { + await fetch("https://www.google.com/") + } + + write(`${i}`) + + \ No newline at end of file diff --git a/test/main.test.ts b/test/main.test.ts index ce5220b..b8196fb 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -5,7 +5,9 @@ import render from "../mod.ts"; (async function main(): Promise { - 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); })(); \ No newline at end of file