Skip to content

Commit

Permalink
refactor: upgrade to deno_ast 0.33 (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Feb 8, 2024
1 parent 8dcae01 commit f8eb29e
Show file tree
Hide file tree
Showing 15 changed files with 1,936 additions and 212 deletions.
449 changes: 254 additions & 195 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"lock": false,
"tasks": {
"test": "deno test --allow-read --allow-net --allow-env --allow-write --allow-run",
"update-snapshots": "deno test --allow-read --allow-net --allow-env --allow-write --allow-run -- --update",
"build": "cp LICENSE js/LICENSE && deno run -A --unstable https://deno.land/x/wasmbuild@0.15.1/main.ts --out js"
"test": "deno test -A",
"update-snapshots": "deno test -A -- --update",
"build": "cp LICENSE js/LICENSE && deno run -A https://deno.land/x/wasmbuild@0.15.1/main.ts --out js"
},
"exclude": [
"lib",
Expand Down
2 changes: 2 additions & 0 deletions js/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export interface TranspileOptions {

export interface CompilerOptions {
checkJs?: boolean;
/** Whether to use TypeScript's experimental decorators. */
experimentalDecorators?: boolean;
/** Determines if reflection meta data is emitted for legacy decorators or
* not. Defaults to `false`. */
emitDecoratorMetadata?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions rs-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ license = "MIT"
[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
deno_ast = { version = "0.32.0", features = ["bundler", "codegen", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "visit", "transpiling"] }
deno_graph = { version = "0.64.1", default-features = true }
deno_ast = { version = "0.33.2", features = ["bundler", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "visit", "transpiling"] }
deno_graph = { version = "0.65.0", default-features = true }
escape8259 = "0.5.2"
futures = "0.3.17"
import_map = "0.18.1"
Expand Down
19 changes: 10 additions & 9 deletions rs-lib/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use deno_ast::swc::common::FileName;
use deno_ast::swc::common::Mark;
use deno_ast::swc::parser::lexer::Lexer;
use deno_ast::swc::parser::StringInput;
use deno_ast::Diagnostic;
use deno_ast::EmitOptions;
use deno_ast::MediaType;
use deno_ast::ModuleSpecifier;
use deno_ast::ParseDiagnostic;
use deno_ast::SourceTextInfo;
use deno_graph::Module;
use std::collections::HashMap;
Expand Down Expand Up @@ -124,7 +124,7 @@ impl swc::bundler::Resolve for BundleResolver<'_> {
&self,
referrer: &swc::common::FileName,
specifier: &str,
) -> Result<swc::common::FileName> {
) -> Result<swc::loader::resolve::Resolution> {
let referrer = if let swc::common::FileName::Url(referrer) = referrer {
referrer
} else {
Expand All @@ -137,7 +137,10 @@ impl swc::bundler::Resolve for BundleResolver<'_> {
if let Some(specifier) =
self.0.resolve_dependency(specifier, referrer, false)
{
Ok(deno_ast::swc::common::FileName::Url(specifier))
Ok(swc::loader::resolve::Resolution {
filename: deno_ast::swc::common::FileName::Url(specifier),
slug: None,
})
} else {
Err(anyhow!(
"Cannot resolve \"{}\" from \"{}\".",
Expand Down Expand Up @@ -259,7 +262,7 @@ pub fn bundle_graph(
}

fn shebang_file(graph: &deno_graph::ModuleGraph) -> Option<String> {
let module = graph.get(graph.roots.get(0)?)?.js()?;
let module = graph.get(graph.roots.first()?)?.js()?;
let source = &module.source;
let first_line = source.lines().next()?;
if first_line.starts_with("#!") {
Expand Down Expand Up @@ -295,9 +298,9 @@ fn transpile_module(
let lexer = Lexer::new(syntax, deno_ast::ES_VERSION, input, Some(&comments));
let mut parser = swc::parser::Parser::new_from(lexer);
let module = parser.parse_module().map_err(|e| {
Diagnostic::from_swc_error(
ParseDiagnostic::from_swc_error(
e,
specifier.as_str(),
specifier,
SourceTextInfo::from_string(source_file.src.to_string()),
)
})?;
Expand All @@ -309,9 +312,7 @@ fn transpile_module(
let info = SourceTextInfo::from_string(source_file.src.to_string());
diagnostics
.into_iter()
.map(|e| {
Diagnostic::from_swc_error(e, specifier.as_str(), info.clone())
})
.map(|e| ParseDiagnostic::from_swc_error(e, specifier, info.clone()))
.collect::<Vec<_>>()
}
};
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.73.0"
channel = "1.75.0"
components = [ "clippy", "rustfmt" ]
23 changes: 23 additions & 0 deletions testdata/es_decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { B } from "./subdir/more_decorators.ts";

function Decorator() {
return function (
target: Record<string, any>,
propertyKey: string,
descriptor: TypedPropertyDescriptor<any>,
) {
const originalFn: Function = descriptor.value as Function;
descriptor.value = async function (...args: any[]) {
return await originalFn.apply(this, args);
};
return descriptor;
};
}

class SomeClass {
@Decorator()
async test() {}
}

new SomeClass().test();
new B().method();
Loading

0 comments on commit f8eb29e

Please sign in to comment.