Skip to content

Commit

Permalink
work on evanw#184: --instrument flag is read into options by validate…
Browse files Browse the repository at this point in the history
…Loader
  • Loading branch information
stoand committed Mar 13, 2023
1 parent 2088bb9 commit b44572d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ type Options struct {
KeepNames bool
IgnoreDCEAnnotations bool
TreeShaking bool
Instrument bool
DropDebugger bool
MangleQuoted bool
Platform Platform
Expand Down
2 changes: 2 additions & 0 deletions internal/js_printer/js_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,8 @@ func (p *printer) printStmt(stmt js_ast.Stmt, flags printStmtFlags) {
}

type Options struct {
Instrument bool

RequireOrImportMetaForSource func(uint32) RequireOrImportMeta

// Cross-module inlining of TypeScript enums is actually done during printing
Expand Down
4 changes: 4 additions & 0 deletions internal/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4093,6 +4093,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS(

// Convert the AST to JavaScript code
printOptions := js_printer.Options{
Instrument: c.options.Instrument,
Indent: indent,
OutputFormat: c.options.OutputFormat,
MinifyIdentifiers: c.options.MinifyIdentifiers,
Expand All @@ -4114,6 +4115,9 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
MangledProps: c.mangledProps,
NeedsMetafile: c.options.NeedsMetafile,
}

fmt.Printf("%b is active", c.options.Instrument)

tree := repr.AST
tree.Directive = "" // This is handled elsewhere
tree.Parts = []js_ast.Part{{Stmts: stmts}}
Expand Down
14 changes: 14 additions & 0 deletions pkg/api/api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ func validateTreeShaking(value TreeShaking, bundle bool, format Format) bool {
}
}

func validateInstrument(value Instrument) bool {
switch value {
case InstrumentDefault:
return false
case InstrumentFalse:
return false
case InstrumentTrue:
return true
default:
panic("Invalid tree shaking")
}
}

func validateLoader(value Loader) config.Loader {
switch value {
case LoaderBase64:
Expand Down Expand Up @@ -1229,6 +1242,7 @@ func validateBuildOptions(
ASCIIOnly: validateASCIIOnly(buildOpts.Charset),
IgnoreDCEAnnotations: buildOpts.IgnoreAnnotations,
TreeShaking: validateTreeShaking(buildOpts.TreeShaking, buildOpts.Bundle, buildOpts.Format),
Instrument: validateInstrument(buildOpts.Instrument),
GlobalName: validateGlobalName(log, buildOpts.GlobalName),
CodeSplitting: buildOpts.Splitting,
OutputFormat: validateFormat(buildOpts.Format),
Expand Down

0 comments on commit b44572d

Please sign in to comment.