eslint-plugin-sfmc 5.1.0 → 5.2.1
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/README.md +38 -36
- package/docs/rules/amp/arg-types.md +13 -2
- package/docs/rules/amp/prefer-boolean-literal.md +50 -0
- package/docs/unicorn-compatibility.md +22 -15
- package/package.json +11 -11
- package/src/ampscript-processor.js +1 -5
- package/src/index.js +12 -4
- package/src/processor.js +1 -5
- package/src/rules/amp/argument-types.js +48 -12
- package/src/rules/amp/function-arity.js +6 -11
- package/src/rules/amp/naming-convention.js +7 -9
- package/src/rules/amp/no-loop-counter-assign.js +12 -11
- package/src/rules/amp/prefer-attribute-value.js +6 -11
- package/src/rules/amp/prefer-boolean-literal.js +99 -0
- package/src/rules/amp/require-variable-declaration.js +15 -14
- package/src/rules/hbs/_shared.js +8 -18
- package/src/rules/hbs/no-mcn-unsupported.js +3 -4
- package/src/rules/ssjs/cache-loop-length.js +8 -11
- package/src/rules/ssjs/http-property-value.js +7 -11
- package/src/rules/ssjs/no-clr-header-access.js +7 -16
- package/src/rules/ssjs/no-deprecated-function.js +9 -14
- package/src/rules/ssjs/no-invalid-property-access.js +7 -11
- package/src/rules/ssjs/no-mcn-unsupported.js +5 -4
- package/src/rules/ssjs/no-property-call.js +4 -4
- package/src/rules/ssjs/no-treatascontent-injection.js +7 -10
- package/src/rules/ssjs/no-unavailable-method.js +14 -14
- package/src/rules/ssjs/no-unknown-function.js +39 -37
- package/src/rules/ssjs/platform-function-arity.js +54 -57
- package/src/rules/ssjs/prefer-parsejson-safe-argument.js +1 -4
- package/src/rules/ssjs/require-hasownproperty.js +70 -91
- package/src/rules/ssjs/require-platform-load-order.js +3 -7
- package/src/rules/ssjs/require-platform-load.js +1 -4
- package/src/rules/ssjs/require-string-clr-content.js +5 -14
- package/src/rules/ssjs/ssjs-argument-types.js +22 -28
- package/src/rules/ssjs/ssjs-core-method-arity.js +20 -24
- package/src/rules/ssjs/ssjs-no-nonfunctional-method.js +20 -26
- package/src/ssjs-processor.js +1 -5
|
@@ -111,10 +111,9 @@ export default {
|
|
|
111
111
|
(c) =>
|
|
112
112
|
c.type === 'Block' && c.range[0] === 0 && /^\s*global\b/.test(c.value),
|
|
113
113
|
);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return fixer.insertTextBeforeRange([0, 0], entry.polyfill + '\n\n');
|
|
114
|
+
return leadingGlobal
|
|
115
|
+
? fixer.insertTextAfterRange(leadingGlobal.range, '\n\n' + entry.polyfill)
|
|
116
|
+
: fixer.insertTextBeforeRange([0, 0], entry.polyfill + '\n\n');
|
|
118
117
|
};
|
|
119
118
|
}
|
|
120
119
|
|
|
@@ -230,17 +229,18 @@ export default {
|
|
|
230
229
|
}
|
|
231
230
|
|
|
232
231
|
// ── Prototype methods with NO polyfill: .trimStart(), .flat(), … ─
|
|
233
|
-
if (knownUnsupportedByPrototypeName.has(lowerMethod)) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
pendingReports.push({ node: property, entry, noPolyfill: true });
|
|
232
|
+
if (!knownUnsupportedByPrototypeName.has(lowerMethod)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (ignored.has(methodName)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Skip known SFMC top-level objects to avoid false positives.
|
|
239
|
+
if (receiver.type === 'Identifier' && SFMC_RECEIVERS.has(receiver.name)) {
|
|
240
|
+
return;
|
|
243
241
|
}
|
|
242
|
+
const entry = knownUnsupportedByPrototypeName.get(lowerMethod);
|
|
243
|
+
pendingReports.push({ node: property, entry, noPolyfill: true });
|
|
244
244
|
},
|
|
245
245
|
|
|
246
246
|
'Program:exit'() {
|
|
@@ -139,43 +139,44 @@ export default {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// ── Instance method calls (Core Library / WSProxy) ────────────
|
|
142
|
-
if (callee.object.type
|
|
143
|
-
|
|
142
|
+
if (callee.object.type !== 'Identifier') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const objectName = callee.object.name;
|
|
144
146
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
147
|
+
// Core library: var de = DataExtension.Init("key"); de.Foo();
|
|
148
|
+
const coreType = coreVariables.get(objectName);
|
|
149
|
+
if (coreType) {
|
|
150
|
+
const objectDefinition = coreObjectLookup.get(coreType);
|
|
151
|
+
if (objectDefinition) {
|
|
152
|
+
const knownMethods = new Set(
|
|
153
|
+
objectDefinition.methods.map((m) => m.toLowerCase()),
|
|
154
|
+
);
|
|
155
|
+
if (!knownMethods.has(methodName.toLowerCase())) {
|
|
156
|
+
context.report({
|
|
157
|
+
node: property,
|
|
158
|
+
messageId: 'unknownCoreMethod',
|
|
159
|
+
data: {
|
|
160
|
+
method: methodName,
|
|
161
|
+
objectType: coreType,
|
|
162
|
+
available: objectDefinition.methods.join(', '),
|
|
163
|
+
},
|
|
164
|
+
});
|
|
164
165
|
}
|
|
165
|
-
return;
|
|
166
166
|
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
167
169
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
170
|
+
// WSProxy: var api = new Script.Util.WSProxy(); api.Foo();
|
|
171
|
+
if (
|
|
172
|
+
wsproxyVariables.has(objectName) &&
|
|
173
|
+
!wsproxyMethodNames.has(methodName.toLowerCase())
|
|
174
|
+
) {
|
|
175
|
+
context.report({
|
|
176
|
+
node: property,
|
|
177
|
+
messageId: 'unknownWsproxyMethod',
|
|
178
|
+
data: { name: methodName },
|
|
179
|
+
});
|
|
179
180
|
}
|
|
180
181
|
},
|
|
181
182
|
};
|
|
@@ -194,10 +195,11 @@ function getCoreInitType(node) {
|
|
|
194
195
|
return null;
|
|
195
196
|
}
|
|
196
197
|
const callee = node.callee;
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
if (
|
|
199
|
+
callee.type !== 'MemberExpression' ||
|
|
200
|
+
callee.property.type !== 'Identifier' ||
|
|
201
|
+
callee.property.name !== 'Init'
|
|
202
|
+
) {
|
|
201
203
|
return null;
|
|
202
204
|
}
|
|
203
205
|
if (callee.object.type === 'Identifier' && coreObjectNames.has(callee.object.name)) {
|
|
@@ -15,10 +15,9 @@ import { platformFunctionLookup } from 'ssjs-data';
|
|
|
15
15
|
* @returns {string} The rendered list.
|
|
16
16
|
*/
|
|
17
17
|
function formatArities(arities) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return `${arities.slice(0, -1).join(', ')} or ${arities.at(-1)}`;
|
|
18
|
+
return arities.length === 1
|
|
19
|
+
? String(arities[0])
|
|
20
|
+
: `${arities.slice(0, -1).join(', ')} or ${arities.at(-1)}`;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export default {
|
|
@@ -42,63 +41,61 @@ export default {
|
|
|
42
41
|
return {
|
|
43
42
|
CallExpression(node) {
|
|
44
43
|
const callee = node.callee;
|
|
45
|
-
if (callee.type !== 'MemberExpression') {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
44
|
if (
|
|
50
|
-
callee.
|
|
51
|
-
callee.object.
|
|
52
|
-
callee.object.object.
|
|
53
|
-
callee.object.
|
|
54
|
-
callee.object.property.
|
|
55
|
-
callee.property.
|
|
45
|
+
callee.type !== 'MemberExpression' ||
|
|
46
|
+
callee.object.type !== 'MemberExpression' ||
|
|
47
|
+
callee.object.object.type !== 'Identifier' ||
|
|
48
|
+
callee.object.object.name !== 'Platform' ||
|
|
49
|
+
callee.object.property.type !== 'Identifier' ||
|
|
50
|
+
callee.object.property.name !== 'Function' ||
|
|
51
|
+
callee.property.type !== 'Identifier'
|
|
56
52
|
) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const methodName = callee.property.name;
|
|
56
|
+
const entry = platformFunctionLookup.get(methodName.toLowerCase());
|
|
57
|
+
if (!entry) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
const actual = node.arguments.length;
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
63
|
+
if (actual < entry.minArgs) {
|
|
64
|
+
context.report({
|
|
65
|
+
node: callee.property,
|
|
66
|
+
messageId: 'tooFewArgs',
|
|
67
|
+
data: {
|
|
68
|
+
name: entry.name,
|
|
69
|
+
min: String(entry.minArgs),
|
|
70
|
+
actual: String(actual),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
} else if (actual > entry.maxArgs) {
|
|
74
|
+
context.report({
|
|
75
|
+
node: callee.property,
|
|
76
|
+
messageId: 'tooManyArgs',
|
|
77
|
+
data: {
|
|
78
|
+
name: entry.name,
|
|
79
|
+
max: String(entry.maxArgs),
|
|
80
|
+
actual: String(actual),
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
} else if (
|
|
84
|
+
Array.isArray(entry.validArities) &&
|
|
85
|
+
!entry.validArities.includes(actual)
|
|
86
|
+
) {
|
|
87
|
+
// Discontinuous overload: actual is within [minArgs, maxArgs]
|
|
88
|
+
// but not one of the exact permitted arities (e.g. HTTPGet
|
|
89
|
+
// accepts only 1 or 6 arguments; 2-5 throw at runtime).
|
|
90
|
+
context.report({
|
|
91
|
+
node: callee.property,
|
|
92
|
+
messageId: 'invalidArity',
|
|
93
|
+
data: {
|
|
94
|
+
name: entry.name,
|
|
95
|
+
arities: formatArities(entry.validArities),
|
|
96
|
+
actual: String(actual),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
102
99
|
}
|
|
103
100
|
},
|
|
104
101
|
};
|
|
@@ -35,70 +35,69 @@ export default {
|
|
|
35
35
|
|
|
36
36
|
const hasGuard = statements.some((statement) => containsHasOwnProperty(statement));
|
|
37
37
|
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
context.report({
|
|
44
|
-
node,
|
|
45
|
-
messageId: 'missingGuard',
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
38
|
+
if (hasGuard) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const keyName = getKeyName(node.left);
|
|
42
|
+
const objectText = context.sourceCode.getText(node.right);
|
|
49
43
|
|
|
44
|
+
if (!keyName) {
|
|
50
45
|
context.report({
|
|
51
46
|
node,
|
|
52
47
|
messageId: 'missingGuard',
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
body.type === 'BlockStatement' ? body.body : [body];
|
|
57
|
-
|
|
58
|
-
// Single-line loops keep compact output to avoid reformatting
|
|
59
|
-
// code the author intentionally wrote on one line.
|
|
60
|
-
const isSingleLine = node.loc.start.line === node.loc.end.line;
|
|
61
|
-
if (isSingleLine) {
|
|
62
|
-
const compactBody = innerStatements
|
|
63
|
-
.map((statement) => sourceCode.getText(statement))
|
|
64
|
-
.join(' ');
|
|
65
|
-
return fixer.replaceText(
|
|
66
|
-
body,
|
|
67
|
-
`{ if (${objectText}.hasOwnProperty(${keyName})) { ${compactBody} } }`,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Multi-line loops: emit a properly-indented guard block.
|
|
72
|
-
const loopLine = sourceCode.lines[node.loc.start.line - 1] ?? '';
|
|
73
|
-
const baseIndent = (loopLine.match(/^[\t ]*/) ?? [''])[0];
|
|
74
|
-
const firstStatement = innerStatements[0];
|
|
75
|
-
const firstStatementLine = firstStatement
|
|
76
|
-
? (sourceCode.lines[firstStatement.loc.start.line - 1] ?? '')
|
|
77
|
-
: '';
|
|
78
|
-
const firstStatementIndent = (firstStatementLine.match(/^[\t ]*/) ?? [
|
|
79
|
-
'',
|
|
80
|
-
])[0];
|
|
81
|
-
const unit =
|
|
82
|
-
firstStatementIndent.length > baseIndent.length
|
|
83
|
-
? firstStatementIndent.slice(baseIndent.length)
|
|
84
|
-
: ' '.repeat(4);
|
|
85
|
-
const guardIndent = baseIndent + unit;
|
|
86
|
-
const statementIndent = guardIndent + unit;
|
|
87
|
-
|
|
88
|
-
const guardedBody = innerStatements
|
|
89
|
-
.map(
|
|
90
|
-
(statement) =>
|
|
91
|
-
`${statementIndent}${sourceCode.getText(statement)}`,
|
|
92
|
-
)
|
|
93
|
-
.join('\n');
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
94
51
|
|
|
52
|
+
context.report({
|
|
53
|
+
node,
|
|
54
|
+
messageId: 'missingGuard',
|
|
55
|
+
fix(fixer) {
|
|
56
|
+
const sourceCode = context.sourceCode;
|
|
57
|
+
const innerStatements = body.type === 'BlockStatement' ? body.body : [body];
|
|
58
|
+
|
|
59
|
+
// Single-line loops keep compact output to avoid reformatting
|
|
60
|
+
// code the author intentionally wrote on one line.
|
|
61
|
+
const isSingleLine = node.loc.start.line === node.loc.end.line;
|
|
62
|
+
if (isSingleLine) {
|
|
63
|
+
const compactBody = innerStatements
|
|
64
|
+
.map((statement) => sourceCode.getText(statement))
|
|
65
|
+
.join(' ');
|
|
95
66
|
return fixer.replaceText(
|
|
96
67
|
body,
|
|
97
|
-
`{
|
|
68
|
+
`{ if (${objectText}.hasOwnProperty(${keyName})) { ${compactBody} } }`,
|
|
98
69
|
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Multi-line loops: emit a properly-indented guard block.
|
|
73
|
+
const loopLine = sourceCode.lines[node.loc.start.line - 1] ?? '';
|
|
74
|
+
const baseIndent = (loopLine.match(/^[\t ]*/) ?? [''])[0];
|
|
75
|
+
const firstStatement = innerStatements[0];
|
|
76
|
+
const firstStatementLine = firstStatement
|
|
77
|
+
? (sourceCode.lines[firstStatement.loc.start.line - 1] ?? '')
|
|
78
|
+
: '';
|
|
79
|
+
const firstStatementIndent = (firstStatementLine.match(/^[\t ]*/) ?? [
|
|
80
|
+
'',
|
|
81
|
+
])[0];
|
|
82
|
+
const unit =
|
|
83
|
+
firstStatementIndent.length > baseIndent.length
|
|
84
|
+
? firstStatementIndent.slice(baseIndent.length)
|
|
85
|
+
: ' '.repeat(4);
|
|
86
|
+
const guardIndent = baseIndent + unit;
|
|
87
|
+
const statementIndent = guardIndent + unit;
|
|
88
|
+
|
|
89
|
+
const guardedBody = innerStatements
|
|
90
|
+
.map(
|
|
91
|
+
(statement) => `${statementIndent}${sourceCode.getText(statement)}`,
|
|
92
|
+
)
|
|
93
|
+
.join('\n');
|
|
94
|
+
|
|
95
|
+
return fixer.replaceText(
|
|
96
|
+
body,
|
|
97
|
+
`{\n${guardIndent}if (${objectText}.hasOwnProperty(${keyName})) {\n${guardedBody}\n${guardIndent}}\n${baseIndent}}`,
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
102
101
|
},
|
|
103
102
|
};
|
|
104
103
|
},
|
|
@@ -120,19 +119,12 @@ function containsHasOwnProperty(node) {
|
|
|
120
119
|
return true;
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (current.type === 'BlockStatement') {
|
|
132
|
-
return current.body.some((child) => containsHasOwnProperty(child));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return false;
|
|
122
|
+
return current.type === 'IfStatement'
|
|
123
|
+
? hasOwnPropertyTest(current.test) ||
|
|
124
|
+
containsHasOwnProperty(current.consequent) ||
|
|
125
|
+
containsHasOwnProperty(current.alternate)
|
|
126
|
+
: current.type === 'BlockStatement' &&
|
|
127
|
+
current.body.some((child) => containsHasOwnProperty(child));
|
|
136
128
|
}
|
|
137
129
|
|
|
138
130
|
function hasOwnPropertyTest(node) {
|
|
@@ -143,24 +135,14 @@ function hasOwnPropertyTest(node) {
|
|
|
143
135
|
current = current.argument;
|
|
144
136
|
}
|
|
145
137
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
current.callee.property.name === 'hasOwnProperty'
|
|
155
|
-
) {
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (current.type === 'LogicalExpression') {
|
|
160
|
-
return hasOwnPropertyTest(current.left) || hasOwnPropertyTest(current.right);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return false;
|
|
138
|
+
return current
|
|
139
|
+
? (current.type === 'CallExpression' &&
|
|
140
|
+
current.callee.type === 'MemberExpression' &&
|
|
141
|
+
current.callee.property.type === 'Identifier' &&
|
|
142
|
+
current.callee.property.name === 'hasOwnProperty') ||
|
|
143
|
+
(current.type === 'LogicalExpression' &&
|
|
144
|
+
(hasOwnPropertyTest(current.left) || hasOwnPropertyTest(current.right)))
|
|
145
|
+
: false;
|
|
164
146
|
}
|
|
165
147
|
|
|
166
148
|
/**
|
|
@@ -175,8 +157,5 @@ function getKeyName(left) {
|
|
|
175
157
|
const id = left.declarations[0].id;
|
|
176
158
|
return id.type === 'Identifier' ? id.name : null;
|
|
177
159
|
}
|
|
178
|
-
|
|
179
|
-
return left.name;
|
|
180
|
-
}
|
|
181
|
-
return null;
|
|
160
|
+
return left.type === 'Identifier' ? left.name : null;
|
|
182
161
|
}
|
|
@@ -103,14 +103,10 @@ function getCoreObjectUsage(node) {
|
|
|
103
103
|
return `${callee.object.object.name}.${callee.object.property.name}`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
callee.object.type === 'Identifier' &&
|
|
106
|
+
return callee.object.type === 'Identifier' &&
|
|
108
107
|
TOP_LEVEL_CORE_NAMES.has(callee.object.name) &&
|
|
109
108
|
callee.property.type === 'Identifier' &&
|
|
110
109
|
callee.property.name === 'Init'
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return null;
|
|
110
|
+
? callee.object.name
|
|
111
|
+
: null;
|
|
116
112
|
}
|
|
@@ -105,10 +105,7 @@ function getCoreObjectUsage(node) {
|
|
|
105
105
|
|
|
106
106
|
// Bare call: Now(), Write(), GUID(), Base64Encode(), Redirect(), …
|
|
107
107
|
if (callee.type === 'Identifier') {
|
|
108
|
-
|
|
109
|
-
return callee.name;
|
|
110
|
-
}
|
|
111
|
-
return null;
|
|
108
|
+
return CORE_LOAD_DEPENDENT_GLOBALS.has(callee.name.toLowerCase()) ? callee.name : null;
|
|
112
109
|
}
|
|
113
110
|
|
|
114
111
|
if (callee.type !== 'MemberExpression') {
|
|
@@ -46,16 +46,10 @@ function isHttpConstructorMember(node) {
|
|
|
46
46
|
* @returns {boolean} Whether the expression yields an HTTP request instance
|
|
47
47
|
*/
|
|
48
48
|
function isHttpRequestInit(node) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return isHttpConstructorMember(node.callee);
|
|
54
|
-
}
|
|
55
|
-
if (node.type === 'CallExpression') {
|
|
56
|
-
return isHttpConstructorMember(node.callee);
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
49
|
+
return node
|
|
50
|
+
? (node.type === 'NewExpression' || node.type === 'CallExpression') &&
|
|
51
|
+
isHttpConstructorMember(node.callee)
|
|
52
|
+
: false;
|
|
59
53
|
}
|
|
60
54
|
|
|
61
55
|
/**
|
|
@@ -153,10 +147,7 @@ export default {
|
|
|
153
147
|
|
|
154
148
|
// resp.content — non-computed member read on a tracked response var.
|
|
155
149
|
'MemberExpression[computed=false]'(node) {
|
|
156
|
-
if (!isTrackedContentMember(node)) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (isWrappedInString(node)) {
|
|
150
|
+
if (!isTrackedContentMember(node) || isWrappedInString(node)) {
|
|
160
151
|
return;
|
|
161
152
|
}
|
|
162
153
|
pending.push(node);
|
|
@@ -143,10 +143,7 @@ export default {
|
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
if (callee.type !== 'MemberExpression') {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (callee.property.type !== 'Identifier') {
|
|
146
|
+
if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') {
|
|
150
147
|
return;
|
|
151
148
|
}
|
|
152
149
|
const methodName = callee.property.name;
|
|
@@ -228,14 +225,16 @@ export default {
|
|
|
228
225
|
|
|
229
226
|
// Multi-part static: DataExtension.Rows.Add(...), TriggeredSend.Tracking.Clicks.Retrieve(...)
|
|
230
227
|
const objectPath = getMemberPath(callee.object);
|
|
231
|
-
if (objectPath
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
228
|
+
if (!objectPath || !coreObjectNames.has(objectPath)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const classLookup = coreMethodArityLookup.get(objectPath.toLowerCase());
|
|
232
|
+
if (!classLookup) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const entry = classLookup.get(methodName.toLowerCase());
|
|
236
|
+
if (entry) {
|
|
237
|
+
checkArguments(entry, node.arguments, `${objectPath}.${methodName}`);
|
|
239
238
|
}
|
|
240
239
|
},
|
|
241
240
|
};
|
|
@@ -247,10 +246,11 @@ function getCoreInitType(node) {
|
|
|
247
246
|
return null;
|
|
248
247
|
}
|
|
249
248
|
const callee = node.callee;
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
if (
|
|
250
|
+
callee.type !== 'MemberExpression' ||
|
|
251
|
+
callee.property.type !== 'Identifier' ||
|
|
252
|
+
callee.property.name !== 'Init'
|
|
253
|
+
) {
|
|
254
254
|
return null;
|
|
255
255
|
}
|
|
256
256
|
if (callee.object.type === 'Identifier' && coreObjectNames.has(callee.object.name)) {
|
|
@@ -313,19 +313,13 @@ function inferArgumentType(node) {
|
|
|
313
313
|
) {
|
|
314
314
|
return 'string[]';
|
|
315
315
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return 'number[]';
|
|
322
|
-
}
|
|
323
|
-
return 'array';
|
|
316
|
+
return elements.every(
|
|
317
|
+
(element) => element.type === 'Literal' && typeof element.value === 'number',
|
|
318
|
+
)
|
|
319
|
+
? 'number[]'
|
|
320
|
+
: 'array';
|
|
324
321
|
}
|
|
325
|
-
|
|
326
|
-
return 'object';
|
|
327
|
-
}
|
|
328
|
-
return null;
|
|
322
|
+
return node.type === 'ObjectExpression' ? 'object' : null;
|
|
329
323
|
}
|
|
330
324
|
|
|
331
325
|
function isTypeCompatible(actual, expected) {
|