Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 704880480
  • Loading branch information
rahul-kamat authored and copybara-github committed Dec 11, 2024
1 parent a3fa922 commit b9dd7d8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ protected PassListBuilder getChecks() {

checks.maybeAdd(checkConsts);

// TODO(user): Enable this pass when it is ready.
// checks.maybeAdd(rewriteCallerCodeLocation);
checks.maybeAdd(rewriteCallerCodeLocation);

if (!options.getConformanceConfigs().isEmpty()) {
checks.maybeAdd(checkConformance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ private boolean isGoogCallerLocationMisused(Node n, Node parent) {
return false;
}

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

Expand Down
33 changes: 33 additions & 0 deletions test/com/google/javascript/jscomp/integration/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4592,6 +4592,39 @@ public void testGoogScopeWithAngular() {
"$jscomp$scope$98447280$0$fn[\"$inject\"] = [\"a\", \"b\"];"));
}

@Test
public void testRewriteCallerCodeLocation() {
// This unit test tests the following:
// (1) RewriteCallerCodeLocation pass adds the code location to the call-site of functions
// that have goog.callerLocation as a default parameter.
// (2) ReplaceIdGenerators pass replaces the code location with an obfuscated string.
CompilerOptions options = createCompilerOptions();

options.setReplaceIdGenerators(true);

test(
options,
lines(
"/** @idGenerator {consistent} */",
"goog.callerLocationIdInternalDoNotCallOrElse = function(id) {",
" return /** @type {!goog.CodeLocation} */ (id);",
"};",
"function signal(here = goog.callerLocation()) {}",
"const mySignal = signal();",
"const mySignal2 = signal();",
"const mySignal3 = signal();"),
lines(
"goog.callerLocationIdInternalDoNotCallOrElse = function(id) {",
" return id;",
"};",
"function signal(here) {",
" here = here === void 0 ? goog.callerLocation() : here;",
"}",
"var mySignal = signal('a');",
"var mySignal2 = signal('b');",
"var mySignal3 = signal('c');"));
}

@Test
public void testGitHubIssue3861() {
CompilerOptions options = createCompilerOptions();
Expand Down

0 comments on commit b9dd7d8

Please sign in to comment.