1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00

upgrade: TypeScript 3.8 (#4100)

This commit is contained in:
Kitson Kelly 2020-02-26 07:33:19 +11:00 committed by GitHub
parent f47f3f9672
commit be787d09d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 77 additions and 27 deletions

View file

@ -270,11 +270,16 @@ export function convertCompilerOptions(str: string): ts.CompilerOptions {
/** An array of TypeScript diagnostic types we ignore. */ /** An array of TypeScript diagnostic types we ignore. */
export const ignoredDiagnostics = [ export const ignoredDiagnostics = [
// TS2306: File 'file:///Users/rld/src/deno/cli/tests/subdir/amd_like.js' is
// not a module.
2306,
// TS1375: 'await' expressions are only allowed at the top level of a file
// when that file is a module, but this file has no imports or exports.
// Consider adding an empty 'export {}' to make this file a module.
1375,
// TS1103: 'for-await-of' statement is only allowed within an async function // TS1103: 'for-await-of' statement is only allowed within an async function
// or async generator. // or async generator.
1103, 1103,
// TS1308: 'await' expression is only allowed within an async function.
1308,
// TS2691: An import path cannot end with a '.ts' extension. Consider // TS2691: An import path cannot end with a '.ts' extension. Consider
// importing 'bad-module' instead. // importing 'bad-module' instead.
2691, 2691,

View file

@ -326,6 +326,48 @@ fn bundle_single_module() {
assert_eq!(output.stderr, b""); assert_eq!(output.stderr, b"");
} }
#[test]
fn bundle_tla() {
// First we have to generate a bundle of some module that has exports.
let tla_import = util::root_path().join("cli/tests/subdir/tla.ts");
assert!(tla_import.is_file());
let t = tempfile::TempDir::new().expect("tempdir fail");
let bundle = t.path().join("tla.bundle.js");
let mut deno = util::deno_cmd()
.current_dir(util::root_path())
.arg("bundle")
.arg(tla_import)
.arg(&bundle)
.spawn()
.expect("failed to spawn script");
let status = deno.wait().expect("failed to wait for the child process");
assert!(status.success());
assert!(bundle.is_file());
// Now we try to use that bundle from another module.
let test = t.path().join("test.js");
std::fs::write(
&test,
"
import { foo } from \"./tla.bundle.js\";
console.log(foo); ",
)
.expect("error writing file");
let output = util::deno_cmd()
.current_dir(util::root_path())
.arg("run")
.arg(&test)
.output()
.expect("failed to spawn script");
// check the output of the test.ts program.
assert!(std::str::from_utf8(&output.stdout)
.unwrap()
.trim()
.ends_with("Hello"));
assert_eq!(output.stderr, b"");
}
#[test] #[test]
fn repl_test_console_log() { fn repl_test_console_log() {
let (out, err, code) = let (out, err, code) =

View file

@ -1,4 +1,3 @@
// looks like an AMD module, but isn't // looks like an AMD module, but isn't
const define = () => {}; const define = () => {};
define(["fake_module"], () => {}); define(["fake_module"], () => {});
export {};

View file

@ -1,2 +1,2 @@
console.log("Hello world!"); console.log("Hello world!");
export {}; export {}; // TODO(ry) This shouldn't be necessary.

1
cli/tests/subdir/tla.ts Normal file
View file

@ -0,0 +1 @@
export const foo = await Promise.resolve("Hello");

View file

@ -132,7 +132,6 @@ class Host {
*/ */
readFile(_fileName) { readFile(_fileName) {
unreachable(); unreachable();
return undefined;
} }
useCaseSensitiveFileNames() { useCaseSensitiveFileNames() {
@ -179,33 +178,22 @@ class Host {
} }
// This looks up any modules that have been mapped to internal names // This looks up any modules that have been mapped to internal names
if (moduleMap.has(fileName)) { const moduleUrl = moduleMap.has(fileName)
fileName = moduleMap.get(fileName); ? moduleMap.get(fileName)
} : fileName;
const { sourceCode, moduleName } = dispatch("op_load_module", { const { sourceCode } = dispatch("op_load_module", {
moduleUrl: fileName, moduleUrl,
languageVersion, languageVersion,
shouldCreateNewSourceFile shouldCreateNewSourceFile
}); });
// If we match the external specifier regex, we will then create an internal
// specifier and then use that when creating the source file
let internalModuleName = moduleName;
const result = externalSpecifierRegEx.exec(moduleName);
if (result) {
const [, specifier] = result;
const internalSpecifier = `$deno$${specifier}`;
moduleMap.set(internalSpecifier, moduleName);
internalModuleName = internalSpecifier;
}
const sourceFile = ts.createSourceFile( const sourceFile = ts.createSourceFile(
internalModuleName, fileName,
sourceCode, sourceCode,
languageVersion languageVersion
); );
sourceFile.moduleName = internalModuleName; sourceFile.moduleName = fileName;
return sourceFile; return sourceFile;
} }
@ -245,7 +233,6 @@ class Host {
_shouldCreateNewSourceFile _shouldCreateNewSourceFile
) { ) {
unreachable(); unreachable();
return undefined;
} }
/** /**
@ -278,6 +265,17 @@ class Host {
/** @type {ts.ResolvedModule[]} */ /** @type {ts.ResolvedModule[]} */
const r = resolvedNames.map(resolvedFileName => { const r = resolvedNames.map(resolvedFileName => {
const extension = getExtension(resolvedFileName); const extension = getExtension(resolvedFileName);
if (!moduleMap.has(resolvedFileName)) {
// If we match the external specifier regex, we will then create an internal
// specifier and then use that when creating the source file
const result = externalSpecifierRegEx.exec(resolvedFileName);
if (result) {
const [, specifier] = result;
const internalSpecifier = `$deno$${specifier}`;
moduleMap.set(internalSpecifier, resolvedFileName);
resolvedFileName = internalSpecifier;
}
}
return { resolvedFileName, extension }; return { resolvedFileName, extension };
}); });
return r; return r;

View file

@ -292,6 +292,8 @@ pub fn get_asset(name: &str) -> Option<&'static str> {
"lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"), "lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"),
"lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"), "lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"),
"lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"), "lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"),
"lib.es2020.bigint.d.ts" => inc!("lib.es2020.bigint.d.ts"),
"lib.es2020.promise.d.ts" => inc!("lib.es2020.promise.d.ts"),
"lib.es2020.string.d.ts" => inc!("lib.es2020.string.d.ts"), "lib.es2020.string.d.ts" => inc!("lib.es2020.string.d.ts"),
"lib.es2020.symbol.wellknown.d.ts" => { "lib.es2020.symbol.wellknown.d.ts" => {
inc!("lib.es2020.symbol.wellknown.d.ts") inc!("lib.es2020.symbol.wellknown.d.ts")

@ -1 +1 @@
Subproject commit 7cf6c70d90b60e962db417d80290288eb786b5fd Subproject commit af614ccea19e844142c8e6b0fdd70ccfdfcfa0db

View file

@ -3,7 +3,6 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
/* eslint-disable no-conditional-assignment */
/* eslint-disable max-len */ /* eslint-disable max-len */
import { YAMLError } from "../error.ts"; import { YAMLError } from "../error.ts";

@ -1 +1 @@
Subproject commit 9ab7948049d96bdd3af67323f758b81a9e4cbc27 Subproject commit b1103a02e8112a20126c84d2d4751ed1302c8ade

View file

@ -29,8 +29,12 @@ def eslint():
# Within the source dirs, eslint does its own globbing, taking into account # Within the source dirs, eslint does its own globbing, taking into account
# the exclusion rules listed in '.eslintignore'. # the exclusion rules listed in '.eslintignore'.
source_globs = ["%s/*.{js,ts}" % d for d in source_dirs] source_globs = ["%s/*.{js,ts}" % d for d in source_dirs]
# Set NODE_PATH so we don't have to maintain a symlink in root_path.
env = os.environ.copy()
env["NODE_PATH"] = os.path.join(root_path, "third_party", "node_modules")
run(["node", script, "--max-warnings=0", "--"] + source_globs, run(["node", script, "--max-warnings=0", "--"] + source_globs,
shell=False, shell=False,
env=env,
quiet=True) quiet=True)