use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class InferJSDocInfoTest method testJSDocFromNamedFunctionPropagatesToDefinedType.
@Test
public void testJSDocFromNamedFunctionPropagatesToDefinedType() {
// Given
testSame(srcs(lines("/**", " * I'm a user type.", " * @constructor", " */", "function Foo() {};", "", // Just a hook to access type "Foo".
"var x = new Foo();")));
JSType xType = inferredTypeOfName("x");
assertThat(xType.toString()).isEqualTo("Foo");
// Then
assertThat(xType.getJSDocInfo().getBlockDescription()).isEqualTo("I'm a user type.");
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class InferJSDocInfoTest method testJSDocFromVariableNameAssignmentPropagatesToDefinedType.
@Test
public void testJSDocFromVariableNameAssignmentPropagatesToDefinedType() {
// Given
testSame(srcs(lines("var /**", " * I'm a user type.", " * @constructor", " */", "Foo = function() {};", "", // Just a hook to access type "Foo".
"var x = new Foo();")));
JSType xType = inferredTypeOfName("x");
assertThat(xType.toString()).isEqualTo("Foo");
// Then
assertThat(xType.getJSDocInfo().getBlockDescription()).isEqualTo("I'm a user type.");
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class InferJSDocInfoTest method testJSDocFromDuplicateDefinitionIsUsedIfThereWasNoOriginalJSDocFromOriginal.
@Test
public void testJSDocFromDuplicateDefinitionIsUsedIfThereWasNoOriginalJSDocFromOriginal() {
// Given
testSame(srcs(lines("var Foo = function() {};", "", "/**", " * I'm a different type.", " * @constructor", " */", "Foo = function() {};", "", // Just a hook to access type "Foo".
"var x = new Foo();")));
JSType xType = inferredTypeOfName("x");
assertThat(xType.toString()).isEqualTo("Foo");
// Then
assertThat(xType.getJSDocInfo().getBlockDescription()).isEqualTo("I'm a different type.");
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class InferJSDocInfoTest method testJSDocIsNotOverriddenByStructuralTypeAssignments_FunctionTypes.
@Test
public void testJSDocIsNotOverriddenByStructuralTypeAssignments_FunctionTypes() {
// Given
testSame(srcs(lines("/**", " * I'm test0.", " * @param {*} a", " * @return {string}", " */", "function test0(a) {};", "", // The type of these objects should be identical.
"/**", " * I'm test1.", " * @param {string} a", " * @return {*}", // We need this so inferrence understands thes two objects/types are stuck together.
" * @const", " */", "var test1 = test0;")));
JSType test0Type = inferredTypeOfName("test0");
JSType test1Type = inferredTypeOfName("test1");
assertThat(test1Type).isSameInstanceAs(test0Type);
// Then
assertThat(test0Type.getJSDocInfo().getBlockDescription()).isEqualTo("I'm test0.");
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class InferJSDocInfoTest method testJSDocFromExternTypesIsPreserved.
@Test
public void testJSDocFromExternTypesIsPreserved() {
// Given
testSame(externs(lines("/**", " * I'm an Object.", " * @param {*=} x", " * @return {!Object}", " * @constructor", " */", "function Object(x) {};")), srcs("var x = new Object();"));
JSType xType = inferredTypeOfName("x");
assertThat(xType.toString()).isEqualTo("Object");
// Then
assertThat(xType.getJSDocInfo().getBlockDescription()).isEqualTo("I'm an Object.");
}
Aggregations