فهرست منبع

Update flatc.js

Lutz Roeder 5 سال پیش
والد
کامیت
13d519e8b2
1فایلهای تغییر یافته به همراه10 افزوده شده و 13 حذف شده
  1. 10 13
      tools/flatc.js

+ 10 - 13
tools/flatc.js

@@ -1,6 +1,7 @@
 
 const flatc = {};
 const fs = require('fs');
+const path = require('path');
 
 flatc.Object = class {
 
@@ -801,7 +802,7 @@ flatc.Root = class extends flatc.Object {
             const parser = new flatc.Parser(text, file, this);
             const includes = parser.include();
             for (const include of includes) {
-                const includeFile = this._resolvePath(paths, file, include);
+                const includeFile = this._resolve(paths, file, include);
                 if (includeFile) {
                     this._parseFile(paths, includeFile);
                     continue;
@@ -812,19 +813,15 @@ flatc.Root = class extends flatc.Object {
         }
     }
 
-    _resolvePath(paths, origin, target) {
-        const originParts = origin.split('/');
-        originParts[originParts.length - 1] = target;
-        const originIncludeFile = originParts.join('/');
-        if (fs.existsSync(originIncludeFile)) {
-            return originIncludeFile;
+    _resolve(paths, origin, target) {
+        const file = path.join(path.dirname(origin), target);
+        if (fs.existsSync(file)) {
+            return file;
         }
-        for (const path of paths) {
-            const pathParts = path.split('/');
-            pathParts.push(target);
-            const pathIncludeFile = pathParts.join('/');
-            if (fs.existsSync(pathIncludeFile)) {
-                return pathIncludeFile;
+        for (const current of paths) {
+            const file = path.join(current, target);
+            if (fs.existsSync(file)) {
+                return file;
             }
         }
         return null;