mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(core): make css parsers tree-shakable (#9496)
This commit is contained in:
committed by
Nathan Walker
parent
7960f8361f
commit
dce7408c05
@@ -343,7 +343,8 @@ export class Binding {
|
||||
}
|
||||
|
||||
let newValue = value;
|
||||
if (this.options.expression) {
|
||||
if (__UI_USE_EXTERNAL_RENDERER__) {
|
||||
} else if (this.options.expression) {
|
||||
const changedModel = {};
|
||||
changedModel[bc.bindingValueKey] = value;
|
||||
changedModel[bc.newPropertyValueKey] = value;
|
||||
@@ -373,38 +374,40 @@ export class Binding {
|
||||
}
|
||||
|
||||
private _getExpressionValue(expression: string, isBackConvert: boolean, changedModel: any): any {
|
||||
try {
|
||||
const exp = PolymerExpressions.getExpression(expression);
|
||||
if (exp) {
|
||||
const context = (this.source && this.source.get && this.source.get()) || global;
|
||||
const model = {};
|
||||
const addedProps = [];
|
||||
const resources = bindableResources.get();
|
||||
for (const prop in resources) {
|
||||
if (resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) {
|
||||
context[prop] = resources[prop];
|
||||
addedProps.push(prop);
|
||||
if (!__UI_USE_EXTERNAL_RENDERER__) {
|
||||
try {
|
||||
const exp = PolymerExpressions.getExpression(expression);
|
||||
if (exp) {
|
||||
const context = (this.source && this.source.get && this.source.get()) || global;
|
||||
const model = {};
|
||||
const addedProps = [];
|
||||
const resources = bindableResources.get();
|
||||
for (const prop in resources) {
|
||||
if (resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) {
|
||||
context[prop] = resources[prop];
|
||||
addedProps.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
this.prepareContextForExpression(context, expression, addedProps);
|
||||
model[contextKey] = context;
|
||||
const result = exp.getValue(model, isBackConvert, changedModel ? changedModel : model);
|
||||
// clear added props
|
||||
const addedPropsLength = addedProps.length;
|
||||
for (let i = 0; i < addedPropsLength; i++) {
|
||||
delete context[addedProps[i]];
|
||||
}
|
||||
addedProps.length = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
this.prepareContextForExpression(context, expression, addedProps);
|
||||
model[contextKey] = context;
|
||||
const result = exp.getValue(model, isBackConvert, changedModel ? changedModel : model);
|
||||
// clear added props
|
||||
const addedPropsLength = addedProps.length;
|
||||
for (let i = 0; i < addedPropsLength; i++) {
|
||||
delete context[addedProps[i]];
|
||||
}
|
||||
addedProps.length = 0;
|
||||
return new Error(expression + ' is not a valid expression.');
|
||||
} catch (e) {
|
||||
const errorMessage = 'Run-time error occured in file: ' + e.sourceURL + ' at line: ' + e.line + ' and column: ' + e.column;
|
||||
|
||||
return result;
|
||||
return new Error(errorMessage);
|
||||
}
|
||||
|
||||
return new Error(expression + ' is not a valid expression.');
|
||||
} catch (e) {
|
||||
const errorMessage = 'Run-time error occured in file: ' + e.sourceURL + ' at line: ' + e.line + ' and column: ' + e.column;
|
||||
|
||||
return new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,14 +424,7 @@ export class Binding {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.options.expression) {
|
||||
const expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
|
||||
if (expressionValue instanceof Error) {
|
||||
Trace.write(expressionValue.message, Trace.categories.Binding, Trace.messageType.error);
|
||||
} else {
|
||||
this.updateTarget(expressionValue);
|
||||
}
|
||||
} else {
|
||||
if (__UI_USE_EXTERNAL_RENDERER__ || !this.options.expression) {
|
||||
if (changedPropertyIndex > -1) {
|
||||
const props = sourceProps.slice(changedPropertyIndex + 1);
|
||||
const propsLength = props.length;
|
||||
@@ -443,6 +439,13 @@ export class Binding {
|
||||
this.updateTarget(data.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
|
||||
if (expressionValue instanceof Error) {
|
||||
Trace.write(expressionValue.message, Trace.categories.Binding, Trace.messageType.error);
|
||||
} else {
|
||||
this.updateTarget(expressionValue);
|
||||
}
|
||||
}
|
||||
|
||||
// we need to do this only if nested objects are used as source and some middle object has changed.
|
||||
@@ -516,7 +519,8 @@ export class Binding {
|
||||
}
|
||||
|
||||
private getSourcePropertyValue() {
|
||||
if (this.options.expression) {
|
||||
if (__UI_USE_EXTERNAL_RENDERER__) {
|
||||
} else if (this.options.expression) {
|
||||
const changedModel = {};
|
||||
changedModel[bc.bindingValueKey] = this.source ? this.source.get() : undefined;
|
||||
const expressionValue = this._getExpressionValue(this.options.expression, false, changedModel);
|
||||
|
||||
Reference in New Issue
Block a user