diff --git a/Cargo.lock b/Cargo.lock index af50dda95d..6112afc093 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -484,9 +484,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0259b3a74f4551823029c6e711093840b0cc1fa774b1d6be49643af65ba5c5f9" +checksum = "d3a0eed03221f7502d8d5febebf1fa45a30e5596602a16edfc3c91048876e1dd" dependencies = [ "futures", "lazy_static", @@ -510,10 +510,11 @@ dependencies = [ [[package]] name = "deno_lint" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e8194edfcd2612361b7149f8d79aef5688f1463d76f8b613b517f4537a27ff9" +checksum = "db3365f8888bbffc7b9b65268bebf4ba6fdaaf808d5a7a06fffe51786b37869a" dependencies = [ + "derive_more", "log", "once_cell", "regex", @@ -534,6 +535,17 @@ dependencies = [ "serde", ] +[[package]] +name = "derive_more" +version = "0.99.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" +dependencies = [ + "proc-macro2 1.0.21", + "quote 1.0.7", + "syn 1.0.41", +] + [[package]] name = "digest" version = "0.8.1" @@ -592,9 +604,9 @@ dependencies = [ [[package]] name = "dprint-plugin-typescript" -version = "0.32.7" +version = "0.32.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca4da0cbd145118f667eee6daa2eb90c2667ca25b0905dba6a7fa1d8ede6530" +checksum = "9971ede7622499e842d0e0f6c24992da34815c1438f26d832b603d1fe9589b46" dependencies = [ "dprint-core", "serde", @@ -2271,9 +2283,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.14.1" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4637a8e92ffe50c39f7aac648f97181bba83206537b998a32b13fac553a6be60" +checksum = "b2033b99b209c5978f2bc04931073fe18f676c5b95b12bb6a9ec3b618569d806" dependencies = [ "anyhow", "crc", @@ -2297,9 +2309,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.10.4" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b9362f9d864172dd964c4a213bbf52e48f5b9fcaf3456441da4b279dd41463" +checksum = "1dd78e25ecc138a4667f5e5ea4d1a1c35d424477882b549d4fc011062eecd50e" dependencies = [ "ast_node", "cfg-if", @@ -2407,9 +2419,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.29.1" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee08c5add657ead50136456ae60c0a018d796cc8f1566eb428edc48a061e545" +checksum = "0958bbaa69e01a45a2268c398a8814014a029c0b4eaecd42f2545fcd642314e8" dependencies = [ "Inflector", "arrayvec", @@ -2482,9 +2494,9 @@ dependencies = [ [[package]] name = "swc_ecmascript" -version = "0.13.1" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41561a31d6b9fb46c6d7ea3ab4bc1e851d0321d18ae038cd7bbe3ea3f4155e3b" +checksum = "f11d30e16321db6eb94b38ec3dd701bc4e7bd5e146aa49451b049817a250b0f1" dependencies = [ "swc_ecma_ast", "swc_ecma_codegen", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ec06e1f705..52b6edeb05 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -32,8 +32,8 @@ winapi = "0.3.9" [dependencies] deno_core = { path = "../core", version = "0.66.0" } -deno_doc = "0.1.14" -deno_lint = "0.2.7" +deno_doc = "0.1.15" +deno_lint = "0.2.9" deno_web = { path = "../op_crates/web", version = "0.17.0" } deno_fetch = { path = "../op_crates/fetch", version = "0.9.0" } @@ -45,7 +45,7 @@ clap = "2.33.3" dissimilar = "1.0.2" dlopen = "0.1.8" encoding_rs = "0.8.24" -dprint-plugin-typescript = "0.32.7" +dprint-plugin-typescript = "0.32.8" filetime = "0.2.12" http = "0.2.1" indexmap = "1.6.0" @@ -63,9 +63,9 @@ rustyline-derive = "0.3.1" serde = { version = "1.0.116", features = ["derive"] } sys-info = "0.7.0" sourcemap = "6.0.1" -swc_bundler = "=0.14.1" -swc_common = { version = "=0.10.4", features = ["sourcemap"] } -swc_ecmascript = { version = "=0.13.1", features = ["codegen", "dep_graph", "parser", "react", "transforms", "visit"] } +swc_bundler = "=0.16.1" +swc_common = { version = "=0.10.5", features = ["sourcemap"] } +swc_ecmascript = { version = "=0.13.3", features = ["codegen", "dep_graph", "parser", "react", "transforms", "visit"] } tempfile = "3.1.0" termcolor = "1.1.0" tokio = { version = "0.2.22", features = ["full"] } diff --git a/cli/ast.rs b/cli/ast.rs index fcce0cc929..3d859e020f 100644 --- a/cli/ast.rs +++ b/cli/ast.rs @@ -482,23 +482,50 @@ pub fn transpile_module( pub struct BundleHook; impl swc_bundler::Hook for BundleHook { - fn get_import_meta_url( + fn get_import_meta_props( &self, span: swc_common::Span, - file: &swc_common::FileName, - ) -> Result, AnyError> { + module_record: &swc_bundler::ModuleRecord, + ) -> Result, AnyError> { + use swc_ecmascript::ast; + // we use custom file names, and swc "wraps" these in `<` and `>` so, we // want to strip those back out. - let mut value = file.to_string(); + let mut value = module_record.file_name.to_string(); value.pop(); value.remove(0); - Ok(Some(swc_ecmascript::ast::Expr::Lit( - swc_ecmascript::ast::Lit::Str(swc_ecmascript::ast::Str { - span, - value: value.into(), - has_escape: false, - }), - ))) + + Ok(vec![ + ast::KeyValueProp { + key: ast::PropName::Ident(ast::Ident::new("url".into(), span)), + value: Box::new(ast::Expr::Lit(ast::Lit::Str(ast::Str { + span, + value: value.into(), + has_escape: false, + }))), + }, + ast::KeyValueProp { + key: ast::PropName::Ident(ast::Ident::new("main".into(), span)), + value: Box::new(if module_record.is_entry { + ast::Expr::Member(ast::MemberExpr { + span, + obj: ast::ExprOrSuper::Expr(Box::new(ast::Expr::MetaProp( + ast::MetaPropExpr { + meta: ast::Ident::new("import".into(), span), + prop: ast::Ident::new("meta".into(), span), + }, + ))), + prop: Box::new(ast::Expr::Ident(ast::Ident::new( + "main".into(), + span, + ))), + computed: false, + }) + } else { + ast::Expr::Lit(ast::Lit::Bool(ast::Bool { span, value: false })) + }), + }, + ]) } } diff --git a/cli/flags.rs b/cli/flags.rs index 42f8d60d75..b0f098ecf8 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -1024,9 +1024,6 @@ rule name: Names of rules to ignore must be specified after ignore comment. -ESLint ignore comments are also supported: - // eslint-disable-next-line @typescrit-eslint/no-explicit-any no-empty - Ignore linting a file by adding an ignore comment at the top of the file: // deno-lint-ignore-file ", diff --git a/cli/lint.rs b/cli/lint.rs index 2550890537..e95af58f2e 100644 --- a/cli/lint.rs +++ b/cli/lint.rs @@ -15,7 +15,6 @@ use crate::media_type::MediaType; use deno_core::error::{generic_error, AnyError, JsStackFrame}; use deno_core::serde_json; use deno_lint::diagnostic::LintDiagnostic; -use deno_lint::linter::FileType; use deno_lint::linter::Linter; use deno_lint::linter::LinterBuilder; use deno_lint::rules; @@ -116,11 +115,8 @@ pub fn print_rules_list() { fn create_linter(syntax: Syntax, rules: Vec>) -> Linter { LinterBuilder::default() - .ignore_file_directives(vec!["deno-lint-ignore-file"]) - .ignore_diagnostic_directives(vec![ - "deno-lint-ignore", - "eslint-disable-next-line", - ]) + .ignore_file_directive("deno-lint-ignore-file") + .ignore_diagnostic_directive("deno-lint-ignore") .lint_unused_ignore_directives(true) // TODO(bartlomieju): switch to true .lint_unknown_rules(false) @@ -140,8 +136,7 @@ fn lint_file( let lint_rules = rules::get_recommended_rules(); let mut linter = create_linter(syntax, lint_rules); - let file_diagnostics = - linter.lint(file_name, source_code.clone(), FileType::Module)?; + let (_, file_diagnostics) = linter.lint(file_name, source_code.clone())?; Ok((file_diagnostics, source_code)) } @@ -167,14 +162,10 @@ fn lint_stdin(json: bool) -> Result<(), AnyError> { let mut has_error = false; let pseudo_file_name = "_stdin.ts"; match linter - .lint( - pseudo_file_name.to_string(), - source.clone(), - FileType::Module, - ) + .lint(pseudo_file_name.to_string(), source.clone()) .map_err(|e| e.into()) { - Ok(diagnostics) => { + Ok((_, diagnostics)) => { for d in diagnostics { has_error = true; reporter.visit_diagnostic(&d, source.split('\n').collect()); diff --git a/cli/module_graph.rs b/cli/module_graph.rs index 08f6c5f32a..9f2689fd6a 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -145,8 +145,7 @@ impl swc_bundler::Load for BundleLoader<'_> { fn load( &self, file: &swc_common::FileName, - ) -> Result<(Rc, swc_ecmascript::ast::Module), AnyError> - { + ) -> Result { match file { swc_common::FileName::Custom(filename) => { let specifier = ModuleSpecifier::resolve_url_or_path(filename) @@ -156,14 +155,19 @@ impl swc_bundler::Load for BundleLoader<'_> { .graph .get_media_type(&specifier) .context("Looking up media type during bundling.")?; - transpile_module( + let (source_file, module) = transpile_module( filename, &src, &media_type, self.emit_options, self.globals, self.cm.clone(), - ) + )?; + Ok(swc_bundler::ModuleData { + fm: source_file, + module, + helpers: Default::default(), + }) } else { Err( GraphError::MissingDependency(specifier, "".to_string()) diff --git a/cli/tests/bundle/fixture06.out b/cli/tests/bundle/fixture06.out index 057c5b8202..3c583c56e1 100644 --- a/cli/tests/bundle/fixture06.out +++ b/cli/tests/bundle/fixture06.out @@ -1,2 +1,12 @@ -console.log(false, "file:///tests/subdir/f.ts"); -console.log(import.meta.main, "file:///tests/fixture06.ts"); +const importMeta = { + url: "file:///tests/fixture06.ts", + main: import.meta.main +}; +const importMeta1 = { + url: "file:///tests/subdir/f.ts", + main: false +}; +const isMain = importMeta1.main; +const modUrl = importMeta1.url; +console.log(isMain, modUrl); +console.log(importMeta.main, importMeta.url); diff --git a/docs/tools/linter.md b/docs/tools/linter.md index d3daabeab5..15e6b7ba59 100644 --- a/docs/tools/linter.md +++ b/docs/tools/linter.md @@ -145,17 +145,3 @@ function bar(a: any) { // ... } ``` - -To provide some compatibility with ESLint `deno lint` also supports -`// eslint-disable-next-line` directive. Just like with `// deno-lint-ignore`, -it's required to specify the ignored rule name: - -```ts -// eslint-disable-next-line no-empty -while (true) {} - -// deno-lint-ignore no-explicit-any -function bar(a: any) { - // ... -} -```