Search in sources :

Example 1 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class NodeTest method testSerializeProperties_isDeclaredConstant.

@Test
public void testSerializeProperties_isDeclaredConstant() {
    Node node = new Node(Token.NAME);
    node.setDeclaredConstantVar(true);
    EnumSet<NodeProperty> result = node.serializeProperties();
    assertThat(result).containsExactly(NodeProperty.IS_DECLARED_CONSTANT);
}
Also used : NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Example 2 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class PropTranslator method setProps.

private static final void setProps() {
    for (Prop rhinoProp : Prop.values()) {
        NodeProperty protoProp = serializeProp(rhinoProp);
        if (protoProp != null) {
            protoToRhinoProp[protoProp.ordinal()] = rhinoProp;
            rhinoToProtoProp[rhinoProp.ordinal()] = protoProp;
        }
    }
}
Also used : Prop(com.google.javascript.rhino.Node.Prop) NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty)

Example 3 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class NodeTest method testSerializeProperties_untranslatableRhinoProp.

@Test
public void testSerializeProperties_untranslatableRhinoProp() {
    Node node = getCall("A");
    node.setSideEffectFlags(2);
    EnumSet<NodeProperty> result = node.serializeProperties();
    // Rhino node prop SIDE_EFFECT_FLAGS does not have a corresponding NodeProperty
    assertThat(node.getSideEffectFlags()).isEqualTo(2);
    assertThat(result).isEmpty();
}
Also used : NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Example 4 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class NodeTest method testSerializeProperties.

@Test
public void testSerializeProperties() {
    Node node = IR.function(IR.name(""), IR.paramList(), IR.block());
    node.setIsAsyncFunction(true);
    node.setIsGeneratorFunction(true);
    EnumSet<NodeProperty> result = node.serializeProperties();
    assertThat(result).containsExactly(NodeProperty.GENERATOR_FN, NodeProperty.ASYNC_FN);
}
Also used : NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Example 5 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class NodeTest method testSerializeProperties_typeBeforeCast.

@Test
public void testSerializeProperties_typeBeforeCast() {
    TestErrorReporter testErrorReporter = new TestErrorReporter();
    JSTypeRegistry registry = new JSTypeRegistry(testErrorReporter);
    Node node = Node.newString(Token.NAME, "f");
    node.setJSTypeBeforeCast(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
    EnumSet<NodeProperty> result = node.serializeProperties();
    // Special case: Rhino node prop TYPE_BEFORE_CAST is converted to NodeProperty.COLOR_FROM_CAST
    assertThat(result).containsExactly(NodeProperty.COLOR_FROM_CAST);
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Aggregations

NodeProperty (com.google.javascript.jscomp.serialization.NodeProperty)7 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)5 Test (org.junit.Test)5 Prop (com.google.javascript.rhino.Node.Prop)1 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)1 TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)1