Skip to content

Commit b9dd7d8

Browse files
rahul-kamatcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 704880480
1 parent a3fa922 commit b9dd7d8

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/com/google/javascript/jscomp/DefaultPassConfig.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ protected PassListBuilder getChecks() {
443443

444444
checks.maybeAdd(checkConsts);
445445

446-
// TODO(user): Enable this pass when it is ready.
447-
// checks.maybeAdd(rewriteCallerCodeLocation);
446+
checks.maybeAdd(rewriteCallerCodeLocation);
448447

449448
if (!options.getConformanceConfigs().isEmpty()) {
450449
checks.maybeAdd(checkConformance);

src/com/google/javascript/jscomp/RewriteCallerCodeLocation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ private boolean isGoogCallerLocationMisused(Node n, Node parent) {
139139
return false;
140140
}
141141

142-
if (n.getSourceFileName().contains("javascript/closure/base.js")) {
143-
// This is the definition of the debug build runtime implementation of goog.callerLocation.
144-
// This is not a misuse.
142+
if (parent.isAssign() && n.getNext() != null && n.getNext().isFunction()) {
143+
// This is the definition of goog.callerLocation, so this is not a misuse.
144+
// i.e: `goog.callerLocation = function(...) { ... }`
145145
return false;
146146
}
147147

test/com/google/javascript/jscomp/integration/IntegrationTest.java

+33
Original file line numberDiff line numberDiff line change
@@ -4592,6 +4592,39 @@ public void testGoogScopeWithAngular() {
45924592
"$jscomp$scope$98447280$0$fn[\"$inject\"] = [\"a\", \"b\"];"));
45934593
}
45944594

4595+
@Test
4596+
public void testRewriteCallerCodeLocation() {
4597+
// This unit test tests the following:
4598+
// (1) RewriteCallerCodeLocation pass adds the code location to the call-site of functions
4599+
// that have goog.callerLocation as a default parameter.
4600+
// (2) ReplaceIdGenerators pass replaces the code location with an obfuscated string.
4601+
CompilerOptions options = createCompilerOptions();
4602+
4603+
options.setReplaceIdGenerators(true);
4604+
4605+
test(
4606+
options,
4607+
lines(
4608+
"/** @idGenerator {consistent} */",
4609+
"goog.callerLocationIdInternalDoNotCallOrElse = function(id) {",
4610+
" return /** @type {!goog.CodeLocation} */ (id);",
4611+
"};",
4612+
"function signal(here = goog.callerLocation()) {}",
4613+
"const mySignal = signal();",
4614+
"const mySignal2 = signal();",
4615+
"const mySignal3 = signal();"),
4616+
lines(
4617+
"goog.callerLocationIdInternalDoNotCallOrElse = function(id) {",
4618+
" return id;",
4619+
"};",
4620+
"function signal(here) {",
4621+
" here = here === void 0 ? goog.callerLocation() : here;",
4622+
"}",
4623+
"var mySignal = signal('a');",
4624+
"var mySignal2 = signal('b');",
4625+
"var mySignal3 = signal('c');"));
4626+
}
4627+
45954628
@Test
45964629
public void testGitHubIssue3861() {
45974630
CompilerOptions options = createCompilerOptions();

0 commit comments

Comments
 (0)