use undef for null

This commit is contained in:
kangwei 2020-06-22 21:11:34 +08:00
parent 9c8f492d03
commit bb698e7b99
3 changed files with 7 additions and 8 deletions

View File

@ -109,11 +109,11 @@ export class Prop implements IPropParent {
} }
return this.items!.map((prop) => { return this.items!.map((prop) => {
const v = prop.export(stage); const v = prop.export(stage);
return v === UNSET ? null : v; return v === UNSET ? undefined : v;
}); });
} }
return null; return undefined;
} }
private _code: string | null = null; private _code: string | null = null;
@ -176,7 +176,7 @@ export class Prop implements IPropParent {
this._code = null; this._code = null;
const t = typeof val; const t = typeof val;
if (val == null) { if (val == null) {
this._value = null; this._value = undefined;
this._type = 'literal'; this._type = 'literal';
} else if (t === 'string' || t === 'number' || t === 'boolean') { } else if (t === 'string' || t === 'number' || t === 'boolean') {
this._type = 'literal'; this._type = 'literal';
@ -192,7 +192,6 @@ export class Prop implements IPropParent {
} else { } else {
this._type = 'map'; this._type = 'map';
} }
this._type = 'map';
} else { } else {
this._type = 'expression'; this._type = 'expression';
this._value = { this._value = {
@ -206,7 +205,7 @@ export class Prop implements IPropParent {
@computed getValue(): CompositeValue { @computed getValue(): CompositeValue {
const v = this.export(TransformStage.Serilize); const v = this.export(TransformStage.Serilize);
if (v === UNSET) { if (v === UNSET) {
return null; return undefined;
} }
return v; return v;
} }

View File

@ -106,7 +106,7 @@ export class Props implements IPropParent {
this.items.forEach(item => { this.items.forEach(item => {
let value = item.export(stage); let value = item.export(stage);
if (value === UNSET) { if (value === UNSET) {
value = null; value = undefined;
} }
let name = item.key as string; let name = item.key as string;
if (name && typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) { if (name && typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) {
@ -129,7 +129,7 @@ export class Props implements IPropParent {
} }
let value = item.export(stage); let value = item.export(stage);
if (value === UNSET) { if (value === UNSET) {
value = null; value = undefined;
} }
if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) { if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) {
name = getOriginalExtraKey(name); name = getOriginalExtraKey(name);

View File

@ -27,7 +27,7 @@ export interface JSBlock {
} }
// JSON 基本类型 // JSON 基本类型
export type JSONValue = boolean | string | number | null | JSONArray | JSONObject; export type JSONValue = boolean | string | number | null | undefined | JSONArray | JSONObject;
export type JSONArray = JSONValue[]; export type JSONArray = JSONValue[];
export interface JSONObject { export interface JSONObject {
[key: string]: JSONValue; [key: string]: JSONValue;