Skip to content

Commit

Permalink
flow annotations
Browse files Browse the repository at this point in the history
no errors when running flow!
  • Loading branch information
SheetJSDev committed Mar 12, 2017
1 parent 4684914 commit 8cd9e81
Show file tree
Hide file tree
Showing 34 changed files with 692 additions and 549 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,13 @@ $ make test # run full tests
$ WTF=1 make test # enable all error messages
```

Flow and JSHint/JSCS checks are available:

```bash
$ make lint # JSHint and JSCS checks
$ make flow # make lint + Flow checking
```

To run the in-browser tests, clone
[The oss.sheetjs.com repo](https://github.com/SheetJS/SheetJS.github.io) and
replace the xlsx.js file (then fire up the browser and go to `stress.html`):
Expand Down
1 change: 1 addition & 0 deletions bits/02_codepage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var current_codepage = 1200, current_cptable;
/*:: declare var cptable:any; */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel.js');
current_cptable = cptable[current_codepage];
Expand Down
248 changes: 127 additions & 121 deletions bits/10_ssf.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions bits/22_xmlutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ if(has_buf) {
};
var corpus = "foo bar baz\u00e2\u0098\u0083\u00f0\u009f\u008d\u00a3";
if(utf8read(corpus) == utf8readb(corpus)) utf8read = utf8readb;
// $FlowIgnore
var utf8readc = function utf8readc(data) { return Buffer(data, 'binary').toString('utf8'); };
if(utf8read(corpus) == utf8readc(corpus)) utf8read = utf8readc;
}

// matches <foo>...</foo> extracts content
var matchtag = (function() {
var mtcache = {};
return function matchtag(f,g) {
var mtcache/*:{[k:string]:RegExp}*/ = ({}/*:any*/);
return function matchtag(f,g/*:?string*/)/*:RegExp*/ {
var t = f+"|"+(g||"");
if(mtcache[t] !== undefined) return mtcache[t];
return (mtcache[t] = new RegExp('<(?:\\w+:)?'+f+'(?: xml:space="preserve")?(?:[^>]*)>([^\u2603]*)</(?:\\w+:)?'+f+'>',(g||"")));
if(mtcache[t]) return mtcache[t];
return (mtcache[t] = new RegExp('<(?:\\w+:)?'+f+'(?: xml:space="preserve")?(?:[^>]*)>([^\u2603]*)</(?:\\w+:)?'+f+'>',((g||"")/*:any*/)));
};
})();

Expand Down
14 changes: 8 additions & 6 deletions bits/23_binutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var __readInt32LE = function(b, idx) { return (b[idx+3]<<24)|(b[idx+2]<<16)|(b[i
var ___unhexlify = function(s) { return s.match(/../g).map(function(x) { return parseInt(x,16);}); };
var __unhexlify = typeof Buffer !== "undefined" ? function(s) { return Buffer.isBuffer(s) ? new Buffer(s, 'hex') : ___unhexlify(s); } : ___unhexlify;

function ReadShift(size, t) {
function ReadShift(size/*:number*/, t/*:?string*/) {
var o="", oI, oR, oo=[], w, vv, i, loc;
switch(t) {
case 'dbcs':
Expand Down Expand Up @@ -130,7 +130,7 @@ function ReadShift(size, t) {
case 2: oI = (t === 'i' ? __readInt16LE : __readUInt16LE)(this, this.l); this.l += 2; return oI;
case 4:
if(t === 'i' || (this[this.l+3] & 0x80)===0) { oI = __readInt32LE(this, this.l); this.l += 4; return oI; }
else { oR = __readUInt32LE(this, this.l); this.l += 4; return oR; } break;
else { oR = __readUInt32LE(this, this.l); this.l += 4; } return oR;
case 8: if(t === 'f') { oR = __double(this, this.l); this.l += 8; return oR; }
/* falls through */
case 16: o = __hexlify(this, this.l, size); break;
Expand All @@ -142,15 +142,17 @@ var __writeUInt16LE = function(b, val, idx) { b[idx] = (val & 0xFF); b[idx+1] =
var __writeUInt32LE = function(b, val, idx) { b[idx] = (val & 0xFF); b[idx+1] = ((val >>> 8) & 0xFF); b[idx+2] = ((val >>> 16) & 0xFF); b[idx+3] = ((val >>> 24) & 0xFF); };
var __writeInt32LE = function(b, val, idx) { b[idx] = (val & 0xFF); b[idx+1] = ((val >> 8) & 0xFF); b[idx+2] = ((val >> 16) & 0xFF); b[idx+3] = ((val >> 24) & 0xFF); };

function WriteShift(t, val, f) {
var size, i;
function WriteShift(t/*:number*/, val/*:string|number*/, f/*:?string*/) {
var size = 0, i = 0;
if(f === 'dbcs') {
/*:: if(typeof val !== 'string') throw new Error("unreachable"); */
for(i = 0; i != val.length; ++i) __writeUInt16LE(this, val.charCodeAt(i), this.l + 2 * i);
size = 2 * val.length;
} else if(f === 'sbcs') {
/*:: if(typeof val !== 'string') throw new Error("unreachable"); */
for(i = 0; i != val.length; ++i) this[this.l + i] = val.charCodeAt(i) & 0xFF;
size = val.length;
} else switch(t) {
} else /*:: if(typeof val === 'number') */ switch(t) {
case 1: size = 1; this[this.l] = val&0xFF; break;
case 2: size = 2; this[this.l] = val&0xFF; val >>>= 8; this[this.l+1] = val&0xFF; break;
case 3: size = 3; this[this.l] = val&0xFF; val >>>= 8; this[this.l+1] = val&0xFF; val >>>= 8; this[this.l+2] = val&0xFF; break;
Expand Down Expand Up @@ -180,7 +182,7 @@ function parsenoop(blob, length/*:number*/) { blob.l += length; }

function writenoop(blob, length/*:number*/) { blob.l += length; }

function new_buf(sz) {
function new_buf(sz/*:number*/)/*:Block*/ {
var o = new_raw_buf(sz);
prep_blob(o, 0);
return o;
Expand Down
2 changes: 1 addition & 1 deletion bits/24_hoppers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function recordhopper(data, cb/*:RecordHopperCB*/, opts/*:?any*/) {
function buf_array()/*:BufArray*/ {
var bufs = [], blksz = 2048;
var newblk = function ba_newblk(sz) {
var o = new_buf(sz);
var o/*:Block*/ = (new_buf(sz)/*:any*/);
prep_blob(o, 0);
return o;
};
Expand Down
2 changes: 1 addition & 1 deletion bits/25_cellutils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* XLS ranges enforced */
function shift_cell_xls(cell, tgt, opts) {
function shift_cell_xls(cell, tgt/*:any*/, opts/*:?any*/) {
var out = dup(cell);
if(tgt.s) {
if(out.cRel) out.c += tgt.s.c;
Expand Down
5 changes: 4 additions & 1 deletion bits/26_crypto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var OFFCRYPTO = {};

var make_offcrypto = function(O, _crypto) {
var crypto;
if(typeof _crypto !== 'undefined') crypto = _crypto;
Expand All @@ -15,7 +16,8 @@ var make_offcrypto = function(O, _crypto) {
j = (j + S[i] + (key[i%key.length]).charCodeAt(0))&255;
t = S[i]; S[i] = S[j]; S[j] = t;
}
i = j = 0; out = Buffer(data.length);
// $FlowIgnore
i = j = 0; var out = Buffer(data.length);
for(c = 0; c != data.length; ++c) {
i = (i + 1)&255;
j = (j + S[i])%256;
Expand All @@ -30,5 +32,6 @@ var make_offcrypto = function(O, _crypto) {
return crypto.createHash('md5').update(hex).digest('hex');
};
};
/*:: declare var crypto:any; */
make_offcrypto(OFFCRYPTO, typeof crypto !== "undefined" ? crypto : undefined);

8 changes: 4 additions & 4 deletions bits/28_binstructs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function parse_StrRun(data, length/*:?number*/) {
}

/* [MS-XLSB] 2.1.7.121 */
function parse_RichStr(data, length/*:number*/) {
function parse_RichStr(data, length/*:number*/)/*:XLString*/ {
var start = data.l;
var flags = data.read_shift(1);
var str = parse_XLWideString(data);
Expand All @@ -24,7 +24,7 @@ function parse_RichStr(data, length/*:number*/) {
data.l = start + length;
return z;
}
function write_RichStr(str, o) {
function write_RichStr(str/*:XLString*/, o/*:?Block*/)/*:Block*/ {
/* TODO: formatted string */
if(o == null) o = new_buf(5+2*str.t.length);
o.write_shift(1,0);
Expand All @@ -33,14 +33,14 @@ function write_RichStr(str, o) {
}

/* [MS-XLSB] 2.5.9 */
function parse_XLSBCell(data) {
function parse_XLSBCell(data)/*:any*/ {
var col = data.read_shift(4);
var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16;
var fPhShow = data.read_shift(1);
return { c:col, iStyleRef: iStyleRef };
}
function write_XLSBCell(cell, o) {
function write_XLSBCell(cell/*:any*/, o/*:?Block*/) {
if(o == null) o = new_buf(8);
o.write_shift(-4, cell.c);
o.write_shift(3, cell.iStyleRef || cell.s);
Expand Down
2 changes: 1 addition & 1 deletion bits/33_coreprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var CORE_PROPS/*:Array<Array<string> >*/ = [
XMLNS.CORE_PROPS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
RELS.CORE_PROPS = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';

var CORE_PROPS_REGEX/*:Array<RegEx>*/ = (function() {
var CORE_PROPS_REGEX/*:Array<RegExp>*/ = (function() {
var r = new Array(CORE_PROPS.length);
for(var i = 0; i < CORE_PROPS.length; ++i) {
var f = CORE_PROPS[i];
Expand Down
1 change: 1 addition & 0 deletions bits/35_custprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function write_cust_props(cp, opts)/*:string*/ {
if(!cp) return o.join("");
var pid = 1;
keys(cp).forEach(function custprop(k) { ++pid;
// $FlowIgnore
o[o.length] = (writextag('property', write_vt(cp[k]), {
'fmtid': '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}',
'pid': pid,
Expand Down
4 changes: 2 additions & 2 deletions bits/39_xlsbiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ function parse_BoundSheet8(blob, length, opts) {
}

/* 2.4.265 TODO */
function parse_SST(blob, length) {
function parse_SST(blob, length)/*:SST*/ {
var cnt = blob.read_shift(4);
var ucnt = blob.read_shift(4);
var strs = [];
var strs/*:SST*/ = ([]/*:any*/);
for(var i = 0; i != ucnt; ++i) {
strs.push(parse_XLUnicodeRichExtendedString(blob));
}
Expand Down
2 changes: 1 addition & 1 deletion bits/42_sstxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function write_sst_xml(sst/*:SST*/, opts)/*:string*/ {
uniqueCount: sst.Unique
}));
for(var i = 0; i != sst.length; ++i) { if(sst[i] == null) continue;
var s = sst[i];
var s/*:XLString*/ = sst[i];
var sitag = "<si>";
if(s.r) sitag += s.r;
else {
Expand Down
4 changes: 2 additions & 2 deletions bits/43_sstbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ function parse_BrtBeginSst(data, length) {
}

/* [MS-XLSB] 2.1.7.45 Shared Strings */
function parse_sst_bin(data, opts) {
var s = [];
function parse_sst_bin(data, opts)/*:SST*/ {
var s/*:SST*/ = ([]/*:any*/);
var pass = false;
recordhopper(data, function hopper_sst(val, R, RT) {
switch(R.n) {
Expand Down
6 changes: 3 additions & 3 deletions bits/47_styxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ function parse_numFmts(t, opts) {
}
}

function write_numFmts(NF, opts) {
function write_numFmts(NF/*:{[n:number]:string}*/, opts) {
var o = ["<numFmts>"];
[[5,8],[23,26],[41,44],[63,66],[164,392]].forEach(function(r) {
for(var i = r[0]; i <= r[1]; ++i) if(NF[i] !== undefined) o[o.length] = (writextag('numFmt',null,{numFmtId:i,formatCode:escapexml(NF[i])}));
for(var i = r[0]; i <= r[1]; ++i) if(NF[i]) o[o.length] = (writextag('numFmt',null,{numFmtId:i,formatCode:escapexml(NF[i])}));
});
if(o.length === 1) return "";
o[o.length] = ("</numFmts>");
Expand Down Expand Up @@ -158,7 +158,7 @@ RELS.STY = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/

function write_sty_xml(wb/*:Workbook*/, opts)/*:string*/ {
var o = [XML_HEADER, STYLES_XML_ROOT], w;
if((w = write_numFmts(wb.SSF)) != null) o[o.length] = w;
if(wb.SSF && (w = write_numFmts(wb.SSF)) != null) o[o.length] = w;
o[o.length] = ('<fonts count="1"><font><sz val="12"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font></fonts>');
o[o.length] = ('<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>');
o[o.length] = ('<borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders>');
Expand Down
2 changes: 1 addition & 1 deletion bits/49_theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function parse_themeElements(data, opts) {
var themeltregex = /<a:themeElements([^>]*)>[^\u2603]*<\/a:themeElements>/;

/* 14.2.7 Theme Part */
function parse_theme_xml(data, opts) {
function parse_theme_xml(data/*:string*/, opts) {
/* 20.1.6.9 theme CT_OfficeStyleSheet */
if(!data || data.length === 0) return themes;

Expand Down
Loading

0 comments on commit 8cd9e81

Please sign in to comment.