Skip to content

Commit

Permalink
Fix typo in language mode warning and remove ES6 specific warning to …
Browse files Browse the repository at this point in the history
…be consistent with other language modes warnings.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187101468
  • Loading branch information
concavelenz authored and Tyler Breisacher committed Feb 27, 2018
1 parent 2edc2a5 commit f793585
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
10 changes: 4 additions & 6 deletions src/com/google/javascript/jscomp/RhinoErrorReporter.java
Expand Up @@ -93,10 +93,8 @@ class RhinoErrorReporter {
static final DiagnosticType STRING_CONTINUATION = static final DiagnosticType STRING_CONTINUATION =
DiagnosticType.warning("JSC_STRING_CONTINUATION", "{0}"); DiagnosticType.warning("JSC_STRING_CONTINUATION", "{0}");


static final DiagnosticType ES6_FEATURE = static final DiagnosticType LANGUAGE_FEATURE =
DiagnosticType.error("ES6_FEATURE", DiagnosticType.error("JSC_LANGUAGE_FEATURE", "{0}.");
"{0}. Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT " +
"or higher to enable ES6 features.");


static final DiagnosticType ES6_TYPED = static final DiagnosticType ES6_TYPED =
DiagnosticType.error("ES6_TYPED", DiagnosticType.error("ES6_TYPED",
Expand Down Expand Up @@ -177,8 +175,8 @@ private RhinoErrorReporter(AbstractCompiler compiler) {
.put(Pattern.compile("^String continuations.*"), STRING_CONTINUATION) .put(Pattern.compile("^String continuations.*"), STRING_CONTINUATION)


.put( .put(
Pattern.compile("^this language feature is only supported for ECMASCRIPT6 mode.*"), Pattern.compile("^This language feature is only supported for .*"),
ES6_FEATURE) LANGUAGE_FEATURE)


.put(Pattern.compile("^type syntax is only supported in ES6 typed mode.*"), ES6_TYPED) .put(Pattern.compile("^type syntax is only supported in ES6 typed mode.*"), ES6_TYPED)


Expand Down
22 changes: 10 additions & 12 deletions src/com/google/javascript/jscomp/parsing/IRFactory.java
Expand Up @@ -860,14 +860,18 @@ static int charno(SourcePosition location) {
return location.column; return location.column;
} }


String languageFeatureWarningMessage(Feature feature) {
return "This language feature is only supported for "
+ LanguageMode.minimumRequiredFor(feature)
+ " mode or better: "
+ feature;
}

void maybeWarnForFeature(ParseTree node, Feature feature) { void maybeWarnForFeature(ParseTree node, Feature feature) {
features = features.with(feature); features = features.with(feature);
if (!isSupportedForInputLanguageMode(feature)) { if (!isSupportedForInputLanguageMode(feature)) {
errorReporter.warning( errorReporter.warning(
"this language feature is only supported for " languageFeatureWarningMessage(feature),
+ LanguageMode.minimumRequiredFor(feature)
+ " mode or better: "
+ feature,
sourceName, sourceName,
lineno(node), charno(node)); lineno(node), charno(node));
} }
Expand All @@ -878,10 +882,7 @@ void maybeWarnForFeature(
features = features.with(feature); features = features.with(feature);
if (!isSupportedForInputLanguageMode(feature)) { if (!isSupportedForInputLanguageMode(feature)) {
errorReporter.warning( errorReporter.warning(
"this language feature is only supported for " languageFeatureWarningMessage(feature),
+ LanguageMode.minimumRequiredFor(feature)
+ " mode or better: "
+ feature,
sourceName, sourceName,
lineno(token), charno(token)); lineno(token), charno(token));
} }
Expand All @@ -891,10 +892,7 @@ void maybeWarnForFeature(Node node, Feature feature) {
features = features.with(feature); features = features.with(feature);
if (!isSupportedForInputLanguageMode(feature)) { if (!isSupportedForInputLanguageMode(feature)) {
errorReporter.warning( errorReporter.warning(
"this language feature is only supported for " languageFeatureWarningMessage(feature),
+ LanguageMode.minimumRequiredFor(feature)
+ " mode or better: "
+ feature,
sourceName, sourceName,
node.getLineno(), node.getCharno()); node.getLineno(), node.getCharno());
} }
Expand Down
4 changes: 2 additions & 2 deletions test/com/google/javascript/jscomp/CommandLineRunnerTest.java
Expand Up @@ -508,12 +508,12 @@ public void testCssNameWiring() throws Exception {


public void testIssue70a() { public void testIssue70a() {
args.add("--language_in=ECMASCRIPT5"); args.add("--language_in=ECMASCRIPT5");
test("function foo({}) {}", RhinoErrorReporter.ES6_FEATURE); test("function foo({}) {}", RhinoErrorReporter.LANGUAGE_FEATURE);
} }


public void testIssue70b() { public void testIssue70b() {
args.add("--language_in=ECMASCRIPT5"); args.add("--language_in=ECMASCRIPT5");
test("function foo([]) {}", RhinoErrorReporter.ES6_FEATURE); test("function foo([]) {}", RhinoErrorReporter.LANGUAGE_FEATURE);
} }


public void testIssue81() { public void testIssue81() {
Expand Down
2 changes: 1 addition & 1 deletion test/com/google/javascript/jscomp/NodeUtilTest.java
Expand Up @@ -51,7 +51,7 @@ public final class NodeUtilTest extends TestCase {


private static Node parse(String js) { private static Node parse(String js) {
CompilerOptions options = new CompilerOptions(); CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_2015); options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);


// To allow octal literals such as 0123 to be parsed. // To allow octal literals such as 0123 to be parsed.
options.setStrictModeInput(false); options.setStrictModeInput(false);
Expand Down
2 changes: 1 addition & 1 deletion test/com/google/javascript/jscomp/parsing/ParserTest.java
Expand Up @@ -3826,7 +3826,7 @@ private static String getRequiresEsNextMessage(Feature feature) {


private static String requiresLanguageModeMessage(LanguageMode languageMode, Feature feature) { private static String requiresLanguageModeMessage(LanguageMode languageMode, Feature feature) {
return String.format( return String.format(
"this language feature is only supported for %s mode or better: %s", "This language feature is only supported for %s mode or better: %s",
languageMode, languageMode,
feature); feature);
} }
Expand Down

0 comments on commit f793585

Please sign in to comment.