Skip to content

Commit 4cb0ca0

Browse files
Currently the GWT compiler adds a var declaration for each catch parameter in
a try/catch statement, but this is unneeded according to the spec, and the Closure compiler will issue errors against it. Change-Id: I05dd0429ec22315d57069046b0139ecce045919e Review-Link: https://gwt-review.googlesource.com/#/c/1810/ git-svn-id: http://google-web-toolkit.googlecode.com/svn/trunk@11490 8db76d5a-ed1c-0410-87a9-c151d255dfc7
1 parent c2b226c commit 4cb0ca0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ public boolean visit(JTryStatement x, Context ctx) {
439439
JsParameter jsParam = jsCatch.getParameter();
440440
names.put(arg.getTarget(), jsParam.getName());
441441
catchMap.put(catchBlock, jsCatch);
442+
catchParamIdentifiers.add(jsParam.getName());
442443

443444
push(jsCatch.getScope());
444445
accept(catchBlock);
@@ -1146,7 +1147,9 @@ public void endVisit(JMethodBody x, Context ctx) {
11461147
for (int i = 0; i < locals.size(); ++i) {
11471148
JsName name = names.get(x.getLocals().get(i));
11481149
String ident = name.getIdent();
1149-
if (!alreadySeen.contains(ident)) {
1150+
if (!alreadySeen.contains(ident)
1151+
// Catch block params don't need var declarations
1152+
&& !catchParamIdentifiers.contains(name)) {
11501153
alreadySeen.add(ident);
11511154
vars.add(new JsVar(x.getSourceInfo(), name));
11521155
}
@@ -2337,6 +2340,8 @@ public static JavaToJavaScriptMap exec(JProgram program, JsProgram jsProgram,
23372340

23382341
private final Map<JBlock, JsCatch> catchMap = new IdentityHashMap<JBlock, JsCatch>();
23392342

2343+
private final Set<JsName> catchParamIdentifiers = new HashSet<JsName>();
2344+
23402345
private final Map<JClassType, JsScope> classScopes = new IdentityHashMap<JClassType, JsScope>();
23412346

23422347
/**

0 commit comments

Comments
 (0)