Skip to content

Commit d5c1e25

Browse files
committed
Added package release file for elements.
elements: LanguageNodes: Grouped property output. compileWrap: Fixed compilation call when compiling module.
1 parent 72f09b4 commit d5c1e25

File tree

8 files changed

+185
-125
lines changed

8 files changed

+185
-125
lines changed

lib/lvbase/src/fileio.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ FileIO::~FileIO(){
3434
}
3535

3636
std::string FileIO::readFromFile(const std::string &path){
37+
if ( !Path::isFile(path) ){
38+
THROW_EXCEPTION(lv::Exception, Utf8("Failed to open file for reading, path is not a file or does not exist: %").format(path), lv::Exception::toCode("~File"));
39+
}
40+
3741
std::ifstream instream(path, std::ifstream::in | std::ifstream::binary);
3842
if ( !instream.is_open() ){
3943
THROW_EXCEPTION(lv::Exception, Utf8("Failed to open file: %").format(path), lv::Exception::toCode("~File"));

lib/lvbase/src/package.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class PackagePrivate{
4747
std::string path;
4848
std::string filePath;
4949
std::string documentation;
50+
std::string release;
5051
Version version;
5152
std::map<std::string, Package::Reference*> dependencies;
5253
std::map<std::string, Package::Library*> libraries;
@@ -149,6 +150,10 @@ Package::Ptr Package::createFromNode(const std::string& path, const std::string
149150
pt->m_d->documentation = m["documentation"].asString();
150151
}
151152

153+
if ( m.hasKey("release") ){
154+
pt->m_d->release = m["release"].asString();
155+
}
156+
152157
if ( m.hasKey("workspace") ){
153158
const MLNode& workspace = m["workspace"];
154159
if ( workspace.hasKey("label") )
@@ -207,11 +212,17 @@ const std::string &Package::documentation() const{
207212
return m_d->documentation;
208213
}
209214

215+
/** \brief Returns the package release */
216+
const std::string &Package::release() const{
217+
return m_d->release;
218+
}
219+
210220
/** \brief Returns the package version */
211221
const Version &Package::version() const{
212222
return m_d->version;
213223
}
214224

225+
/** \brief Returns a map of dependencies with string keys */
215226
const std::map<std::string, Package::Reference*>& Package::dependencies() const{
216227
return m_d->dependencies;
217228
}

lib/lvbase/src/package.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ class LV_BASE_EXPORT Package{
139139
const std::string& path() const;
140140
const std::string& filePath() const;
141141
const std::string& documentation() const;
142+
const std::string& release() const;
142143
const Version& version() const;
143-
/** Returns a map of dependencies with string keys */
144144
const std::map<std::string, Package::Reference*>& dependencies() const;
145145
const std::map<std::string, Package::Library*>& libraries() const;
146146
const std::vector<std::string> internalLibraries() const;

lib/lvelements/src/compiler/compiler.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "compiler.h"
1717
#include "live/visuallog.h"
1818
#include "live/packagegraph.h"
19+
#include "live/modulecontext.h"
1920
#include "languagenodes_p.h"
2021
#include "elementssections_p.h"
2122
#include "elementsmodule.h"
@@ -128,13 +129,13 @@ std::string Compiler::compileToJs(const std::string &path, const std::string &co
128129
return result;
129130
}
130131

131-
std::string Compiler::compileModuleFileToJs(const Module::Ptr &plugin, const std::string &path, const std::string &contents, BaseNode *node){
132+
std::string Compiler::compileModuleFileToJs(const Module::Ptr &module, const std::string &path, const std::string &contents, BaseNode *node){
132133
std::string result;
133134
el::JSSection* section = new el::JSSection;
134135
section->from = 0;
135136
section->to = static_cast<int>(contents.size());
136137

137-
Utf8 outputPath = moduleFileBuildPath(plugin, path);
138+
Utf8 outputPath = moduleFileBuildPath(module, path);
138139
Utf8 relativePathFromOutput;
139140

140141
auto outputPathSegments = outputPath.split("/");
@@ -180,14 +181,24 @@ std::string Compiler::compileModuleFileToJs(const Module::Ptr &plugin, const std
180181
if ( m_d->config.m_fileOutput ){
181182
std::string outputFile = outputPath.data();
182183
std::string displayFilePath = path;
183-
Utf8::replaceAll(displayFilePath, plugin->packagePath(), "");
184+
Utf8::replaceAll(displayFilePath, module->packagePath(), "");
184185

185186
bool shouldWrite = true;
186187
if ( m_d->config.m_fileOutputOnlyOnModified && Path::exists(outputFile) ){
187188
DateTime sourceModifiedStamp = Path::lastModified(path);
188189
DateTime outputModifiedStamp = Path::lastModified(outputFile);
189190
shouldWrite = outputModifiedStamp < sourceModifiedStamp;
190191
}
192+
if ( shouldWrite && module->context() ){
193+
auto package = module->context()->package;
194+
if ( !package->release().empty() ){
195+
shouldWrite = false;
196+
if ( !Path::exists(outputPath.data()) ){
197+
Utf8 msg = Utf8("Released package '%' missing build file: %").format(package->name(), displayFilePath);
198+
THROW_EXCEPTION(lv::Exception, msg, Exception::toCode("~File"));
199+
}
200+
}
201+
}
191202

192203
if ( shouldWrite ){
193204
m_d->config.m_fileIO->writeToFile(outputPath.data(), result);

lib/lvelements/src/compiler/languagenodes.cpp

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,62 +2008,17 @@ void ComponentDeclarationNode::convertToJs(const std::string &source, std::vecto
20082008
std::string id = slice(source, m_idComponents[i]->id());
20092009
auto properties = m_idComponents[i]->properties();
20102010

2011-
for (uint32_t idx = 0; idx < properties.size(); ++idx)
2012-
{
2013-
*compose << indent(indentValue + 2) << ConversionContext::baseComponentName(ctx) << ".addProperty(" << id << ", '" << slice(source, properties[idx]->name())
2014-
<< "', { type: \'" << slice(source, properties[idx]->type()) << "\', notify: \'"
2015-
<< slice(source, properties[idx]->name()) << "Changed\' })\n";
2011+
for (uint32_t idx = 0; idx < properties.size(); ++idx){
2012+
std::string propertyName = slice(source, properties[idx]->name());
2013+
PropertyAccessorDeclarationNode::PropertyAccess accessPair;
2014+
properties[idx]->convertToJs(source, id, indentValue + 2, ctx, accessPair, compose);
20162015
}
20172016
}
20182017

20192018
for (size_t i = 0; i < m_properties.size(); ++i){
20202019
std::string propertyName = slice(source, m_properties[i]->name());
2021-
PropertyAccessorDeclarationNode* propertyGetter = nullptr;
2022-
PropertyAccessorDeclarationNode* propertySetter = nullptr;
2023-
for ( size_t j = 0; j < m_propertyAccesors.size(); ++j ){
2024-
PropertyAccessorDeclarationNode* pa = m_propertyAccesors[j];
2025-
if ( slice(source, pa->name()) == propertyName ){
2026-
if ( pa->access() == PropertyAccessorDeclarationNode::Getter ){
2027-
propertyGetter = pa;
2028-
propertyGetter->setIsPropertyAttached(true);
2029-
} else if ( pa->access() == PropertyAccessorDeclarationNode::Setter ){
2030-
propertySetter = pa;
2031-
propertySetter->setIsPropertyAttached(true);
2032-
}
2033-
}
2034-
}
2035-
*compose << indent(indentValue + 2) << ConversionContext::baseComponentName(ctx) << ".addProperty(this, '" << slice(source, m_properties[i]->name())
2036-
<< "', { type: \'" << (m_properties[i]->type() ? slice(source, m_properties[i]->type()) : "") << "\', notify: \'"
2037-
<< slice(source, m_properties[i]->name()) << "Changed\' ";
2038-
2039-
if ( propertyGetter ){
2040-
*compose << ", get: function()";
2041-
JSSection* jssection = new JSSection;
2042-
jssection->from = propertyGetter->body()->startByte();
2043-
jssection->to = propertyGetter->body()->endByte();
2044-
propertyGetter->body()->convertToJs(source, jssection->m_children, indentValue + 1, ctx);
2045-
std::vector<std::string> flat;
2046-
jssection->flatten(source, flat);
2047-
for (auto s: flat){
2048-
*compose << s << "\n";
2049-
}
2050-
delete jssection;
2051-
}
2052-
if ( propertySetter ){
2053-
*compose << ", set: function(" << (propertySetter->firstParameterName() ? slice(source, propertySetter->firstParameterName()) : "") << ")";
2054-
JSSection* jssection = new JSSection;
2055-
jssection->from = propertySetter->body()->startByte();
2056-
jssection->to = propertySetter->body()->endByte();
2057-
propertySetter->body()->convertToJs(source, jssection->m_children, indentValue + 1, ctx);
2058-
std::vector<std::string> flat;
2059-
jssection->flatten(source, flat);
2060-
for (auto s: flat){
2061-
*compose << s << "\n";
2062-
}
2063-
delete jssection;
2064-
}
2065-
2066-
*compose << "})\n";
2020+
PropertyAccessorDeclarationNode::PropertyAccess accessPair = propertyAccessors(source, propertyName);
2021+
m_properties[i]->convertToJs(source, "this", indentValue + 2, ctx, accessPair, compose);
20672022
}
20682023

20692024
for (size_t i = 0; i < m_events.size(); ++i){
@@ -2379,6 +2334,25 @@ void ComponentDeclarationNode::convertToJs(const std::string &source, std::vecto
23792334
fragments.push_back(compose);
23802335
}
23812336

2337+
PropertyAccessorDeclarationNode::PropertyAccess ComponentDeclarationNode::propertyAccessors(const std::string &source, const std::string &propertyName){
2338+
PropertyAccessorDeclarationNode::PropertyAccess result;
2339+
2340+
for ( size_t j = 0; j < m_propertyAccesors.size(); ++j ){
2341+
PropertyAccessorDeclarationNode* pa = m_propertyAccesors[j];
2342+
if ( slice(source, pa->name()) == propertyName ){
2343+
if ( pa->access() == PropertyAccessorDeclarationNode::Getter ){
2344+
result.getter = pa;
2345+
pa->setIsPropertyAttached(true);
2346+
} else if ( pa->access() == PropertyAccessorDeclarationNode::Setter ){
2347+
result.setter = pa;
2348+
pa->setIsPropertyAttached(true);
2349+
}
2350+
}
2351+
}
2352+
2353+
return result;
2354+
}
2355+
23822356
std::string ComponentDeclarationNode::name(const std::string& source) const{
23832357
std::string name = slice(source, m_name);
23842358

@@ -2436,33 +2410,30 @@ void NewComponentExpressionNode::convertToJs(const std::string &source, std::vec
24362410
}
24372411

24382412
if (isRoot || !m_id){
2439-
for (size_t i = 0; i < m_properties.size(); ++i)
2440-
{
2441-
*compose << indent(indt + 2) << ConversionContext::baseComponentName(ctx) << ".addProperty(" + id_root + ", '" << slice(source, m_properties[i]->name())
2442-
<< "', { type: '" << (m_properties[i]->type() ? slice(source, m_properties[i]->type()) : "") << "', notify: '"
2443-
<< slice(source, m_properties[i]->name()) << "Changed' })\n";
2413+
for (size_t i = 0; i < m_properties.size(); ++i){
2414+
std::string propertyName = slice(source, m_properties[i]->name());
2415+
PropertyAccessorDeclarationNode::PropertyAccess accessPair;
2416+
m_properties[i]->convertToJs(source, id_root, indt + 2, ctx, accessPair, compose);
24442417
}
24452418
}
24462419

24472420
if (isRoot && !m_idComponents.empty()){
2448-
for (size_t i = 0; i < m_idComponents.size();++i)
2449-
{
2421+
for (size_t i = 0; i < m_idComponents.size();++i){
24502422
std::string id = slice(source, m_idComponents[i]->id());
24512423
auto properties = m_idComponents[i]->properties();
24522424

2453-
for (size_t idx = 0; idx < properties.size(); ++idx)
2454-
{
2455-
*compose << indent(indt + 1) << ConversionContext::baseComponentName(ctx) << ".addProperty(" << id << ", '" << slice(source, properties[idx]->name())
2456-
<< "', { type: '" << slice(source, properties[idx]->type()) << "', notify: '"
2457-
<< slice(source, properties[idx]->name()) << "Changed' })\n";
2425+
for (size_t idx = 0; idx < properties.size(); ++idx){
2426+
std::string propertyName = slice(source, properties[idx]->name());
2427+
PropertyAccessorDeclarationNode::PropertyAccess accessPair;
2428+
properties[idx]->convertToJs(source, id, indt + 1, ctx, accessPair, compose);
24582429
}
24592430
}
24602431
}
24612432

24622433
for (size_t i = 0; i < m_properties.size(); ++i){
24632434

24642435
std::string bindingsInJs = m_properties[i]->bindingIdentifiersToJs(source);
2465-
if (bindingsInJs.size() > 0){
2436+
if (bindingsInJs.size() > 0 && m_properties[i]->isBindingsAssignment() ){
24662437
std::string comp = "";
24672438
if (m_properties[i]->expression()){
24682439
comp += indent(indt + 1) + ConversionContext::baseComponentName(ctx) + ".assignPropertyExpression(this,\n"
@@ -2891,6 +2862,50 @@ std::string PropertyDeclarationNode::bindingIdentifiersToJs(const std::string &s
28912862
return m_bindingContainer->bindingIdentifiersToJs(source);
28922863
}
28932864

2865+
void PropertyDeclarationNode::convertToJs(
2866+
const std::string &source,
2867+
const std::string &componentReference,
2868+
int indt,
2869+
BaseNode::ConversionContext *ctx,
2870+
const PropertyAccessorDeclarationNode::PropertyAccess &propertyAccess,
2871+
ElementsInsertion* compose)
2872+
{
2873+
*compose << indent(indt) << ConversionContext::baseComponentName(ctx) << ".addProperty(" + componentReference + ", '" << slice(source, name())
2874+
<< "', { type: '" << (type() ? slice(source, type()) : "") << "', notify: '"
2875+
<< slice(source, name()) << "Changed'";
2876+
2877+
2878+
if ( propertyAccess.getter ){
2879+
*compose << ", get: function()";
2880+
JSSection* jssection = new JSSection;
2881+
jssection->from = propertyAccess.getter->body()->startByte();
2882+
jssection->to = propertyAccess.getter->body()->endByte();
2883+
propertyAccess.getter->body()->convertToJs(source, jssection->m_children, indt + 1, ctx);
2884+
std::vector<std::string> flat;
2885+
jssection->flatten(source, flat);
2886+
for (auto s: flat){
2887+
*compose << s << "\n";
2888+
}
2889+
delete jssection;
2890+
}
2891+
if ( propertyAccess.setter ){
2892+
*compose << ", set: function(" << (propertyAccess.setter->firstParameterName() ? slice(source, propertyAccess.setter->firstParameterName()) : "") << ")";
2893+
JSSection* jssection = new JSSection;
2894+
jssection->from = propertyAccess.setter->body()->startByte();
2895+
jssection->to = propertyAccess.setter->body()->endByte();
2896+
propertyAccess.setter->body()->convertToJs(source, jssection->m_children, indt + 1, ctx);
2897+
std::vector<std::string> flat;
2898+
jssection->flatten(source, flat);
2899+
for (auto s: flat){
2900+
*compose << s << "\n";
2901+
}
2902+
delete jssection;
2903+
}
2904+
2905+
2906+
*compose << "})\n";
2907+
}
2908+
28942909
StaticPropertyDeclarationNode::StaticPropertyDeclarationNode(const TSNode &node)
28952910
: BaseNode(node, "StaticPropertyDeclaration")
28962911
, m_name(nullptr)

0 commit comments

Comments
 (0)