Permalink
Browse files

FIX: new @ (and related)

ALL 1098 PASS
  • Loading branch information...
shanebdavis committed Jan 9, 2018
1 parent f484ccf commit 6580675895f27bf88b43d118e88b51d3a9ff4610
@@ -130,6 +130,7 @@ import &StandardImport, &CaffeineEight
@rule
simpleNewValue:
:this
:thisProperty
:globalIdentifier
:identifierReference
@@ -6,7 +6,7 @@ class NewInstanceStn extends &BaseStn
[child] = @children
childJs =
switch child.type
when :FunctionInvocation, :Reference, :GlobalIdentifier
when :FunctionInvocation, :Reference, :GlobalIdentifier, :This
child.toJs newObjectFunctionInvocation: true
else
"(#{child.toJs()})"
@@ -28,7 +28,11 @@ class FunctionInvocationStn extends &AccessorChainStn
valueJs = @functionValue.toJsExpression()
if newObjectFunctionInvocation
valueJs = "(#{valueJs})" unless @functionValue.type == :Reference || @functionValue.type == :GlobalIdentifier
switch @functionValue.type
when :Reference, :GlobalIdentifier, :This
null
else
valueJs = "(#{valueJs})"
"#{valueJs}#{@applyRequiredParens (array a in @argStns with a.toJsExpression()).join ', '}"
@@ -46,6 +46,7 @@ Caf.defMod(module, () => {
});
this.rule({
simpleNewValue: [
"this",
"thisProperty",
"globalIdentifier",
"identifierReference",
@@ -14,6 +14,7 @@ Caf.defMod(module, () => {
case "FunctionInvocation":
case "Reference":
case "GlobalIdentifier":
case "This":
return child.toJs({ newObjectFunctionInvocation: true });
default:
return `(${Caf.toString(child.toJs())})`;
@@ -53,13 +53,14 @@ Caf.defMod(module, () => {
}
valueJs = this.functionValue.toJsExpression();
if (newObjectFunctionInvocation) {
if (
!(
this.functionValue.type === "Reference" ||
this.functionValue.type === "GlobalIdentifier"
)
) {
valueJs = `(${Caf.toString(valueJs)})`;
switch (this.functionValue.type) {
case "Reference":
case "GlobalIdentifier":
case "This":
null;
break;
default:
valueJs = `(${Caf.toString(valueJs)})`;
}
}
return `${Caf.toString(valueJs)}${Caf.toString(
@@ -33,6 +33,14 @@ module.exports = suite: parseTestSuite
.bar
""": "(new Foo).bar;"
withThisBase:
"new @": "new this;"
"new @ props, children": "new this(props, children);"
withThisProp:
"new @foo": "new this.foo;"
"new @foo props, children": "new this.foo(props, children);"
withLiteralRequire:
"new require('caffeine-eight').foo": '(new require("caffeine-eight")).foo;'
"new require('caffeine-eight') 123": 'new require("caffeine-eight")(123);'

0 comments on commit 6580675

Please sign in to comment.