From 0ceb554343ff3d311a19f027b7aa8f0806bbb162 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 9 Jan 2019 12:59:46 -0500 Subject: Native ES modules (#1460) * Native ES modules This is a major refactor of internal compiler. Before: JS and TS both were sent through the typescript compiler where their imports were parsed and handled. Both compiled to AMD JS and finally sent to V8 Now: JS is sent directly into V8. TS is sent through the typescript compiler, but tsc generates ES modules now instead of AMD. This generated JS is then dumped into V8. This should much faster for pure JS code. It may improve TS compilation speed. In the future this allows us to separate TS out of the runtime heap and into its own dedicated snapshot. This will result in a smaller runtime heap, and thus should be faster. Some tests were unfortunately disabled to ease landing this patch: 1. compiler_tests.ts which I intend to bring back in later commits. 2. Some text_encoding_test.ts tests which made the file invalid utf8. See PR for a discussion. Also worth noting that this is necessary to support WASM --- tests/013_dynamic_import.disabled | 2 ++ tests/013_dynamic_import.test | 2 -- tests/014_duplicate_import.disabled | 2 ++ tests/014_duplicate_import.test | 2 -- tests/020_json_modules.ts | 4 ++-- tests/async_error.ts.out | 6 +----- tests/error_001.ts.out | 6 +----- tests/error_002.ts.out | 6 +----- tests/error_008_checkjs.js.out | 12 ++---------- tests/error_008_checkjs.test | 1 + tests/subdir/auto_print_hello.ts | 2 +- 11 files changed, 13 insertions(+), 32 deletions(-) create mode 100644 tests/013_dynamic_import.disabled delete mode 100644 tests/013_dynamic_import.test create mode 100644 tests/014_duplicate_import.disabled delete mode 100644 tests/014_duplicate_import.test (limited to 'tests') diff --git a/tests/013_dynamic_import.disabled b/tests/013_dynamic_import.disabled new file mode 100644 index 000000000..8fe463b20 --- /dev/null +++ b/tests/013_dynamic_import.disabled @@ -0,0 +1,2 @@ +args: tests/013_dynamic_import.ts --reload +output: tests/013_dynamic_import.ts.out diff --git a/tests/013_dynamic_import.test b/tests/013_dynamic_import.test deleted file mode 100644 index 8fe463b20..000000000 --- a/tests/013_dynamic_import.test +++ /dev/null @@ -1,2 +0,0 @@ -args: tests/013_dynamic_import.ts --reload -output: tests/013_dynamic_import.ts.out diff --git a/tests/014_duplicate_import.disabled b/tests/014_duplicate_import.disabled new file mode 100644 index 000000000..57d5b6e8b --- /dev/null +++ b/tests/014_duplicate_import.disabled @@ -0,0 +1,2 @@ +args: tests/014_duplicate_import.ts --reload +output: tests/014_duplicate_import.ts.out diff --git a/tests/014_duplicate_import.test b/tests/014_duplicate_import.test deleted file mode 100644 index 57d5b6e8b..000000000 --- a/tests/014_duplicate_import.test +++ /dev/null @@ -1,2 +0,0 @@ -args: tests/014_duplicate_import.ts --reload -output: tests/014_duplicate_import.ts.out diff --git a/tests/020_json_modules.ts b/tests/020_json_modules.ts index 89963751c..71c0eb8db 100644 --- a/tests/020_json_modules.ts +++ b/tests/020_json_modules.ts @@ -1,3 +1,3 @@ import * as config from "./subdir/config.json"; - -console.log(JSON.stringify(config)); +// TODO Shouldn't need 'default' +console.log(JSON.stringify(config["default"])); diff --git a/tests/async_error.ts.out b/tests/async_error.ts.out index 1e7e901f6..8054551e4 100644 --- a/tests/async_error.ts.out +++ b/tests/async_error.ts.out @@ -3,8 +3,4 @@ before error world Error: error at foo ([WILDCARD]tests/async_error.ts:4:9) - at eval ([WILDCARD]tests/async_error.ts:7:1) - at _gatherDependencies ([WILDCARD]/js/compiler.ts:[WILDCARD]) - at run ([WILDCARD]/js/compiler.ts:[WILDCARD]) - at denoMain ([WILDCARD]/js/main.ts:[WILDCARD]) - at :1:1 + at [WILDCARD]tests/async_error.ts:7:1 diff --git a/tests/error_001.ts.out b/tests/error_001.ts.out index 1ab615fc0..7a8491225 100644 --- a/tests/error_001.ts.out +++ b/tests/error_001.ts.out @@ -1,8 +1,4 @@ [WILDCARD]Error: bad at foo (file://[WILDCARD]tests/error_001.ts:2:9) at bar (file://[WILDCARD]tests/error_001.ts:6:3) - at eval (file://[WILDCARD]tests/error_001.ts:9:1) - at _gatherDependencies ([WILDCARD]/js/compiler.ts:[WILDCARD]) - at run ([WILDCARD]/js/compiler.ts:[WILDCARD]) - at denoMain ([WILDCARD]/js/main.ts:[WILDCARD]) - at :1:1 + at file://[WILDCARD]tests/error_001.ts:9:1 diff --git a/tests/error_002.ts.out b/tests/error_002.ts.out index 5a9c21e89..0f3b08303 100644 --- a/tests/error_002.ts.out +++ b/tests/error_002.ts.out @@ -1,8 +1,4 @@ [WILDCARD]Error: exception from mod1 at throwsError (file://[WILDCARD]/tests/subdir/mod1.ts:16:9) at foo (file://[WILDCARD]/tests/error_002.ts:4:3) - at eval (file://[WILDCARD]/tests/error_002.ts:7:1) - at _drainRunQueue ([WILDCARD]/js/compiler.ts:[WILDCARD]) - at run ([WILDCARD]/js/compiler.ts:[WILDCARD]) - at denoMain ([WILDCARD]/js/main.ts:[WILDCARD]) - at :1:1 + at file://[WILDCARD]/tests/error_002.ts:7:1 diff --git a/tests/error_008_checkjs.js.out b/tests/error_008_checkjs.js.out index 793c2f68c..c40012712 100644 --- a/tests/error_008_checkjs.js.out +++ b/tests/error_008_checkjs.js.out @@ -1,10 +1,2 @@ -[WILDCARD]/tests/error_008_checkjs.jsILDCARD] - error TS2552: Cannot find name 'consol'. Did you mean 'console'? - -ILDCARD] consol.log("hello world!"); -[WILDCARD]~~~~~~ - - $asset$/lib.deno_runtime.d.tsILDCARD] -[WILDCARD]declare const console: consoleTypes.Console; -[WILDCARD]~~~~~~~ -[WILDCARD]'console' is declared here. - +ReferenceError: consol is not defined + at [WILDCARD]tests/error_008_checkjs.js:2:1 diff --git a/tests/error_008_checkjs.test b/tests/error_008_checkjs.test index eebd64aaf..0e43421e4 100644 --- a/tests/error_008_checkjs.test +++ b/tests/error_008_checkjs.test @@ -1,3 +1,4 @@ args: tests/error_008_checkjs.js --reload +check_stderr: true exit_code: 1 output: tests/error_008_checkjs.js.out diff --git a/tests/subdir/auto_print_hello.ts b/tests/subdir/auto_print_hello.ts index a00040281..5efa72e03 100644 --- a/tests/subdir/auto_print_hello.ts +++ b/tests/subdir/auto_print_hello.ts @@ -1,2 +1,2 @@ console.log("hello!"); -export = {}; +export default {}; -- cgit v1.2.3