summaryrefslogtreecommitdiff
path: root/cli/emit.rs
diff options
context:
space:
mode:
authorjuju <gliheng@live.com>2022-01-12 20:05:06 +0800
committerGitHub <noreply@github.com>2022-01-12 13:05:06 +0100
commit50e8ab8a8630a272e9862f2fb7014107474405c6 (patch)
treef6c070945cc67d6b30506d422cdf23d5cb58babd /cli/emit.rs
parent62291e9b0e99406ac7f5a95dc329400f9f966825 (diff)
feat(cli): add ignore directives to bundled code (#13309)
This commit adds lint and fmt ignore directives to bundled code as well as a comment stating that the code was bundled and shouldn't be edited manually.
Diffstat (limited to 'cli/emit.rs')
-rw-r--r--cli/emit.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/cli/emit.rs b/cli/emit.rs
index 50d4eb821..35d6f1110 100644
--- a/cli/emit.rs
+++ b/cli/emit.rs
@@ -42,6 +42,13 @@ use std::result;
use std::sync::Arc;
use std::time::Instant;
+const IGNORE_DIRECTIVES: &[&str] = &[
+ "// deno-fmt-ignore-file",
+ "// deno-lint-ignore-file",
+ "// This code was bundled using `deno bundle` and it's not recommended to edit it manually",
+ ""
+];
+
/// Represents the "default" type library that should be used when type
/// checking the code in the module graph. Note that a user provided config
/// of `"lib"` would override this value.
@@ -503,6 +510,7 @@ impl From<BundleType> for swc::bundler::ModuleType {
pub(crate) struct BundleOptions {
pub bundle_type: BundleType,
pub ts_config: TsConfig,
+ pub emit_ignore_directives: bool,
}
/// A module loader for swc which does the appropriate retrieval and transpiling
@@ -630,12 +638,21 @@ pub(crate) fn bundle(
let mut srcmap = Vec::new();
{
let cfg = swc::codegen::Config { minify: false };
- let wr = Box::new(swc::codegen::text_writer::JsWriter::new(
+ let mut wr = Box::new(swc::codegen::text_writer::JsWriter::new(
cm.clone(),
"\n",
&mut buf,
Some(&mut srcmap),
));
+
+ if options.emit_ignore_directives {
+ // write leading comments in bundled file
+ use swc::codegen::text_writer::WriteJs;
+ use swc::common::source_map::DUMMY_SP;
+ let cmt = IGNORE_DIRECTIVES.join("\n") + "\n";
+ wr.write_comment(DUMMY_SP, &cmt)?;
+ }
+
let mut emitter = swc::codegen::Emitter {
cfg,
cm: cm.clone(),