New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace some props on the object returned by getMode during compile time #3772
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ public class AmpPassTest extends Es6CompilerTestCase { | |
"dev.fine"); | ||
|
||
@Override protected CompilerPass getProcessor(Compiler compiler) { | ||
return new AmpPass(compiler, suffixTypes); | ||
return new AmpPass(compiler, true, suffixTypes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment for that is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, did you mean to do something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
|
||
@Override protected int getNumRepetitions() { | ||
|
@@ -129,4 +129,64 @@ public void testShouldPreserveNoneCalls() throws Exception { | |
" console.log('this is preserved', someValue);", | ||
"})()")); | ||
} | ||
|
||
public void testGetModeLocalDevPropertyReplacement() throws Exception { | ||
test( | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { localDev: true } }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().localDev) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()"), | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { localDev: true }; }", | ||
"var $mode = { getMode: getMode };", | ||
" if (false) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()")); | ||
} | ||
|
||
public void testGetModeTestPropertyReplacement() throws Exception { | ||
test( | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { test: true } }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().test) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()"), | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { test: true }; }", | ||
"var $mode = { getMode: getMode };", | ||
" if (false) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()")); | ||
} | ||
|
||
public void testGetModeMinifiedPropertyReplacement() throws Exception { | ||
test( | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { minified: false } }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().minified) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()"), | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { minified: false }; }", | ||
"var $mode = { getMode: getMode };", | ||
" if (true) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.ampproject; | ||
|
||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.javascript.jscomp.Compiler; | ||
import com.google.javascript.jscomp.CompilerPass; | ||
import com.google.javascript.jscomp.Es6CompilerTestCase; | ||
|
||
|
||
/** | ||
* Tests {@link AmpPass}. | ||
*/ | ||
public class AmpPassTestEnvTest extends Es6CompilerTestCase { | ||
|
||
ImmutableSet<String> suffixTypes = ImmutableSet.of(); | ||
|
||
@Override protected CompilerPass getProcessor(Compiler compiler) { | ||
return new AmpPass(compiler, false, suffixTypes); | ||
} | ||
|
||
@Override protected int getNumRepetitions() { | ||
// This pass only runs once. | ||
return 1; | ||
} | ||
|
||
public void testGetModeLocalDevPropertyReplacementInTestingEnv() throws Exception { | ||
test( | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { localDev: true } }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().localDev) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()"), | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { localDev: true }; }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().localDev) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()")); | ||
} | ||
|
||
public void testGetModeTestPropertyReplacementInTestingEnv() throws Exception { | ||
test( | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { test: true } }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().test) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()"), | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { test: true }; }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().test) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()")); | ||
} | ||
|
||
public void testGetModeMinifiedPropertyReplacementInTestingEnv() throws Exception { | ||
test( | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { minified: false } }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().minified) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()"), | ||
LINE_JOINER.join( | ||
"(function() {", | ||
"function getMode() { return { minified: false }; }", | ||
"var $mode = { getMode: getMode };", | ||
" if ($mode.getMode().minified) {", | ||
" console.log('hello world');", | ||
" }", | ||
"})()")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these