Skip to content

Commit

Permalink
Test cases to show collapse property behavior for object methods
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164630454
  • Loading branch information
simran-arora authored and blickly committed Aug 8, 2017
1 parent b9350a8 commit e44a6d8
Showing 1 changed file with 49 additions and 18 deletions.
67 changes: 49 additions & 18 deletions test/com/google/javascript/jscomp/CollapsePropertiesTest.java
Expand Up @@ -1700,8 +1700,6 @@ public void testComputedPropertyNames() {
"bar.foo();"));
}

// What should be the ideal behavior of these? Should a function such as Bar.getB() be renamed to
// Bar$getB() and be removed from the class scope?
public void testClassProperties() {
// Call class method inside class scope
testSame(
Expand Down Expand Up @@ -1797,12 +1795,10 @@ public void testSuperExtern() {

}

// check against existing test cases
public void testPropertyMethodAssignment() {
// ES5 version - currently throws an error (Not true that aggregate warnings (<[JSC_UNSAFE_THIS.
// dangerous use of this in static method foo.myFunc at testcode line 4 : 11]>) is empty)
public void testPropertyMethodAssignment_unsafeThis() {
// ES5 version
setLanguage(LanguageMode.ECMASCRIPT3, LanguageMode.ECMASCRIPT3);
/*test(
test(
LINE_JOINER.join(
"var foo = { ",
" bar: 1, ",
Expand All @@ -1811,35 +1807,70 @@ public void testPropertyMethodAssignment() {
" }",
"};",
"foo.myFunc();"),
LINE_JOINER.join(
"var foo$bar = 1;",
"var foo$myFunc = function myFunc() {",
" return this.bar",
"};",
"foo$myFunc();"),
warning(CollapseProperties.UNSAFE_THIS));

// ES6 version
setLanguage(LanguageMode.ECMASCRIPT_2015, LanguageMode.ECMASCRIPT_2015);
test(
LINE_JOINER.join(
"var foo = { ",
" bar: 1, ",
" foo$myFunc: function myFunc() {",
" return this.bar",
" myFunc() {",
" return this.bar;",
" }",
"};",
"foo$myFunc();"));*/
"foo.myFunc();"),
LINE_JOINER.join(
"var foo$bar = 1;",
"var foo$myFunc = function() {",
" return this.bar",
"};",
"foo$myFunc();"),
warning(CollapseProperties.UNSAFE_THIS));
}

// ES6 version - currently throws an error (Not true that aggregate warnings (<[JSC_UNSAFE_THIS.
// dangerous use of this in static method foo.myFunc at testcode line 4 : 11]>) is empty)
setLanguage(LanguageMode.ECMASCRIPT_2015, LanguageMode.ECMASCRIPT_2015);
/*test(
public void testPropertyMethodAssignment_noThis() {
// ES5 Version
setLanguage(LanguageMode.ECMASCRIPT3, LanguageMode.ECMASCRIPT3);
test(
LINE_JOINER.join(
"var foo = { ",
" bar: 1, ",
" myFunc() {",
" return this.bar",
" myFunc: function myFunc() {",
" return 5",
" }",
"};",
"foo.myFunc();"),
LINE_JOINER.join(
"var foo$bar = 1;",
"var foo$myFunc = function myFunc() {",
" return 5;",
"};",
"foo$myFunc();"));

// ES6 version
setLanguage(LanguageMode.ECMASCRIPT_2015, LanguageMode.ECMASCRIPT_2015);
test(
LINE_JOINER.join(
"var foo = { ",
" bar: 1, ",
" myFunc() {",
" return this.bar",
" return 5;",
" }",
"};",
"foo$myFunc();"));*/
"foo.myFunc();"),
LINE_JOINER.join(
"var foo$bar = 1;",
"var foo$myFunc = function() {",
" return 5;",
"};",
"foo$myFunc();"));
}

public void testLetConstObjectAssignmentProperties() {
Expand Down

0 comments on commit e44a6d8

Please sign in to comment.