last minute clean up of comments and formatting

This commit is contained in:
Brian Mulhall
2020-04-04 15:41:09 -05:00
parent 33904b7f46
commit 1931f9e353
3 changed files with 9 additions and 10 deletions

View File

@@ -1,11 +1,12 @@
Tinytest.add('minifier-js - verify simple JS minifications work', (test) => {
Tinytest.add('minifier-js - verify terser is able to minify files', (test) => {
let terserResult = meteorJsMinify('function add(first,second){return first + second; }\n');
test.equal(terserResult.code, 'function add(n,d){return n+d}');
});
// this feature has been reqested in this issue https://github.com/terser/terser/issues/632
// so when we bump the terser version up and this fails we will know when its been done :)
Tinytest.add('minifier-js - numeric seperator test', (test) => {
// so when we bump up the terser version in the future and this test fails we will know when
// its been done and can remove this test :)
Tinytest.add('minifier-js - unsupported feature test (numeric seperators)', (test) => {
test.throws(() => meteorJsMinify('let number = 1_000_000_000_000;\n') );
});

View File

@@ -4,7 +4,7 @@ meteorJsMinify = function (source) {
var result = {};
const NODE_ENV = process.env.NODE_ENV || "development";
const terserOptions = {
const options = {
compress: {
drop_debugger: false, // remove debugger; statements
unused: false, // drop unreferenced functions and variables
@@ -19,7 +19,7 @@ meteorJsMinify = function (source) {
safari10: true, // set this option to true to work around the Safari 10/11 await bug
};
const terserResult = terser.minify(source, terserOptions);
const terserResult = terser.minify(source, options);
// the terser api doesnt throw exceptions, so we throw one ourselves
if (terserResult.error) throw terserResult.error;

View File

@@ -30,13 +30,14 @@ class MeteorBabelMinifier {
const lines = file.getContentsAsString().split(/\n/);
const lineContent = lines[error.line - 1];
let originalSourceFileLineNumber = 0;
// Count backward from the failed line to find the oringal filename
for (let i = (error.line - 1); i >= 0; i--) {
let currentLine = lines[i];
// If the line is a boatload of slashes, we're in the right place.
// If the line is a boatload of slashes (8 or more), we're in the right place.
if (/^\/\/\/{6,}$/.test(currentLine)) {
// If 4 lines back is the same exact line, we've found the framing.
@@ -50,15 +51,13 @@ class MeteorBabelMinifier {
`Source file: ${originalFilePath} (${originalSourceFileLineNumber}:${error.col})\n` +
`Line content: ${lineContent}\n`);
}
}
originalSourceFileLineNumber++;
}
}
// this object will collect all the minified code in the
// data field and then post-minfiication file sizes in
// stats field
// data field and post-minfiication file sizes in the stats field
const toBeAdded = {
data: "",
stats: Object.create(null)
@@ -92,7 +91,6 @@ class MeteorBabelMinifier {
// of code being minified
toBeAdded.data += minified.code;
}
toBeAdded.data += '\n\n';
Plugin.nudge();