From 565a21eb0eee61048f6f770bfb24a03131fbc958 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 17 Aug 2018 00:28:02 +0900 Subject: [PATCH] chore: format files in tests/ --- js/runtime.ts | 47 +++++++++++++++++++-------------------- tests/010_set_interval.ts | 6 ++--- tests/async_error.ts | 3 +-- tests/async_error.ts.out | 4 ++-- tests/error_001.ts | 4 ++-- tools/format.py | 1 + 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/js/runtime.ts b/js/runtime.ts index fdfbbe799a..a0fd6d6220 100644 --- a/js/runtime.ts +++ b/js/runtime.ts @@ -344,30 +344,29 @@ class TypeScriptHost implements ts.LanguageServiceHost { containingFile: string ): ts.ResolvedModule[] { //util.log("resolveModuleNames", { moduleNames, reusedNames }); - return moduleNames - .map(name => { - let resolvedFileName; - if (name === "deno") { - resolvedFileName = resolveModuleName("deno.d.ts", ASSETS); - } else if (name === "typescript") { - resolvedFileName = resolveModuleName("typescript.d.ts", ASSETS); - } else { - resolvedFileName = resolveModuleName(name, containingFile); - } - // According to the interface we shouldn't return `undefined` but if we - // fail to return the same length of modules to those we cannot resolve - // then TypeScript fails on an assertion that the lengths can't be - // different, so we have to return an "empty" resolved module - // TODO: all this does is push the problem downstream, and TypeScript - // will complain it can't identify the type of the file and throw - // a runtime exception, so we need to handle missing modules better - resolvedFileName = resolvedFileName || ""; - // This flags to the compiler to not go looking to transpile functional - // code, anything that is in `/$asset$/` is just library code - const isExternalLibraryImport = resolvedFileName.startsWith(ASSETS); - // TODO: we should be returning a ts.ResolveModuleFull - return { resolvedFileName, isExternalLibraryImport }; - }); + return moduleNames.map(name => { + let resolvedFileName; + if (name === "deno") { + resolvedFileName = resolveModuleName("deno.d.ts", ASSETS); + } else if (name === "typescript") { + resolvedFileName = resolveModuleName("typescript.d.ts", ASSETS); + } else { + resolvedFileName = resolveModuleName(name, containingFile); + } + // According to the interface we shouldn't return `undefined` but if we + // fail to return the same length of modules to those we cannot resolve + // then TypeScript fails on an assertion that the lengths can't be + // different, so we have to return an "empty" resolved module + // TODO: all this does is push the problem downstream, and TypeScript + // will complain it can't identify the type of the file and throw + // a runtime exception, so we need to handle missing modules better + resolvedFileName = resolvedFileName || ""; + // This flags to the compiler to not go looking to transpile functional + // code, anything that is in `/$asset$/` is just library code + const isExternalLibraryImport = resolvedFileName.startsWith(ASSETS); + // TODO: we should be returning a ts.ResolveModuleFull + return { resolvedFileName, isExternalLibraryImport }; + }); } } diff --git a/tests/010_set_interval.ts b/tests/010_set_interval.ts index e013d00bc6..f58cc3fcd1 100644 --- a/tests/010_set_interval.ts +++ b/tests/010_set_interval.ts @@ -1,7 +1,7 @@ const id = setInterval(function() { - console.log("test") + console.log("test"); }, 200); setTimeout(function() { - clearInterval(id) -}, 500) + clearInterval(id); +}, 500); diff --git a/tests/async_error.ts b/tests/async_error.ts index 12dee11eb0..7ce25d0cb6 100644 --- a/tests/async_error.ts +++ b/tests/async_error.ts @@ -1,9 +1,8 @@ - console.log("hello"); const foo = async () => { console.log("before error"); throw Error("error"); -} +}; foo(); console.log("world"); diff --git a/tests/async_error.ts.out b/tests/async_error.ts.out index 1290629b17..c98c79bfc6 100644 --- a/tests/async_error.ts.out +++ b/tests/async_error.ts.out @@ -1,8 +1,8 @@ hello before error Error: error - at foo ([WILDCARD]tests/async_error.ts:5:9) - at eval ([WILDCARD]tests/async_error.ts:8:1) + at foo ([WILDCARD]tests/async_error.ts:4:9) + at eval ([WILDCARD]tests/async_error.ts:7:1) at eval () at execute (deno/js/runtime.ts:[WILDCARD]) at FileModule.compileAndRun (deno/js/runtime.ts:[WILDCARD]) diff --git a/tests/error_001.ts b/tests/error_001.ts index 624bc55da0..ab6e17a524 100644 --- a/tests/error_001.ts +++ b/tests/error_001.ts @@ -3,7 +3,7 @@ function foo() { } function bar() { - foo() + foo(); } -bar() +bar(); diff --git a/tools/format.py b/tools/format.py index f2d94a6f4b..51bf2c1fb0 100755 --- a/tools/format.py +++ b/tools/format.py @@ -23,6 +23,7 @@ run(["yapf", "-i"] + find_exts("tools/", ".py") + find_exts("build_extra", ".py")) run(["node", prettier, "--write"] + find_exts("js/", ".js", ".ts") + + find_exts("tests/", ".js", ".ts") + ["rollup.config.js", "tsconfig.json", "tslint.json"]) # Requires rustfmt 0.8.2 (flags were different in previous versions)