忽略表外存在空字符串导致类型推断错误问题
类型提升时给出警告信息
This commit is contained in:
@@ -89,7 +89,7 @@ export class TableParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected process_table(raw: RawTableData): TableData {
|
protected process_table(raw: RawTableData): TableData {
|
||||||
|
const type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool, DataType.null];
|
||||||
let headers: ColumnDescription[] = [];
|
let headers: ColumnDescription[] = [];
|
||||||
|
|
||||||
let column_values: xlsl.CellObject[][] = [];
|
let column_values: xlsl.CellObject[][] = [];
|
||||||
@@ -109,17 +109,17 @@ export class TableParser {
|
|||||||
ignored_columns.add(c);
|
ignored_columns.add(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let column_cells = this.get_column(rows, c, 1);
|
const start_raw = 1;
|
||||||
|
let column_cells = this.get_column(rows, c, start_raw);
|
||||||
let type = DataType.null;
|
let type = DataType.null;
|
||||||
let types = new Set<DataType>();
|
for (let i = 0; i < column_cells.length; i++) {
|
||||||
for (const cell of column_cells) {
|
const cell = column_cells[i];
|
||||||
types.add(this.get_data_type(cell));
|
var t = this.get_data_type(cell);
|
||||||
}
|
if (type_order.indexOf(t) < type_order.indexOf(type)) {
|
||||||
let type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool ];
|
if (type != DataType.null) {
|
||||||
for (const t of type_order) {
|
console.log(colors.yellow(`\t\t${first.v} 的数据类型被提升为 ${t}\n\t\t ${this.dump_row_values(rows[start_raw + i])}`));
|
||||||
if (types.has(t)) {
|
}
|
||||||
type = t;
|
type = t;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let comment: string = undefined;
|
let comment: string = undefined;
|
||||||
@@ -217,7 +217,11 @@ export class TableParser {
|
|||||||
}
|
}
|
||||||
let all_empty = true;
|
let all_empty = true;
|
||||||
for (const cell of row) {
|
for (const cell of row) {
|
||||||
all_empty = all_empty && this.get_data_type(cell) == DataType.null;
|
let current_empty = this.get_data_type(cell) == DataType.null;
|
||||||
|
if (!current_empty) {
|
||||||
|
current_empty = this.get_data_type(cell) == DataType.string && (cell.v as string).trim().length == 0;
|
||||||
|
}
|
||||||
|
all_empty = all_empty && current_empty;
|
||||||
}
|
}
|
||||||
if (all_empty) return false;
|
if (all_empty) return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -263,4 +267,12 @@ export class TableParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected dump_row_values(row: xlsl.CellObject[]) {
|
||||||
|
let ret = [];
|
||||||
|
for (const cell of row) {
|
||||||
|
ret.push(this.get_cell_value(cell, this.get_data_type(cell)));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user