TreeFrogFramework  2.8
tjsloader.h
Go to the documentation of this file.
1 #pragma once
2 #include <QJSValue>
3 #include <TGlobal>
4 #include <TJSInstance>
5 #include <TJSModule>
6 
7 
9 public:
10  enum AltJS {
11  Default = 0, // JavaScript (ES5)
12  Jsx,
13  };
14 
15  TJSLoader(const QString &moduleName, AltJS alt = Default);
16  TJSLoader(const QString &defaultMember, const QString &moduleName, AltJS alt = Default);
17 
18  TJSModule *load(bool reload = false);
19  void import(const QString &moduleName);
20  void import(const QString &defaultMember, const QString &moduleName);
21  TJSInstance loadAsConstructor(const QJSValue &arg) const;
22  TJSInstance loadAsConstructor(const QJSValueList &args = QJSValueList()) const;
23 
24  void setSearchPaths(const QStringList &paths);
25  static void setDefaultSearchPaths(const QStringList &paths);
26  static QStringList defaultSearchPaths();
27  static QString compileJsx(const QString &jsx);
28 
29 protected:
30  QJSValue importTo(TJSModule *context, bool isMain) const;
31  QString search(const QString &moduleName, AltJS alt) const;
32  QString absolutePath(const QString &moduleName, const QDir &dir, AltJS alt) const;
33  void replaceRequire(TJSModule *context, QString &content, const QDir &dir) const;
34 
35 private:
36  QString _module;
37  AltJS _altJs;
38  QString _member;
39  QStringList _searchPaths;
40  QList<QPair<QString, QString>> _importFiles;
41 
42  friend class TJSModule;
43 };
44 
The TJSInstance class acts as a instance for JavaScript data types.
Definition: tjsinstance.h:7
The TJSLoader class loads a JavaScript module in server side.
Definition: tjsloader.h:8
AltJS
Definition: tjsloader.h:10
@ Jsx
Definition: tjsloader.h:12
The TJSModule class represents a module for evaluating JavaScript code.
Definition: tjsmodule.h:15
#define T_CORE_EXPORT
Definition: tdeclexport.h:28