// Marking a symbol as unbound prevents it from being renamed or minified.
// This is only used when a module is compiled independently. We use a very
// different way of handling exports and renaming/minifying when bundling.
Marking a symbol as unbound prevents it from being renamed or minified.
This is only used when a module is compiled independently. We use a very
different way of handling exports and renaming/minifying when bundling.
// Marking a symbol as unbound prevents it from being renamed or minified . // This is only used when a module is compiled independently . We use a very // different way of handling exports and renaming / minifying when bundling .
func (c *linkerContext) preventExportsFromBeingRenamed(sourceIndex uint32) {
	repr, ok := c.graph.Files[sourceIndex].InputFile.Repr.(*graph.JSRepr)
	if !ok {
		return
	}
	hasImportOrExport := false
	for _, part := range repr.AST.Parts {
		for _, stmt := range part.Stmts {
			switch s := stmt.Data.(type) {
			case *js_ast.SImport:
				record := &repr.AST.ImportRecords[s.ImportRecordIndex]
				if record.SourceIndex.IsValid() && record.SourceIndex.GetIndex() == runtime.SourceIndex {
					continue
				}
				hasImportOrExport = true
			case *js_ast.SLocal:
				if s.IsExport {
					for _, decl := range s.Decls {
						preventBindingsFromBeingRenamed(decl.Binding, c.graph.Symbols)
					}
					hasImportOrExport = true
				}
			case *js_ast.SFunction:
				if s.IsExport {
					c.graph.Symbols.Get(s.Fn.Name.Ref).Kind = js_ast.SymbolUnbound
					hasImportOrExport = true
				}
			case *js_ast.SClass:
				if s.IsExport {
					c.graph.Symbols.Get(s.Class.Name.Ref).Kind = js_ast.SymbolUnbound
					hasImportOrExport = true
				}
			case *js_ast.SExportClause, *js_ast.SExportDefault, *js_ast.SExportStar:
				hasImportOrExport = true
			case *js_ast.SExportFrom:
				hasImportOrExport = true
			}
		}
	}
	 Otherwise, we consider this potentially a script-type file instead of an
	 ES6 module. In that case, preserve the names of all top-level symbols
	 since they are all potentially exported (e.g. if this is used in a
	 <script> tag). All symbols in nested scopes are still minified.
	if !hasImportOrExport {
		for _, member := range repr.AST.ModuleScope.Members {
			c.graph.Symbols.Get(member.Ref).MustNotBeRenamed = true
		}
	}
}
func ( c * linkerContext ) preventExportsFromBeingRenamed ( sourceIndex uint32 ) { repr , ok := c . graph . Files [ sourceIndex ] . InputFile . Repr . ( * graph . JSRepr ) if ! ok { return } hasImportOrExport := false for _ , part := range repr . AST . Parts { for _ , stmt := range part . Stmts { switch s := stmt . Data . ( type ) { case * js_ast . SImport : record := & repr . AST . ImportRecords [ s . ImportRecordIndex ] if record . SourceIndex . IsValid ( ) && record . SourceIndex . GetIndex ( ) == runtime . SourceIndex { continue } hasImportOrExport = true case * js_ast . SLocal : if s . IsExport { for _ , decl := range s . Decls { preventBindingsFromBeingRenamed ( decl . Binding , c . graph . Symbols ) } hasImportOrExport = true } case * js_ast . SFunction : if s . IsExport { c . graph . Symbols . Get ( s . Fn . Name . Ref ) . Kind = js_ast . SymbolUnbound hasImportOrExport = true } case * js_ast . SClass : if s . IsExport { c . graph . Symbols . Get ( s . Class . Name . Ref ) . Kind = js_ast . SymbolUnbound hasImportOrExport = true } case * js_ast . SExportClause , * js_ast . SExportDefault , * js_ast . SExportStar : hasImportOrExport = true case * js_ast . SExportFrom : hasImportOrExport = true } } } if ! hasImportOrExport { for _ , member := range repr . AST . ModuleScope . Members { c . graph . Symbols . Get ( member . Ref ) . MustNotBeRenamed = true } } }
Marking a symbol as unbound prevents it from being renamed or minified.
Marking a symbol as unbound prevents it from being renamed or minified .
// Ignore imports from the internal runtime code. These are generated // automatically and aren't part of the original source code. We // shouldn't consider the file a module if the only ES6 import or // export is the automatically generated one. // Heuristic: If this module has top-level import or export statements, we // consider this an ES6 module and only preserve the names of the exported // symbols. Everything else is minified since the names are private. // // Otherwise, we consider this potentially a script-type file instead of an // ES6 module. In that case, preserve the names of all top-level symbols // since they are all potentially exported (e.g. if this is used in a // <script> tag). All symbols in nested scopes are still minified.