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 <bm2736...@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-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to