Skip to content

Commit

Permalink
Cleanup of assets and remove fetch_asset from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jan 10, 2020
1 parent 9d5189a commit 17d70cf
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 38 deletions.
10 changes: 0 additions & 10 deletions cli/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ pub static COMPILER_SNAPSHOT_MAP: &[u8] =
pub static COMPILER_SNAPSHOT_DTS: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.d.ts"));

static DENO_RUNTIME: &str = include_str!("js/lib.deno_runtime.d.ts");

/// Same as deno_typescript::get_asset but also has lib.deno_runtime.d.ts
pub fn get_asset(name: &str) -> Option<&'static str> {
match name {
"lib.deno_runtime.d.ts" => Some(DENO_RUNTIME),
_ => deno_typescript::get_asset(name),
}
}

#[test]
fn cli_snapshot() {
let mut isolate = deno_core::Isolate::new(
Expand Down
4 changes: 2 additions & 2 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ let oldProgram: ts.Program;
((): void => {
const ops = core.ops();
for (const [name, opId] of Object.entries(ops)) {
const opName = `OP_${name.toUpperCase()}` as keyof typeof dispatch;
const opName = `OP_${name.toUpperCase()}`;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(dispatch as any)[opName] = opId;
}
const host = new Host({ writeFile(): void {} });
const options = host.getCompilationSettings();
oldProgram = ts.createProgram({
rootNames: [`${ASSETS}/example.ts`],
rootNames: [`${ASSETS}/bootstrap.ts`],
options,
host
});
Expand Down
4 changes: 3 additions & 1 deletion cli/js/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ export class Host implements ts.CompilerHost {
: SourceFile.get(fileName);
assert(sourceFile != null);
if (!sourceFile.tsSourceFile) {
assert(sourceFile.sourceCode != null);
sourceFile.tsSourceFile = ts.createSourceFile(
fileName,
sourceFile.sourceCode,
languageVersion
);
delete sourceFile.sourceCode;
}
return sourceFile!.tsSourceFile;
return sourceFile.tsSourceFile;
} catch (e) {
if (onError) {
onError(String(e));
Expand Down
2 changes: 1 addition & 1 deletion cli/js/compiler_sourcefile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class SourceFile {

mediaType!: MediaType;
processed = false;
sourceCode!: string;
sourceCode?: string;
tsSourceFile?: ts.SourceFile;
url!: string;

Expand Down
2 changes: 1 addition & 1 deletion cli/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn create_worker_and_state(
}

fn types_command() {
let content = crate::js::get_asset("lib.deno_runtime.d.ts").unwrap();
let content = deno_typescript::get_asset("lib.deno_runtime.d.ts").unwrap();
println!("{}", content);
}

Expand Down
22 changes: 0 additions & 22 deletions cli/ops/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
"fetch_source_files",
s.core_op(json_op(s.stateful_op(op_fetch_source_files))),
);
i.register_op(
"fetch_asset",
s.core_op(json_op(s.stateful_op(op_fetch_asset))),
);
i.register_op("compile", s.core_op(json_op(s.stateful_op(op_compile))));
i.register_op("transpile", s.core_op(json_op(s.stateful_op(op_transpile))));
}
Expand Down Expand Up @@ -155,24 +151,6 @@ fn op_fetch_source_files(
Ok(JsonOp::Async(future))
}

#[derive(Deserialize)]
struct FetchAssetArgs {
name: String,
}

fn op_fetch_asset(
_state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: FetchAssetArgs = serde_json::from_value(args)?;
if let Some(source_code) = crate::js::get_asset(&args.name) {
Ok(JsonOp::Sync(json!(source_code)))
} else {
panic!("op_fetch_asset bad asset {}", args.name)
}
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct CompileArgs {
Expand Down
2 changes: 1 addition & 1 deletion deno_typescript/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn get_asset(name: &str) -> Option<&'static str> {
"lib.deno_runtime.d.ts" => {
Some(include_str!("../cli/js/lib.deno_runtime.d.ts"))
}
"example.ts" => Some("console.log(\"hello deno\");"),
"bootstrap.ts" => Some("console.log(\"hello deno\");"),
"typescript.d.ts" => inc!("typescript.d.ts"),
"lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
"lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),
Expand Down

0 comments on commit 17d70cf

Please sign in to comment.