+ " have the same discrepencies on IE 6 as function constructors",
synopsis="")
public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
if (node instanceof FunctionDeclaration) {
FunctionDeclaration decl = ((FunctionDeclaration) node);
FunctionConstructor ctor = decl.getInitializer();
Scope s2 = Scope.fromFunctionConstructor(scope, ctor);
FunctionConstructor rewritten
= (FunctionConstructor) QuasiBuilder.substV(
"function @ident(@formals*) { @stmts*; @body*; }",
"ident", ctor.getIdentifier(),
"formals", expandAll(
new ParseTreeNodeContainer(ctor.getParams()), s2),
"stmts", new ParseTreeNodeContainer(s2.getStartStatements()),
"body", expandAll(
new ParseTreeNodeContainer(ctor.getBody().children()), s2)
);
return new FunctionDeclaration(rewritten);
}
return NONE;
}
});
w.addRule(new Rule() {
@Override
@RuleDescription(
name="ie6functions",
reason="simulate IE 6's broken scoping of function constructors as "
+ "described in JScript Deviations Section 2.3",
synopsis="")
public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
if (node instanceof FunctionConstructor) {
FunctionConstructor ctor = (FunctionConstructor) node;
Scope s2 = Scope.fromFunctionConstructor(scope, ctor);
if (ctor.getIdentifierName() == null) {
return expandAll(node, s2);
}
Identifier ident = ctor.getIdentifier();
Reference identRef = new Reference(ident);
identRef.setFilePosition(ident.getFilePosition());
scope.addStartStatement(
new Declaration(FilePosition.UNKNOWN, ident, identRef));
return QuasiBuilder.substV(
"(@var = function @ident(@formals*) { @stmts*; @body*; })",
"var", identRef,
"ident", ident,
"formals", new ParseTreeNodeContainer(ctor.getParams()),
"stmts", new ParseTreeNodeContainer(s2.getStartStatements()),
"body", expandAll(
new ParseTreeNodeContainer(ctor.getBody().children()), s2)
);
}
return NONE;
}
});