From a4d7d97d794694dedf793b6432b4f66caa9de7a7 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Thu, 8 Dec 2022 00:31:17 -0500 Subject: [PATCH] fix #2723: skip `import.meta` warnings in packages --- internal/js_parser/js_parser.go | 6 +++++- internal/js_parser/js_parser_lower.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/js_parser/js_parser.go b/internal/js_parser/js_parser.go index c69f14041c4..1e9e804c412 100644 --- a/internal/js_parser/js_parser.go +++ b/internal/js_parser/js_parser.go @@ -12293,7 +12293,11 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO p.markSyntaxFeature(compat.ImportMeta, r) } else if p.options.mode != config.ModePassThrough && !p.options.outputFormat.KeepES6ImportExportSyntax() { r := logger.Range{Loc: expr.Loc, Len: e.RangeLen} - p.log.AddIDWithNotes(logger.MsgID_JS_EmptyImportMeta, logger.Warning, &p.tracker, r, fmt.Sprintf( + kind := logger.Warning + if p.suppressWarningsAboutWeirdCode || p.fnOrArrowDataVisit.tryBodyCount > 0 { + kind = logger.Debug + } + p.log.AddIDWithNotes(logger.MsgID_JS_EmptyImportMeta, kind, &p.tracker, r, fmt.Sprintf( "\"import.meta\" is not available with the %q output format and will be empty", p.options.outputFormat.String()), []logger.MsgData{{Text: "You need to set the output format to \"esm\" for \"import.meta\" to work correctly."}}) } diff --git a/internal/js_parser/js_parser_lower.go b/internal/js_parser/js_parser_lower.go index 63d2c75cb3c..7ea11a57c9c 100644 --- a/internal/js_parser/js_parser_lower.go +++ b/internal/js_parser/js_parser_lower.go @@ -131,7 +131,11 @@ func (p *parser) markSyntaxFeature(feature compat.JSFeature, r logger.Range) (di case compat.ImportMeta: // This can't be polyfilled - p.log.AddIDWithNotes(logger.MsgID_JS_EmptyImportMeta, logger.Warning, &p.tracker, r, fmt.Sprintf( + kind := logger.Warning + if p.suppressWarningsAboutWeirdCode || p.fnOrArrowDataVisit.tryBodyCount > 0 { + kind = logger.Debug + } + p.log.AddIDWithNotes(logger.MsgID_JS_EmptyImportMeta, kind, &p.tracker, r, fmt.Sprintf( "\"import.meta\" is not available in %s and will be empty", where), notes) return