@nativescript/vite 8.0.0-alpha.1 → 8.0.0-alpha.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/configuration/angular.d.ts +1 -1
- package/configuration/angular.js +286 -119
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +40 -23
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +3 -3
- package/configuration/javascript.js.map +1 -1
- package/configuration/solid.js +7 -0
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +3 -3
- package/configuration/typescript.js.map +1 -1
- package/helpers/angular/angular-linker.js +39 -34
- package/helpers/angular/angular-linker.js.map +1 -1
- package/helpers/angular/inline-decorator-component-templates.d.ts +3 -0
- package/helpers/angular/inline-decorator-component-templates.js +400 -0
- package/helpers/angular/inline-decorator-component-templates.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +7 -0
- package/helpers/angular/shared-linker.js +37 -1
- package/helpers/angular/shared-linker.js.map +1 -1
- package/helpers/angular/synthesize-decorator-ctor-parameters.d.ts +1 -0
- package/helpers/angular/synthesize-decorator-ctor-parameters.js +256 -0
- package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +1 -0
- package/helpers/angular/synthesize-injectable-factories.d.ts +3 -0
- package/helpers/angular/synthesize-injectable-factories.js +414 -0
- package/helpers/angular/synthesize-injectable-factories.js.map +1 -0
- package/helpers/esbuild-platform-resolver.js +5 -5
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/external-configs.d.ts +9 -1
- package/helpers/external-configs.js +31 -6
- package/helpers/external-configs.js.map +1 -1
- package/helpers/import-meta-path.d.ts +4 -0
- package/helpers/import-meta-path.js +5 -0
- package/helpers/import-meta-path.js.map +1 -0
- package/helpers/import-specifier.d.ts +1 -0
- package/helpers/import-specifier.js +18 -0
- package/helpers/import-specifier.js.map +1 -0
- package/helpers/main-entry.d.ts +4 -2
- package/helpers/main-entry.js +86 -10
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-transform.js +8 -127
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +12 -1
- package/helpers/nativeclass-transformer-plugin.js +175 -36
- package/helpers/nativeclass-transformer-plugin.js.map +1 -1
- package/hmr/client/css-handler.js +60 -20
- package/hmr/client/css-handler.js.map +1 -1
- package/hmr/client/index.js +453 -5
- package/hmr/client/index.js.map +1 -1
- package/hmr/entry-runtime.d.ts +10 -0
- package/hmr/entry-runtime.js +263 -21
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/client/index.js +22 -18
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/server/linker.js +36 -2
- package/hmr/frameworks/angular/server/linker.js.map +1 -1
- package/hmr/helpers/ast-normalizer.js +22 -10
- package/hmr/helpers/ast-normalizer.js.map +1 -1
- package/hmr/server/constants.d.ts +1 -0
- package/hmr/server/constants.js +2 -0
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/core-sanitize.d.ts +42 -0
- package/hmr/server/core-sanitize.js +189 -0
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/import-map.d.ts +65 -0
- package/hmr/server/import-map.js +213 -0
- package/hmr/server/import-map.js.map +1 -0
- package/hmr/server/websocket.d.ts +79 -3
- package/hmr/server/websocket.js +1888 -233
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/runtime/dev-overlay.d.ts +38 -0
- package/hmr/shared/runtime/dev-overlay.js +664 -0
- package/hmr/shared/runtime/dev-overlay.js.map +1 -0
- package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
- package/hmr/shared/runtime/http-only-boot.js +53 -6
- package/hmr/shared/runtime/http-only-boot.js.map +1 -1
- package/hmr/shared/runtime/module-provenance.d.ts +1 -0
- package/hmr/shared/runtime/module-provenance.js +66 -0
- package/hmr/shared/runtime/module-provenance.js.map +1 -0
- package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
- package/hmr/shared/runtime/platform-polyfills.js +122 -0
- package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.js +175 -53
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/vendor-bootstrap.js +51 -6
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +5 -0
- package/hmr/shared/vendor/manifest.js +339 -13
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/registry.js +104 -7
- package/hmr/shared/vendor/registry.js.map +1 -1
- package/package.json +6 -2
- package/shims/solid-jsx-runtime.d.ts +7 -0
- package/shims/solid-jsx-runtime.js +17 -0
- package/shims/solid-jsx-runtime.js.map +1 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
const DECORATE_ASSIGNMENT_RE = /(^|[^\w$.])([A-Za-z_$][\w$]*)\s*=\s*__decorate(?:\$\w+)?\s*\(/gm;
|
|
2
|
+
export function synthesizeDecoratorCtorParameters(code) {
|
|
3
|
+
let changed = false;
|
|
4
|
+
let lastIndex = 0;
|
|
5
|
+
let output = '';
|
|
6
|
+
for (const match of code.matchAll(DECORATE_ASSIGNMENT_RE)) {
|
|
7
|
+
const prefix = match[1] ?? '';
|
|
8
|
+
const className = match[2];
|
|
9
|
+
const assignmentStart = (match.index ?? 0) + prefix.length;
|
|
10
|
+
const equalsIndex = code.indexOf('=', assignmentStart + className.length);
|
|
11
|
+
const decorateIndex = code.indexOf('__decorate', equalsIndex);
|
|
12
|
+
const openParenIndex = code.indexOf('(', decorateIndex);
|
|
13
|
+
if (equalsIndex === -1 || decorateIndex === -1 || openParenIndex === -1 || hasCtorParameters(code, className)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const closeParenIndex = findMatchingDelimiter(code, openParenIndex, '(', ')');
|
|
17
|
+
if (closeParenIndex === -1) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const statementEnd = findStatementEnd(code, closeParenIndex + 1);
|
|
21
|
+
const decorateCall = code.slice(decorateIndex, closeParenIndex + 1);
|
|
22
|
+
const decorators = splitDecoratorArray(decorateCall);
|
|
23
|
+
if (!decorators.some(isAngularClassDecorator)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const paramTypes = extractParamTypes(decorators);
|
|
27
|
+
if (!paramTypes?.length) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
output += code.slice(lastIndex, assignmentStart);
|
|
31
|
+
output += `${className}.ctorParameters = () => [${paramTypes.map((paramType) => `{ type: ${paramType} }`).join(', ')}];\n`;
|
|
32
|
+
output += code.slice(assignmentStart, statementEnd);
|
|
33
|
+
lastIndex = statementEnd;
|
|
34
|
+
changed = true;
|
|
35
|
+
}
|
|
36
|
+
if (!changed) {
|
|
37
|
+
return code;
|
|
38
|
+
}
|
|
39
|
+
output += code.slice(lastIndex);
|
|
40
|
+
return output;
|
|
41
|
+
}
|
|
42
|
+
function hasCtorParameters(code, className) {
|
|
43
|
+
return [`${className}.ctorParameters`, `Object.defineProperty(${className}, "ctorParameters"`, `Object.defineProperty(${className}, 'ctorParameters'`].some((marker) => code.includes(marker));
|
|
44
|
+
}
|
|
45
|
+
function splitDecoratorArray(decorateCall) {
|
|
46
|
+
const openParenIndex = decorateCall.indexOf('(');
|
|
47
|
+
const closeParenIndex = decorateCall.lastIndexOf(')');
|
|
48
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const args = splitTopLevel(decorateCall.slice(openParenIndex + 1, closeParenIndex));
|
|
52
|
+
if (!args.length) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const decoratorArray = args[0].trim();
|
|
56
|
+
if (!decoratorArray.startsWith('[') || !decoratorArray.endsWith(']')) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return splitTopLevel(decoratorArray.slice(1, -1));
|
|
60
|
+
}
|
|
61
|
+
function extractParamTypes(decorators) {
|
|
62
|
+
for (const decorator of decorators) {
|
|
63
|
+
if (!decorator.includes('__decorateMetadata')) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const openParenIndex = decorator.indexOf('(');
|
|
67
|
+
const closeParenIndex = findMatchingDelimiter(decorator, openParenIndex, '(', ')');
|
|
68
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const args = splitTopLevel(decorator.slice(openParenIndex + 1, closeParenIndex));
|
|
72
|
+
if (args.length < 2 || stripQuotes(args[0].trim()) !== 'design:paramtypes') {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const paramArray = args[1].trim();
|
|
76
|
+
if (!paramArray.startsWith('[') || !paramArray.endsWith(']')) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
return splitTopLevel(paramArray.slice(1, -1));
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
function isAngularClassDecorator(decorator) {
|
|
84
|
+
return /(?:^|\W)(?:Injectable|Component|Directive|Pipe|NgModule)(?:\$\d+)?\s*\(/.test(decorator);
|
|
85
|
+
}
|
|
86
|
+
function stripQuotes(value) {
|
|
87
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
88
|
+
return value.slice(1, -1);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function findStatementEnd(source, startIndex) {
|
|
93
|
+
let index = startIndex;
|
|
94
|
+
while (index < source.length && /\s/.test(source[index])) {
|
|
95
|
+
index++;
|
|
96
|
+
}
|
|
97
|
+
if (source[index] === ';') {
|
|
98
|
+
return index + 1;
|
|
99
|
+
}
|
|
100
|
+
return startIndex;
|
|
101
|
+
}
|
|
102
|
+
function findMatchingDelimiter(source, openIndex, openChar, closeChar) {
|
|
103
|
+
if (openIndex < 0 || source[openIndex] !== openChar) {
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
let depth = 0;
|
|
107
|
+
let quote = null;
|
|
108
|
+
let escape = false;
|
|
109
|
+
let inLineComment = false;
|
|
110
|
+
let inBlockComment = false;
|
|
111
|
+
for (let index = openIndex; index < source.length; index++) {
|
|
112
|
+
const char = source[index];
|
|
113
|
+
const next = source[index + 1];
|
|
114
|
+
if (inLineComment) {
|
|
115
|
+
if (char === '\n') {
|
|
116
|
+
inLineComment = false;
|
|
117
|
+
}
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (inBlockComment) {
|
|
121
|
+
if (char === '*' && next === '/') {
|
|
122
|
+
inBlockComment = false;
|
|
123
|
+
index++;
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (quote) {
|
|
128
|
+
if (escape) {
|
|
129
|
+
escape = false;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (char === '\\') {
|
|
133
|
+
escape = true;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (char === quote) {
|
|
137
|
+
quote = null;
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (char === '/' && next === '/') {
|
|
142
|
+
inLineComment = true;
|
|
143
|
+
index++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (char === '/' && next === '*') {
|
|
147
|
+
inBlockComment = true;
|
|
148
|
+
index++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
152
|
+
quote = char;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (char === openChar) {
|
|
156
|
+
depth++;
|
|
157
|
+
}
|
|
158
|
+
else if (char === closeChar) {
|
|
159
|
+
depth--;
|
|
160
|
+
if (depth === 0) {
|
|
161
|
+
return index;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return -1;
|
|
166
|
+
}
|
|
167
|
+
function splitTopLevel(source) {
|
|
168
|
+
const parts = [];
|
|
169
|
+
let start = 0;
|
|
170
|
+
let parenDepth = 0;
|
|
171
|
+
let bracketDepth = 0;
|
|
172
|
+
let braceDepth = 0;
|
|
173
|
+
let quote = null;
|
|
174
|
+
let escape = false;
|
|
175
|
+
let inLineComment = false;
|
|
176
|
+
let inBlockComment = false;
|
|
177
|
+
for (let index = 0; index < source.length; index++) {
|
|
178
|
+
const char = source[index];
|
|
179
|
+
const next = source[index + 1];
|
|
180
|
+
if (inLineComment) {
|
|
181
|
+
if (char === '\n') {
|
|
182
|
+
inLineComment = false;
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (inBlockComment) {
|
|
187
|
+
if (char === '*' && next === '/') {
|
|
188
|
+
inBlockComment = false;
|
|
189
|
+
index++;
|
|
190
|
+
}
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (quote) {
|
|
194
|
+
if (escape) {
|
|
195
|
+
escape = false;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (char === '\\') {
|
|
199
|
+
escape = true;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (char === quote) {
|
|
203
|
+
quote = null;
|
|
204
|
+
}
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (char === '/' && next === '/') {
|
|
208
|
+
inLineComment = true;
|
|
209
|
+
index++;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (char === '/' && next === '*') {
|
|
213
|
+
inBlockComment = true;
|
|
214
|
+
index++;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
218
|
+
quote = char;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (char === '(') {
|
|
222
|
+
parenDepth++;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (char === ')') {
|
|
226
|
+
parenDepth--;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (char === '[') {
|
|
230
|
+
bracketDepth++;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (char === ']') {
|
|
234
|
+
bracketDepth--;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (char === '{') {
|
|
238
|
+
braceDepth++;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (char === '}') {
|
|
242
|
+
braceDepth--;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (char === ',' && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
|
|
246
|
+
parts.push(source.slice(start, index).trim());
|
|
247
|
+
start = index + 1;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const tail = source.slice(start).trim();
|
|
251
|
+
if (tail) {
|
|
252
|
+
parts.push(tail);
|
|
253
|
+
}
|
|
254
|
+
return parts;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=synthesize-decorator-ctor-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-decorator-ctor-parameters.js","sourceRoot":"","sources":["../../../../../packages/vite/helpers/angular/synthesize-decorator-ctor-parameters.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,iEAAiE,CAAC;AAEjG,MAAM,UAAU,iCAAiC,CAAC,IAAY;IAC7D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;QAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,KAA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AAE,CAAC;YACb,SAAS;QACV,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAClB,UAAU,EAAE,CAAC;YACb,SAAS;QACV,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,IAAI,UAAU,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YAChF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAC9C,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;QACnB,CAAC;IACF,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACxC,IAAI,IAAI,EAAE,CAAC;QACV,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
const DECORATE_ASSIGNMENT_RE = /(^|[^\w$.])([A-Za-z_$][\w$]*)\s*=\s*__decorate(?:\$\w+)?\s*\(/gm;
|
|
2
|
+
const SYNTHETIC_INJECT_IDENTIFIER = '__nsInject';
|
|
3
|
+
export function synthesizeMissingInjectableFactories(code, options = {}) {
|
|
4
|
+
let changed = false;
|
|
5
|
+
let requiresInjectHelper = false;
|
|
6
|
+
let lastIndex = 0;
|
|
7
|
+
let output = '';
|
|
8
|
+
for (const match of code.matchAll(DECORATE_ASSIGNMENT_RE)) {
|
|
9
|
+
const prefix = match[1] ?? '';
|
|
10
|
+
const className = match[2];
|
|
11
|
+
const assignmentStart = (match.index ?? 0) + prefix.length;
|
|
12
|
+
const equalsIndex = code.indexOf('=', assignmentStart + className.length);
|
|
13
|
+
const decorateIndex = code.indexOf('__decorate', equalsIndex);
|
|
14
|
+
const openParenIndex = code.indexOf('(', decorateIndex);
|
|
15
|
+
if (equalsIndex === -1 || decorateIndex === -1 || openParenIndex === -1) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const closeParenIndex = findMatchingDelimiter(code, openParenIndex, '(', ')');
|
|
19
|
+
if (closeParenIndex === -1) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const statementEnd = findStatementEnd(code, closeParenIndex + 1);
|
|
23
|
+
if (hasInjectableMetadata(code, className)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const decorateCall = code.slice(decorateIndex, closeParenIndex + 1);
|
|
27
|
+
const paramTypes = resolveParamTypes(code, className, assignmentStart, decorateCall);
|
|
28
|
+
if (!paramTypes) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (paramTypes.length > 0 && !options.vendorInjectExport) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const synthesized = buildInjectableMetadata(className, decorateCall, paramTypes);
|
|
35
|
+
if (!synthesized) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
requiresInjectHelper || (requiresInjectHelper = paramTypes.length > 0);
|
|
39
|
+
output += code.slice(lastIndex, assignmentStart);
|
|
40
|
+
output += `${synthesized}\n`;
|
|
41
|
+
output += code.slice(assignmentStart, statementEnd);
|
|
42
|
+
lastIndex = statementEnd;
|
|
43
|
+
changed = true;
|
|
44
|
+
}
|
|
45
|
+
if (!changed) {
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
48
|
+
output += code.slice(lastIndex);
|
|
49
|
+
if (!requiresInjectHelper) {
|
|
50
|
+
return output;
|
|
51
|
+
}
|
|
52
|
+
return ensureInjectHelperImport(output, options.vendorInjectExport);
|
|
53
|
+
}
|
|
54
|
+
function buildInjectableMetadata(className, decorateCall, paramTypes) {
|
|
55
|
+
const openParenIndex = decorateCall.indexOf('(');
|
|
56
|
+
const closeParenIndex = decorateCall.lastIndexOf(')');
|
|
57
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const args = splitTopLevel(decorateCall.slice(openParenIndex + 1, closeParenIndex));
|
|
61
|
+
if (args.length < 2) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const decoratorArray = args[0].trim();
|
|
65
|
+
if (!decoratorArray.startsWith('[') || !decoratorArray.endsWith(']')) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const decorators = splitTopLevel(decoratorArray.slice(1, -1));
|
|
69
|
+
const injectableDecorator = decorators.find(isInjectableDecorator);
|
|
70
|
+
if (!injectableDecorator) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const ctorArgs = paramTypes.map((param) => `${SYNTHETIC_INJECT_IDENTIFIER}(${param})`).join(', ');
|
|
74
|
+
const factory = `Object.defineProperty(${className}, "ɵfac", { value: function ${className}_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ${className})(${ctorArgs}); }, configurable: true, writable: true });`;
|
|
75
|
+
const providedIn = extractProvidedIn(injectableDecorator);
|
|
76
|
+
const provider = `Object.defineProperty(${className}, "ɵprov", { value: /* @__PURE__ */ ({ token: ${className}, providedIn: ${providedIn ?? 'null'}, factory: ${className}.ɵfac, value: undefined }), configurable: true, writable: true });`;
|
|
77
|
+
return `${factory}\n${provider}`;
|
|
78
|
+
}
|
|
79
|
+
function hasInjectableMetadata(code, className) {
|
|
80
|
+
return [`${className}.ɵfac`, `${className}.ɵprov`, `Object.defineProperty(${className}, "ɵfac"`, `Object.defineProperty(${className}, 'ɵfac'`, `Object.defineProperty(${className}, "ɵprov"`, `Object.defineProperty(${className}, 'ɵprov'`].some((marker) => code.includes(marker));
|
|
81
|
+
}
|
|
82
|
+
function ensureInjectHelperImport(code, vendorInjectExport) {
|
|
83
|
+
if (!vendorInjectExport || code.includes(` as ${SYNTHETIC_INJECT_IDENTIFIER}`) || code.includes(` ${SYNTHETIC_INJECT_IDENTIFIER} from `)) {
|
|
84
|
+
return code;
|
|
85
|
+
}
|
|
86
|
+
const importStatement = `import { ${vendorInjectExport} as ${SYNTHETIC_INJECT_IDENTIFIER} } from "./vendor.mjs";\n`;
|
|
87
|
+
const importMatches = [...code.matchAll(/^import[\s\S]*?;\n?/gm)];
|
|
88
|
+
if (!importMatches.length) {
|
|
89
|
+
return `${importStatement}${code}`;
|
|
90
|
+
}
|
|
91
|
+
const lastImport = importMatches[importMatches.length - 1];
|
|
92
|
+
const insertIndex = (lastImport.index ?? 0) + lastImport[0].length;
|
|
93
|
+
return `${code.slice(0, insertIndex)}${importStatement}${code.slice(insertIndex)}`;
|
|
94
|
+
}
|
|
95
|
+
function resolveParamTypes(code, className, assignmentStart, decorateCall) {
|
|
96
|
+
const explicitParamTypes = extractParamTypes(splitDecoratorArray(decorateCall));
|
|
97
|
+
if (explicitParamTypes) {
|
|
98
|
+
return explicitParamTypes;
|
|
99
|
+
}
|
|
100
|
+
const classBody = extractClassBody(code, className, assignmentStart);
|
|
101
|
+
if (classBody == null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const constructorParams = extractConstructorParams(classBody);
|
|
105
|
+
if (constructorParams == null) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
if (!constructorParams.trim()) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
if (isSyntheticRestConstructor(classBody, constructorParams)) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function extractParamTypes(decorators) {
|
|
117
|
+
for (const decorator of decorators) {
|
|
118
|
+
if (!decorator.includes('__decorateMetadata')) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const openParenIndex = decorator.indexOf('(');
|
|
122
|
+
const closeParenIndex = findMatchingDelimiter(decorator, openParenIndex, '(', ')');
|
|
123
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const args = splitTopLevel(decorator.slice(openParenIndex + 1, closeParenIndex));
|
|
127
|
+
if (args.length < 2) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const metadataKey = stripQuotes(args[0].trim());
|
|
131
|
+
if (metadataKey !== 'design:paramtypes') {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const paramArray = args[1].trim();
|
|
135
|
+
if (!paramArray.startsWith('[') || !paramArray.endsWith(']')) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
return splitTopLevel(paramArray.slice(1, -1));
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
function splitDecoratorArray(decorateCall) {
|
|
143
|
+
const openParenIndex = decorateCall.indexOf('(');
|
|
144
|
+
const closeParenIndex = decorateCall.lastIndexOf(')');
|
|
145
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
const args = splitTopLevel(decorateCall.slice(openParenIndex + 1, closeParenIndex));
|
|
149
|
+
if (args.length < 1) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
const decoratorArray = args[0].trim();
|
|
153
|
+
if (!decoratorArray.startsWith('[') || !decoratorArray.endsWith(']')) {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
return splitTopLevel(decoratorArray.slice(1, -1));
|
|
157
|
+
}
|
|
158
|
+
function extractClassBody(code, className, assignmentStart) {
|
|
159
|
+
const prefix = code.slice(0, assignmentStart);
|
|
160
|
+
const classMarkers = [`var ${className} = class ${className}`, `let ${className} = class ${className}`, `const ${className} = class ${className}`, `${className} = class ${className}`];
|
|
161
|
+
const classStart = classMarkers.map((marker) => prefix.lastIndexOf(marker)).reduce((latest, current) => Math.max(latest, current), -1);
|
|
162
|
+
if (classStart === -1) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
const openBraceIndex = code.indexOf('{', classStart);
|
|
166
|
+
const closeBraceIndex = findMatchingDelimiter(code, openBraceIndex, '{', '}');
|
|
167
|
+
if (openBraceIndex === -1 || closeBraceIndex === -1) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return code.slice(openBraceIndex + 1, closeBraceIndex);
|
|
171
|
+
}
|
|
172
|
+
function extractConstructorParams(classBody) {
|
|
173
|
+
const constructorIndex = classBody.indexOf('constructor(');
|
|
174
|
+
if (constructorIndex === -1) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const openParenIndex = classBody.indexOf('(', constructorIndex);
|
|
178
|
+
const closeParenIndex = findMatchingDelimiter(classBody, openParenIndex, '(', ')');
|
|
179
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
return classBody.slice(openParenIndex + 1, closeParenIndex);
|
|
183
|
+
}
|
|
184
|
+
function isSyntheticRestConstructor(classBody, constructorParams) {
|
|
185
|
+
const restMatch = constructorParams.trim().match(/^\.\.\.\s*([A-Za-z_$][\w$]*)$/);
|
|
186
|
+
if (!restMatch) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const restName = restMatch[1];
|
|
190
|
+
const constructorIndex = classBody.indexOf('constructor(');
|
|
191
|
+
const openBraceIndex = classBody.indexOf('{', constructorIndex);
|
|
192
|
+
const closeBraceIndex = findMatchingDelimiter(classBody, openBraceIndex, '{', '}');
|
|
193
|
+
if (constructorIndex === -1 || openBraceIndex === -1 || closeBraceIndex === -1) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const constructorBody = classBody.slice(openBraceIndex + 1, closeBraceIndex);
|
|
197
|
+
return new RegExp(`\\bsuper\\(\\.\\.\\.${escapeRegex(restName)}\\);`).test(constructorBody);
|
|
198
|
+
}
|
|
199
|
+
function extractProvidedIn(decorator) {
|
|
200
|
+
const args = extractCallArgs(decorator, 'Injectable');
|
|
201
|
+
if (!args) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const trimmed = args.trim();
|
|
205
|
+
if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
for (const property of splitTopLevel(trimmed.slice(1, -1))) {
|
|
209
|
+
const colonIndex = property.indexOf(':');
|
|
210
|
+
if (colonIndex === -1) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const key = property.slice(0, colonIndex).trim();
|
|
214
|
+
if (key !== 'providedIn') {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const value = property.slice(colonIndex + 1).trim();
|
|
218
|
+
return value || null;
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
function isInjectableDecorator(decorator) {
|
|
223
|
+
return /(?:^|\W)Injectable\s*\(/.test(decorator);
|
|
224
|
+
}
|
|
225
|
+
function extractCallArgs(source, callName) {
|
|
226
|
+
const nameIndex = source.search(new RegExp(`(?:^|\\W)${escapeRegex(callName)}\\s*\\(`));
|
|
227
|
+
if (nameIndex === -1) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const openParenIndex = source.indexOf('(', nameIndex);
|
|
231
|
+
const closeParenIndex = findMatchingDelimiter(source, openParenIndex, '(', ')');
|
|
232
|
+
if (openParenIndex === -1 || closeParenIndex === -1) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
return source.slice(openParenIndex + 1, closeParenIndex);
|
|
236
|
+
}
|
|
237
|
+
function findStatementEnd(source, startIndex) {
|
|
238
|
+
let index = startIndex;
|
|
239
|
+
while (index < source.length && /\s/.test(source[index])) {
|
|
240
|
+
index++;
|
|
241
|
+
}
|
|
242
|
+
if (source[index] === ';') {
|
|
243
|
+
return index + 1;
|
|
244
|
+
}
|
|
245
|
+
return startIndex;
|
|
246
|
+
}
|
|
247
|
+
function stripQuotes(value) {
|
|
248
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
249
|
+
return value.slice(1, -1);
|
|
250
|
+
}
|
|
251
|
+
return value;
|
|
252
|
+
}
|
|
253
|
+
function splitTopLevel(source) {
|
|
254
|
+
const parts = [];
|
|
255
|
+
let start = 0;
|
|
256
|
+
let parenDepth = 0;
|
|
257
|
+
let bracketDepth = 0;
|
|
258
|
+
let braceDepth = 0;
|
|
259
|
+
let quote = null;
|
|
260
|
+
let escape = false;
|
|
261
|
+
let inLineComment = false;
|
|
262
|
+
let inBlockComment = false;
|
|
263
|
+
for (let index = 0; index < source.length; index++) {
|
|
264
|
+
const char = source[index];
|
|
265
|
+
const next = source[index + 1];
|
|
266
|
+
if (inLineComment) {
|
|
267
|
+
if (char === '\n') {
|
|
268
|
+
inLineComment = false;
|
|
269
|
+
}
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (inBlockComment) {
|
|
273
|
+
if (char === '*' && next === '/') {
|
|
274
|
+
inBlockComment = false;
|
|
275
|
+
index++;
|
|
276
|
+
}
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (quote) {
|
|
280
|
+
if (escape) {
|
|
281
|
+
escape = false;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (char === '\\') {
|
|
285
|
+
escape = true;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (char === quote) {
|
|
289
|
+
quote = null;
|
|
290
|
+
}
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (char === '/' && next === '/') {
|
|
294
|
+
inLineComment = true;
|
|
295
|
+
index++;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (char === '/' && next === '*') {
|
|
299
|
+
inBlockComment = true;
|
|
300
|
+
index++;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
304
|
+
quote = char;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (char === '(') {
|
|
308
|
+
parenDepth++;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (char === ')') {
|
|
312
|
+
parenDepth--;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (char === '[') {
|
|
316
|
+
bracketDepth++;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (char === ']') {
|
|
320
|
+
bracketDepth--;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (char === '{') {
|
|
324
|
+
braceDepth++;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (char === '}') {
|
|
328
|
+
braceDepth--;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (char === ',' && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
|
|
332
|
+
const part = source.slice(start, index).trim();
|
|
333
|
+
if (part) {
|
|
334
|
+
parts.push(part);
|
|
335
|
+
}
|
|
336
|
+
start = index + 1;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const tail = source.slice(start).trim();
|
|
340
|
+
if (tail) {
|
|
341
|
+
parts.push(tail);
|
|
342
|
+
}
|
|
343
|
+
return parts;
|
|
344
|
+
}
|
|
345
|
+
function findMatchingDelimiter(source, openIndex, openChar, closeChar) {
|
|
346
|
+
if (openIndex < 0 || source[openIndex] !== openChar) {
|
|
347
|
+
return -1;
|
|
348
|
+
}
|
|
349
|
+
let depth = 0;
|
|
350
|
+
let quote = null;
|
|
351
|
+
let escape = false;
|
|
352
|
+
let inLineComment = false;
|
|
353
|
+
let inBlockComment = false;
|
|
354
|
+
for (let index = openIndex; index < source.length; index++) {
|
|
355
|
+
const char = source[index];
|
|
356
|
+
const next = source[index + 1];
|
|
357
|
+
if (inLineComment) {
|
|
358
|
+
if (char === '\n') {
|
|
359
|
+
inLineComment = false;
|
|
360
|
+
}
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (inBlockComment) {
|
|
364
|
+
if (char === '*' && next === '/') {
|
|
365
|
+
inBlockComment = false;
|
|
366
|
+
index++;
|
|
367
|
+
}
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (quote) {
|
|
371
|
+
if (escape) {
|
|
372
|
+
escape = false;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (char === '\\') {
|
|
376
|
+
escape = true;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (char === quote) {
|
|
380
|
+
quote = null;
|
|
381
|
+
}
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (char === '/' && next === '/') {
|
|
385
|
+
inLineComment = true;
|
|
386
|
+
index++;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (char === '/' && next === '*') {
|
|
390
|
+
inBlockComment = true;
|
|
391
|
+
index++;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
395
|
+
quote = char;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (char === openChar) {
|
|
399
|
+
depth++;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (char === closeChar) {
|
|
403
|
+
depth--;
|
|
404
|
+
if (depth === 0) {
|
|
405
|
+
return index;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return -1;
|
|
410
|
+
}
|
|
411
|
+
function escapeRegex(value) {
|
|
412
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
413
|
+
}
|
|
414
|
+
//# sourceMappingURL=synthesize-injectable-factories.js.map
|