google / google/closure-compiler

--replace_strings does not understand goog.module names

Open
#2,756 3 comments 0 reactions 0 assignees View on GitHub
P2
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Given this code:

```javascript
// err.js
goog.module('example.Err');
class Err extends Error {}
exports = Err;

// thrower.js
goog.module('example.thrower');
const Err = goog.require('example.Err');
function throwErr() {
throw new Err('please replace me');
}
```

String replacement does not occur when compiling with `--replace_strings='example.Err(?)'`.

It does occur when compiling with `--replace_strings='Err(?)'`.

Just using the short name is not a great solution, since short names can conflict, and module names can be shortened differently, across different modules in the compilation unit.

The same issue exists with `goog.scope`, but then at least you can simply avoid scoping the error type. With `goog.module`, the namespace must be removed, so there is no way to specify that a string replacement should be applied to a certain error type.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.