How to use warning method of compiler Package

Best Syzkaller code snippet using compiler.warning

glosure.go

Source:glosure.go Github

copy

Full Screen

...124 UseClosureApi bool125 // Closure compiler compilation level. Valid levels are: WhiteSpaceOnly,126 // SimpleOptimizations (default), AdvancedOptimizations.127 CompilationLevel CompilationLevel128 // Closure compiler warning level. Valid levels are: Quite, Default, and129 // Verbose.130 WarningLevel WarningLevel131 // Formatting of the compiled output. Valid formattings are: PrettyPrint,132 // and PrintInputDelimiter.133 Formatting Formatting134 // Whether to optimize out all unused JavaScript code.135 OnlyClosureDependencies bool136 // List of exern JavaScript files.137 Externs []string138 // JavaScript files that should be included in every compilation.139 BaseFiles []string140 // Whether to perform an angular pass.141 AngularPass bool142 // Whether to process jQuery primitives.143 ProcessJqueryPrimitives bool144 // Warnings that should be treated as errors.145 CompErrors []WarningClass146 // Warnings.147 CompWarnings []WarningClass148 // Warnings that are suppressed.149 CompSuppressed []WarningClass150 fileServer http.Handler151 depg depgraph.DependencyGraph152 mutex sync.Mutex153}154func NewCompiler(root string) Compiler {155 _, javaLookupErr := exec.LookPath("java")156 return Compiler{157 Root: root,158 ErrorHandler: http.NotFound,159 CompiledSuffix: DefaultCompiledSuffix,160 CompilationLevel: SimpleOptimizations,161 WarningLevel: Default,162 SourceSuffix: DefaultSourceSuffix,163 CompileOnDemand: true,164 UseClosureApi: javaLookupErr != nil,165 fileServer: http.FileServer(http.Dir(root)),166 depg: depgraph.New(),167 mutex: sync.Mutex{},168 }169}170// Enables strict compilation. Almost all warnings are treated as errors.171func (cc *Compiler) Strict() {172 cc.WarningLevel = Verbose173 // All of warning classes, except the unknown type.174 cc.CompErrors = []WarningClass{175 AccessControls, AmbiguousFunctionDecl, CheckEventfulObjectDisposal,176 CheckRegExp, CheckStructDictInheritance, CheckTypes, CheckVars, Const,177 ConstantProperty, Deprecated, DuplicateMessage, Es3, Es5Strict,178 ExternsValidation, FileoverviewTags, GlobalThis, InternetExplorerChecks,179 InvalidCasts, MisplacedTypeAnnotation, MissingProperties, MissingProvide,180 MissingRequire, MissingReturn, NonStandardJsDocs,181 SuspiciousCode, StrictModuleDepCheck, TypeInvalidation, UndefinedNames,182 UndefinedVars, UnknownDefines, UselessCode, Visibility,183 }184 cc.CompWarnings = []WarningClass{}185 cc.CompSuppressed = []WarningClass{}186}187// Enables options for debugger convenience.188func (cc *Compiler) Debug() {189 cc.WarningLevel = Verbose190 // All of warning classes, except the unknown type.191 cc.CompWarnings = []WarningClass{192 AccessControls, AmbiguousFunctionDecl, CheckEventfulObjectDisposal,193 CheckRegExp, CheckStructDictInheritance, CheckTypes, CheckVars, Const,194 ConstantProperty, Deprecated, DuplicateMessage, Es3, Es5Strict,195 ExternsValidation, FileoverviewTags, GlobalThis, InternetExplorerChecks,196 InvalidCasts, MisplacedTypeAnnotation, MissingProperties, MissingProvide,197 MissingRequire, MissingReturn, NonStandardJsDocs,198 SuspiciousCode, StrictModuleDepCheck, TypeInvalidation, UndefinedNames,199 UndefinedVars, UnknownDefines, UselessCode, Visibility,200 }201 cc.CompErrors = []WarningClass{}202 cc.CompSuppressed = []WarningClass{}203 cc.Formatting = PrettyPrint204}205// Glosure's main handler function.206func ServeHttp(res http.ResponseWriter, req *http.Request, cc *Compiler) {207 path := req.URL.Path208 if !cc.isCompiledJavascript(path) {209 cc.ErrorHandler(res, req)210 return211 }212 if !cc.sourceFileExists(path) {213 cc.ErrorHandler(res, req)214 return215 }216 forceCompile := req.URL.Query().Get("force") == "1"217 if !cc.CompileOnDemand || (!forceCompile && cc.jsIsAlreadyCompiled(path)) {218 cc.fileServer.ServeHTTP(res, req)219 return220 }221 err := cc.Compile(path)222 if err != nil {223 cc.ErrorHandler(res, req)224 return225 }226 glog.Info("JavaScript source is successfully compiled: ", path)227 cc.fileServer.ServeHTTP(res, req)228}229func (cc *Compiler) isCompiledJavascript(path string) bool {230 return strings.HasSuffix(path, cc.CompiledSuffix)231}232func (cc *Compiler) isSourceJavascript(path string) bool {233 return strings.HasSuffix(path, cc.SourceSuffix) &&234 !strings.HasSuffix(path, cc.CompiledSuffix)235}236func (cc *Compiler) getSourceJavascriptPath(relPath string) string {237 return path.Join(cc.Root, relPath[:len(relPath) - len(cc.CompiledSuffix)] +238 cc.SourceSuffix)239}240func (cc *Compiler) getCompiledJavascriptPath(relPath string) string {241 if cc.isCompiledJavascript(relPath) {242 return path.Join(cc.Root, relPath)243 }244 return path.Join(cc.Root, relPath[:len(relPath) - len(cc.SourceSuffix)] +245 cc.CompiledSuffix)246}247func (cc *Compiler) sourceFileExists(path string) bool {248 srcPath := cc.getSourceJavascriptPath(path)249 _, err := os.Stat(srcPath)250 return err == nil251}252func (cc *Compiler) jsIsAlreadyCompiled(path string) bool {253 srcPath := cc.getSourceJavascriptPath(path)254 srcStat, err := os.Stat(srcPath)255 if err != nil {256 return false257 }258 outPath := cc.getCompiledJavascriptPath(path)259 outStat, err := os.Stat(outPath)260 if err != nil {261 return false262 }263 if outStat.ModTime().Before(srcStat.ModTime()) {264 return false265 }266 return true267}268func (cc *Compiler) downloadCompilerJar() (string, error) {269 const ccJarPath = "__compiler__.jar"270 const ccDlUrl = "http://dl.google.com/closure-compiler/compiler-latest.zip"271 jarFilePath := filepath.Join(cc.Root, ccJarPath)272 _, err := os.Stat(jarFilePath)273 if err == nil {274 return jarFilePath, nil275 }276 glog.Info("Downloading closure compiler from: ", ccDlUrl)277 zipFilePath := filepath.Join(cc.Root, "__compiler__.zip")278 zipFile, err := os.Create(zipFilePath)279 defer zipFile.Close()280 res, err := http.Get(ccDlUrl)281 defer res.Body.Close()282 // TODO(soheil): Maybe verify checksum?283 _, err = io.Copy(zipFile, res.Body)284 if err != nil {285 return "", err286 }287 r, err := zip.OpenReader(zipFilePath)288 if err != nil {289 return "", err290 }291 defer r.Close()292 for _, f := range r.File {293 if f.Name != "compiler.jar" {294 continue295 }296 cmpJar, err := f.Open()297 if err != nil {298 return "", err299 }300 jarFile, err := os.Create(jarFilePath)301 defer jarFile.Close()302 glog.V(1).Info("Decompressing compiler.jar to ", jarFilePath)303 io.Copy(jarFile, cmpJar)304 break305 }306 return jarFilePath, nil307}308func (cc *Compiler) Compile(relOutPath string) error {309 if !cc.UseClosureApi {310 _, err := exec.LookPath("java")311 if err != nil {312 glog.Fatal("No java found in $PATH.")313 }314 if cc.CompilerJarPath == "" {315 cc.CompilerJarPath, err = cc.downloadCompilerJar()316 if err != nil {317 glog.Fatal("Cannot download the closure compiler.")318 }319 }320 }321 srcPath := cc.getSourceJavascriptPath(relOutPath)322 outPath := cc.getCompiledJavascriptPath(relOutPath)323 srcPkgs, err := getClosurePackage(srcPath)324 useClosureDeps := err == nil325 cc.mutex.Lock()326 defer cc.mutex.Unlock()327 jsFiles := make([]string, 0)328 if useClosureDeps {329 if len(cc.depg.Nodes) == 0 {330 cc.reloadDependencyGraph()331 }332 nodes := []*depgraph.Node{}333 for _, srcPkg := range srcPkgs {334 node, ok := cc.depg.Nodes[srcPkgs[0]]335 if !ok {336 return errors.New(fmt.Sprintf("Package %s not found in %s.", srcPkg,337 cc.Root))338 }339 nodes = append(nodes, node)340 }341 deps := cc.depg.GetDependencies(nodes)342 for _, dep := range(deps) {343 jsFiles = append(jsFiles, dep.Path)344 }345 } else {346 jsFiles = append(jsFiles, srcPath)347 }348 if cc.UseClosureApi {349 return cc.CompileWithClosureApi(jsFiles, nil, outPath)350 }351 return cc.CompileWithClosureJar(jsFiles, srcPkgs, outPath)352}353func (cc *Compiler) CompileWithClosureJar(jsFiles []string, entryPkgs []string,354 outPath string) error {355 args := []string{"-jar", cc.CompilerJarPath}356 for _, b := range cc.BaseFiles {357 args = append(args, "--js", b)358 }359 for _, file := range jsFiles {360 args = append(args, "--js", file)361 }362 if len(entryPkgs) != 0 && cc.OnlyClosureDependencies {363 args = append(args,364 "--manage_closure_dependencies", "true",365 "--only_closure_dependencies", "true")366 for _, entryPkg := range entryPkgs {367 args = append(args, "--closure_entry_point", entryPkg)368 }369 }370 for _, e := range cc.Externs {371 args = append(args, "--externs", e)372 }373 args = append(args,374 "--js_output_file", outPath,375 "--compilation_level", string(cc.CompilationLevel),376 "--warning_level", string(cc.WarningLevel))377 if cc.AngularPass {378 args = append(args, "--angular_pass", "true")379 }380 if cc.ProcessJqueryPrimitives {381 args = append(args, "--process_jquery_primitives", "true")382 }383 for _, e := range cc.CompErrors {384 args = append(args, "--jscomp_error", string(e))385 }386 for _, e := range cc.CompWarnings {387 args = append(args, "--jscomp_warning", string(e))388 }389 for _, e := range cc.CompSuppressed {390 args = append(args, "--jscomp_off", string(e))391 }392 if cc.Formatting != "" {393 args = append(args, "--formatting", string(cc.Formatting))394 }395 cmd := exec.Command("java", args...)396 stdErr, err := cmd.StderrPipe()397 if err != nil {398 return errors.New("Cannot attach to stderr of the compiler.")399 }400 stdOut, err := cmd.StdoutPipe()401 if err != nil {402 return errors.New("Cannot attach to stdout of the compiler.")403 }404 err = cmd.Start()405 if err != nil {406 return errors.New("Cannot run the compiler.")407 }408 io.Copy(os.Stderr, stdErr)409 io.Copy(os.Stdout, stdOut)410 err = cmd.Wait()411 return err412}413func (cc *Compiler) CompileWithClosureApi(jsFiles []string, entryPkgs []string,414 outPath string) error {415 var srcBuffer bytes.Buffer416 for _, file := range(jsFiles) {417 content, err := ioutil.ReadFile(file)418 if err != nil {419 // We should never reach this line. This is just an assert.420 panic("Cannot read a file: " + file)421 }422 srcBuffer.Write(content)423 }424 var extBuffer bytes.Buffer425 for _, file := range(cc.Externs) {426 content, err := ioutil.ReadFile(file)427 if err != nil {428 panic("Cannot read an extern file: " + file)429 }430 extBuffer.Write(content)431 }432 res, err := cc.dialClosureApi(srcBuffer.String(), extBuffer.String())433 if err != nil {434 return err435 }436 if len(res.Errors) != 0 {437 for _, cErr := range(res.Errors) {438 fmt.Fprintf(os.Stderr, "Compilation error: %s\n\t%s\n\t%s\n",439 cErr.Error, cErr.Line, errAnchor(cErr.Charno))440 }441 return errors.New("Compilation error.")442 }443 if len(res.Warnings) != 0 {444 for _, cWarn := range(res.Warnings) {445 fmt.Fprintf(os.Stderr, "Compilation warning: %s\n\t%s\n\t%s\n",446 cWarn.Warning, cWarn.Line, errAnchor(cWarn.Charno))447 }448 }449 ioutil.WriteFile(outPath, []byte(res.CompiledCode), 0644)450 return nil451}452func errAnchor(charNo int) string {453 indent := charNo - 1454 if indent < 0 {455 indent = 0456 }457 return strings.Repeat("-", int(indent)) + "^"458}459func concatContent(nodes []*depgraph.Node) string {460 var buffer bytes.Buffer461 for _, val := range nodes {462 content, err := ioutil.ReadFile(val.Path)463 if err != nil {464 // TODO(soheil): Should we simply ignore such errors?465 continue466 }467 buffer.Write(content)468 }469 return buffer.String()470}471func (cc *Compiler) reloadDependencyGraph() {472 // TODO(soheil): Here, we are loading the files twice. We can make it in one473 // pass.474 filepath.Walk(cc.Root,475 func(path string, info os.FileInfo, err error) error {476 if !cc.isSourceJavascript(path) {477 return nil478 }479 pkgs, err := getClosurePackage(path)480 if err != nil {481 return nil482 }483 for _, pkg := range pkgs {484 glog.V(1).Info("Found package ", pkg, " in ", path)485 cc.depg.AddFile(pkg, path)486 }487 return nil488 })489 for _, node := range cc.depg.Nodes {490 deps, err := getClosureDependecies(node.Path)491 if err != nil || deps == nil {492 continue493 }494 for _, dep := range deps {495 glog.V(1).Info("Found dependency from ", node.Pkg, " to ", dep)496 cc.depg.AddDependency(node.Pkg, dep)497 }498 }499}500type ClosureApiResult struct {501 CompiledCode string502 Errors []ClosureError `json:"errors"`503 Warnings []ClosureWarning `json:"warnings"`504 ServerErrors []struct {505 Code int `json:"code"`506 Error string `json:"error"`507 } `json:"serverErrors"`508}509type ClosureError struct {510 Charno int511 Lineno int512 File string513 ErrorType string `json:"type"`514 Error string515 Line string516}517type ClosureWarning struct {518 Charno int519 Lineno int520 File string521 WarningType string `json:"type"`522 Warning string523 Line string524}525func (cc *Compiler) getClosureApiParams(src string, ext string) url.Values {526 params := make(url.Values)527 params.Set("js_code", src)528 if len(ext) > 0 {529 params.Set("js_externs", ext)530 }531 params.Set("output_format", "json")532 params.Add("output_info", "compiled_code")533 params.Add("output_info", "warnings")534 params.Add("output_info", "errors")535 params.Set("warning_level", string(cc.WarningLevel))536 params.Set("compilation_level", string(cc.CompilationLevel))537 return params538}539func (cc *Compiler) dialClosureApi(src string, ext string) (*ClosureApiResult,540 error) {541 const URL = "http://closure-compiler.appspot.com/compile"542 params := cc.getClosureApiParams(src, ext)543 resp, err := http.PostForm(URL, params)544 if err != nil {545 return nil, errors.New("Cannot send a compilation request to " + URL)546 }547 defer resp.Body.Close()548 body, err := ioutil.ReadAll(resp.Body)549 if err != nil {...

