@teleporthq/teleport-plugin-common 0.45.13 → 0.45.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/node-handlers/node-to-jsx/index.ts +183 -0
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/index.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/index.js +9 -47
- package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts +21 -6
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.js +102 -19
- package/dist/cjs/node-handlers/node-to-jsx/utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.js +8 -46
- package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts +21 -6
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.js +94 -19
- package/dist/esm/node-handlers/node-to-jsx/utils.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +7 -0
- package/src/node-handlers/node-to-jsx/index.ts +12 -62
- package/src/node-handlers/node-to-jsx/utils.ts +148 -22
|
@@ -594,6 +594,189 @@ describe('generateJSXSyntax', () => {
|
|
|
594
594
|
})
|
|
595
595
|
})
|
|
596
596
|
|
|
597
|
+
describe('a rendering condition whose right side is a global state', () => {
|
|
598
|
+
const SELECTED_ID = 'f3a1c2d4-selected'
|
|
599
|
+
const PROFILE_ID = 'b7e9d0a2-profile'
|
|
600
|
+
const globalStateDefinitions = {
|
|
601
|
+
[SELECTED_ID]: { id: SELECTED_ID, name: 'selectedRow', type: 'string', defaultValue: '' },
|
|
602
|
+
[PROFILE_ID]: { id: PROFILE_ID, name: 'profile', type: 'object', defaultValue: {} },
|
|
603
|
+
} as unknown as JSXGenerationParams['globalStateDefinitions']
|
|
604
|
+
|
|
605
|
+
const globalState = (id: string, refPath?: string[]) => ({
|
|
606
|
+
type: 'dynamic',
|
|
607
|
+
content: { referenceType: 'globalState', id, ...(refPath ? { refPath } : {}) },
|
|
608
|
+
})
|
|
609
|
+
|
|
610
|
+
const generateCondition = (renderingConditions: unknown) => {
|
|
611
|
+
const ownerContainer = elementNode('container', {}, [])
|
|
612
|
+
ownerContainer.content.renderingConditions = renderingConditions as never
|
|
613
|
+
const conditionParams: JSXGenerationParams = {
|
|
614
|
+
...params,
|
|
615
|
+
stateDefinitions: { count: { type: 'number', defaultValue: 0 } },
|
|
616
|
+
globalStateDefinitions,
|
|
617
|
+
globalReferences: [],
|
|
618
|
+
globalStateReferences: [],
|
|
619
|
+
}
|
|
620
|
+
const result = generateJSXSyntax(
|
|
621
|
+
elementNode('container', {}, [ownerContainer]),
|
|
622
|
+
conditionParams,
|
|
623
|
+
{ ...options, localIdentifier: 'row' }
|
|
624
|
+
)
|
|
625
|
+
const expressionChild = result.children[0] as types.JSXExpressionContainer
|
|
626
|
+
return {
|
|
627
|
+
code: generate((expressionChild.expression as types.LogicalExpression).left).code,
|
|
628
|
+
references: conditionParams.globalStateReferences,
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const listItemField = { type: 'dynamic', content: { referenceType: 'local', refPath: ['id'] } }
|
|
633
|
+
|
|
634
|
+
it('reads the state by its declared name and registers it on the file', () => {
|
|
635
|
+
const { code, references } = generateCondition({
|
|
636
|
+
reference: listItemField,
|
|
637
|
+
condition: { conditions: [{ operation: '===', operand: globalState(SELECTED_ID) }] },
|
|
638
|
+
})
|
|
639
|
+
|
|
640
|
+
expect(code).toBe('row.id === selectedRow')
|
|
641
|
+
expect(references).toEqual([{ id: SELECTED_ID, name: 'selectedRow' }])
|
|
642
|
+
})
|
|
643
|
+
|
|
644
|
+
it('follows a field path into an object state', () => {
|
|
645
|
+
const { code, references } = generateCondition({
|
|
646
|
+
reference: listItemField,
|
|
647
|
+
condition: {
|
|
648
|
+
conditions: [{ operation: '!==', operand: globalState(PROFILE_ID, ['team', 'id']) }],
|
|
649
|
+
},
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
expect(code).toBe('row.id !== profile?.team?.id')
|
|
653
|
+
expect(references).toEqual([{ id: PROFILE_ID, name: 'profile' }])
|
|
654
|
+
})
|
|
655
|
+
|
|
656
|
+
it('compares a global state against a global state', () => {
|
|
657
|
+
const { code, references } = generateCondition({
|
|
658
|
+
reference: globalState(SELECTED_ID),
|
|
659
|
+
condition: {
|
|
660
|
+
conditions: [{ operation: '===', operand: globalState(PROFILE_ID, ['id']) }],
|
|
661
|
+
},
|
|
662
|
+
})
|
|
663
|
+
|
|
664
|
+
expect(code).toBe('selectedRow === profile?.id')
|
|
665
|
+
expect(references).toEqual([
|
|
666
|
+
{ id: SELECTED_ID, name: 'selectedRow' },
|
|
667
|
+
{ id: PROFILE_ID, name: 'profile' },
|
|
668
|
+
])
|
|
669
|
+
})
|
|
670
|
+
|
|
671
|
+
it('resolves the right side of collection and length operators the same way', () => {
|
|
672
|
+
const stateCount = { type: 'dynamic', content: { referenceType: 'state', id: 'count' } }
|
|
673
|
+
const operandOf = (operation: string) =>
|
|
674
|
+
generateCondition({
|
|
675
|
+
reference: stateCount,
|
|
676
|
+
condition: { conditions: [{ operation, operand: globalState(SELECTED_ID) }] },
|
|
677
|
+
})
|
|
678
|
+
|
|
679
|
+
expect(operandOf('contains').code).toBe('(count || []).includes(selectedRow)')
|
|
680
|
+
expect(operandOf('lengthEquals').code).toBe('(count || []).length === selectedRow')
|
|
681
|
+
expect(operandOf('hasKey').code).toBe(
|
|
682
|
+
'Object.prototype.hasOwnProperty.call(count || [], selectedRow)'
|
|
683
|
+
)
|
|
684
|
+
expect(operandOf('contains').references).toEqual([{ id: SELECTED_ID, name: 'selectedRow' }])
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
it('resolves a right side on a per-entry reference nested inside a group', () => {
|
|
688
|
+
const { code, references } = generateCondition({
|
|
689
|
+
reference: listItemField,
|
|
690
|
+
condition: {
|
|
691
|
+
conditions: [
|
|
692
|
+
{ operation: '===', operand: 'a' },
|
|
693
|
+
{
|
|
694
|
+
conditions: [
|
|
695
|
+
{
|
|
696
|
+
operation: '===',
|
|
697
|
+
operand: globalState(PROFILE_ID, ['id']),
|
|
698
|
+
reference: globalState(SELECTED_ID),
|
|
699
|
+
},
|
|
700
|
+
],
|
|
701
|
+
},
|
|
702
|
+
],
|
|
703
|
+
matchingCriteria: 'all',
|
|
704
|
+
},
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
expect(code).toBe('row.id === "a" && selectedRow === profile?.id')
|
|
708
|
+
expect(references).toEqual([
|
|
709
|
+
{ id: SELECTED_ID, name: 'selectedRow' },
|
|
710
|
+
{ id: PROFILE_ID, name: 'profile' },
|
|
711
|
+
])
|
|
712
|
+
})
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
describe('a rendering condition whose right side is a built-in global', () => {
|
|
716
|
+
const builtInGlobal = (id: string | undefined, refPath: string[]) => ({
|
|
717
|
+
type: 'dynamic',
|
|
718
|
+
content: { referenceType: 'global', ...(id ? { id } : {}), refPath },
|
|
719
|
+
})
|
|
720
|
+
const listItemField = { type: 'dynamic', content: { referenceType: 'local', refPath: ['id'] } }
|
|
721
|
+
|
|
722
|
+
const generateCondition = (reference: unknown, operand: unknown) => {
|
|
723
|
+
const ownerContainer = elementNode('container', {}, [])
|
|
724
|
+
ownerContainer.content.renderingConditions = {
|
|
725
|
+
reference,
|
|
726
|
+
condition: { conditions: [{ operation: '===', operand }] },
|
|
727
|
+
} as never
|
|
728
|
+
const conditionParams: JSXGenerationParams = {
|
|
729
|
+
...params,
|
|
730
|
+
globalReferences: [],
|
|
731
|
+
globalStateReferences: [],
|
|
732
|
+
}
|
|
733
|
+
const result = generateJSXSyntax(
|
|
734
|
+
elementNode('container', {}, [ownerContainer]),
|
|
735
|
+
conditionParams,
|
|
736
|
+
{ ...options, localIdentifier: 'row' }
|
|
737
|
+
)
|
|
738
|
+
const expressionChild = result.children[0] as types.JSXExpressionContainer
|
|
739
|
+
return {
|
|
740
|
+
code: generate((expressionChild.expression as types.LogicalExpression).left).code,
|
|
741
|
+
references: conditionParams.globalReferences,
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
it('registers a global named by its runtime identifier', () => {
|
|
746
|
+
const { code, references } = generateCondition(
|
|
747
|
+
listItemField,
|
|
748
|
+
builtInGlobal('currentUser', ['id'])
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
expect(code).toBe("row.id === currentUser?.['id']")
|
|
752
|
+
expect(references).toEqual(['currentUser'])
|
|
753
|
+
})
|
|
754
|
+
|
|
755
|
+
it('derives the runtime identifier of a global named only by its display path', () => {
|
|
756
|
+
const withoutId = generateCondition(
|
|
757
|
+
listItemField,
|
|
758
|
+
builtInGlobal(undefined, ['Current User', 'id'])
|
|
759
|
+
)
|
|
760
|
+
const withOpaqueId = generateCondition(
|
|
761
|
+
listItemField,
|
|
762
|
+
builtInGlobal('TQ_opaque', ['Current User', 'id'])
|
|
763
|
+
)
|
|
764
|
+
|
|
765
|
+
expect(withoutId.code).toBe("row.id === currentUser?.['id']")
|
|
766
|
+
expect(withoutId.references).toEqual(['currentUser'])
|
|
767
|
+
expect(withOpaqueId.code).toBe("row.id === currentUser?.['id']")
|
|
768
|
+
expect(withOpaqueId.references).toEqual(['currentUser'])
|
|
769
|
+
})
|
|
770
|
+
|
|
771
|
+
it('reads the same global the same way on either side', () => {
|
|
772
|
+
const company = builtInGlobal(undefined, ['Company', 'ownerId'])
|
|
773
|
+
const { code, references } = generateCondition(company, builtInGlobal('currentUser', ['id']))
|
|
774
|
+
|
|
775
|
+
expect(code).toBe("company?.['ownerId'] === currentUser?.['id']")
|
|
776
|
+
expect(references).toEqual(['company', 'currentUser'])
|
|
777
|
+
})
|
|
778
|
+
})
|
|
779
|
+
|
|
597
780
|
describe('navlink href via differentiatorValue', () => {
|
|
598
781
|
// The navlink attribute flow is exercised end-to-end in the resolver tests;
|
|
599
782
|
// here we only confirm that an `expr`-typed attribute which mentions
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ import * as URLSearchParamSync from './utils/url-search-param-sync';
|
|
|
8
8
|
import * as URLQueryWriter from './utils/url-query-writer';
|
|
9
9
|
import * as RouteUtils from './utils/route-utils';
|
|
10
10
|
import ParsedASTNode from './utils/parsed-ast';
|
|
11
|
-
import { createBinaryExpression, createClassConditionExpression } from './node-handlers/node-to-jsx/utils';
|
|
12
|
-
export { ASTBuilders, StyleBuilders, HASTBuilders, ASTUtils, StyleUtils, HASTUtils, URLSearchParamSync, URLQueryWriter, RouteUtils, ParsedASTNode, createBinaryExpression, createClassConditionExpression, };
|
|
11
|
+
import { createBinaryExpression, createClassConditionExpression, createConditionOperandResolver, createGlobalStateClassConditionIdentifier, isGlobalStateReference } from './node-handlers/node-to-jsx/utils';
|
|
12
|
+
export { ASTBuilders, StyleBuilders, HASTBuilders, ASTUtils, StyleUtils, HASTUtils, URLSearchParamSync, URLQueryWriter, RouteUtils, ParsedASTNode, createBinaryExpression, createClassConditionExpression, createConditionOperandResolver, createGlobalStateClassConditionIdentifier, isGlobalStateReference, };
|
|
13
|
+
export type { ConditionReferenceRegistry } from './node-handlers/node-to-jsx/utils';
|
|
13
14
|
export { default as createHTMLTemplateSyntax } from './node-handlers/node-to-html';
|
|
14
15
|
export { default as createJSXSyntax } from './node-handlers/node-to-jsx';
|
|
15
16
|
export * from './node-handlers/node-to-html/types';
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AAExD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAA;AAC7C,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,kBAAkB,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,cAAc,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EACL,sBAAsB,EACtB,8BAA8B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AAExD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAA;AAC7C,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,kBAAkB,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,cAAc,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EACL,sBAAsB,EACtB,8BAA8B,EAC9B,8BAA8B,EAC9B,yCAAyC,EACzC,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAE1C,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,8BAA8B,EAC9B,8BAA8B,EAC9B,yCAAyC,EACzC,sBAAsB,GACvB,CAAA;AAED,YAAY,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AACnF,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAExE,cAAc,oCAAoC,CAAA;AAClD,cAAc,mCAAmC,CAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.createJSXSyntax = exports.createHTMLTemplateSyntax = exports.createClassConditionExpression = exports.createBinaryExpression = exports.ParsedASTNode = exports.RouteUtils = exports.URLQueryWriter = exports.URLSearchParamSync = exports.HASTUtils = exports.StyleUtils = exports.ASTUtils = exports.HASTBuilders = exports.StyleBuilders = exports.ASTBuilders = void 0;
|
|
32
|
+
exports.createJSXSyntax = exports.createHTMLTemplateSyntax = exports.isGlobalStateReference = exports.createGlobalStateClassConditionIdentifier = exports.createConditionOperandResolver = exports.createClassConditionExpression = exports.createBinaryExpression = exports.ParsedASTNode = exports.RouteUtils = exports.URLQueryWriter = exports.URLSearchParamSync = exports.HASTUtils = exports.StyleUtils = exports.ASTUtils = exports.HASTBuilders = exports.StyleBuilders = exports.ASTBuilders = void 0;
|
|
33
33
|
var ASTBuilders = __importStar(require("./builders/ast-builders"));
|
|
34
34
|
exports.ASTBuilders = ASTBuilders;
|
|
35
35
|
var StyleBuilders = __importStar(require("./builders/style-builders"));
|
|
@@ -53,6 +53,9 @@ exports.ParsedASTNode = parsed_ast_1.default;
|
|
|
53
53
|
var utils_1 = require("./node-handlers/node-to-jsx/utils");
|
|
54
54
|
Object.defineProperty(exports, "createBinaryExpression", { enumerable: true, get: function () { return utils_1.createBinaryExpression; } });
|
|
55
55
|
Object.defineProperty(exports, "createClassConditionExpression", { enumerable: true, get: function () { return utils_1.createClassConditionExpression; } });
|
|
56
|
+
Object.defineProperty(exports, "createConditionOperandResolver", { enumerable: true, get: function () { return utils_1.createConditionOperandResolver; } });
|
|
57
|
+
Object.defineProperty(exports, "createGlobalStateClassConditionIdentifier", { enumerable: true, get: function () { return utils_1.createGlobalStateClassConditionIdentifier; } });
|
|
58
|
+
Object.defineProperty(exports, "isGlobalStateReference", { enumerable: true, get: function () { return utils_1.isGlobalStateReference; } });
|
|
56
59
|
var node_to_html_1 = require("./node-handlers/node-to-html");
|
|
57
60
|
Object.defineProperty(exports, "createHTMLTemplateSyntax", { enumerable: true, get: function () { return __importDefault(node_to_html_1).default; } });
|
|
58
61
|
var node_to_jsx_1 = require("./node-handlers/node-to-jsx");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAAsD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAAsD;AAqBpD,kCAAW;AApBb,uEAA0D;AAqBxD,sCAAa;AApBf,qEAAwD;AAqBtD,oCAAY;AAnBd,0DAA6C;AAoB3C,4BAAQ;AAnBV,8DAAiD;AAoB/C,gCAAU;AAnBZ,4DAA+C;AAoB7C,8BAAS;AAnBX,gFAAmE;AAoBjE,gDAAkB;AAnBpB,uEAA0D;AAoBxD,wCAAc;AAnBhB,8DAAiD;AAoB/C,gCAAU;AAnBZ,kEAA8C;AAoB5C,wBApBK,oBAAa,CAoBL;AAlBf,2DAM0C;AAaxC,uGAlBA,8BAAsB,OAkBA;AACtB,+GAlBA,sCAA8B,OAkBA;AAC9B,+GAlBA,sCAA8B,OAkBA;AAC9B,0HAlBA,iDAAyC,OAkBA;AACzC,uGAlBA,8BAAsB,OAkBA;AAIxB,6DAAkF;AAAzE,yIAAA,OAAO,OAA4B;AAC5C,2DAAwE;AAA/D,+HAAA,OAAO,OAAmB;AAEnC,qEAAkD;AAClD,oEAAiD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/node-handlers/node-to-jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EACL,eAAe,EAiBhB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAKL,SAAS,EACV,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/node-handlers/node-to-jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EACL,eAAe,EAiBhB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAKL,SAAS,EACV,MAAM,SAAS,CAAA;AAsuBhB,QAAA,MAAM,mBAAmB,EAAE,SAAS,CAAC,eAAe,EAAE,KAAK,CAAC,UAAU,CAySrE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -190,34 +190,6 @@ var trackGlobalRefsInExpression = function (expression, params) {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
|
-
// The recognised runtime identifiers a `global` reference's `id` can legitimately
|
|
194
|
-
// already hold (Shape A). Anything else — notably the opaque `TQ_...` node id every
|
|
195
|
-
// dynamic UIDL reference carries for editor bookkeeping — is not a real identifier
|
|
196
|
-
// and must be re-derived from `refPath` (Shape B/C), or code generation would emit
|
|
197
|
-
// an undeclared variable that throws at runtime.
|
|
198
|
-
var KNOWN_GLOBAL_REF_IDS = new Set([
|
|
199
|
-
'locale',
|
|
200
|
-
'locales',
|
|
201
|
-
'company',
|
|
202
|
-
'currentUser',
|
|
203
|
-
'userIsLoggedIn',
|
|
204
|
-
'ecommerce',
|
|
205
|
-
'cart',
|
|
206
|
-
]);
|
|
207
|
-
var normalizeGlobalRef = function (node) {
|
|
208
|
-
if (!node.content.refPath || node.content.refPath.length === 0) {
|
|
209
|
-
return node;
|
|
210
|
-
}
|
|
211
|
-
if (node.content.id && KNOWN_GLOBAL_REF_IDS.has(node.content.id)) {
|
|
212
|
-
return node;
|
|
213
|
-
}
|
|
214
|
-
var firstSeg = node.content.refPath[0];
|
|
215
|
-
var mappedId = ast_utils_1.GLOBAL_REF_ID_MAP[firstSeg];
|
|
216
|
-
if (!mappedId) {
|
|
217
|
-
return node;
|
|
218
|
-
}
|
|
219
|
-
return __assign(__assign({}, node), { content: __assign(__assign({}, node.content), { id: mappedId, refPath: node.content.refPath.slice(1) }) });
|
|
220
|
-
};
|
|
221
193
|
var getElementType = function (node) {
|
|
222
194
|
if (node.type === 'element' &&
|
|
223
195
|
node.content &&
|
|
@@ -855,7 +827,7 @@ var addAttributesToJSXTag = function (attrs, elementTag, options, params, elemen
|
|
|
855
827
|
var dynamicRef = attributeValue;
|
|
856
828
|
var referenceType = dynamicRef.content.referenceType;
|
|
857
829
|
if (referenceType === 'global') {
|
|
858
|
-
var normRef = normalizeGlobalRef(dynamicRef);
|
|
830
|
+
var normRef = (0, utils_1.normalizeGlobalRef)(dynamicRef);
|
|
859
831
|
params.globalReferences.push(normRef.content.id);
|
|
860
832
|
// Use the normalized ref to generate the attribute expression
|
|
861
833
|
var globalExpr = (0, utils_1.createDynamicValueExpression)(normRef, options);
|
|
@@ -1068,7 +1040,7 @@ var generateNode = function (node, params, options) {
|
|
|
1068
1040
|
return [jsxTag];
|
|
1069
1041
|
}
|
|
1070
1042
|
case 'global': {
|
|
1071
|
-
var globalNode = normalizeGlobalRef(node);
|
|
1043
|
+
var globalNode = (0, utils_1.normalizeGlobalRef)(node);
|
|
1072
1044
|
params.globalReferences.push(globalNode.content.id);
|
|
1073
1045
|
return [(0, utils_1.createDynamicValueExpression)(globalNode, options)];
|
|
1074
1046
|
}
|
|
@@ -1360,22 +1332,11 @@ var generateRepeatNode = function (node, params, options) {
|
|
|
1360
1332
|
// resolves it to a ConditionalIdentifier. Shared by the top-level reference
|
|
1361
1333
|
// and the optional per-entry references of a conditional expression.
|
|
1362
1334
|
var trackAndResolveConditionIdentifier = function (reference, params, options) {
|
|
1363
|
-
if (reference
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1369
|
-
if (reference.type === 'dynamic' &&
|
|
1370
|
-
'referenceType' in reference.content &&
|
|
1371
|
-
reference.content.referenceType === 'globalState') {
|
|
1372
|
-
var gsName = (0, utils_1.resolveGlobalStateName)(reference.content.id, params.globalStateDefinitions);
|
|
1373
|
-
params.globalStateReferences.push({ id: reference.content.id, name: gsName });
|
|
1374
|
-
}
|
|
1375
|
-
var effectiveRef = reference.type === 'dynamic' &&
|
|
1376
|
-
'referenceType' in reference.content &&
|
|
1377
|
-
reference.content.referenceType === 'global'
|
|
1378
|
-
? normalizeGlobalRef(reference)
|
|
1335
|
+
if ((0, utils_1.isGlobalStateReference)(reference)) {
|
|
1336
|
+
(0, utils_1.registerGlobalStateReference)(reference, params);
|
|
1337
|
+
}
|
|
1338
|
+
var effectiveRef = (0, utils_1.isGlobalReference)(reference)
|
|
1339
|
+
? (0, utils_1.registerGlobalReference)(reference, params)
|
|
1379
1340
|
: reference;
|
|
1380
1341
|
return (0, utils_1.createConditionIdentifier)(effectiveRef, params, options);
|
|
1381
1342
|
};
|
|
@@ -1396,6 +1357,7 @@ var wrapWithConditional = function (subTree, reference, condition, params, optio
|
|
|
1396
1357
|
? trackAndResolveConditionIdentifier(conditionEntry.reference, params, options)
|
|
1397
1358
|
: undefined;
|
|
1398
1359
|
},
|
|
1360
|
+
resolveOperandReference: (0, utils_1.createConditionOperandResolver)(params),
|
|
1399
1361
|
});
|
|
1400
1362
|
};
|
|
1401
1363
|
var generateConditionalNode = function (node, params, options) {
|
|
@@ -1598,7 +1560,7 @@ var generateNativeSlotNode = function (node, params, options) {
|
|
|
1598
1560
|
var resolveDynamicReferenceExpression = function (dynamicRef, params, options) {
|
|
1599
1561
|
var referenceType = dynamicRef.content.referenceType;
|
|
1600
1562
|
if (referenceType === 'global') {
|
|
1601
|
-
var normDynRef = normalizeGlobalRef(dynamicRef);
|
|
1563
|
+
var normDynRef = (0, utils_1.normalizeGlobalRef)(dynamicRef);
|
|
1602
1564
|
params.globalReferences.push(normDynRef.content.id);
|
|
1603
1565
|
return (0, utils_1.createDynamicValueExpression)(normDynRef, options);
|
|
1604
1566
|
}
|