summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-11-08 23:27:36 +0100
committerGitHub <noreply@github.com>2020-11-08 23:27:36 +0100
commit6743383d2e89939ae9c12d8de027f05ae4d37518 (patch)
tree1ae255e50969312f9a688ef690bda9eedabb8b12 /cli
parentb244766f9d31183ee10d37db37c30ca49a3c8aa2 (diff)
upgrade: deno_doc, deno_lint, dprint, swc (#8292)
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml12
-rw-r--r--cli/ast.rs49
-rw-r--r--cli/flags.rs3
-rw-r--r--cli/lint.rs19
-rw-r--r--cli/module_graph.rs12
-rw-r--r--cli/tests/bundle/fixture06.out14
6 files changed, 69 insertions, 40 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index ec06e1f70..52b6edeb0 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 fcce0cc92..3d859e020 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<Option<swc_ecmascript::ast::Expr>, AnyError> {
+ module_record: &swc_bundler::ModuleRecord,
+ ) -> Result<Vec<swc_ecmascript::ast::KeyValueProp>, 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 42f8d60d7..b0f098ecf 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 255089053..e95af58f2 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<Box<dyn LintRule>>) -> 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 08f6c5f32..9f2689fd6 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_common::SourceFile>, swc_ecmascript::ast::Module), AnyError>
- {
+ ) -> Result<swc_bundler::ModuleData, AnyError> {
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, "<bundle>".to_string())
diff --git a/cli/tests/bundle/fixture06.out b/cli/tests/bundle/fixture06.out
index 057c5b820..3c583c56e 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);