MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxDeclareNodeHoist

Function fxDeclareNodeHoist

xs/sources/xsScope.c:552–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550}
551
552void fxDeclareNodeHoist(void* it, void* param)
553{
554 txDeclareNode* self = it;
555 txHoister* hoister = param;
556 txDeclareNode* node;
557 txScope* scope;
558 if (self->description->token == XS_TOKEN_ARG) {
559 node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
560 if (node) {
561 if ((node->description->token == XS_TOKEN_ARG) && (hoister->functionScope->node->flags & (mxArrowFlag | mxAsyncFlag | mxMethodFlag | mxNotSimpleParametersFlag | mxStrictFlag)))
562 fxReportParserError(hoister->parser, self->line, "duplicate argument %s", self->symbol->string);
563 }
564 else {
565 fxScopeAddDeclareNode(hoister->functionScope, self);
566 }
567 }
568 else if ((self->description->token == XS_TOKEN_CONST) || (self->description->token == XS_TOKEN_LET) || (self->description->token == XS_TOKEN_USING)) {
569 node = fxScopeGetDeclareNode(hoister->scope, self->symbol);
570 if (!node && (hoister->scope == hoister->bodyScope)) {
571 node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
572 if (node && (node->description->token != XS_TOKEN_ARG))
573 node = C_NULL;
574 }
575 if (node)
576 fxReportParserError(hoister->parser, self->line, "duplicate variable %s", self->symbol->string);
577 else
578 fxScopeAddDeclareNode(hoister->scope, self);
579 }
580 else {
581 scope = hoister->scope;
582 node = C_NULL;
583 while (scope != hoister->bodyScope) {
584 node = fxScopeGetDeclareNode(scope, self->symbol);
585 if (node) {
586 if ((node->description->token == XS_TOKEN_CONST) || (node->description->token == XS_TOKEN_LET) || (node->description->token == XS_TOKEN_USING) || (node->description->token == XS_TOKEN_DEFINE))
587 break;
588 node = C_NULL;
589 }
590 scope = scope->scope;
591 }
592 if (!node) {
593 node = fxScopeGetDeclareNode(scope, self->symbol);
594 if (node) {
595 if ((node->description->token != XS_TOKEN_CONST) && (node->description->token != XS_TOKEN_LET) && (node->description->token != XS_TOKEN_USING))
596 node = C_NULL;
597 }
598 }
599 if (node)
600 fxReportParserError(hoister->parser, self->line, "duplicate variable %s", self->symbol->string);
601 else {
602 node = fxScopeGetDeclareNode(hoister->functionScope, self->symbol);
603 if (!node || ((node->description->token != XS_TOKEN_ARG) && (node->description->token != XS_TOKEN_VAR)))
604 fxScopeAddDeclareNode(hoister->bodyScope, self);
605 scope = hoister->scope;
606 while (scope != hoister->bodyScope) {
607 fxScopeAddDeclareNode(scope, fxDeclareNodeNew(hoister->parser, XS_NO_TOKEN, self->symbol));
608 scope = scope->scope;
609 }

Callers

nothing calls this directly

Calls 4

fxScopeGetDeclareNodeFunction · 0.85
fxReportParserErrorFunction · 0.85
fxScopeAddDeclareNodeFunction · 0.85
fxDeclareNodeNewFunction · 0.85

Tested by

no test coverage detected