github.com/evanw/esbuild@v0.21.4/internal/logger/msg_ids.go (about) 1 package logger 2 3 // Most non-error log messages are given a message ID that can be used to set 4 // the log level for that message. Errors do not get a message ID because you 5 // cannot turn errors into non-errors (otherwise the build would incorrectly 6 // succeed). Some internal log messages do not get a message ID because they 7 // are part of verbose and/or internal debugging output. These messages use 8 // "MsgID_None" instead. 9 type MsgID = uint8 10 11 const ( 12 MsgID_None MsgID = iota 13 14 // JavaScript 15 MsgID_JS_AssertToWith 16 MsgID_JS_AssertTypeJSON 17 MsgID_JS_AssignToConstant 18 MsgID_JS_AssignToDefine 19 MsgID_JS_AssignToImport 20 MsgID_JS_CallImportNamespace 21 MsgID_JS_ClassNameWillThrow 22 MsgID_JS_CommonJSVariableInESM 23 MsgID_JS_DeleteSuperProperty 24 MsgID_JS_DirectEval 25 MsgID_JS_DuplicateCase 26 MsgID_JS_DuplicateClassMember 27 MsgID_JS_DuplicateObjectKey 28 MsgID_JS_EmptyImportMeta 29 MsgID_JS_EqualsNaN 30 MsgID_JS_EqualsNegativeZero 31 MsgID_JS_EqualsNewObject 32 MsgID_JS_HTMLCommentInJS 33 MsgID_JS_ImpossibleTypeof 34 MsgID_JS_IndirectRequire 35 MsgID_JS_PrivateNameWillThrow 36 MsgID_JS_SemicolonAfterReturn 37 MsgID_JS_SuspiciousBooleanNot 38 MsgID_JS_SuspiciousDefine 39 MsgID_JS_SuspiciousLogicalOperator 40 MsgID_JS_SuspiciousNullishCoalescing 41 MsgID_JS_ThisIsUndefinedInESM 42 MsgID_JS_UnsupportedDynamicImport 43 MsgID_JS_UnsupportedJSXComment 44 MsgID_JS_UnsupportedRegExp 45 MsgID_JS_UnsupportedRequireCall 46 47 // CSS 48 MsgID_CSS_CSSSyntaxError 49 MsgID_CSS_InvalidAtCharset 50 MsgID_CSS_InvalidAtImport 51 MsgID_CSS_InvalidAtLayer 52 MsgID_CSS_InvalidCalc 53 MsgID_CSS_JSCommentInCSS 54 MsgID_CSS_UndefinedComposesFrom 55 MsgID_CSS_UnsupportedAtCharset 56 MsgID_CSS_UnsupportedAtNamespace 57 MsgID_CSS_UnsupportedCSSProperty 58 MsgID_CSS_UnsupportedCSSNesting 59 60 // Bundler 61 MsgID_Bundler_AmbiguousReexport 62 MsgID_Bundler_DifferentPathCase 63 MsgID_Bundler_EmptyGlob 64 MsgID_Bundler_IgnoredBareImport 65 MsgID_Bundler_IgnoredDynamicImport 66 MsgID_Bundler_ImportIsUndefined 67 MsgID_Bundler_RequireResolveNotExternal 68 69 // Source maps 70 MsgID_SourceMap_InvalidSourceMappings 71 MsgID_SourceMap_SectionsInSourceMap 72 MsgID_SourceMap_MissingSourceMap 73 MsgID_SourceMap_UnsupportedSourceMapComment 74 75 // package.json 76 MsgID_PackageJSON_FIRST // Keep this first 77 MsgID_PackageJSON_InvalidBrowser 78 MsgID_PackageJSON_InvalidImportsOrExports 79 MsgID_PackageJSON_InvalidSideEffects 80 MsgID_PackageJSON_InvalidType 81 MsgID_PackageJSON_LAST // Keep this last 82 83 // tsconfig.json 84 MsgID_TSConfigJSON_FIRST // Keep this first 85 MsgID_TSConfigJSON_Cycle 86 MsgID_TSConfigJSON_InvalidImportsNotUsedAsValues 87 MsgID_TSConfigJSON_InvalidJSX 88 MsgID_TSConfigJSON_InvalidPaths 89 MsgID_TSConfigJSON_InvalidTarget 90 MsgID_TSConfigJSON_InvalidTopLevelOption 91 MsgID_TSConfigJSON_Missing 92 MsgID_TSConfigJSON_LAST // Keep this last 93 94 MsgID_END // Keep this at the end (used only for tests) 95 ) 96 97 func StringToMsgIDs(str string, logLevel LogLevel, overrides map[MsgID]LogLevel) { 98 switch str { 99 // JS 100 case "assert-to-with": 101 overrides[MsgID_JS_AssertToWith] = logLevel 102 case "assert-type-json": 103 overrides[MsgID_JS_AssertTypeJSON] = logLevel 104 case "assign-to-constant": 105 overrides[MsgID_JS_AssignToConstant] = logLevel 106 case "assign-to-define": 107 overrides[MsgID_JS_AssignToDefine] = logLevel 108 case "assign-to-import": 109 overrides[MsgID_JS_AssignToImport] = logLevel 110 case "call-import-namespace": 111 overrides[MsgID_JS_CallImportNamespace] = logLevel 112 case "class-name-will-throw": 113 overrides[MsgID_JS_ClassNameWillThrow] = logLevel 114 case "commonjs-variable-in-esm": 115 overrides[MsgID_JS_CommonJSVariableInESM] = logLevel 116 case "delete-super-property": 117 overrides[MsgID_JS_DeleteSuperProperty] = logLevel 118 case "direct-eval": 119 overrides[MsgID_JS_DirectEval] = logLevel 120 case "duplicate-case": 121 overrides[MsgID_JS_DuplicateCase] = logLevel 122 case "duplicate-class-member": 123 overrides[MsgID_JS_DuplicateClassMember] = logLevel 124 case "duplicate-object-key": 125 overrides[MsgID_JS_DuplicateObjectKey] = logLevel 126 case "empty-import-meta": 127 overrides[MsgID_JS_EmptyImportMeta] = logLevel 128 case "equals-nan": 129 overrides[MsgID_JS_EqualsNaN] = logLevel 130 case "equals-negative-zero": 131 overrides[MsgID_JS_EqualsNegativeZero] = logLevel 132 case "equals-new-object": 133 overrides[MsgID_JS_EqualsNewObject] = logLevel 134 case "html-comment-in-js": 135 overrides[MsgID_JS_HTMLCommentInJS] = logLevel 136 case "impossible-typeof": 137 overrides[MsgID_JS_ImpossibleTypeof] = logLevel 138 case "indirect-require": 139 overrides[MsgID_JS_IndirectRequire] = logLevel 140 case "private-name-will-throw": 141 overrides[MsgID_JS_PrivateNameWillThrow] = logLevel 142 case "semicolon-after-return": 143 overrides[MsgID_JS_SemicolonAfterReturn] = logLevel 144 case "suspicious-boolean-not": 145 overrides[MsgID_JS_SuspiciousBooleanNot] = logLevel 146 case "suspicious-define": 147 overrides[MsgID_JS_SuspiciousDefine] = logLevel 148 case "suspicious-logical-operator": 149 overrides[MsgID_JS_SuspiciousLogicalOperator] = logLevel 150 case "suspicious-nullish-coalescing": 151 overrides[MsgID_JS_SuspiciousNullishCoalescing] = logLevel 152 case "this-is-undefined-in-esm": 153 overrides[MsgID_JS_ThisIsUndefinedInESM] = logLevel 154 case "unsupported-dynamic-import": 155 overrides[MsgID_JS_UnsupportedDynamicImport] = logLevel 156 case "unsupported-jsx-comment": 157 overrides[MsgID_JS_UnsupportedJSXComment] = logLevel 158 case "unsupported-regexp": 159 overrides[MsgID_JS_UnsupportedRegExp] = logLevel 160 case "unsupported-require-call": 161 overrides[MsgID_JS_UnsupportedRequireCall] = logLevel 162 163 // CSS 164 case "css-syntax-error": 165 overrides[MsgID_CSS_CSSSyntaxError] = logLevel 166 case "invalid-@charset": 167 overrides[MsgID_CSS_InvalidAtCharset] = logLevel 168 case "invalid-@import": 169 overrides[MsgID_CSS_InvalidAtImport] = logLevel 170 case "invalid-@layer": 171 overrides[MsgID_CSS_InvalidAtLayer] = logLevel 172 case "invalid-calc": 173 overrides[MsgID_CSS_InvalidCalc] = logLevel 174 case "js-comment-in-css": 175 overrides[MsgID_CSS_JSCommentInCSS] = logLevel 176 case "undefined-composes-from": 177 overrides[MsgID_CSS_UndefinedComposesFrom] = logLevel 178 case "unsupported-@charset": 179 overrides[MsgID_CSS_UnsupportedAtCharset] = logLevel 180 case "unsupported-@namespace": 181 overrides[MsgID_CSS_UnsupportedAtNamespace] = logLevel 182 case "unsupported-css-property": 183 overrides[MsgID_CSS_UnsupportedCSSProperty] = logLevel 184 case "unsupported-css-nesting": 185 overrides[MsgID_CSS_UnsupportedCSSNesting] = logLevel 186 187 // Bundler 188 case "ambiguous-reexport": 189 overrides[MsgID_Bundler_AmbiguousReexport] = logLevel 190 case "different-path-case": 191 overrides[MsgID_Bundler_DifferentPathCase] = logLevel 192 case "empty-glob": 193 overrides[MsgID_Bundler_EmptyGlob] = logLevel 194 case "ignored-bare-import": 195 overrides[MsgID_Bundler_IgnoredBareImport] = logLevel 196 case "ignored-dynamic-import": 197 overrides[MsgID_Bundler_IgnoredDynamicImport] = logLevel 198 case "import-is-undefined": 199 overrides[MsgID_Bundler_ImportIsUndefined] = logLevel 200 case "require-resolve-not-external": 201 overrides[MsgID_Bundler_RequireResolveNotExternal] = logLevel 202 203 // Source maps 204 case "invalid-source-mappings": 205 overrides[MsgID_SourceMap_InvalidSourceMappings] = logLevel 206 case "sections-in-source-map": 207 overrides[MsgID_SourceMap_SectionsInSourceMap] = logLevel 208 case "missing-source-map": 209 overrides[MsgID_SourceMap_MissingSourceMap] = logLevel 210 case "unsupported-source-map-comment": 211 overrides[MsgID_SourceMap_UnsupportedSourceMapComment] = logLevel 212 213 case "package.json": 214 for i := MsgID_PackageJSON_FIRST; i <= MsgID_PackageJSON_LAST; i++ { 215 overrides[i] = logLevel 216 } 217 218 case "tsconfig.json": 219 for i := MsgID_TSConfigJSON_FIRST; i <= MsgID_TSConfigJSON_LAST; i++ { 220 overrides[i] = logLevel 221 } 222 223 default: 224 // Ignore invalid entries since this message id may have 225 // been renamed/removed since when this code was written 226 } 227 } 228 229 func MsgIDToString(id MsgID) string { 230 switch id { 231 // JS 232 case MsgID_JS_AssertToWith: 233 return "assert-to-with" 234 case MsgID_JS_AssertTypeJSON: 235 return "assert-type-json" 236 case MsgID_JS_AssignToConstant: 237 return "assign-to-constant" 238 case MsgID_JS_AssignToDefine: 239 return "assign-to-define" 240 case MsgID_JS_AssignToImport: 241 return "assign-to-import" 242 case MsgID_JS_CallImportNamespace: 243 return "call-import-namespace" 244 case MsgID_JS_ClassNameWillThrow: 245 return "class-name-will-throw" 246 case MsgID_JS_CommonJSVariableInESM: 247 return "commonjs-variable-in-esm" 248 case MsgID_JS_DeleteSuperProperty: 249 return "delete-super-property" 250 case MsgID_JS_DirectEval: 251 return "direct-eval" 252 case MsgID_JS_DuplicateCase: 253 return "duplicate-case" 254 case MsgID_JS_DuplicateClassMember: 255 return "duplicate-class-member" 256 case MsgID_JS_DuplicateObjectKey: 257 return "duplicate-object-key" 258 case MsgID_JS_EmptyImportMeta: 259 return "empty-import-meta" 260 case MsgID_JS_EqualsNaN: 261 return "equals-nan" 262 case MsgID_JS_EqualsNegativeZero: 263 return "equals-negative-zero" 264 case MsgID_JS_EqualsNewObject: 265 return "equals-new-object" 266 case MsgID_JS_HTMLCommentInJS: 267 return "html-comment-in-js" 268 case MsgID_JS_ImpossibleTypeof: 269 return "impossible-typeof" 270 case MsgID_JS_IndirectRequire: 271 return "indirect-require" 272 case MsgID_JS_PrivateNameWillThrow: 273 return "private-name-will-throw" 274 case MsgID_JS_SemicolonAfterReturn: 275 return "semicolon-after-return" 276 case MsgID_JS_SuspiciousBooleanNot: 277 return "suspicious-boolean-not" 278 case MsgID_JS_SuspiciousDefine: 279 return "suspicious-define" 280 case MsgID_JS_SuspiciousLogicalOperator: 281 return "suspicious-logical-operator" 282 case MsgID_JS_SuspiciousNullishCoalescing: 283 return "suspicious-nullish-coalescing" 284 case MsgID_JS_ThisIsUndefinedInESM: 285 return "this-is-undefined-in-esm" 286 case MsgID_JS_UnsupportedDynamicImport: 287 return "unsupported-dynamic-import" 288 case MsgID_JS_UnsupportedJSXComment: 289 return "unsupported-jsx-comment" 290 case MsgID_JS_UnsupportedRegExp: 291 return "unsupported-regexp" 292 case MsgID_JS_UnsupportedRequireCall: 293 return "unsupported-require-call" 294 295 // CSS 296 case MsgID_CSS_CSSSyntaxError: 297 return "css-syntax-error" 298 case MsgID_CSS_InvalidAtCharset: 299 return "invalid-@charset" 300 case MsgID_CSS_InvalidAtImport: 301 return "invalid-@import" 302 case MsgID_CSS_InvalidAtLayer: 303 return "invalid-@layer" 304 case MsgID_CSS_InvalidCalc: 305 return "invalid-calc" 306 case MsgID_CSS_JSCommentInCSS: 307 return "js-comment-in-css" 308 case MsgID_CSS_UndefinedComposesFrom: 309 return "undefined-composes-from" 310 case MsgID_CSS_UnsupportedAtCharset: 311 return "unsupported-@charset" 312 case MsgID_CSS_UnsupportedAtNamespace: 313 return "unsupported-@namespace" 314 case MsgID_CSS_UnsupportedCSSProperty: 315 return "unsupported-css-property" 316 case MsgID_CSS_UnsupportedCSSNesting: 317 return "unsupported-css-nesting" 318 319 // Bundler 320 case MsgID_Bundler_AmbiguousReexport: 321 return "ambiguous-reexport" 322 case MsgID_Bundler_DifferentPathCase: 323 return "different-path-case" 324 case MsgID_Bundler_EmptyGlob: 325 return "empty-glob" 326 case MsgID_Bundler_IgnoredBareImport: 327 return "ignored-bare-import" 328 case MsgID_Bundler_IgnoredDynamicImport: 329 return "ignored-dynamic-import" 330 case MsgID_Bundler_ImportIsUndefined: 331 return "import-is-undefined" 332 case MsgID_Bundler_RequireResolveNotExternal: 333 return "require-resolve-not-external" 334 335 // Source maps 336 case MsgID_SourceMap_InvalidSourceMappings: 337 return "invalid-source-mappings" 338 case MsgID_SourceMap_SectionsInSourceMap: 339 return "sections-in-source-map" 340 case MsgID_SourceMap_MissingSourceMap: 341 return "missing-source-map" 342 case MsgID_SourceMap_UnsupportedSourceMapComment: 343 return "unsupported-source-map-comment" 344 345 default: 346 if id >= MsgID_PackageJSON_FIRST && id <= MsgID_PackageJSON_LAST { 347 return "package.json" 348 } 349 if id >= MsgID_TSConfigJSON_FIRST && id <= MsgID_TSConfigJSON_LAST { 350 return "tsconfig.json" 351 } 352 } 353 354 return "" 355 } 356 357 // Some message IDs are more diverse internally than externally (in case we 358 // want to expand the set of them later on). So just map these to the largest 359 // one arbitrarily since you can't tell the difference externally anyway. 360 func StringToMaximumMsgID(id string) MsgID { 361 overrides := make(map[MsgID]LogLevel) 362 maxID := MsgID_None 363 StringToMsgIDs(id, LevelInfo, overrides) 364 for id := range overrides { 365 if id > maxID { 366 maxID = id 367 } 368 } 369 return maxID 370 }