sfmc-language-lsp 1.9.0 → 1.9.2
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/cjs/codeActions/ssjs.cjs +66 -12
- package/dist/cjs/codeActions/ssjs.d.ts +2 -2
- package/dist/cjs/codeActions/ssjs.d.ts.map +1 -1
- package/dist/cjs/codeActions/ssjs.js.map +1 -1
- package/dist/cjs/data/ssjs.cjs +19 -24
- package/dist/cjs/data/ssjs.d.ts +14 -28
- package/dist/cjs/data/ssjs.d.ts.map +1 -1
- package/dist/cjs/data/ssjs.js.map +1 -1
- package/dist/cjs/utils/polyfill.cjs +30 -0
- package/dist/cjs/utils/polyfill.d.ts +18 -0
- package/dist/cjs/utils/polyfill.d.ts.map +1 -0
- package/dist/cjs/utils/polyfill.js.map +1 -0
- package/dist/cjs/validators/ssjs.cjs +77 -71
- package/dist/cjs/validators/ssjs.d.ts +15 -7
- package/dist/cjs/validators/ssjs.d.ts.map +1 -1
- package/dist/cjs/validators/ssjs.js.map +1 -1
- package/dist/esm/codeActions/ssjs.d.ts +2 -2
- package/dist/esm/codeActions/ssjs.d.ts.map +1 -1
- package/dist/esm/codeActions/ssjs.js +67 -13
- package/dist/esm/codeActions/ssjs.js.map +1 -1
- package/dist/esm/data/ssjs.d.ts +14 -28
- package/dist/esm/data/ssjs.d.ts.map +1 -1
- package/dist/esm/data/ssjs.js +19 -24
- package/dist/esm/data/ssjs.js.map +1 -1
- package/dist/esm/utils/polyfill.d.ts +18 -0
- package/dist/esm/utils/polyfill.d.ts.map +1 -0
- package/dist/esm/utils/polyfill.js +26 -0
- package/dist/esm/utils/polyfill.js.map +1 -0
- package/dist/esm/validators/ssjs.d.ts +15 -7
- package/dist/esm/validators/ssjs.d.ts.map +1 -1
- package/dist/esm/validators/ssjs.js +77 -71
- package/dist/esm/validators/ssjs.js.map +1 -1
- package/dist/types/codeActions/ssjs.d.ts +2 -2
- package/dist/types/codeActions/ssjs.d.ts.map +1 -1
- package/dist/types/data/ssjs.d.ts +14 -28
- package/dist/types/data/ssjs.d.ts.map +1 -1
- package/dist/types/utils/polyfill.d.ts +18 -0
- package/dist/types/utils/polyfill.d.ts.map +1 -0
- package/dist/types/validators/ssjs.d.ts +15 -7
- package/dist/types/validators/ssjs.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -3,8 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSsjsCodeActions = getSsjsCodeActions;
|
|
4
4
|
const types_js_1 = require("../types.cjs");
|
|
5
5
|
const ssjs_js_1 = require("../validators/ssjs.cjs");
|
|
6
|
+
const polyfill_js_1 = require("../utils/polyfill.cjs");
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Compute the insertion point for a polyfill. ESLint reads a leading
|
|
9
|
+
* `global` directive comment, so the polyfill must be inserted after that
|
|
10
|
+
* line (when present) to keep the directive at the very top of the file.
|
|
11
|
+
* Otherwise the polyfill goes to the very top of the document.
|
|
12
|
+
* @param text - Full document text.
|
|
13
|
+
* @returns The zero-based line/character position to insert at.
|
|
14
|
+
*/
|
|
15
|
+
function polyfillInsertPosition(text) {
|
|
16
|
+
const lines = text.split('\n');
|
|
17
|
+
for (const [index, line] of lines.entries()) {
|
|
18
|
+
const trimmed = line.trim();
|
|
19
|
+
if (trimmed.length === 0)
|
|
20
|
+
continue;
|
|
21
|
+
// Insert after a leading `/* global ... */` ESLint directive comment.
|
|
22
|
+
if (/^\/\*\s*global\b/.test(trimmed) && trimmed.endsWith('*/')) {
|
|
23
|
+
return { line: index + 1, character: 0 };
|
|
24
|
+
}
|
|
25
|
+
// First meaningful line is not a global directive — insert at the top.
|
|
26
|
+
return { line: 0, character: 0 };
|
|
27
|
+
}
|
|
28
|
+
return { line: 0, character: 0 };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Type guard for the polyfill payload attached to `ssjs/polyfill-required`
|
|
8
32
|
* diagnostics by the SSJS validator.
|
|
9
33
|
* @param data - The diagnostic's `data` field.
|
|
10
34
|
* @returns True when the payload carries an owner, method, and polyfill source.
|
|
@@ -16,10 +40,23 @@ function isPolyfillData(data) {
|
|
|
16
40
|
typeof data.method === 'string' &&
|
|
17
41
|
typeof data.polyfill === 'string');
|
|
18
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Type guard for the replacement payload attached to
|
|
45
|
+
* `ssjs/replace-with-platform-function` diagnostics by the SSJS validator.
|
|
46
|
+
* @param data - The diagnostic's `data` field.
|
|
47
|
+
* @returns True when the payload carries an owner, member, and replacement.
|
|
48
|
+
*/
|
|
49
|
+
function isReplaceData(data) {
|
|
50
|
+
return (typeof data === 'object' &&
|
|
51
|
+
data !== null &&
|
|
52
|
+
typeof data.owner === 'string' &&
|
|
53
|
+
typeof data.member === 'string' &&
|
|
54
|
+
typeof data.replacement === 'string');
|
|
55
|
+
}
|
|
19
56
|
/**
|
|
20
57
|
* Return quick-fix code actions for SSJS diagnostics. Currently offers an
|
|
21
|
-
* "insert polyfill" action for `ssjs/
|
|
22
|
-
* verified polyfill source (from ssjs-data) at the top of the document.
|
|
58
|
+
* "insert polyfill" action for `ssjs/polyfill-required` diagnostics, inserting
|
|
59
|
+
* the verified polyfill source (from ssjs-data) at the top of the document.
|
|
23
60
|
* @param text - Full document text.
|
|
24
61
|
* @param uri - Document URI.
|
|
25
62
|
* @param diagnostics - Diagnostics to generate actions for.
|
|
@@ -30,19 +67,39 @@ function getSsjsCodeActions(text, uri, diagnostics) {
|
|
|
30
67
|
for (const diagnostic of diagnostics) {
|
|
31
68
|
if (diagnostic.source !== 'ssjs')
|
|
32
69
|
continue;
|
|
33
|
-
|
|
70
|
+
// "Replace with Platform.Function.*" — for static members that have no
|
|
71
|
+
// polyfill but a direct SFMC alternative (e.g. JSON.parse → ParseJSON).
|
|
72
|
+
if (diagnostic.code === ssjs_js_1.DIAG_CODE_SSJS_REPLACE_WITH_PLATFORM_FUNCTION &&
|
|
73
|
+
isReplaceData(diagnostic.data)) {
|
|
74
|
+
const { owner, member, replacement } = diagnostic.data;
|
|
75
|
+
actions.push({
|
|
76
|
+
title: `Replace ${owner}.${member} with ${replacement}`,
|
|
77
|
+
kind: types_js_1.CodeActionKind.QuickFix,
|
|
78
|
+
isPreferred: true,
|
|
79
|
+
diagnostics: [diagnostic],
|
|
80
|
+
edit: {
|
|
81
|
+
changes: {
|
|
82
|
+
// The diagnostic range covers the `Owner.member` text;
|
|
83
|
+
// replace it in place with the Platform.Function call.
|
|
84
|
+
[uri]: [{ range: diagnostic.range, newText: replacement }],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (diagnostic.code !== ssjs_js_1.DIAG_CODE_SSJS_POLYFILL_REQUIRED)
|
|
34
91
|
continue;
|
|
35
92
|
if (!isPolyfillData(diagnostic.data))
|
|
36
93
|
continue;
|
|
37
94
|
const { owner, method, polyfill } = diagnostic.data;
|
|
38
95
|
// Avoid offering the fix when the polyfill is already present in the
|
|
39
96
|
// document. The first non-blank line of the polyfill is a stable marker.
|
|
40
|
-
const marker = polyfill
|
|
41
|
-
.split('\n')
|
|
42
|
-
.find((l) => l.trim().length > 0)
|
|
43
|
-
?.trim();
|
|
97
|
+
const marker = (0, polyfill_js_1.polyfillMarker)(polyfill);
|
|
44
98
|
if (marker && text.includes(marker))
|
|
45
99
|
continue;
|
|
100
|
+
// Insert after a leading `/* global ... */` directive (if any) so the
|
|
101
|
+
// ESLint directive stays at the very top of the file.
|
|
102
|
+
const insertAt = polyfillInsertPosition(text);
|
|
46
103
|
actions.push({
|
|
47
104
|
title: `Insert polyfill for ${owner}.${method}`,
|
|
48
105
|
kind: types_js_1.CodeActionKind.QuickFix,
|
|
@@ -52,10 +109,7 @@ function getSsjsCodeActions(text, uri, diagnostics) {
|
|
|
52
109
|
changes: {
|
|
53
110
|
[uri]: [
|
|
54
111
|
{
|
|
55
|
-
range: {
|
|
56
|
-
start: { line: 0, character: 0 },
|
|
57
|
-
end: { line: 0, character: 0 },
|
|
58
|
-
},
|
|
112
|
+
range: { start: insertAt, end: insertAt },
|
|
59
113
|
newText: `${polyfill.trimEnd()}\n\n`,
|
|
60
114
|
},
|
|
61
115
|
],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CodeAction, Diagnostic } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Return quick-fix code actions for SSJS diagnostics. Currently offers an
|
|
4
|
-
* "insert polyfill" action for `ssjs/
|
|
5
|
-
* verified polyfill source (from ssjs-data) at the top of the document.
|
|
4
|
+
* "insert polyfill" action for `ssjs/polyfill-required` diagnostics, inserting
|
|
5
|
+
* the verified polyfill source (from ssjs-data) at the top of the document.
|
|
6
6
|
* @param text - Full document text.
|
|
7
7
|
* @param uri - Document URI.
|
|
8
8
|
* @param diagnostics - Diagnostics to generate actions for.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssjs.d.ts","sourceRoot":"","sources":["../../../src/codeActions/ssjs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ssjs.d.ts","sourceRoot":"","sources":["../../../src/codeActions/ssjs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAgE1D;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,UAAU,EAAE,GAC1B,UAAU,EAAE,CA8Dd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssjs.js","sourceRoot":"","sources":["../../../src/codeActions/ssjs.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"ssjs.js","sourceRoot":"","sources":["../../../src/codeActions/ssjs.ts"],"names":[],"mappings":";;A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AQ,CAAC,CAAC;QACxC,IAAI,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,SAAS;QAE9C,sEAAsE;QACtE,sDAAsD;QACtD,MAAM,QAAQ,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAE9C,OAAO,CAAC,IAAI,CAAC;YACT,KAAK,EAAE,uBAAuB,KAAK,IAAI,MAAM,EAAE;YAC/C,IAAI,EAAE,yBAAc,CAAC,QAAQ;YAC7B,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,CAAC,UAAU,CAAC;YACzB,IAAI,EAAE;gBACF,OAAO,EAAE;oBACL,CAAC,GAAG,CAAC,EAAE;wBACH;4BACI,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE;4BACzC,OAAO,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM;yBACvC;qBACJ;iBACJ;aACJ;SACJ,CAAC,CAAC;IACP,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/dist/cjs/data/ssjs.cjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* propagate automatically.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.
|
|
11
|
+
exports.replaceableStaticLookup = exports.polyfillablePrototypeLookup = exports.polyfillableStaticLookup = exports.polyfillableMethods = exports.ecmascriptBuiltins = exports.requiresCoreLoadGlobals = exports.scriptUtilRequestMethods = exports.scriptUtilConstructors = exports.platformRecipientMethods = exports.errorUtilMethods = exports.dateTimeTimezoneMethods = exports.dateTimeMethods = exports.httpHeaderMethods = exports.httpMethods = exports.wsproxyMethods = exports.coreLibraryObjects = exports.platformRequestMethods = exports.platformResponseMethods = exports.platformVariableMethods = exports.ssjsGlobals = exports.platformFunctionLookup = exports.platformFunctions = exports.platformMethods = void 0;
|
|
12
12
|
const ssjs_data_1 = require("ssjs-data");
|
|
13
13
|
const urls_1 = require("ssjs-data/urls");
|
|
14
14
|
// ── Top-level Platform methods ───────────────────────────────────────────────
|
|
@@ -120,29 +120,6 @@ exports.ecmascriptBuiltins = ssjs_data_1.ECMASCRIPT_BUILTINS.map((b) => {
|
|
|
120
120
|
mdnUrl: (0, urls_1.mdnBuiltinUrl)(b.owner, b.name),
|
|
121
121
|
};
|
|
122
122
|
});
|
|
123
|
-
// ── Known-unsupported ECMAScript members ─────────────────────────────────────
|
|
124
|
-
/**
|
|
125
|
-
* ECMAScript members empirically confirmed ABSENT or BROKEN in the SFMC SSJS
|
|
126
|
-
* engine and not covered by a shipped polyfill. Consumed by validateSsjs to
|
|
127
|
-
* warn when authored/generated SSJS references a member that fails at runtime.
|
|
128
|
-
*/
|
|
129
|
-
exports.knownUnsupportedMembers = ssjs_data_1.KNOWN_UNSUPPORTED.map((m) => ({
|
|
130
|
-
...m,
|
|
131
|
-
}));
|
|
132
|
-
/**
|
|
133
|
-
* Static known-unsupported members keyed by `Owner.member` (lowercased), e.g.
|
|
134
|
-
* `json.parse`, `object.keys`, `math.trunc`. These have an explicit owner
|
|
135
|
-
* prefix in source so they can be flagged unambiguously.
|
|
136
|
-
*/
|
|
137
|
-
exports.knownUnsupportedStaticLookup = new Map(exports.knownUnsupportedMembers
|
|
138
|
-
.filter((m) => m.isStatic)
|
|
139
|
-
.map((m) => [`${m.owner}.${m.member}`.toLowerCase(), m]));
|
|
140
|
-
/**
|
|
141
|
-
* Prototype (instance) known-unsupported members keyed by member name
|
|
142
|
-
* (lowercased), e.g. `includes`, `flat`, `trimstart`. Flagged as warnings
|
|
143
|
-
* because a regex cannot prove the receiver's type.
|
|
144
|
-
*/
|
|
145
|
-
exports.knownUnsupportedPrototypeLookup = new Map(exports.knownUnsupportedMembers.filter((m) => !m.isStatic).map((m) => [m.member.toLowerCase(), m]));
|
|
146
123
|
// ── Polyfillable ECMAScript members ──────────────────────────────────────────
|
|
147
124
|
/**
|
|
148
125
|
* ECMAScript members empirically confirmed ABSENT or BROKEN in the SFMC SSJS
|
|
@@ -172,4 +149,22 @@ exports.polyfillableStaticLookup = new Map(exports.polyfillableMethods
|
|
|
172
149
|
exports.polyfillablePrototypeLookup = new Map(exports.polyfillableMethods
|
|
173
150
|
.filter((m) => !m.isStatic && !m.ambiguousWithString)
|
|
174
151
|
.map((m) => [m.method.toLowerCase(), m]));
|
|
152
|
+
/**
|
|
153
|
+
* Static members with NO polyfill that have a direct `Platform.Function.*`
|
|
154
|
+
* replacement (e.g. `JSON.parse` → `Platform.Function.ParseJSON`). Keyed by
|
|
155
|
+
* `Owner.member` (lowercased). Consumed by validateSsjs to emit a
|
|
156
|
+
* `ssjs/replace-with-platform-function` diagnostic carrying the replacement,
|
|
157
|
+
* so the editor can offer a "replace with …" quick-fix.
|
|
158
|
+
*/
|
|
159
|
+
exports.replaceableStaticLookup = new Map(ssjs_data_1.KNOWN_UNSUPPORTED
|
|
160
|
+
.filter((m) => m.isStatic && typeof m.replacement === 'string')
|
|
161
|
+
.map((m) => [
|
|
162
|
+
`${m.owner}.${m.member}`.toLowerCase(),
|
|
163
|
+
{
|
|
164
|
+
member: m.member,
|
|
165
|
+
owner: m.owner,
|
|
166
|
+
replacement: m.replacement,
|
|
167
|
+
suggestion: m.suggestion,
|
|
168
|
+
},
|
|
169
|
+
]));
|
|
175
170
|
//# sourceMappingURL=ssjs.js.map
|
package/dist/cjs/data/ssjs.d.ts
CHANGED
|
@@ -39,16 +39,6 @@ export interface EcmascriptBuiltin {
|
|
|
39
39
|
guideUrl?: string;
|
|
40
40
|
mdnUrl?: string;
|
|
41
41
|
}
|
|
42
|
-
export interface KnownUnsupportedMember {
|
|
43
|
-
member: string;
|
|
44
|
-
owner: string;
|
|
45
|
-
esVersion: 3 | 5 | 6;
|
|
46
|
-
isStatic: boolean;
|
|
47
|
-
isProperty?: boolean;
|
|
48
|
-
category: 'unavailable' | 'broken';
|
|
49
|
-
hasPolyfill: boolean;
|
|
50
|
-
suggestion: string;
|
|
51
|
-
}
|
|
52
42
|
export interface PolyfillableMethod {
|
|
53
43
|
method: string;
|
|
54
44
|
owner: string;
|
|
@@ -89,24 +79,6 @@ export declare const scriptUtilRequestMethods: SsjsFunction[];
|
|
|
89
79
|
*/
|
|
90
80
|
export declare const requiresCoreLoadGlobals: Set<string>;
|
|
91
81
|
export declare const ecmascriptBuiltins: EcmascriptBuiltin[];
|
|
92
|
-
/**
|
|
93
|
-
* ECMAScript members empirically confirmed ABSENT or BROKEN in the SFMC SSJS
|
|
94
|
-
* engine and not covered by a shipped polyfill. Consumed by validateSsjs to
|
|
95
|
-
* warn when authored/generated SSJS references a member that fails at runtime.
|
|
96
|
-
*/
|
|
97
|
-
export declare const knownUnsupportedMembers: KnownUnsupportedMember[];
|
|
98
|
-
/**
|
|
99
|
-
* Static known-unsupported members keyed by `Owner.member` (lowercased), e.g.
|
|
100
|
-
* `json.parse`, `object.keys`, `math.trunc`. These have an explicit owner
|
|
101
|
-
* prefix in source so they can be flagged unambiguously.
|
|
102
|
-
*/
|
|
103
|
-
export declare const knownUnsupportedStaticLookup: Map<string, KnownUnsupportedMember>;
|
|
104
|
-
/**
|
|
105
|
-
* Prototype (instance) known-unsupported members keyed by member name
|
|
106
|
-
* (lowercased), e.g. `includes`, `flat`, `trimstart`. Flagged as warnings
|
|
107
|
-
* because a regex cannot prove the receiver's type.
|
|
108
|
-
*/
|
|
109
|
-
export declare const knownUnsupportedPrototypeLookup: Map<string, KnownUnsupportedMember>;
|
|
110
82
|
/**
|
|
111
83
|
* ECMAScript members empirically confirmed ABSENT or BROKEN in the SFMC SSJS
|
|
112
84
|
* engine but for which a verified polyfill exists in ssjs-data. Consumed by
|
|
@@ -129,4 +101,18 @@ export declare const polyfillableStaticLookup: Map<string, PolyfillableMethod>;
|
|
|
129
101
|
* the eslint plugin.
|
|
130
102
|
*/
|
|
131
103
|
export declare const polyfillablePrototypeLookup: Map<string, PolyfillableMethod>;
|
|
104
|
+
export interface ReplaceableMethod {
|
|
105
|
+
member: string;
|
|
106
|
+
owner: string;
|
|
107
|
+
replacement: string;
|
|
108
|
+
suggestion: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Static members with NO polyfill that have a direct `Platform.Function.*`
|
|
112
|
+
* replacement (e.g. `JSON.parse` → `Platform.Function.ParseJSON`). Keyed by
|
|
113
|
+
* `Owner.member` (lowercased). Consumed by validateSsjs to emit a
|
|
114
|
+
* `ssjs/replace-with-platform-function` diagnostic carrying the replacement,
|
|
115
|
+
* so the editor can offer a "replace with …" quick-fix.
|
|
116
|
+
*/
|
|
117
|
+
export declare const replaceableStaticLookup: Map<string, ReplaceableMethod>;
|
|
132
118
|
//# sourceMappingURL=ssjs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssjs.d.ts","sourceRoot":"","sources":["../../../src/data/ssjs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyBH,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MA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YAAY,EAGnC,CAAC;AAIJ,eAAO,MAAM,iBAAiB,EAAE,YAAY,EAGzC,CAAC;AAIJ,eAAO,MAAM,eAAe,EAAE,YAAY,EAGvC,CAAC;AAIJ,eAAO,MAAM,uBAAuB,EAAE,YAAY,EAG/C,CAAC;AAIJ,eAAO,MAAM,gBAAgB,EAAE,YAAY,EAGxC,CAAC;AAIJ,eAAO,MAAM,wBAAwB,EAAE,YAAY,EAGhD,CAAC;AAIJ,eAAO,MAAM,sBAAsB,EAAE,YAAY,EAG9C,CAAC;AAIJ,eAAO,MAAM,wBAAwB,EAAE,YAAY,EAGhD,CAAC;AAIJ;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,GAAG,CAAC,MAAM,CAE/C,CAAC;AAIF,eAAO,MAAM,kBAAkB,EAAE,iBAAiB,EAchD,CAAC;AAIH;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAAkB,EAEjD,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,iCAIpC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,iCAIvC,CAAC;AAIF,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gCAYnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssjs.js","sourceRoot":"","sources":["../../../src/data/ssjs.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,yCAoBmB;AACnB,yCAAgF;
|
|
1
|
+
{"version":3,"file":"ssjs.js","sourceRoot":"","sources":["../../../src/data/ssjs.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,yCAoBmB;AACnB,yCAAgF;AAuDhF,gFAAgF;AAEnE,QAA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AAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;KACzB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAC/D,CAAC;AAEF;;;;;;;GAOG;AACU,QAAA,2BAA2B,GAAG,IAAI,GAAG,CAC9C,2BAAmB;KACd,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC;KACpD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAC/C,CAAC;AAWF;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG,IAAI,GAAG,CACzC,6BAA0F;KACtF,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,CAAC;KAC9D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACR,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE;IACtC;QACI,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,WAAW,EAAE,CAAC,CAAC,WAAqB;QACpC,UAAU,EAAE,CAAC,CAAC,UAAU;KAC3B;CACJ,CAAC,CACT,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.polyfillMarker = polyfillMarker;
|
|
4
|
+
exports.isPolyfillPresent = isPolyfillPresent;
|
|
5
|
+
/**
|
|
6
|
+
* Extract a stable marker line from a polyfill source string. Polyfills are
|
|
7
|
+
* prefixed with a JSDoc block, so the marker is the first code line — the one
|
|
8
|
+
* that declares or assigns the polyfilled member (e.g.
|
|
9
|
+
* `String.prototype.search = function (...) {` or `function bindFn(...) {`).
|
|
10
|
+
* Its presence in a document means the polyfill has already been inserted.
|
|
11
|
+
* @param polyfill - The polyfill source string.
|
|
12
|
+
* @returns The trimmed first code line, or undefined when none is found.
|
|
13
|
+
*/
|
|
14
|
+
function polyfillMarker(polyfill) {
|
|
15
|
+
const lines = polyfill.split('\n').map((l) => l.trim());
|
|
16
|
+
// skip blank lines and the leading JSDoc block (/** ... */)
|
|
17
|
+
const marker = lines.find((l) => l.length > 0 && !l.startsWith('/**') && !l.startsWith('*') && !l.startsWith('*/'));
|
|
18
|
+
return marker;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Determine whether a polyfill is already present in a document.
|
|
22
|
+
* @param text - Full document text.
|
|
23
|
+
* @param polyfill - The polyfill source string.
|
|
24
|
+
* @returns True when the polyfill's marker line is found in the document.
|
|
25
|
+
*/
|
|
26
|
+
function isPolyfillPresent(text, polyfill) {
|
|
27
|
+
const marker = polyfillMarker(polyfill);
|
|
28
|
+
return marker !== undefined && text.includes(marker);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=polyfill.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract a stable marker line from a polyfill source string. Polyfills are
|
|
3
|
+
* prefixed with a JSDoc block, so the marker is the first code line — the one
|
|
4
|
+
* that declares or assigns the polyfilled member (e.g.
|
|
5
|
+
* `String.prototype.search = function (...) {` or `function bindFn(...) {`).
|
|
6
|
+
* Its presence in a document means the polyfill has already been inserted.
|
|
7
|
+
* @param polyfill - The polyfill source string.
|
|
8
|
+
* @returns The trimmed first code line, or undefined when none is found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function polyfillMarker(polyfill: string): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Determine whether a polyfill is already present in a document.
|
|
13
|
+
* @param text - Full document text.
|
|
14
|
+
* @param polyfill - The polyfill source string.
|
|
15
|
+
* @returns True when the polyfill's marker line is found in the document.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isPolyfillPresent(text: string, polyfill: string): boolean;
|
|
18
|
+
//# sourceMappingURL=polyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../../src/utils/polyfill.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOnE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../../src/utils/polyfill.ts"],"names":[],"mappings":";;AASA,wCAOC;AAQD,8CAGC;AA3BD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,QAAgB;IAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,4DAA4D;IAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CACrB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAC3F,CAAC;IACF,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,QAAgB;IAC5D,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -1,28 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SSJS_ESLINT_DUPLICATE_DIAG_CODES = exports.
|
|
3
|
+
exports.SSJS_ESLINT_DUPLICATE_DIAG_CODES = exports.DIAG_CODE_SSJS_REPLACE_WITH_PLATFORM_FUNCTION = exports.DIAG_CODE_SSJS_MCN_NOT_SUPPORTED = exports.DIAG_CODE_SSJS_POLYFILL_REQUIRED = void 0;
|
|
4
4
|
exports.validateSsjs = validateSsjs;
|
|
5
5
|
const types_js_1 = require("../types.cjs");
|
|
6
6
|
const types_js_2 = require("../types.cjs");
|
|
7
7
|
const comments_js_1 = require("../utils/comments.cjs");
|
|
8
8
|
const positions_js_1 = require("../utils/positions.cjs");
|
|
9
|
+
const polyfill_js_1 = require("../utils/polyfill.cjs");
|
|
9
10
|
const ssjs_js_1 = require("../data/ssjs.cjs");
|
|
10
11
|
// Diagnostic codes that code actions identify and act on, and that overlap with
|
|
11
12
|
// eslint-plugin-sfmc rules. When `disableLspDiagnosticsForEslintRules` is enabled
|
|
12
13
|
// these codes are filtered out (the eslint plugin reports the same problems via AST).
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
//
|
|
15
|
+
// Methods that are simply absent in the SFMC engine and have NO polyfill are
|
|
16
|
+
// intentionally NOT diagnosed here — TypeScript's own diagnostics (e.g.
|
|
17
|
+
// `sfmc-ts(2550)` / `sfmc-ts(2304)`) already flag those. We only emit a
|
|
18
|
+
// diagnostic when a verified polyfill exists, so the user can act on it.
|
|
19
|
+
exports.DIAG_CODE_SSJS_POLYFILL_REQUIRED = 'ssjs/polyfill-required';
|
|
15
20
|
exports.DIAG_CODE_SSJS_MCN_NOT_SUPPORTED = 'ssjs/mcn-not-supported';
|
|
21
|
+
// Static members with no polyfill but a direct Platform.Function replacement
|
|
22
|
+
// (e.g. JSON.parse → Platform.Function.ParseJSON). TypeScript also flags these
|
|
23
|
+
// (JSON is undefined), but we additionally offer a "replace with …" quick-fix.
|
|
24
|
+
exports.DIAG_CODE_SSJS_REPLACE_WITH_PLATFORM_FUNCTION = 'ssjs/replace-with-platform-function';
|
|
16
25
|
/**
|
|
17
26
|
* SSJS diagnostic codes that duplicate eslint-plugin-sfmc rules (the
|
|
18
|
-
* `ssjs/no-unavailable-method` rule covers
|
|
19
|
-
*
|
|
20
|
-
* `disableLspDiagnosticsForEslintRules` setting.
|
|
27
|
+
* `ssjs/no-unavailable-method` rule covers polyfill-required members) and can
|
|
28
|
+
* be suppressed via the `disableLspDiagnosticsForEslintRules` setting.
|
|
21
29
|
*/
|
|
22
30
|
exports.SSJS_ESLINT_DUPLICATE_DIAG_CODES = new Set([
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
31
|
+
exports.DIAG_CODE_SSJS_POLYFILL_REQUIRED,
|
|
32
|
+
exports.DIAG_CODE_SSJS_REPLACE_WITH_PLATFORM_FUNCTION,
|
|
25
33
|
]);
|
|
34
|
+
/**
|
|
35
|
+
* Build the `ssjs/polyfill-required` diagnostic message, tailored to whether the
|
|
36
|
+
* member is absent from the SFMC engine (`category: 'unavailable'`) or present
|
|
37
|
+
* but returns wrong results (`category: 'broken'`).
|
|
38
|
+
* @param qualifiedName - Fully-qualified member, e.g. `Array.isArray` or `String.prototype.search`.
|
|
39
|
+
* @param category - Whether the member is unavailable or merely broken in the engine.
|
|
40
|
+
* @returns The diagnostic message string.
|
|
41
|
+
*/
|
|
42
|
+
function polyfillRequiredMessage(qualifiedName, category) {
|
|
43
|
+
return category === 'broken'
|
|
44
|
+
? `${qualifiedName} is broken in the SFMC SSJS engine and returns wrong results, but a polyfill exists. Insert the polyfill to use it safely.`
|
|
45
|
+
: `${qualifiedName} is not available in SFMC SSJS, but a polyfill exists. Insert the polyfill to use it safely.`;
|
|
46
|
+
}
|
|
26
47
|
/**
|
|
27
48
|
* Validate an SSJS document and return LSP Diagnostics.
|
|
28
49
|
* @param text - Full document text.
|
|
@@ -206,82 +227,65 @@ function validateSsjs(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
206
227
|
});
|
|
207
228
|
}
|
|
208
229
|
}
|
|
209
|
-
// 4.
|
|
210
|
-
// in the SFMC engine
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
230
|
+
// 4. Polyfill-required ECMAScript built-in members. These are absent/broken
|
|
231
|
+
// in the SFMC engine but a verified polyfill exists in ssjs-data, so the
|
|
232
|
+
// diagnostic carries the polyfill source in `data` for an "insert
|
|
233
|
+
// polyfill" code action. Members with NO polyfill are deliberately left
|
|
234
|
+
// to TypeScript's own diagnostics and are not reported here.
|
|
235
|
+
//
|
|
236
|
+
// When the polyfill is already present in the document the diagnostic is
|
|
237
|
+
// suppressed entirely (no squiggle) — the method is now safe to use.
|
|
238
|
+
//
|
|
239
|
+
// 4a. Static polyfillable members (e.g. Array.isArray, Array.of, Math.max)
|
|
240
|
+
// — matched on an explicit owner prefix.
|
|
241
|
+
if (ssjs_js_1.polyfillableStaticLookup.size > 0) {
|
|
242
|
+
const staticPolyPattern = /\b([A-Z]\w*)\s*\.\s*([A-Za-z_$][\w$]*)/g;
|
|
243
|
+
let m;
|
|
244
|
+
while ((m = staticPolyPattern.exec(text)) !== null && problems < max) {
|
|
245
|
+
if ((0, comments_js_1.isInCommentRange)(m.index, commentRanges))
|
|
218
246
|
continue;
|
|
219
|
-
const
|
|
220
|
-
const entry = ssjs_js_1.knownUnsupportedStaticLookup.get(key);
|
|
247
|
+
const entry = ssjs_js_1.polyfillableStaticLookup.get(`${m[1]}.${m[2]}`.toLowerCase());
|
|
221
248
|
if (!entry)
|
|
222
249
|
continue;
|
|
223
|
-
|
|
224
|
-
diagnostics.push({
|
|
225
|
-
severity: types_js_1.DiagnosticSeverity.Error,
|
|
226
|
-
range: {
|
|
227
|
-
start: (0, positions_js_1.offsetToPosition)(text, staticMatch.index),
|
|
228
|
-
end: (0, positions_js_1.offsetToPosition)(text, staticMatch.index + staticMatch[0].length),
|
|
229
|
-
},
|
|
230
|
-
message: `${entry.owner}.${entry.member} is not available in SFMC SSJS. ${entry.suggestion}`,
|
|
231
|
-
source: 'ssjs',
|
|
232
|
-
code: exports.DIAG_CODE_SSJS_KNOWN_UNSUPPORTED,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// 4b. Prototype (instance) members — flagged as warnings because a regex
|
|
237
|
-
// cannot prove the receiver type (e.g. ".includes(", ".flat(",
|
|
238
|
-
// ".trimStart("). Only call-shaped uses (member followed by "(") are
|
|
239
|
-
// considered to reduce false positives on property reads.
|
|
240
|
-
if (ssjs_js_1.knownUnsupportedPrototypeLookup.size > 0) {
|
|
241
|
-
const protoPattern = /\.\s*([A-Za-z_$][\w$]*)\s*\(/g;
|
|
242
|
-
let protoMatch;
|
|
243
|
-
while ((protoMatch = protoPattern.exec(text)) !== null && problems < max) {
|
|
244
|
-
if ((0, comments_js_1.isInCommentRange)(protoMatch.index, commentRanges))
|
|
250
|
+
if ((0, polyfill_js_1.isPolyfillPresent)(text, entry.polyfill))
|
|
245
251
|
continue;
|
|
246
|
-
const entry = ssjs_js_1.knownUnsupportedPrototypeLookup.get(protoMatch[1].toLowerCase());
|
|
247
|
-
if (!entry)
|
|
248
|
-
continue;
|
|
249
|
-
// Skip if preceded by a known static owner — that case is handled by 4a.
|
|
250
252
|
problems++;
|
|
251
|
-
const
|
|
253
|
+
const data = {
|
|
254
|
+
owner: entry.owner,
|
|
255
|
+
method: entry.method,
|
|
256
|
+
polyfill: entry.polyfill,
|
|
257
|
+
};
|
|
252
258
|
diagnostics.push({
|
|
253
259
|
severity: types_js_1.DiagnosticSeverity.Warning,
|
|
254
260
|
range: {
|
|
255
|
-
start: (0, positions_js_1.offsetToPosition)(text,
|
|
256
|
-
end: (0, positions_js_1.offsetToPosition)(text,
|
|
261
|
+
start: (0, positions_js_1.offsetToPosition)(text, m.index),
|
|
262
|
+
end: (0, positions_js_1.offsetToPosition)(text, m.index + m[0].length),
|
|
257
263
|
},
|
|
258
|
-
message: `${entry.owner
|
|
264
|
+
message: polyfillRequiredMessage(`${entry.owner}.${entry.method}`, entry.category),
|
|
259
265
|
source: 'ssjs',
|
|
260
|
-
code: exports.
|
|
266
|
+
code: exports.DIAG_CODE_SSJS_POLYFILL_REQUIRED,
|
|
267
|
+
data,
|
|
261
268
|
});
|
|
262
269
|
}
|
|
263
270
|
}
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// — matched on an explicit owner prefix.
|
|
271
|
-
if (ssjs_js_1.polyfillableStaticLookup.size > 0) {
|
|
272
|
-
const staticPolyPattern = /\b([A-Z]\w*)\s*\.\s*([A-Za-z_$][\w$]*)/g;
|
|
271
|
+
// 4a-ii. Replaceable static members (no polyfill, but a direct
|
|
272
|
+
// Platform.Function alternative exists, e.g. JSON.parse →
|
|
273
|
+
// Platform.Function.ParseJSON). Emit a diagnostic carrying the
|
|
274
|
+
// replacement so the editor can offer a "replace with …" quick-fix.
|
|
275
|
+
if (ssjs_js_1.replaceableStaticLookup.size > 0) {
|
|
276
|
+
const replacePattern = /\b([A-Z]\w*)\s*\.\s*([A-Za-z_$][\w$]*)/g;
|
|
273
277
|
let m;
|
|
274
|
-
while ((m =
|
|
278
|
+
while ((m = replacePattern.exec(text)) !== null && problems < max) {
|
|
275
279
|
if ((0, comments_js_1.isInCommentRange)(m.index, commentRanges))
|
|
276
280
|
continue;
|
|
277
|
-
const entry = ssjs_js_1.
|
|
281
|
+
const entry = ssjs_js_1.replaceableStaticLookup.get(`${m[1]}.${m[2]}`.toLowerCase());
|
|
278
282
|
if (!entry)
|
|
279
283
|
continue;
|
|
280
284
|
problems++;
|
|
281
285
|
const data = {
|
|
282
286
|
owner: entry.owner,
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
member: entry.member,
|
|
288
|
+
replacement: entry.replacement,
|
|
285
289
|
};
|
|
286
290
|
diagnostics.push({
|
|
287
291
|
severity: types_js_1.DiagnosticSeverity.Warning,
|
|
@@ -289,17 +293,17 @@ function validateSsjs(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
289
293
|
start: (0, positions_js_1.offsetToPosition)(text, m.index),
|
|
290
294
|
end: (0, positions_js_1.offsetToPosition)(text, m.index + m[0].length),
|
|
291
295
|
},
|
|
292
|
-
message: `${entry.owner}.${entry.
|
|
296
|
+
message: `${entry.owner}.${entry.member} is not available in SFMC SSJS. Use ${entry.replacement} instead.`,
|
|
293
297
|
source: 'ssjs',
|
|
294
|
-
code: exports.
|
|
298
|
+
code: exports.DIAG_CODE_SSJS_REPLACE_WITH_PLATFORM_FUNCTION,
|
|
295
299
|
data,
|
|
296
300
|
});
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
+
// 4b. Prototype polyfillable members (e.g. .forEach, .map, .filter).
|
|
304
|
+
// Members also valid on String.prototype in ES3 (ambiguousWithString,
|
|
305
|
+
// e.g. slice/indexOf/lastIndexOf) are EXCLUDED from the lookup to avoid
|
|
306
|
+
// false positives on string receivers — only call-shaped uses match.
|
|
303
307
|
if (ssjs_js_1.polyfillablePrototypeLookup.size > 0) {
|
|
304
308
|
const protoPolyPattern = /\.\s*([A-Za-z_$][\w$]*)\s*\(/g;
|
|
305
309
|
let m;
|
|
@@ -309,6 +313,8 @@ function validateSsjs(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
309
313
|
const entry = ssjs_js_1.polyfillablePrototypeLookup.get(m[1].toLowerCase());
|
|
310
314
|
if (!entry)
|
|
311
315
|
continue;
|
|
316
|
+
if ((0, polyfill_js_1.isPolyfillPresent)(text, entry.polyfill))
|
|
317
|
+
continue;
|
|
312
318
|
problems++;
|
|
313
319
|
const memberStart = m.index + m[0].indexOf(m[1]);
|
|
314
320
|
const owner = entry.owner.replace('.prototype', '');
|
|
@@ -323,9 +329,9 @@ function validateSsjs(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
323
329
|
start: (0, positions_js_1.offsetToPosition)(text, memberStart),
|
|
324
330
|
end: (0, positions_js_1.offsetToPosition)(text, memberStart + m[1].length),
|
|
325
331
|
},
|
|
326
|
-
message: `${owner}.prototype.${entry.method}
|
|
332
|
+
message: polyfillRequiredMessage(`${owner}.prototype.${entry.method}`, entry.category),
|
|
327
333
|
source: 'ssjs',
|
|
328
|
-
code: exports.
|
|
334
|
+
code: exports.DIAG_CODE_SSJS_POLYFILL_REQUIRED,
|
|
329
335
|
data,
|
|
330
336
|
});
|
|
331
337
|
}
|