@nordcraft/search 1.0.39 → 1.0.41
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/dist/rules/actions/legacyActionRule.js +168 -2
- package/dist/rules/actions/legacyActionRule.js.map +1 -1
- package/dist/rules/actions/legacyActionRule.test.js +304 -1
- package/dist/rules/actions/legacyActionRule.test.js.map +1 -1
- package/dist/rules/formulas/legacyFormulaRule.js +5 -23
- package/dist/rules/formulas/legacyFormulaRule.js.map +1 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.js +73 -58
- package/dist/rules/formulas/noReferenceProjectFormulaRule.js.map +1 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.test.js +34 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.test.js.map +1 -1
- package/dist/util/helpers.js +13 -2
- package/dist/util/helpers.js.map +1 -1
- package/package.json +2 -2
- package/src/rules/actions/legacyActionRule.test.ts +316 -1
- package/src/rules/actions/legacyActionRule.ts +191 -4
- package/src/rules/formulas/legacyFormulaRule.ts +9 -31
- package/src/rules/formulas/noReferenceProjectFormulaRule.test.ts +36 -1
- package/src/rules/formulas/noReferenceProjectFormulaRule.ts +78 -64
- package/src/types.d.ts +7 -1
- package/src/util/helpers.ts +28 -3
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { valueFormula } from '@nordcraft/core/dist/formula/formulaUtils';
|
|
2
|
+
import { set } from '@nordcraft/core/dist/utils/collections';
|
|
3
|
+
import { isLegacyAction, renameArguments } from '../../util/helpers';
|
|
2
4
|
export const legacyActionRule = {
|
|
3
5
|
code: 'legacy action',
|
|
4
6
|
level: 'warning',
|
|
@@ -14,8 +16,172 @@ export const legacyActionRule = {
|
|
|
14
16
|
name: value.name,
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
|
-
report(path, details)
|
|
19
|
+
report(path, details, unfixableLegacyActions.has(value.name)
|
|
20
|
+
? undefined
|
|
21
|
+
: !formulaNamedActions.includes(value.name) ||
|
|
22
|
+
// Check if the first argument is a value formula with a string value
|
|
23
|
+
(value.arguments?.[0].formula.type === 'value' &&
|
|
24
|
+
typeof value.arguments[0].formula.value === 'string')
|
|
25
|
+
? ['replace-legacy-action']
|
|
26
|
+
: undefined);
|
|
18
27
|
}
|
|
19
28
|
},
|
|
29
|
+
fixes: {
|
|
30
|
+
'replace-legacy-action': ({ path, value, nodeType, files }) => {
|
|
31
|
+
if (nodeType !== 'action-model') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!isLegacyAction(value)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let newAction;
|
|
38
|
+
switch (value.name) {
|
|
39
|
+
case 'If': {
|
|
40
|
+
const trueActions = value.events?.['true']?.actions ?? [];
|
|
41
|
+
const falseActions = value.events?.['false']?.actions ?? [];
|
|
42
|
+
const trueCondition = (value.arguments ?? [])[0];
|
|
43
|
+
newAction = {
|
|
44
|
+
type: 'Switch',
|
|
45
|
+
cases: [
|
|
46
|
+
{
|
|
47
|
+
condition: trueCondition?.formula ?? null,
|
|
48
|
+
actions: trueActions,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
default: { actions: falseActions },
|
|
52
|
+
};
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 'PreventDefault': {
|
|
56
|
+
newAction = {
|
|
57
|
+
name: '@toddle/preventDefault',
|
|
58
|
+
arguments: [],
|
|
59
|
+
label: 'Prevent default',
|
|
60
|
+
};
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'StopPropagation': {
|
|
64
|
+
newAction = {
|
|
65
|
+
name: '@toddle/stopPropagation',
|
|
66
|
+
arguments: [],
|
|
67
|
+
label: 'Stop propagation',
|
|
68
|
+
};
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 'UpdateVariable':
|
|
72
|
+
case 'Update Variable': {
|
|
73
|
+
const variableName = value.arguments?.[0]?.formula.type === 'value'
|
|
74
|
+
? value.arguments[0].formula.value
|
|
75
|
+
: undefined;
|
|
76
|
+
if (typeof variableName !== 'string') {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
const variableValue = value.arguments?.[1]?.formula;
|
|
80
|
+
if (!variableValue) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
newAction = {
|
|
84
|
+
type: 'SetVariable',
|
|
85
|
+
variable: variableName,
|
|
86
|
+
data: variableValue,
|
|
87
|
+
};
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'SetTimeout': {
|
|
91
|
+
newAction = {
|
|
92
|
+
...value,
|
|
93
|
+
name: '@toddle/sleep',
|
|
94
|
+
arguments: renameArguments({ 'Delay in ms': 'Delay in milliseconds' }, value.arguments),
|
|
95
|
+
events: value.events?.['timeout']
|
|
96
|
+
? { tick: value.events.timeout }
|
|
97
|
+
: undefined,
|
|
98
|
+
label: 'Sleep',
|
|
99
|
+
};
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'SetInterval': {
|
|
103
|
+
newAction = {
|
|
104
|
+
...value,
|
|
105
|
+
name: '@toddle/interval',
|
|
106
|
+
arguments: renameArguments({ 'Interval in ms': 'Interval in milliseconds' }, value.arguments),
|
|
107
|
+
label: 'Interval',
|
|
108
|
+
};
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'Debug': {
|
|
112
|
+
newAction = {
|
|
113
|
+
...value,
|
|
114
|
+
name: '@toddle/logToConsole',
|
|
115
|
+
label: 'Log to console',
|
|
116
|
+
};
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case 'GoToURL': {
|
|
120
|
+
newAction = {
|
|
121
|
+
name: '@toddle/gotToURL', // Yes, the typo is in the action name
|
|
122
|
+
arguments: renameArguments({ url: 'URL' }, value.arguments),
|
|
123
|
+
label: 'Go to URL',
|
|
124
|
+
};
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 'TriggerEvent': {
|
|
128
|
+
const eventName = value.arguments?.[0]?.formula.type === 'value'
|
|
129
|
+
? value.arguments[0].formula.value
|
|
130
|
+
: undefined;
|
|
131
|
+
if (typeof eventName !== 'string') {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
const eventData = value.arguments?.[1]?.formula;
|
|
135
|
+
if (!eventData) {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
newAction = {
|
|
139
|
+
type: 'TriggerEvent',
|
|
140
|
+
event: eventName,
|
|
141
|
+
data: eventData,
|
|
142
|
+
};
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'FocusElement': {
|
|
146
|
+
newAction = {
|
|
147
|
+
name: '@toddle/focus',
|
|
148
|
+
arguments: [
|
|
149
|
+
{
|
|
150
|
+
name: 'Element',
|
|
151
|
+
formula: {
|
|
152
|
+
type: 'function',
|
|
153
|
+
name: '@toddle/getElementById',
|
|
154
|
+
arguments: [
|
|
155
|
+
{
|
|
156
|
+
name: 'Id',
|
|
157
|
+
formula: value.arguments?.[0]?.formula ?? valueFormula(null),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
label: 'Focus',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (newAction) {
|
|
168
|
+
return set(files, path, newAction);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
},
|
|
20
172
|
};
|
|
173
|
+
// These actions take a first argument which is a formula as the name
|
|
174
|
+
// of the thing to update/trigger. We can only safely autofix these if
|
|
175
|
+
// the argument is a value operation and a string
|
|
176
|
+
const formulaNamedActions = [
|
|
177
|
+
'UpdateVariable',
|
|
178
|
+
'Update Variable',
|
|
179
|
+
'TriggerEvent',
|
|
180
|
+
];
|
|
181
|
+
const unfixableLegacyActions = new Set([
|
|
182
|
+
'CopyToClipboard', // Previously, this action would JSON stringify non-string inputs
|
|
183
|
+
'Update URL parameter', // The user will need to pick a history mode (push/replace)
|
|
184
|
+
'Fetch', // This was mainly used for APIs v1
|
|
185
|
+
'@toddle/setSessionCookies', // The new 'Set cookie' action takes more arguments
|
|
186
|
+
]);
|
|
21
187
|
//# sourceMappingURL=legacyActionRule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacyActionRule.js","sourceRoot":"","sources":["../../../src/rules/actions/legacyActionRule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"legacyActionRule.js","sourceRoot":"","sources":["../../../src/rules/actions/legacyActionRule.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AACxE,OAAO,EAAE,GAAG,EAAE,MAAM,wCAAwC,CAAA;AAE5D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpE,MAAM,CAAC,MAAM,gBAAgB,GAExB;IACH,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC3C,IAAI,QAAQ,KAAK,cAAc,EAAE,CAAC;YAChC,OAAM;QACR,CAAC;QACD,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,IAAI,OAAqC,CAAA;YACzC,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;gBACpB,OAAO,GAAG;oBACR,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAA;YACH,CAAC;YACD,MAAM,CACJ,IAAI,EACJ,OAAO,EACP,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;gBACpC,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;oBACvC,qEAAqE;oBAC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AK;oBACP,CAAC;oBACD,SAAS,GAAG;wBACV,IAAI,EAAE,cAAc;wBACpB,KAAK,EAAE,SAAS;wBAChB,IAAI,EAAE,SAAS;qBAChB,CAAA;oBACD,MAAK;gBACP,CAAC;gBACD,KAAK,cAAc,CAAC,CAAC,CAAC;oBACpB,SAAS,GAAG;wBACV,IAAI,EAAE,eAAe;wBACrB,SAAS,EAAE;4BACT;gCACE,IAAI,EAAE,SAAS;gCACf,OAAO,EAAE;oCACP,IAAI,EAAE,UAAU;oCAChB,IAAI,EAAE,wBAAwB;oCAC9B,SAAS,EAAE;wCACT;4CACE,IAAI,EAAE,IAAI;4CACV,OAAO,EACL,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC;yCACtD;qCACF;iCACF;6BACF;yBACF;wBACD,KAAK,EAAE,OAAO;qBACf,CAAA;gBACH,CAAC;YACH,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;YACpC,CAAC;QACH,CAAC;KACF;CACF,CAAA;AAED,qEAAqE;AACrE,sEAAsE;AACtE,iDAAiD;AACjD,MAAM,mBAAmB,GAAG;IAC1B,gBAAgB;IAChB,iBAAiB;IACjB,cAAc;CACf,CAAA;AAED,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,iBAAiB,EAAE,iEAAiE;IACpF,sBAAsB,EAAE,2DAA2D;IACnF,OAAO,EAAE,mCAAmC;IAC5C,2BAA2B,EAAE,mDAAmD;CACjF,CAAC,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { fixProject } from '../../fixProject';
|
|
2
3
|
import { searchProject } from '../../searchProject';
|
|
3
4
|
import { legacyActionRule } from './legacyActionRule';
|
|
4
|
-
describe('
|
|
5
|
+
describe('find legacyActions', () => {
|
|
5
6
|
test('should detect legacy actions used in components', () => {
|
|
6
7
|
const problems = Array.from(searchProject({
|
|
7
8
|
files: {
|
|
@@ -85,4 +86,306 @@ describe('legacyAction', () => {
|
|
|
85
86
|
expect(problems).toHaveLength(0);
|
|
86
87
|
});
|
|
87
88
|
});
|
|
89
|
+
describe('fix legacyActions', () => {
|
|
90
|
+
test('should replace the If action with a Switch action', () => {
|
|
91
|
+
const legacyIfAction = {
|
|
92
|
+
name: 'If',
|
|
93
|
+
events: {
|
|
94
|
+
true: {
|
|
95
|
+
actions: [
|
|
96
|
+
{
|
|
97
|
+
name: '@toddle/logToConsole',
|
|
98
|
+
arguments: [
|
|
99
|
+
{
|
|
100
|
+
name: 'Label',
|
|
101
|
+
description: 'A label for the message.',
|
|
102
|
+
formula: { type: 'value', value: '' },
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'Data',
|
|
106
|
+
type: { type: 'Any' },
|
|
107
|
+
description: 'The data you want to log to the console.',
|
|
108
|
+
formula: {
|
|
109
|
+
type: 'value',
|
|
110
|
+
value: '<Data>',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
label: 'Log to console',
|
|
115
|
+
group: 'debugging',
|
|
116
|
+
description: 'Log a message to the browser console.',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
false: {
|
|
121
|
+
actions: [
|
|
122
|
+
{
|
|
123
|
+
name: '@toddle/logToConsole',
|
|
124
|
+
arguments: [
|
|
125
|
+
{
|
|
126
|
+
name: 'Label',
|
|
127
|
+
description: 'A label for the message.',
|
|
128
|
+
formula: { type: 'value', value: '' },
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'Data',
|
|
132
|
+
type: { type: 'Any' },
|
|
133
|
+
description: 'The data you want to log to the console.',
|
|
134
|
+
formula: {
|
|
135
|
+
type: 'value',
|
|
136
|
+
value: '<Data>',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
label: 'Log to console',
|
|
141
|
+
group: 'debugging',
|
|
142
|
+
description: 'Log a message to the browser console.',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
arguments: [
|
|
148
|
+
{
|
|
149
|
+
name: 'Condition',
|
|
150
|
+
formula: { type: 'value', value: true },
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
const projectFiles = {
|
|
155
|
+
formulas: {},
|
|
156
|
+
components: {
|
|
157
|
+
apiComponent: {
|
|
158
|
+
name: 'test',
|
|
159
|
+
nodes: {
|
|
160
|
+
root: {
|
|
161
|
+
tag: 'p',
|
|
162
|
+
type: 'element',
|
|
163
|
+
attrs: {},
|
|
164
|
+
style: {},
|
|
165
|
+
events: {
|
|
166
|
+
click: {
|
|
167
|
+
trigger: 'click',
|
|
168
|
+
actions: [legacyIfAction],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
classes: {},
|
|
172
|
+
children: [],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
formulas: {},
|
|
176
|
+
apis: {},
|
|
177
|
+
attributes: {},
|
|
178
|
+
variables: {},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
const fixedProject = fixProject({
|
|
183
|
+
files: projectFiles,
|
|
184
|
+
rule: legacyActionRule,
|
|
185
|
+
fixType: 'replace-legacy-action',
|
|
186
|
+
});
|
|
187
|
+
const fixedAction = (fixedProject.components['apiComponent']?.nodes['root']).events['click'].actions[0];
|
|
188
|
+
expect(fixedAction).toMatchInlineSnapshot(`
|
|
189
|
+
{
|
|
190
|
+
"cases": [
|
|
191
|
+
{
|
|
192
|
+
"actions": [
|
|
193
|
+
{
|
|
194
|
+
"arguments": [
|
|
195
|
+
{
|
|
196
|
+
"description": "A label for the message.",
|
|
197
|
+
"formula": {
|
|
198
|
+
"type": "value",
|
|
199
|
+
"value": "",
|
|
200
|
+
},
|
|
201
|
+
"name": "Label",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"description": "The data you want to log to the console.",
|
|
205
|
+
"formula": {
|
|
206
|
+
"type": "value",
|
|
207
|
+
"value": "<Data>",
|
|
208
|
+
},
|
|
209
|
+
"name": "Data",
|
|
210
|
+
"type": {
|
|
211
|
+
"type": "Any",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
"description": "Log a message to the browser console.",
|
|
216
|
+
"group": "debugging",
|
|
217
|
+
"label": "Log to console",
|
|
218
|
+
"name": "@toddle/logToConsole",
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
"condition": {
|
|
222
|
+
"type": "value",
|
|
223
|
+
"value": true,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
"default": {
|
|
228
|
+
"actions": [
|
|
229
|
+
{
|
|
230
|
+
"arguments": [
|
|
231
|
+
{
|
|
232
|
+
"description": "A label for the message.",
|
|
233
|
+
"formula": {
|
|
234
|
+
"type": "value",
|
|
235
|
+
"value": "",
|
|
236
|
+
},
|
|
237
|
+
"name": "Label",
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"description": "The data you want to log to the console.",
|
|
241
|
+
"formula": {
|
|
242
|
+
"type": "value",
|
|
243
|
+
"value": "<Data>",
|
|
244
|
+
},
|
|
245
|
+
"name": "Data",
|
|
246
|
+
"type": {
|
|
247
|
+
"type": "Any",
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
"description": "Log a message to the browser console.",
|
|
252
|
+
"group": "debugging",
|
|
253
|
+
"label": "Log to console",
|
|
254
|
+
"name": "@toddle/logToConsole",
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
"type": "Switch",
|
|
259
|
+
}
|
|
260
|
+
`);
|
|
261
|
+
});
|
|
262
|
+
test('should replace the TriggerEvent action with the builtin action', () => {
|
|
263
|
+
const legacyAction = {
|
|
264
|
+
name: 'TriggerEvent',
|
|
265
|
+
arguments: [
|
|
266
|
+
{
|
|
267
|
+
name: 'name',
|
|
268
|
+
formula: { type: 'value', value: 'sdfsdf' },
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: 'data',
|
|
272
|
+
formula: { type: 'value', value: 'test' },
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
};
|
|
276
|
+
const projectFiles = {
|
|
277
|
+
formulas: {},
|
|
278
|
+
components: {
|
|
279
|
+
apiComponent: {
|
|
280
|
+
name: 'test',
|
|
281
|
+
nodes: {
|
|
282
|
+
root: {
|
|
283
|
+
tag: 'p',
|
|
284
|
+
type: 'element',
|
|
285
|
+
attrs: {},
|
|
286
|
+
style: {},
|
|
287
|
+
events: {
|
|
288
|
+
click: {
|
|
289
|
+
trigger: 'click',
|
|
290
|
+
actions: [legacyAction],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
classes: {},
|
|
294
|
+
children: [],
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
formulas: {},
|
|
298
|
+
apis: {},
|
|
299
|
+
attributes: {},
|
|
300
|
+
variables: {},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
const fixedProject = fixProject({
|
|
305
|
+
files: projectFiles,
|
|
306
|
+
rule: legacyActionRule,
|
|
307
|
+
fixType: 'replace-legacy-action',
|
|
308
|
+
});
|
|
309
|
+
const fixedAction = (fixedProject.components['apiComponent']?.nodes['root']).events['click'].actions[0];
|
|
310
|
+
expect(fixedAction).toMatchInlineSnapshot(`
|
|
311
|
+
{
|
|
312
|
+
"data": {
|
|
313
|
+
"type": "value",
|
|
314
|
+
"value": "test",
|
|
315
|
+
},
|
|
316
|
+
"event": "sdfsdf",
|
|
317
|
+
"type": "TriggerEvent",
|
|
318
|
+
}
|
|
319
|
+
`);
|
|
320
|
+
});
|
|
321
|
+
test('should replace the TriggerEvent action with the builtin action', () => {
|
|
322
|
+
const legacyAction = {
|
|
323
|
+
name: 'FocusElement',
|
|
324
|
+
arguments: [
|
|
325
|
+
{
|
|
326
|
+
name: 'elementId',
|
|
327
|
+
formula: { type: 'value', value: 'my-id' },
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
};
|
|
331
|
+
const projectFiles = {
|
|
332
|
+
formulas: {},
|
|
333
|
+
components: {
|
|
334
|
+
apiComponent: {
|
|
335
|
+
name: 'test',
|
|
336
|
+
nodes: {
|
|
337
|
+
root: {
|
|
338
|
+
tag: 'p',
|
|
339
|
+
type: 'element',
|
|
340
|
+
attrs: {},
|
|
341
|
+
style: {},
|
|
342
|
+
events: {
|
|
343
|
+
click: {
|
|
344
|
+
trigger: 'click',
|
|
345
|
+
actions: [legacyAction],
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
classes: {},
|
|
349
|
+
children: [],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
formulas: {},
|
|
353
|
+
apis: {},
|
|
354
|
+
attributes: {},
|
|
355
|
+
variables: {},
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
const fixedProject = fixProject({
|
|
360
|
+
files: projectFiles,
|
|
361
|
+
rule: legacyActionRule,
|
|
362
|
+
fixType: 'replace-legacy-action',
|
|
363
|
+
});
|
|
364
|
+
const fixedAction = (fixedProject.components['apiComponent']?.nodes['root']).events['click'].actions[0];
|
|
365
|
+
expect(fixedAction).toMatchInlineSnapshot(`
|
|
366
|
+
{
|
|
367
|
+
"arguments": [
|
|
368
|
+
{
|
|
369
|
+
"formula": {
|
|
370
|
+
"arguments": [
|
|
371
|
+
{
|
|
372
|
+
"formula": {
|
|
373
|
+
"type": "value",
|
|
374
|
+
"value": "my-id",
|
|
375
|
+
},
|
|
376
|
+
"name": "Id",
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
"name": "@toddle/getElementById",
|
|
380
|
+
"type": "function",
|
|
381
|
+
},
|
|
382
|
+
"name": "Element",
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
"label": "Focus",
|
|
386
|
+
"name": "@toddle/focus",
|
|
387
|
+
}
|
|
388
|
+
`);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
88
391
|
//# sourceMappingURL=legacyActionRule.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacyActionRule.test.js","sourceRoot":"","sources":["../../../src/rules/actions/legacyActionRule.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"legacyActionRule.test.js","sourceRoot":"","sources":["../../../src/rules/actions/legacyActionRule.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,aAAa,CAAC;YACZ,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE;gBACZ,UAAU,EAAE;oBACV,YAAY,EAAE;wBACZ,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;wBACb,MAAM,EAAE;4BACN,OAAO,EAAE,MAAM;4BACf,OAAO,EAAE;gCACP;oCACE,IAAI,EAAE,IAAI;oCACV,MAAM,EAAE;wCACN,IAAI,EAAE;4CACJ,OAAO,EAAE,EAAE;yCACZ;wCACD,KAAK,EAAE;4CACL,OAAO,EAAE,EAAE;yCAC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@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isToddleFormula } from '@nordcraft/core/dist/formula/formulaTypes';
|
|
2
2
|
import { omitKeys, set } from '@nordcraft/core/dist/utils/collections';
|
|
3
3
|
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
4
|
+
import { ARRAY_ARGUMENT_MAPPINGS, PREDICATE_ARGUMENT_MAPPINGS, renameArguments, } from '../../util/helpers';
|
|
4
5
|
export const legacyFormulaRule = {
|
|
5
6
|
code: 'legacy formula',
|
|
6
7
|
level: 'warning',
|
|
@@ -10,8 +11,10 @@ export const legacyFormulaRule = {
|
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
report(data.path, { name: data.value.name },
|
|
13
|
-
// The TYPE
|
|
14
|
-
data.value.name !== 'TYPE'
|
|
14
|
+
// The TYPE and BOOLEAN formulas cannot be autofixed since the logic has changed between the 2 implementations
|
|
15
|
+
data.value.name !== 'TYPE' && data.value.name !== 'BOOLEAN'
|
|
16
|
+
? ['replace-legacy-formula']
|
|
17
|
+
: undefined);
|
|
15
18
|
},
|
|
16
19
|
fixes: {
|
|
17
20
|
'replace-legacy-formula': (data) => {
|
|
@@ -321,14 +324,6 @@ export const legacyFormulaRule = {
|
|
|
321
324
|
};
|
|
322
325
|
return set(data.files, data.path, newAppendFormula);
|
|
323
326
|
}
|
|
324
|
-
case 'BOOLEAN': {
|
|
325
|
-
const newBooleanFormula = {
|
|
326
|
-
...data.value,
|
|
327
|
-
name: '@toddle/boolean',
|
|
328
|
-
display_name: 'Boolean',
|
|
329
|
-
};
|
|
330
|
-
return set(data.files, data.path, newBooleanFormula);
|
|
331
|
-
}
|
|
332
327
|
case 'CLAMP': {
|
|
333
328
|
const newClampFormula = {
|
|
334
329
|
...data.value,
|
|
@@ -740,17 +735,4 @@ const builtInFormulas = new Set([
|
|
|
740
735
|
'uppercase',
|
|
741
736
|
]);
|
|
742
737
|
// cSpell: enable
|
|
743
|
-
const ARRAY_ARGUMENT_MAPPINGS = { List: 'Array' };
|
|
744
|
-
const PREDICATE_ARGUMENT_MAPPINGS = {
|
|
745
|
-
...ARRAY_ARGUMENT_MAPPINGS,
|
|
746
|
-
'Predicate fx': 'Formula',
|
|
747
|
-
};
|
|
748
|
-
const renameArguments = (mappings, args) => args?.map((arg) => ({
|
|
749
|
-
...arg,
|
|
750
|
-
// Let's adjust the names
|
|
751
|
-
name: typeof arg.name === 'string'
|
|
752
|
-
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
753
|
-
(mappings[arg.name] ?? arg.name)
|
|
754
|
-
: arg.name,
|
|
755
|
-
})) ?? [];
|
|
756
738
|
//# sourceMappingURL=legacyFormulaRule.js.map
|