@@ -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+
23822356std::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+
28942909StaticPropertyDeclarationNode::StaticPropertyDeclarationNode (const TSNode &node)
28952910 : BaseNode(node, " StaticPropertyDeclaration" )
28962911 , m_name(nullptr )
0 commit comments