Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 7586d4c

Browse files
committed
fix: avoid generating invalid JavaScript when merging IIFE files
1 parent 47ad5cf commit 7586d4c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: snapshot/android/snapshot-generator.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,19 @@ SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFi
4848
const bundlePreambleContent = fs.readFileSync(BUNDLE_PREAMBLE_PATH, "utf8");
4949
const bundleEndingContent = fs.readFileSync(BUNDLE_ENDING_PATH, "utf8");
5050

51-
const inputFilesContent = inputFiles.map(file => fs.readFileSync(file, "utf8")).join("\n");
51+
// IMPORTANT: join by "\n;" as we are joining IIFE functions and if the snapshot tool is used
52+
// along with Uglify configuration for replacing `;` with `/n`, we will generate invalid JavaScript
53+
// Example:
54+
// (function() {
55+
// some code here
56+
// })()
57+
// // sourceMapUrl......
58+
// ** when we join without `;` here, the next IIFE is assumed as a function call to the result of the first IIFE
59+
// (function() {
60+
// some code here
61+
// })()
62+
// // sourceMapUrl......
63+
const inputFilesContent = inputFiles.map(file => fs.readFileSync(file, "utf8")).join("\n;");
5264
const snapshotFileContent = bundlePreambleContent + "\n" + inputFilesContent + "\n" + bundleEndingContent;
5365
fs.writeFileSync(outputFile, snapshotFileContent, { encoding: "utf8" });
5466
}

0 commit comments

Comments
 (0)