fix(compiler): support empty array and map literals.
This was broken after 152a117d5c
Fixes #8336
This commit is contained in:
@ -7,6 +7,8 @@ import {
|
||||
interpolate,
|
||||
checkBinding,
|
||||
castByValue,
|
||||
EMPTY_ARRAY,
|
||||
EMPTY_MAP,
|
||||
pureProxy1,
|
||||
pureProxy2,
|
||||
pureProxy3,
|
||||
@ -72,6 +74,8 @@ var impDevModeEqual = devModeEqual;
|
||||
var impInterpolate = interpolate;
|
||||
var impCheckBinding = checkBinding;
|
||||
var impCastByValue = castByValue;
|
||||
var impEMPTY_ARRAY = EMPTY_ARRAY;
|
||||
var impEMPTY_MAP = EMPTY_MAP;
|
||||
|
||||
export class Identifiers {
|
||||
static ViewUtils = new CompileIdentifierMetadata({
|
||||
@ -179,6 +183,11 @@ export class Identifiers {
|
||||
{name: 'interpolate', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impInterpolate});
|
||||
static castByValue = new CompileIdentifierMetadata(
|
||||
{name: 'castByValue', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impCastByValue});
|
||||
static EMPTY_ARRAY = new CompileIdentifierMetadata(
|
||||
{name: 'EMPTY_ARRAY', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impEMPTY_ARRAY});
|
||||
static EMPTY_MAP = new CompileIdentifierMetadata(
|
||||
{name: 'EMPTY_MAP', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impEMPTY_MAP});
|
||||
|
||||
static pureProxies = [
|
||||
null,
|
||||
new CompileIdentifierMetadata(
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
} from './util';
|
||||
import {CompilerConfig} from '../config';
|
||||
import {CompileBinding} from './compile_binding';
|
||||
import {Identifiers} from '../identifiers';
|
||||
|
||||
export class CompileView implements NameResolver {
|
||||
public viewType: ViewType;
|
||||
@ -155,6 +156,9 @@ export class CompileView implements NameResolver {
|
||||
}
|
||||
|
||||
createLiteralArray(values: o.Expression[]): o.Expression {
|
||||
if (values.length === 0) {
|
||||
return o.importExpr(Identifiers.EMPTY_ARRAY);
|
||||
}
|
||||
var proxyExpr = o.THIS_EXPR.prop(`_arr_${this.literalArrayCount++}`);
|
||||
var proxyParams: o.FnParam[] = [];
|
||||
var proxyReturnEntries: o.Expression[] = [];
|
||||
@ -169,6 +173,9 @@ export class CompileView implements NameResolver {
|
||||
}
|
||||
|
||||
createLiteralMap(entries: Array<Array<string | o.Expression>>): o.Expression {
|
||||
if (entries.length === 0) {
|
||||
return o.importExpr(Identifiers.EMPTY_MAP);
|
||||
}
|
||||
var proxyExpr = o.THIS_EXPR.prop(`_map_${this.literalMapCount++}`);
|
||||
var proxyParams: o.FnParam[] = [];
|
||||
var proxyReturnEntries: Array<Array<string | o.Expression>> = [];
|
||||
|
@ -156,6 +156,9 @@ export function castByValue<T>(input: any, value: T): T {
|
||||
return <T>input;
|
||||
}
|
||||
|
||||
export const EMPTY_ARRAY = CONST_EXPR([]);
|
||||
export const EMPTY_MAP = CONST_EXPR({});
|
||||
|
||||
export function pureProxy1<P0, R>(fn: (p0: P0) => R): (p0: P0) => R {
|
||||
var result: R;
|
||||
var v0;
|
||||
|
Reference in New Issue
Block a user