Do not throw on an empty file with a ; (#1503)

Fixes "TypeError: Cannot read property 'replace' of undefined"

This was discovered by #1480 and also affects non-typescript
master
Christopher Chedeau 2017-05-04 09:40:11 -07:00 committed by GitHub
parent e6eee0467d
commit bdf6050434
4 changed files with 16 additions and 4 deletions

View File

@ -284,10 +284,12 @@ function printDocToString(doc, options) {
out.pop();
}
out[out.length - 1] = out[out.length - 1].replace(
/[^\S\n]*$/,
""
);
if (out.length) {
out[out.length - 1] = out[out.length - 1].replace(
/[^\S\n]*$/,
""
);
}
}
let length = ind.indent * options.tabWidth + ind.align.spaces;

View File

@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`empty.js 1`] = `
;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`;

1
tests/empty/empty.js Normal file
View File

@ -0,0 +1 @@
;

View File

@ -0,0 +1 @@
run_spec(__dirname);