Skip to content

Commit

Permalink
Allow command line option control for CommonJS module loading errors.
Browse files Browse the repository at this point in the history
Closes #2056

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135125911
  • Loading branch information
brad4d authored and blickly committed Oct 5, 2016
1 parent 6d1c49d commit 98ffc24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/DiagnosticGroups.java
Expand Up @@ -98,6 +98,7 @@ public DiagnosticGroup forName(String name) {
static final String DIAGNOSTIC_GROUP_NAMES =
"accessControls, ambiguousFunctionDecl, checkEventfulObjectDisposal, "
+ "checkRegExp, checkTypes, checkVars, "
+ "commonJsModuleLoad, "
+ "conformanceViolations, const, constantProperty, deprecated, "
+ "deprecatedAnnotations, duplicateMessage, es3, "
+ "es5Strict, externsValidation, fileoverviewTags, globalThis, "
Expand All @@ -110,6 +111,10 @@ public DiagnosticGroup forName(String name) {
+ "unusedLocalVariables, unusedPrivateMembers, uselessCode, "
+ "useOfGoogBase, underscore, visibility";

public static final DiagnosticGroup COMMON_JS_MODULE_LOAD =
DiagnosticGroups.registerGroup(
"commonJsModuleLoad", ProcessCommonJSModules.COMMON_JS_MODULE_LOAD_ERROR);

public static final DiagnosticGroup GLOBAL_THIS =
DiagnosticGroups.registerGroup("globalThis",
CheckGlobalThis.GLOBAL_THIS);
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/ProcessCommonJSModules.java
Expand Up @@ -43,7 +43,7 @@ public final class ProcessCommonJSModules implements CompilerPass {
private static final String EXPORTS = "exports";
private static final String MODULE = "module";

private static final DiagnosticType LOAD_ERROR = DiagnosticType.error(
public static final DiagnosticType COMMON_JS_MODULE_LOAD_ERROR = DiagnosticType.error(
"JSC_COMMONJS_MODULE_LOAD_ERROR",
"Failed to load module \"{0}\"");

Expand Down Expand Up @@ -323,7 +323,7 @@ private void visitRequireCall(NodeTraversal t, Node require, Node parent) {
String requireName = require.getSecondChild().getString();
ModulePath modulePath = t.getInput().getPath().resolveCommonJsModule(requireName);
if (modulePath == null) {
compiler.report(t.makeError(require, LOAD_ERROR, requireName));
compiler.report(t.makeError(require, COMMON_JS_MODULE_LOAD_ERROR, requireName));
return;
}

Expand Down Expand Up @@ -716,7 +716,7 @@ private void fixTypeNode(NodeTraversal t, Node typeNode) {
String moduleName = name.substring(0, endIndex);
ModulePath modulePath = t.getInput().getPath().resolveCommonJsModule(moduleName);
if (modulePath == null) {
t.makeError(typeNode, LOAD_ERROR, moduleName);
t.makeError(typeNode, COMMON_JS_MODULE_LOAD_ERROR, moduleName);
return;
}

Expand Down

0 comments on commit 98ffc24

Please sign in to comment.