diff --git a/cli/compilers/mod.rs b/cli/compilers/mod.rs index a1c8712902cb96..59843dba2e4bd7 100644 --- a/cli/compilers/mod.rs +++ b/cli/compilers/mod.rs @@ -11,6 +11,7 @@ mod wasm; pub use js::JsCompiler; pub use json::JsonCompiler; pub use ts::runtime_compile_async; +pub use ts::runtime_transpile_async; pub use ts::TsCompiler; pub use wasm::WasmCompiler; diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index f362658771f3a0..deb2ce0675730c 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -639,6 +639,34 @@ pub fn runtime_compile_async( .boxed() } +pub fn runtime_transpile_async( + global_state: ThreadSafeGlobalState, + sources: &HashMap, + options: &Option, +) -> Pin> { + let req_msg = json!({ + "type": msg::CompilerRequestType::RuntimeTranspile as i32, + "sources": sources, + "options": options, + }) + .to_string() + .into_boxed_str() + .into_boxed_bytes(); + + let worker = TsCompiler::setup_worker(global_state.clone()); + let worker_ = worker.clone(); + + async move { + worker.post_message(req_msg).await?; + worker.await?; + debug!("Sent message to worker"); + let msg = (worker_.get_message().await?).unwrap(); + let json_str = std::str::from_utf8(&msg).unwrap(); + Ok(json!(json_str)) + } + .boxed() +} + #[cfg(test)] mod tests { use super::*; diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index c003a463c70613..fbb731ab60488d 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -8,10 +8,10 @@ import "./ts_global.d.ts"; import { emitBundle, setRootExports } from "./bundler.ts"; import { bold, cyan, yellow } from "./colors.ts"; -import { CompilerOptions } from "./compiler_api.ts"; +import { CompilerOptions, TranspileOnlyResult } from "./compiler_api.ts"; import { Console } from "./console.ts"; import { core } from "./core.ts"; -import { Diagnostic, DiagnosticItem } from "./diagnostics.ts"; +import { Diagnostic } from "./diagnostics.ts"; import { fromTypeScriptDiagnostic } from "./diagnostics_util.ts"; import { cwd } from "./dir.ts"; import * as dispatch from "./dispatch.ts"; @@ -68,14 +68,21 @@ interface CompilerRequestRuntimeCompile { rootName: string; sources?: Record; bundle: boolean; - options?: CompilerOptions; + options?: string; +} + +interface CompilerRequestRuntimeTranspile { + type: CompilerRequestType.RuntimeTranspile; + sources: Record; + options?: string; } /** The format of the work message payload coming from the privileged side */ type CompilerRequest = | CompilerRequestCompile | CompilerRequestBundle - | CompilerRequestRuntimeCompile; + | CompilerRequestRuntimeCompile + | CompilerRequestRuntimeTranspile; interface ConfigureResponse { ignoredOptions?: string[]; @@ -87,8 +94,6 @@ interface EmitResult { diagnostics?: Diagnostic; } -type CompilationResult = [DiagnosticItem[] | undefined, Record]; - // Startup boilerplate. This is necessary because the compiler has its own // snapshot. (It would be great if we could remove these things or centralize // them somewhere else.) @@ -167,6 +172,116 @@ const ignoredCompilerOptions: readonly string[] = [ "watch" ]; +/** Default options used by the compiler Host when compiling. */ +const defaultCompileOptions: ts.CompilerOptions = { + allowJs: true, + allowNonTsExtensions: true, + // TODO(#3324) Enable strict mode for user code. + // strict: true, + checkJs: false, + esModuleInterop: true, + module: ts.ModuleKind.ESNext, + outDir: OUT_DIR, + resolveJsonModule: true, + sourceMap: true, + stripComments: true, + target: ts.ScriptTarget.ESNext, + jsx: ts.JsxEmit.React +}; + +/** Default options used when doing a transpile only. */ +const defaultTranspileOptions: ts.CompilerOptions = { + esModuleInterop: true, + module: ts.ModuleKind.ESNext, + sourceMap: true, + scriptComments: true, + target: ts.ScriptTarget.ESNext +}; + +function convertCompilerOptions(str: string): ts.CompilerOptions { + const options: CompilerOptions = JSON.parse(str); + const out: Record = {}; + const keys = Object.keys(options) as Array; + for (const key of keys) { + switch (key) { + case "jsx": + const value = options[key]; + if (value === "preserve") { + out[key] = ts.JsxEmit.Preserve; + } else if (value === "react") { + out[key] = ts.JsxEmit.React; + } else { + out[key] = ts.JsxEmit.ReactNative; + } + break; + case "module": + switch (options[key]) { + case "amd": + out[key] = ts.ModuleKind.AMD; + break; + case "commonjs": + out[key] = ts.ModuleKind.CommonJS; + break; + case "es2015": + case "es6": + out[key] = ts.ModuleKind.ES2015; + break; + case "esnext": + out[key] = ts.ModuleKind.ESNext; + break; + case "none": + out[key] = ts.ModuleKind.None; + break; + case "system": + out[key] = ts.ModuleKind.System; + break; + case "umd": + out[key] = ts.ModuleKind.UMD; + break; + default: + throw new TypeError("Unexpected module type"); + } + break; + case "target": + switch (options[key]) { + case "es3": + out[key] = ts.ScriptTarget.ES3; + break; + case "es5": + out[key] = ts.ScriptTarget.ES5; + break; + case "es6": + case "es2015": + out[key] = ts.ScriptTarget.ES2015; + break; + case "es2016": + out[key] = ts.ScriptTarget.ES2016; + break; + case "es2017": + out[key] = ts.ScriptTarget.ES2017; + break; + case "es2018": + out[key] = ts.ScriptTarget.ES2018; + break; + case "es2019": + out[key] = ts.ScriptTarget.ES2019; + break; + case "es2020": + out[key] = ts.ScriptTarget.ES2020; + break; + case "esnext": + out[key] = ts.ScriptTarget.ESNext; + break; + default: + throw new TypeError("Unexpected emit target."); + } + default: + out[key] = options[key]; + } + } + return out as ts.CompilerOptions; +} + /** An array of TypeScript diagnostic types we ignore. */ const ignoredDiagnostics = [ // TS1103: 'for-await-of' statement is only allowed within an async function @@ -312,6 +427,11 @@ class SourceFile { } } +function resolveModules(specifiers: string[], referrer?: string): string[] { + util.log("compiler::resolveModules", { specifiers, referrer }); + return sendSync(dispatch.OP_RESOLVE_MODULES, { specifiers, referrer }); +} + /** Ops to Rust to resolve special static assets. */ function fetchAsset(name: string): string { return sendSync(dispatch.OP_FETCH_ASSET, { name }); @@ -400,7 +520,8 @@ async function processImports( return []; } const sources = specifiers.map(([, moduleSpecifier]) => moduleSpecifier); - const sourceFiles = await fetchSourceFiles(sources, referrer); + const resolveSources = resolveModules(sources, referrer); + const sourceFiles = await fetchSourceFiles(resolveSources, referrer); assert(sourceFiles.length === specifiers.length); for (let i = 0; i < sourceFiles.length; i++) { const sourceFileJson = sourceFiles[i]; @@ -457,21 +578,7 @@ class Host implements ts.CompilerHost { private _requestType: CompilerRequestType; private _rootNames: string[]; - private readonly _options: ts.CompilerOptions = { - allowJs: true, - allowNonTsExtensions: true, - // TODO(#3324) Enable strict mode for user code. - // strict: true, - checkJs: false, - esModuleInterop: true, - module: ts.ModuleKind.ESNext, - outDir: OUT_DIR, - resolveJsonModule: true, - sourceMap: true, - stripComments: true, - target: ts.ScriptTarget.ESNext, - jsx: ts.JsxEmit.React - }; + private readonly _options = defaultCompileOptions; private _getAsset(filename: string): SourceFile { const sourceFile = SourceFile.get(filename); @@ -804,16 +911,20 @@ self.compilerMain = function compilerMain(): void { break; } case CompilerRequestType.RuntimeCompile: { - const { rootName, sources } = request; + const { rootName, sources, options } = request; util.log(">>> runtime compile start", { rootName, sources: sources ? Object.keys(sources) : undefined }); + const resolvedRootName = sources + ? rootName + : resolveModules([rootName])[0]; + const rootNames = sources - ? processLocalImports(sources, [[rootName, rootName]]) - : await processImports([[rootName, rootName]]); + ? processLocalImports(sources, [[resolvedRootName, resolvedRootName]]) + : await processImports([[resolvedRootName, resolvedRootName]]); const emitMap: Record = {}; @@ -826,10 +937,20 @@ self.compilerMain = function compilerMain(): void { cache: sources ? false : true }); - host.configure({ outDir: undefined }); + const compilerOptions = options + ? Object.assign( + {}, + { outDir: undefined }, + convertCompilerOptions(options) + ) + : { outDir: undefined }; + host.configure(compilerOptions); - const options = host.getCompilationSettings(); - const program = ts.createProgram(rootNames, options, host); + const program = ts.createProgram( + rootNames, + host.getCompilationSettings(), + host + ); const diagnostics = ts .getPreEmitDiagnostics(program) @@ -852,6 +973,30 @@ self.compilerMain = function compilerMain(): void { break; } + case CompilerRequestType.RuntimeTranspile: { + const result: Record = {}; + const { sources, options } = request; + const compilerOptions = options + ? Object.assign( + {}, + defaultTranspileOptions, + convertCompilerOptions(options) + ) + : defaultTranspileOptions; + for (const [fileName, inputText] of Object.entries(sources)) { + const { outputText: source, sourceMapText: map } = ts.transpileModule( + inputText, + { + fileName, + compilerOptions + } + ); + result[fileName] = { source, map }; + postMessage(result); + } + + break; + } default: util.log( `!!! unhandled CompilerRequestType: ${ diff --git a/cli/js/compiler_api.ts b/cli/js/compiler_api.ts index a3b88ef41f7224..9bc708bef07297 100644 --- a/cli/js/compiler_api.ts +++ b/cli/js/compiler_api.ts @@ -245,46 +245,77 @@ export interface CompilerOptions { types?: string[]; } -/** Takes a set of TypeScript sources and resolves with the transpiled strings. - * This does no type checking and validation, it effectively "strips" the types - * from the file. +/** Internal function to just validate that the specifier looks relative, that + * it starts with `./`. */ +function checkRelative(specifier: string): string { + return specifier.match(/^([\.\/\\]|https?:\/{2}|file:\/{2})/) + ? specifier + : `./${specifier}`; +} + +/** The results of a transpile only command, where the `source` contains the + * emitted source, and `map` optionally contains the source map. + */ +export interface TranspileOnlyResult { + source: string; + map?: string; +} + +/** Takes a set of TypeScript sources and resolves with a map where the key was + * the original file name provided in sources and the result contains the + * `source` and optionally the `map` from the transpile operation. This does no + * type checking and validation, it effectively "strips" the types from the + * file. * - * const out = await Deno.transpileOnly([`const foo: string = "foo";`]); + * const results = await Deno.transpileOnly({ + * "foo.ts": `const foo: string = "foo";` + * }); * - * @param sources An array of strings which contain the sourcefile(s) which - * should be transpiled. + * @param sources A map where the key is the filename and the value is the text + * to transpile. The filename is only used in the transpile and + * not resolved, for example to fill in the source name in the + * source map. * @param options An option object of options to send to the compiler. This is * a subset of ts.CompilerOptions which can be supported by Deno. * Many of the options related to type checking and emitting * type declaration files will have no impact on the output. */ export function transpileOnly( - sources: string[], + sources: Record, options?: CompilerOptions -): Promise { - return sendAsync(dispatch.OP_TRANSPILE, { +): Promise> { + util.log("Deno.transpileOnly"); + const payload = { sources, options: options ? JSON.stringify(options) : undefined - }); + }; + return sendAsync(dispatch.OP_TRANSPILE, payload); } -/** Takes a set of TypeScript sources and resolves with the transpiled strings. - * This does no type checking and validation, it effectively "strips" the types - * from the file. +/** Takes a set of TypeScript sources and returns a map where the key was + * the original file name provided in sources and the result contains the + * `source` and optionally the `map` from the transpile operation. This does no + * type checking and validation, it effectively "strips" the types from the + * file. * - * const out = Deno.transpileOnlySync([`const foo: string = "foo";`]); + * const results = Deno.transpileOnlySync({ + * "foo.ts": `const foo: string = "foo";` + * }); * - * @param sources An array of strings which contain the sourcefile(s) which - * should be transpiled. + * @param sources A map where the key is the filename and the value is the text + * to transpile. The filename is only used in the transpile and + * not resolved, for example to fill in the source name in the + * source map. * @param options An option object of options to send to the compiler. This is * a subset of ts.CompilerOptions which can be supported by Deno. * Many of the options related to type checking and emitting * type declaration files will have no impact on the output. */ export function transpileOnlySync( - sources: string[], + sources: Record, options?: CompilerOptions -): string[] { +): Record { + util.log("Deno.transpileOnlySync"); return sendSync(dispatch.OP_TRANSPILE, { sources, options: options ? JSON.stringify(options) : undefined @@ -324,12 +355,16 @@ export function compile( options?: CompilerOptions ): Promise<[Diagnostic[] | undefined, Record]> { const payload = { - rootName, + rootName: sources ? rootName : checkRelative(rootName), sources, options: options ? JSON.stringify(options) : undefined, bundle: false }; - util.log("Deno.compile", payload); + util.log("Deno.compile", { + rootName: payload.rootName, + sources: !!sources, + options + }); return sendAsync(dispatch.OP_COMPILE, payload).then(payload => JSON.parse(payload) ); @@ -367,12 +402,18 @@ export function compileSync( sources?: Record, options?: CompilerOptions ): [Diagnostic[] | undefined, Record] { - return sendSync(dispatch.OP_COMPILE, { - rootName, + const payload = { + rootName: sources ? rootName : checkRelative(rootName), sources, options: options ? JSON.stringify(options) : undefined, bundle: false + }; + util.log("Deno.compileSync", { + rootName: payload.rootName, + sources: !!sources, + options }); + return sendSync(dispatch.OP_COMPILE, payload); } /** Takes a root module name, and optionally a record set of sources. Resolves @@ -408,12 +449,18 @@ export function bundle( sources?: Record, options?: CompilerOptions ): Promise<[Diagnostic[] | undefined, string]> { - return sendAsync(dispatch.OP_COMPILE, { - rootName, + const payload = { + rootName: sources ? rootName : checkRelative(rootName), sources, options: options ? JSON.stringify(options) : undefined, bundle: true + }; + util.log("Deno.bundle", { + rootName: payload.rootName, + sources: !!sources, + options }); + return sendAsync(dispatch.OP_COMPILE, payload); } /** Takes a root module name, and optionally a record set of sources. Returns a @@ -449,10 +496,16 @@ export function bundleSync( sources?: Record, options?: CompilerOptions ): [Diagnostic[] | undefined, string] { - return sendSync(dispatch.OP_COMPILE, { - rootName, + const payload = { + rootName: sources ? rootName : checkRelative(rootName), sources, options: options ? JSON.stringify(options) : undefined, bundle: true + }; + util.log("Deno.bundleSync", { + rootName: payload.rootName, + sources: !!sources, + options }); + return sendSync(dispatch.OP_COMPILE, payload); } diff --git a/cli/js/compiler_api_test.ts b/cli/js/compiler_api_test.ts new file mode 100644 index 00000000000000..1ec5dd33a6f7c1 --- /dev/null +++ b/cli/js/compiler_api_test.ts @@ -0,0 +1,10 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import { assert, assertEquals, test } from "./test_util.ts"; + +const { compile, compileSync } = Deno; + +test(async function compilerApiCompileSources() { + const result = await Deno.compile("/foo.ts", { + "/foo.ts": `console.log("foo");\nexport {}\n` + }); +}); diff --git a/cli/js/dispatch.ts b/cli/js/dispatch.ts index f2fc1d220473e9..fb3f1f89658f13 100644 --- a/cli/js/dispatch.ts +++ b/cli/js/dispatch.ts @@ -18,6 +18,7 @@ export let OP_START: number; export let OP_APPLY_SOURCE_MAP: number; export let OP_FORMAT_ERROR: number; export let OP_CACHE: number; +export let OP_RESOLVE_MODULES: number; export let OP_FETCH_SOURCE_FILES: number; export let OP_OPEN: number; export let OP_CLOSE: number; diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno_runtime.d.ts index b0ce26fa747694..b099da541f1d43 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno_runtime.d.ts @@ -1657,41 +1657,61 @@ declare namespace Deno { types?: string[]; } - /** Takes a set of TypeScript sources and resolves with the transpiled strings. - * This does no type checking and validation, it effectively "strips" the types - * from the file. + /** The results of a transpile only command, where the `source` contains the + * emitted source, and `map` optionally contains the source map. + */ + export interface TranspileOnlyResult { + source: string; + map?: string; + } + + /** Takes a set of TypeScript sources and resolves with a map where the key was + * the original file name provided in sources and the result contains the + * `source` and optionally the `map` from the transpile operation. This does no + * type checking and validation, it effectively "strips" the types from the + * file. * - * const out = await Deno.transpileOnly([`const foo: string = "foo";`]); + * const results = await Deno.transpileOnly({ + * "foo.ts": `const foo: string = "foo";` + * }); * - * @param sources An array of strings which contain the sourcefile(s) which - * should be transpiled. + * @param sources A map where the key is the filename and the value is the text + * to transpile. The filename is only used in the transpile and + * not resolved, for example to fill in the source name in the + * source map. * @param options An option object of options to send to the compiler. This is * a subset of ts.CompilerOptions which can be supported by Deno. * Many of the options related to type checking and emitting * type declaration files will have no impact on the output. */ export function transpileOnly( - sources: string[], + sources: Record, options?: CompilerOptions - ): Promise; + ): Promise>; - /** Takes a set of TypeScript sources and resolves with the transpiled strings. - * This does no type checking and validation, it effectively "strips" the types - * from the file. + /** Takes a set of TypeScript sources and returns a map where the key was + * the original file name provided in sources and the result contains the + * `source` and optionally the `map` from the transpile operation. This does no + * type checking and validation, it effectively "strips" the types from the + * file. * - * const out = Deno.transpileOnlySync([`const foo: string = "foo";`]); + * const results = Deno.transpileOnlySync({ + * "foo.ts": `const foo: string = "foo";` + * }); * - * @param sources An array of strings which contain the sourcefile(s) which - * should be transpiled. + * @param sources A map where the key is the filename and the value is the text + * to transpile. The filename is only used in the transpile and + * not resolved, for example to fill in the source name in the + * source map. * @param options An option object of options to send to the compiler. This is * a subset of ts.CompilerOptions which can be supported by Deno. * Many of the options related to type checking and emitting * type declaration files will have no impact on the output. */ export function transpileOnlySync( - sources: string[], + sources: Record, options?: CompilerOptions - ): string[]; + ): Record; /** Takes a root module name, any optionally a record set of sources. Resolves * with a compiled set of modules. If just a root name is provided, the modules diff --git a/cli/js/unit_test_runner.ts b/cli/js/unit_test_runner.ts index 740408e9bd5609..9b05343520c22d 100755 --- a/cli/js/unit_test_runner.ts +++ b/cli/js/unit_test_runner.ts @@ -9,14 +9,14 @@ import { interface TestResult { perms: string; - output: string; + output?: string; result: number; } function permsToCliFlags(perms: Permissions): string[] { return Object.keys(perms) - .map((key): string => { - if (!perms[key]) return ""; + .map(key => { + if (!perms[key as keyof Permissions]) return ""; const cliFlag = key.replace( /\.?([A-Z])/g, diff --git a/cli/js/unit_tests.ts b/cli/js/unit_tests.ts index c63fc5f2626f2d..00b15f0ac9b2c7 100644 --- a/cli/js/unit_tests.ts +++ b/cli/js/unit_tests.ts @@ -9,6 +9,7 @@ import "./buffer_test.ts"; import "./build_test.ts"; import "./chmod_test.ts"; import "./chown_test.ts"; +import "./compiler_api_test.ts"; import "./console_test.ts"; import "./copy_file_test.ts"; import "./custom_event_test.ts"; diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs index 896e6f65803ad4..d4d8e2e28f3409 100644 --- a/cli/ops/compiler.rs +++ b/cli/ops/compiler.rs @@ -1,6 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::compilers::runtime_compile_async; +use crate::compilers::runtime_transpile_async; use crate::futures::future::try_join_all; use crate::futures::future::FutureExt; use crate::futures::future::TryFutureExt; @@ -13,6 +14,10 @@ use std::collections::HashMap; pub fn init(i: &mut Isolate, s: &ThreadSafeState) { i.register_op("cache", s.core_op(json_op(s.stateful_op(op_cache)))); + i.register_op( + "resolve_modules", + s.core_op(json_op(s.stateful_op(op_resolve_modules))), + ); i.register_op( "fetch_source_files", s.core_op(json_op(s.stateful_op(op_fetch_source_files))), @@ -52,36 +57,62 @@ fn op_cache( Ok(JsonOp::Sync(json!({}))) } -#[derive(Deserialize)] -struct FetchSourceFilesArgs { +#[derive(Deserialize, Debug)] +struct SpecifiersReferrerArgs { specifiers: Vec, referrer: Option, } -fn op_fetch_source_files( +fn op_resolve_modules( state: &ThreadSafeState, args: Value, _data: Option, ) -> Result { - let args: FetchSourceFilesArgs = serde_json::from_value(args)?; + let args: SpecifiersReferrerArgs = serde_json::from_value(args)?; // TODO(ry) Maybe a security hole. Only the compiler worker should have access // to this. Need a test to demonstrate the hole. let is_dyn_import = false; - let (referrer, ref_specifier) = if let Some(referrer) = args.referrer { + let (referrer, is_main) = if let Some(referrer) = args.referrer { + (referrer, false) + } else { + ("".to_owned(), true) + }; + + let mut specifiers = vec![]; + + for specifier in &args.specifiers { + let resolved_specifier = state + .resolve(specifier, &referrer, is_main, is_dyn_import); + match resolved_specifier { + Ok(ms) => specifiers.push(ms.as_str().to_owned()), + Err(err) => return Err(err), + } + } + + Ok(JsonOp::Sync(json!(specifiers))) +} + +fn op_fetch_source_files( + state: &ThreadSafeState, + args: Value, + _data: Option, +) -> Result { + let args: SpecifiersReferrerArgs = serde_json::from_value(args)?; + + let ref_specifier = if let Some(referrer) = args.referrer { let specifier = ModuleSpecifier::resolve_url(&referrer) .expect("Referrer is not a valid specifier"); - (referrer, Some(specifier)) + Some(specifier) } else { - // main script import - (".".to_string(), None) + None }; let mut futures = vec![]; for specifier in &args.specifiers { let resolved_specifier = - state.resolve(specifier, &referrer, false, is_dyn_import)?; + ModuleSpecifier::resolve_url(&specifier).expect("Invalid specifier"); let fut = state .global_state .file_fetcher @@ -173,29 +204,31 @@ fn op_compile( ) -> Result { let args: CompileArgs = serde_json::from_value(args)?; debug!("{:#?}", args); - Ok(JsonOp::Async( - runtime_compile_async( - state.global_state.clone(), - &args.root_name, - &args.sources, - args.bundle, - &args.options, - ), - )) + Ok(JsonOp::Async(runtime_compile_async( + state.global_state.clone(), + &args.root_name, + &args.sources, + args.bundle, + &args.options, + ))) } #[derive(Deserialize, Debug)] struct TranspileArgs { - sources: Vec, + sources: HashMap, options: Option, } fn op_transpile( - _state: &ThreadSafeState, + state: &ThreadSafeState, args: Value, _zero_copy: Option, ) -> Result { let args: TranspileArgs = serde_json::from_value(args)?; debug!("{:#?}", args); - Ok(JsonOp::Sync(json!(r#"{}"#))) + Ok(JsonOp::Async(runtime_transpile_async( + state.global_state.clone(), + &args.sources, + &args.options, + ))) } diff --git a/cli/tests/compiler_api_compile.ts b/cli/tests/compiler_api_compile.ts deleted file mode 100644 index b2646a30dec43d..00000000000000 --- a/cli/tests/compiler_api_compile.ts +++ /dev/null @@ -1,15 +0,0 @@ -const [maybeDiagnostics, emitMap] = await Deno.compile("/foo.ts", { - "/foo.ts": `import * as bar from "/bar.ts";\n\nconsole.log(bar);`, - "/bar.ts": `export const bar = "bar";` -}); - -if (maybeDiagnostics) { - console.log("Diagnostics:"); - console.log(maybeDiagnostics || ""); -} - -for (const [filename, source] of Object.entries(emitMap)) { - console.log(filename); - console.log(source); - console.log(); -} diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts new file mode 100644 index 00000000000000..c901ba259c4f63 --- /dev/null +++ b/cli/tests/compiler_api_test.ts @@ -0,0 +1,7 @@ +const result = await Deno.transpileOnly({ + "foo.ts": `class Foo { foo() { console.log("foo") }}\n\nexport {}` +}, { + module: "amd" +}); + +console.log(result);