Skip to content

Commit

Permalink
Don't let an internal failure from uglify bring down the entire deplo…
Browse files Browse the repository at this point in the history
…yment. Fixes gh-617
  • Loading branch information
rwaldron committed Mar 6, 2016
1 parent 36b6727 commit 810c88d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
73 changes: 39 additions & 34 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,40 +1040,45 @@ actions.compress = function(source) {
return source;
}
}

ast.figure_out_scope();
ast = ast.transform(uglify.Compressor({
// ------
booleans: true,
cascade: true,
conditionals: true,
comparisons: true,
evaluate: true,
hoist_funs: true,
hoist_vars: true,
if_return: true,
join_vars: true,
loops: true,
properties: true,
screw_ie8: true,
sequences: true,
unsafe: true,
// ------
keep_fargs: false,
keep_fnames: false,
warnings: false,
drop_console: false,
}));

ast.figure_out_scope(mangle);
ast.compute_char_frequency(mangle);
ast.mangle_names(mangle);

var stream = uglify.OutputStream();

ast.print(stream);

return stream.toString();
// Guard against internal Uglify exceptions that
// really shouldn't be our problem, but it happens.
try {
ast.figure_out_scope();
ast = ast.transform(uglify.Compressor({
// ------
booleans: true,
cascade: true,
conditionals: true,
comparisons: true,
evaluate: true,
hoist_funs: true,
hoist_vars: true,
if_return: true,
join_vars: true,
loops: true,
properties: true,
screw_ie8: true,
sequences: true,
unsafe: true,
// ------
keep_fargs: false,
keep_fnames: false,
warnings: false,
drop_console: false,
}));

ast.figure_out_scope(mangle);
ast.compute_char_frequency(mangle);
ast.mangle_names(mangle);

var stream = uglify.OutputStream();

ast.print(stream);

return stream.toString();
} catch (error) {
return source;
}
};

if (global.IS_TEST_ENV) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,30 @@ exports['deploy.compress'] = {

test.done();
},

avoidCompleteFailure: function(test) {
test.expect(2);

this.uparse.restore();
this.uparse = sandbox.stub(uglify, 'parse', () => {
return {
figure_out_scope: () => {
throw new TypeError();
}
};
});
var result = '';
try {
result = deploy.compress('return;');
test.equal(this.aparse.lastCall.args[1].allowReturnOutsideFunction, true);
} catch (e) {
test.ok(false, e.message);
}

test.equal(result, 'return;');

test.done();
},
};

exports['deploy.tarBundle'] = {
Expand Down

0 comments on commit 810c88d

Please sign in to comment.