Full Screen

Full Screen

log.go

Source:log.go Github

copy

Full Screen

...9 FlatWarning uint8 = 110 Error uint8 = 211 Warning uint8 = 312)13const warningMark = "<!>"14// CompilerLog is a compiler log.15type CompilerLog struct {16 Type uint817 Row int18 Column int19 Path string20 Message string21}22func (clog *CompilerLog) flatError() string {23 return clog.Message24}25func (clog *CompilerLog) error() string {26 var log strings.Builder27 log.WriteString(clog.Path)28 log.WriteByte(':')29 log.WriteString(fmt.Sprint(clog.Row))30 log.WriteByte(':')31 log.WriteString(fmt.Sprint(clog.Column))32 log.WriteByte(' ')33 log.WriteString(clog.Message)34 return log.String()35}36func (clog *CompilerLog) flatWarning() string {37 return warningMark + " " + clog.Message38}39func (clog *CompilerLog) warning() string {40 var log strings.Builder41 log.WriteString(warningMark)42 log.WriteByte(' ')43 log.WriteString(clog.Path)44 log.WriteByte(':')45 log.WriteString(fmt.Sprint(clog.Row))46 log.WriteByte(':')47 log.WriteString(fmt.Sprint(clog.Column))48 log.WriteByte(' ')49 log.WriteString(clog.Message)50 return log.String()51}52func (clog CompilerLog) String() string {53 switch clog.Type {54 case FlatError:55 return clog.flatError()56 case Error:57 return clog.error()58 case FlatWarning:59 return clog.flatWarning()60 case Warning:61 return clog.warning()62 }63 return ""64}...

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4}5import "fmt"6func main() {7 fmt.Println("Hello, World!")8}9import "fmt"10func main() {11 fmt.Println("Hello, World!")12}13import "fmt"14func main() {15 fmt.Println("Hello, World!")16}17import "fmt"18func main() {19 fmt.Println("Hello, World!")20}21import "fmt"22func main() {23 fmt.Println("Hello, World!")24}25import "fmt"26func main() {27 fmt.Println("Hello, World!")28}29import "fmt"30func main() {31 fmt.Println("Hello, World!")32}33import "fmt"34func main() {35 fmt.Println("Hello, World!")36}37import "fmt"38func main() {39 fmt.Println("Hello, World!")40}41import "fmt"42func main() {43 fmt.Println("Hello, World!")44}45import "fmt"46func main() {47 fmt.Println("Hello, World!")48}49import "fmt"50func main() {51 fmt.Println("Hello, World!")52}53import "fmt

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4}5import "fmt"6func main() {7 fmt.Println("Hello, World!")8}9import "fmt"10func main() {11 fmt.Println("Hello, World!")12}13import "fmt"14func main() {15 fmt.Println("Hello, World!")16}17import "fmt"18func main() {19 fmt.Println("Hello, World!")20}21import "fmt"22func main() {23 fmt.Println("Hello, World!")24}25import "fmt"26func main() {27 fmt.Println("Hello, World!")28}29import "fmt"30func main() {31 fmt.Println("Hello, World!")32}33import "fmt"34func main() {35 fmt.Println("Hello, World!")36}37import "fmt"38func main() {39 fmt.Println("Hello, World!")40}41import "fmt"42func main() {43 fmt.Println("Hello, World!")44}45import "fmt"46func main() {47 fmt.Println("Hello, World!")48}49import "fmt"50func main() {51 fmt.Println("Hello, World!")52}53import "fmt"54func main() {55 fmt.Println("Hello,

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import "fmt"2type compiler struct {3}4func (c compiler) warning() {5 fmt.Println("warning")6}7type java struct {8}9func main() {10 j := java{}11 j.warning()12}13import "fmt"14type compiler struct {15}16func (c compiler) warning() {17 fmt.Println("warning")18}19type java struct {20}21func (j java) warning() {22 fmt.Println("warning from java")23}24func main() {25 j := java{}26 j.warning()27}28import "fmt"29type compiler struct {30}31func (c compiler) warning() {32 fmt.Println("warning")33}34type java struct {35}36func (j java) warning() {37 fmt.Println("warning from java")38}39func main() {40 j := java{}41 c := compiler(j)42 c.warning()43}44import "fmt"45type compiler struct {46}47func (c compiler) warning() {48 fmt.Println("warning")49}50type java struct {51}52func (j java) warning() {53 fmt.Println("warning from java")54}55func main() {56 j := java{}57 c := compiler(j)58 c.warning()59 j.warning()60}

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3fmt.Println("This is a warning")4}5fmt.Println("This is a warning")6func (c *compiler) Errorf(pos token.Pos, format string, args ...interface{}) {7c.errorList = append(c.errorList, &Error{pos, fmt.Sprintf(format, args...)})8}9import "fmt"10func main() {11fmt.Println("This is an error")12}13fmt.Println("This is an error")14How to use the initimport method of the compiler class?15How to use the initimportedpackage method of the compiler class?16How to use the initimportedpkg method of the compiler class?17How to use the importimportedpkg method of the compiler class?18How to use the importdot method of the compiler class?19How to use the importpackage method of the compiler class?20How to use the importdot method of the compiler class?21How to use the importmethod method of the

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 log.Println("Hello, playground")5}6func warning(format string, args ...interface{})7import (8func main() {9 fmt.Println("Hello, playground")10 build.Default.Warning("Hello, playground")11}

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3fmt.Println("Hello, playground")4}5./2.go:7:2: imported and not used: "fmt"6./2.go:7:2: imported and not used: "fmt"7import "fmt"8func main() {9fmt.Println("Hello, playground")10}11./3.go:7:2: imported and not used: "fmt"12./3.go:7:2: imported and not used: "fmt"13import "fmt"14func main() {15fmt.Println("Hello, playground")16}17./4.go:7:2: imported and not used: "fmt"18./4.go:7:2: imported and not used: "fmt"19import "fmt"20func main() {21fmt.Println("Hello, playground")22}23./5.go:7:2: imported and not used: "fmt"24./5.go:7:2: imported and not used: "fmt"

Full Screen

Full Screen

warning

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 compiler := new(Compiler)4 compiler.Warning("This is a warning")5}6type Compiler struct {7}8func (c *Compiler) Warning(msg string) {9 t := reflect.TypeOf(c)10 fn := reflect.ValueOf(c).Pointer()11 fnName := runtime.FuncForPC(fn).Name()12 _, file, line, _ := runtime.Caller(1)13 fmt.Printf("%s:%d: %s: %s14}152.go:18: *main.Compiler: main.(*Compiler).Warning: This is a warning16import (17func main() {18 compiler := new(Compiler)19 compiler.Warning("This is a warning")20}21type Compiler struct {22}23func (c *Compiler) Warning(msg string) {24 logFile, err := os.Create("log.txt")25 if err != nil {26 log.Fatal(err)27 }28 log.SetOutput(logFile)29 log.Println("Warning:", msg)30}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful