You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/05/28 05:43:29 UTC
[incubator-echarts] 03/04: fix: fix class error in ES6 built file
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch label-enhancement
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 678b42d5797c3b975cdacef834e0aa6fffed078d
Author: pissang <bm...@gmail.com>
AuthorDate: Thu May 28 13:41:56 2020 +0800
fix: fix class error in ES6 built file
---
src/util/clazz.ts | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/util/clazz.ts b/src/util/clazz.ts
index ddf3549..7507bdf 100644
--- a/src/util/clazz.ts
+++ b/src/util/clazz.ts
@@ -99,17 +99,25 @@ export function enableClassExtend(rootClz: ExtendableConstructor, mandatoryMetho
// constructor.
// If this constructor/$constructor is declared, it is responsible for
// calling the super constructor.
- const ExtendedClass = (class {
- constructor() {
- if (!proto.$constructor) {
- superClass.apply(this, arguments);
+ function ExtendedClass(this: any, ...args: any[]) {
+ if (!proto.$constructor) {
+ try {
+ // Will throw error if superClass is a es6 native class.
+ superClass.apply(this, args);
}
- else {
- proto.$constructor.apply(this, arguments);
+ catch (e) {
+ const ins = zrUtil.createObject(
+ // @ts-ignore
+ ExtendedClass.prototype, new superClass(...args)
+ );
+ return ins;
}
}
- static [IS_EXTENDED_CLASS] = true;
- }) as ExtendableConstructor;
+ else {
+ proto.$constructor.apply(this, arguments);
+ }
+ };
+ ExtendedClass[IS_EXTENDED_CLASS] = true;
zrUtil.extend(ExtendedClass.prototype, proto);
@@ -119,7 +127,7 @@ export function enableClassExtend(rootClz: ExtendableConstructor, mandatoryMetho
zrUtil.inherits(ExtendedClass, this);
ExtendedClass.superClass = superClass;
- return ExtendedClass as ExtendableConstructor;
+ return ExtendedClass as unknown as ExtendableConstructor;
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org