Skip to content

Commit

Permalink
fix(infrastructure): Rework goog.module positioning (#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickrodee authored Jul 16, 2018
1 parent cd1f972 commit fbbf58a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scripts/rewrite-decl-statements-for-closure-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ function transform(srcFile, rootDir) {
}

// Specify goog.module after the @license comment and append newline at the end of the file.
const pos = outputCode.indexOf(' */') + 3;
// First, get the first occurence of a multiline comment terminator with 0 or more preceding whitespace characters.
const result = /\s*\*\//.exec(outputCode);
// Then, get the index of that first matching character set plus the length of the matching characters, plus one
// extra character for more space. We now have the position at which we need to inject the "goog.module(...)"
// declaration and can assemble the module-declared code. Yay!
const pos = result.index + result[0].length + 1;
outputCode = outputCode.substr(0, pos) + '\ngoog.module(\'' + packageStr + '\');\n' + outputCode.substr(pos);
fs.writeFileSync(srcFile, outputCode, 'utf8');
logProgress(`[rewrite] ${srcFile}`);
Expand Down

0 comments on commit fbbf58a

Please sign in to comment.