Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(infrastructure): Rework goog.module positioning #3098

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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