}
CYTarget *CYArrayComprehension::Replace(CYContext &context) {
- CYVariable *cyv($V("$cyv"));
+ CYIdentifier *cyv(context.Unique());
- return $C0($F(NULL, $P1($L($I("$cyv")), comprehensions_->Parameters(context)), $$
- ->* $E($ CYAssign(cyv, $ CYArray()))
- ->* comprehensions_->Replace(context, $E($C1($M(cyv, $S("push")), expression_)))
- ->* $ CYReturn(cyv)
+ return $C0($F(NULL, $P1($L(cyv), comprehensions_->Parameters(context)), $$
+ ->* $E($ CYAssign($V(cyv), $ CYArray()))
+ ->* comprehensions_->Replace(context, $E($C1($M($V(cyv), $S("push")), expression_)))
+ ->* $ CYReturn($V(cyv))
));
}
return this;
}
+CYStatement *CYForInitialized::Replace(CYContext &context) {
+ CYAssignment *assignment(declaration_->Replace(context, CYIdentifierVariable));
+ return $ CYBlock($$
+ ->* (assignment == NULL ? NULL : $ CYExpress(assignment))
+ ->* $ CYForIn(declaration_->Target(context), set_, code_));
+}
+
CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const {
return $ CYFunctionParameter(declaration_);
}
}
CYStatement *CYForOfComprehension::Replace(CYContext &context, CYStatement *statement) const {
- CYIdentifier *cys($I("$cys"));
+ CYIdentifier *cys(context.Unique());
- return $E($C0($F(NULL, $P1($L($I("$cys"))), $$
- ->* $E($ CYAssign($V(cys), set_))
+ return $ CYBlock($$
+ ->* $ CYLet(false, $L1($L(cys, set_)))
->* $ CYForIn(declaration_->Target(context), $V(cys), $ CYBlock($$
->* $E($ CYAssign(declaration_->Target(context), $M($V(cys), declaration_->Target(context))))
->* CYComprehension::Replace(context, statement)
- ))
)));
}
CYScope scope(!localize, context);
+ $I("arguments")->Replace(context, CYIdentifierMagic);
+
parameters_->Replace(context, code_);
context.ReplaceAll(code_);
}
CYProperty *CYProperty::ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update) {
- update |= name_->Computed();
+ update |= Update();
if (update)
Replace(context, builder, self, false);
if (next_ != NULL)
Replace(context, builder, self, name, protect);
}
+bool CYProperty::Update() const {
+ return name_->Computed();
+}
+
void CYPropertyGetter::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) {
CYIdentifier *unique(context.Unique());
builder.declarations_
CYDefineProperty(self, name, true, !protect, $ CYPropertyValue($S("value"), $V(unique), $ CYPropertyValue($S("writable"), $ CYTrue()))));
}
+bool CYPropertyMethod::Update() const {
+ return true;
+}
+
void CYPropertySetter::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) {
CYIdentifier *unique(context.Unique());
builder.declarations_
if (existing == NULL)
return internal_;
- switch (kind) {
- case CYIdentifierArgument:
- case CYIdentifierCatch:
- case CYIdentifierMagic:
- _assert(false);
- default:
- break;
- }
-
- if (existing->kind_ == CYIdentifierGlobal)
+ if (kind == CYIdentifierGlobal);
+ else if (existing->kind_ == CYIdentifierGlobal || existing->kind_ == CYIdentifierMagic)
existing->kind_ = kind;
- else if (kind == CYIdentifierGlobal)
- ;
else if (existing->kind_ == CYIdentifierLexical || kind == CYIdentifierLexical)
_assert(false); // XXX: throw new SyntaxError()
CYStatement *CYWith::Replace(CYContext &context) {
context.Replace(scope_);
+ CYScope scope(true, context);
+ scope.Damage();
context.ReplaceAll(code_);
+ scope.Close(context);
return this;
}