summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--os.go8
-rw-r--r--runtime.ts42
-rw-r--r--testdata/012_async.ts11
-rw-r--r--testdata/012_async.ts.out3
-rw-r--r--util.go2
6 files changed, 53 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 204adccf9..939d3f939 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ deno: msg.pb.go $(GO_FILES)
go build -o deno
assets.go: dist/main.js
- cp node_modules/typescript/lib/lib.d.ts dist/
+ cp node_modules/typescript/lib/lib.*d.ts dist/
cp deno.d.ts dist/
go-bindata -pkg main -o assets.go dist/
diff --git a/os.go b/os.go
index 5a96516ea..d1923837e 100644
--- a/os.go
+++ b/os.go
@@ -76,14 +76,18 @@ func HandleCodeFetch(moduleSpecifier string, containingFile string) (out []byte)
return
}
- //println("HandleCodeFetch", "moduleSpecifier", moduleSpecifier,
- // "containingFile", containingFile, "filename", filename)
+ logDebug("HandleCodeFetch moduleSpecifier %s containingFile %s filename %s",
+ moduleSpecifier, containingFile, filename)
if isRemote(moduleName) {
sourceCodeBuf, err = FetchRemoteSource(moduleName, filename)
} else if strings.HasPrefix(moduleName, assetPrefix) {
f := strings.TrimPrefix(moduleName, assetPrefix)
sourceCodeBuf, err = Asset("dist/" + f)
+ if err != nil {
+ logDebug("%s Asset doesn't exist. Return without error", moduleName)
+ err = nil
+ }
} else {
assert(moduleName == filename,
"if a module isn't remote, it should have the same filename")
diff --git a/runtime.ts b/runtime.ts
index 9fb51b69a..ca7af884c 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -57,6 +57,10 @@ export class FileModule {
readonly sourceCode = "",
public outputCode = ""
) {
+ util.assert(
+ !FileModule.map.has(fileName),
+ `FileModule.map already has ${fileName}`
+ );
FileModule.map.set(fileName, this);
if (outputCode !== "") {
this.scriptVersion = "1";
@@ -124,8 +128,8 @@ export function makeDefine(fileName: string): AmdDefine {
export function resolveModule(
moduleSpecifier: string,
containingFile: string
-): FileModule {
- util.log("resolveModule", { moduleSpecifier, containingFile });
+): null | FileModule {
+ //util.log("resolveModule", { moduleSpecifier, containingFile });
util.assert(moduleSpecifier != null && moduleSpecifier.length > 0);
// We ask golang to sourceCodeFetch. It will load the sourceCode and if
// there is any outputCode cached, it will return that as well.
@@ -133,8 +137,16 @@ export function resolveModule(
moduleSpecifier,
containingFile
);
- util.log("resolveModule", { containingFile, moduleSpecifier, filename });
- return new FileModule(filename, sourceCode, outputCode);
+ if (sourceCode.length == 0) {
+ return null;
+ }
+ util.log("resolveModule sourceCode length ", sourceCode.length);
+ let m = FileModule.load(filename);
+ if (m != null) {
+ return m;
+ } else {
+ return new FileModule(filename, sourceCode, outputCode);
+ }
}
function resolveModuleName(
@@ -160,7 +172,9 @@ class Compiler {
module: ts.ModuleKind.AMD,
outDir: "$deno$",
inlineSourceMap: true,
- inlineSources: true
+ lib: ["es2017"],
+ inlineSources: true,
+ target: ts.ScriptTarget.ES2017
};
/*
allowJs: true,
@@ -224,15 +238,21 @@ class TypeScriptHost implements ts.LanguageServiceHost {
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined {
util.log("getScriptSnapshot", fileName);
- const m = FileModule.load(fileName);
- util.assert(m != null);
+ const m = resolveModule(fileName, ".");
+ if (m == null) {
+ util.log("getScriptSnapshot", fileName, "NOT FOUND");
+ return undefined;
+ }
+ //const m = resolveModule(fileName, ".");
util.assert(m.sourceCode.length > 0);
return ts.ScriptSnapshot.fromString(m.sourceCode);
}
fileExists(fileName: string): boolean {
- util.log("fileExist", fileName);
- return true;
+ const m = resolveModule(fileName, ".");
+ const exists = m != null;
+ util.log("fileExist", fileName, exists);
+ return exists;
}
readFile(path: string, encoding?: string): string | undefined {
@@ -255,8 +275,8 @@ class TypeScriptHost implements ts.LanguageServiceHost {
}
getDefaultLibFileName(options: ts.CompilerOptions): string {
- util.log("getDefaultLibFileName");
const fn = ts.getDefaultLibFileName(options);
+ util.log("getDefaultLibFileName", fn);
const m = resolveModule(fn, "/$asset$/");
return m.fileName;
}
@@ -266,7 +286,7 @@ class TypeScriptHost implements ts.LanguageServiceHost {
containingFile: string,
reusedNames?: string[]
): Array<ts.ResolvedModule | undefined> {
- util.log("resolveModuleNames", { moduleNames, reusedNames });
+ //util.log("resolveModuleNames", { moduleNames, reusedNames });
return moduleNames.map((name: string) => {
let resolvedFileName;
if (name === "deno") {
diff --git a/testdata/012_async.ts b/testdata/012_async.ts
new file mode 100644
index 000000000..57ae355c2
--- /dev/null
+++ b/testdata/012_async.ts
@@ -0,0 +1,11 @@
+// Check that we can use the async keyword.
+async function main() {
+ await new Promise((resolve, reject) => {
+ console.log("2");
+ setTimeout(resolve, 100);
+ });
+ console.log("3");
+}
+
+console.log("1");
+main();
diff --git a/testdata/012_async.ts.out b/testdata/012_async.ts.out
new file mode 100644
index 000000000..01e79c32a
--- /dev/null
+++ b/testdata/012_async.ts.out
@@ -0,0 +1,3 @@
+1
+2
+3
diff --git a/util.go b/util.go
index 5878d87b9..11c4514cf 100644
--- a/util.go
+++ b/util.go
@@ -9,7 +9,7 @@ import (
func logDebug(format string, v ...interface{}) {
// Unless the debug flag is specified, discard logs.
if *flagDebug {
- fmt.Printf(format+"\n", v)
+ fmt.Printf(format+"\n", v...)
}
}