@nstudio/nativescript-compiler 9.2.0-alpha.10 → 9.2.0-alpha.11

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.
Files changed (135) hide show
  1. package/dist/api/ir.js +7 -1
  2. package/dist/driver/cli.js +2 -0
  3. package/dist/driver/compile.js +22 -10
  4. package/dist/driver/unimplemented.js +15 -0
  5. package/dist/kotlin/access.js +22 -4
  6. package/dist/kotlin/arguments.js +5 -0
  7. package/dist/kotlin/builtins.js +0 -4
  8. package/dist/kotlin/calls.js +6 -2
  9. package/dist/kotlin/class-methods.js +9 -3
  10. package/dist/kotlin/components.js +13 -8
  11. package/dist/kotlin/core-api.js +2 -13
  12. package/dist/kotlin/declarations.js +2 -0
  13. package/dist/kotlin/expression-statements.js +5 -4
  14. package/dist/kotlin/functions.js +13 -4
  15. package/dist/kotlin/global-calls.js +11 -0
  16. package/dist/kotlin/literals.js +51 -5
  17. package/dist/kotlin/names.js +2 -2
  18. package/dist/kotlin/native/api.js +9 -1
  19. package/dist/kotlin/native/subclasses.js +4 -3
  20. package/dist/kotlin/native/types.js +8 -5
  21. package/dist/kotlin/operators.js +4 -1
  22. package/dist/kotlin/prototype-calls.js +5 -0
  23. package/dist/kotlin/render.js +62 -0
  24. package/dist/kotlin/statements.js +9 -0
  25. package/dist/kotlin/static-calls.js +4 -3
  26. package/dist/kotlin/types.js +6 -6
  27. package/dist/plugins/native-android.js +7 -3
  28. package/dist/plugins/native-ios.js +2 -0
  29. package/dist/plugins/source.js +73 -23
  30. package/dist/program/app-modules.js +91 -16
  31. package/dist/program/app-paths.js +80 -12
  32. package/dist/program/class-mixins.js +463 -0
  33. package/dist/program/core-facts.js +7 -0
  34. package/dist/program/glob.js +274 -0
  35. package/dist/program/platform.js +32 -4
  36. package/dist/program/program.js +212 -20
  37. package/dist/program/source-lines.js +4 -1
  38. package/dist/program/vite-plugins.js +144 -0
  39. package/dist/semantics/apis/globals.js +2 -2
  40. package/dist/semantics/apis/object.js +1 -0
  41. package/dist/semantics/apis/statics.js +6 -0
  42. package/dist/semantics/ast.js +20 -2
  43. package/dist/semantics/classes.js +36 -1
  44. package/dist/semantics/globals.js +3 -0
  45. package/dist/semantics/lang.js +13 -1
  46. package/dist/semantics/nullish.js +29 -11
  47. package/dist/semantics/refuse-receivers.js +3 -3
  48. package/dist/semantics/refuse-scope.js +2 -7
  49. package/dist/semantics/runtime.js +1 -0
  50. package/dist/semantics/states/value-states.js +1 -1
  51. package/dist/semantics/throws.js +1 -0
  52. package/dist/semantics/translator-methods.js +1 -1
  53. package/dist/semantics/types.js +21 -1
  54. package/dist/swift/access.js +25 -10
  55. package/dist/swift/arguments.js +10 -2
  56. package/dist/swift/assignment.js +12 -1
  57. package/dist/swift/builtins.js +0 -4
  58. package/dist/swift/calls.js +6 -2
  59. package/dist/swift/class-methods.js +3 -3
  60. package/dist/swift/components.js +28 -8
  61. package/dist/swift/construction.js +4 -0
  62. package/dist/swift/core-api.js +9 -12
  63. package/dist/swift/functions.js +13 -2
  64. package/dist/swift/generics.js +5 -1
  65. package/dist/swift/global-calls.js +2 -0
  66. package/dist/swift/literals.js +53 -6
  67. package/dist/swift/names.js +1 -1
  68. package/dist/swift/native/sdk-tables.js +52 -4
  69. package/dist/swift/native/sdk.js +9 -1
  70. package/dist/swift/operators.js +4 -1
  71. package/dist/swift/parameters.js +5 -2
  72. package/dist/swift/placement.js +42 -1
  73. package/dist/swift/prototype-calls.js +17 -2
  74. package/dist/swift/render.js +64 -0
  75. package/dist/swift/results.js +1 -1
  76. package/dist/swift/statements.js +9 -0
  77. package/dist/swift/static-calls.js +8 -3
  78. package/dist/swift/types.js +9 -9
  79. package/dist/targets/android/build.js +13 -9
  80. package/dist/targets/ios/build.js +11 -10
  81. package/dist/targets/ios/dependencies.js +12 -0
  82. package/dist/targets/resources.js +15 -1
  83. package/dist/template/plan.js +105 -8
  84. package/dist/types/adapter-api.d.ts +13 -0
  85. package/dist/types/ir.d.ts +47 -0
  86. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +102 -7485
  87. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -3
  88. package/kit-android/generated/source-lines.json +1 -1
  89. package/kit-android/src/fromcore/kotlin/org/nativescript/kit/CoreBridge.kt +67 -1
  90. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +26 -0
  91. package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +4 -4
  92. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +24 -146
  93. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -281
  94. package/kit-apple/Sources/NativeScriptKit/Core/{Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_91b5f3.swift → Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_fa18e1.swift} +28 -103
  95. package/kit-apple/Sources/NativeScriptKit/Core/__Namespace.Utils.swift +17 -15
  96. package/kit-apple/Sources/NativeScriptKit/Core/application-settings.index.ios.swift +8 -8
  97. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +4 -4
  98. package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +7 -7
  99. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +2 -1
  100. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +1 -1
  101. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +34 -244
  102. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +1 -2
  103. package/kit-apple/Sources/NativeScriptKit/Core/ui.action-bar.index.ios.swift +3 -3
  104. package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +4 -4
  105. package/kit-apple/Sources/NativeScriptKit/Core/ui.content-view.index.swift +8 -8
  106. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +4 -4
  107. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
  108. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -3
  109. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-helper.view-helper-common.swift +7 -7
  110. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +4 -4
  111. package/kit-apple/Sources/NativeScriptKit/Core/ui.html-view.index.ios.swift +4 -4
  112. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.image-common.swift +2 -2
  113. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +4 -4
  114. package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +4 -4
  115. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.absolute-layout.index.ios.swift +4 -4
  116. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.dock-layout.index.ios.swift +4 -4
  117. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +3 -3
  118. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.grid-layout.index.ios.swift +4 -4
  119. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.stack-layout.index.ios.swift +4 -4
  120. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.wrap-layout.index.ios.swift +4 -4
  121. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +3 -3
  122. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +4 -4
  123. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +4 -4
  124. package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +4 -4
  125. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +4 -4
  126. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +1 -1
  127. package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +4 -4
  128. package/kit-apple/Sources/NativeScriptKit/Core/utils.common.swift +9 -9
  129. package/kit-apple/Sources/NativeScriptKit/Core/utils.layout-helper.index.ios.swift +10 -10
  130. package/kit-apple/Sources/NativeScriptKit/CoreBridge.swift +67 -1
  131. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +4 -0
  132. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +25 -0
  133. package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +6 -0
  134. package/package.json +1 -1
  135. package/kit-apple/Sources/NativeScriptKit/Core/Object_toString_charAt_charCodeAt_concat_indexOf_lastIndexOf_and_44_more_fc25df.swift +0 -481
@@ -0,0 +1,274 @@
1
+ // Static Vite `import.meta.glob(...)` / `import.meta.globEager(...)` expansion for ahead-of-time compilation.
2
+ import { existsSync, readdirSync, statSync } from 'node:fs';
3
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
4
+ import ts from 'typescript';
5
+ /** Converts a Vite glob pattern (supporting `**`, `*`, `?`, `{a,b}`) to a RegExp matching POSIX relative paths. */
6
+ function globToRegExp(pattern) {
7
+ let re = '^';
8
+ for (let i = 0; i < pattern.length; i++) {
9
+ const ch = pattern[i];
10
+ if (ch === '*') {
11
+ if (pattern[i + 1] === '*') {
12
+ if (pattern[i + 2] === '/') {
13
+ re += '(?:.*/)?';
14
+ i += 2;
15
+ }
16
+ else {
17
+ re += '.*';
18
+ i++;
19
+ }
20
+ }
21
+ else {
22
+ re += '[^/]*';
23
+ }
24
+ }
25
+ else if (ch === '?') {
26
+ re += '[^/]';
27
+ }
28
+ else if (ch === '{') {
29
+ const end = pattern.indexOf('}', i + 1);
30
+ if (end > i) {
31
+ const alts = pattern.slice(i + 1, end).split(',').map((a) => a.replace(/[.+^$|()[\]\\]/g, '\\$&'));
32
+ re += `(?:${alts.join('|')})`;
33
+ i = end;
34
+ }
35
+ else {
36
+ re += '\\{';
37
+ }
38
+ }
39
+ else if (/[.+^$|()[\]\\]/.test(ch)) {
40
+ re += `\\${ch}`;
41
+ }
42
+ else {
43
+ re += ch;
44
+ }
45
+ }
46
+ return new RegExp(re + '$');
47
+ }
48
+ /** Recursively walks files under `dir` (skipping `node_modules` and `.git`), returning POSIX relative paths. */
49
+ function walkFiles(dir, prefix = '') {
50
+ if (!existsSync(dir))
51
+ return [];
52
+ const out = [];
53
+ for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
54
+ if (entry.name === 'node_modules' || entry.name === '.git')
55
+ continue;
56
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
57
+ if (entry.isDirectory())
58
+ out.push(...walkFiles(join(dir, entry.name), rel));
59
+ else
60
+ out.push(rel);
61
+ }
62
+ return out;
63
+ }
64
+ /** Finds nearest directory containing package.json above `from`, falling back to `dirname(from)`. */
65
+ function projectRootOf(from) {
66
+ for (let dir = dirname(from);; dir = dirname(dir)) {
67
+ if (existsSync(join(dir, 'package.json')))
68
+ return dir;
69
+ if (dirname(dir) === dir)
70
+ return dirname(from);
71
+ }
72
+ }
73
+ /** Parses static `import.meta.glob(...)` / `import.meta.globEager(...)` calls in `sf`. */
74
+ function findGlobCalls(sf) {
75
+ const specs = [];
76
+ const visit = (node) => {
77
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
78
+ const method = node.expression.name.text;
79
+ const target = node.expression.expression;
80
+ if ((method === 'glob' || method === 'globEager') && ts.isMetaProperty(target) && target.keywordToken === ts.SyntaxKind.ImportKeyword && target.name.text === 'meta') {
81
+ const parsed = parseGlobCall(node, method === 'globEager');
82
+ if (parsed)
83
+ specs.push(parsed);
84
+ }
85
+ }
86
+ ts.forEachChild(node, visit);
87
+ };
88
+ visit(sf);
89
+ return specs;
90
+ }
91
+ function parseGlobCall(call, defaultEager) {
92
+ const first = call.arguments[0];
93
+ if (!first)
94
+ return null;
95
+ const patterns = [];
96
+ if (ts.isStringLiteralLike(first)) {
97
+ patterns.push(first.text);
98
+ }
99
+ else if (ts.isArrayLiteralExpression(first)) {
100
+ for (const el of first.elements) {
101
+ if (!ts.isStringLiteralLike(el))
102
+ return null;
103
+ patterns.push(el.text);
104
+ }
105
+ }
106
+ else {
107
+ return null;
108
+ }
109
+ let eager = defaultEager;
110
+ let importName = null;
111
+ let query = '';
112
+ const opts = call.arguments[1];
113
+ if (opts && ts.isObjectLiteralExpression(opts)) {
114
+ for (const p of opts.properties) {
115
+ if (!ts.isPropertyAssignment(p))
116
+ continue;
117
+ const key = ts.isIdentifier(p.name) || ts.isStringLiteralLike(p.name) ? p.name.text : null;
118
+ const v = p.initializer;
119
+ if (key === 'eager')
120
+ eager = v.kind === ts.SyntaxKind.TrueKeyword;
121
+ else if (key === 'import' && ts.isStringLiteralLike(v))
122
+ importName = v.text;
123
+ else if (key === 'query') {
124
+ if (ts.isStringLiteralLike(v))
125
+ query = v.text.startsWith('?') ? v.text : `?${v.text}`;
126
+ else if (ts.isObjectLiteralExpression(v)) {
127
+ const qs = v.properties
128
+ .filter(ts.isPropertyAssignment)
129
+ .map((q) => {
130
+ const qk = ts.isIdentifier(q.name) || ts.isStringLiteralLike(q.name) ? q.name.text : '';
131
+ const qv = ts.isStringLiteralLike(q.initializer) ? q.initializer.text : q.initializer.getText();
132
+ return qv === 'true' || qv === '' ? qk : `${qk}=${qv}`;
133
+ })
134
+ .filter(Boolean)
135
+ .join('&');
136
+ if (qs)
137
+ query = `?${qs}`;
138
+ }
139
+ }
140
+ else if (key === 'as' && ts.isStringLiteralLike(v)) {
141
+ if (v.text === 'raw') {
142
+ query = '?raw';
143
+ importName ??= 'default';
144
+ }
145
+ else if (v.text === 'url') {
146
+ query = '?url';
147
+ importName ??= 'default';
148
+ }
149
+ }
150
+ }
151
+ }
152
+ const typeArg = call.typeArguments?.[0]?.getText() ?? null;
153
+ return { call, patterns, eager, importName, query, typeArg };
154
+ }
155
+ /** Resolves a list of Vite glob patterns (supporting `!` exclusions and `/` root-relative patterns) to sorted matches. */
156
+ function resolvePatterns(patterns, filePath, appRoot) {
157
+ const fileDir = dirname(filePath);
158
+ const rootDir = appRoot ?? projectRootOf(filePath);
159
+ const matched = new Map();
160
+ const expandOne = (raw) => {
161
+ const isRoot = raw.startsWith('/');
162
+ let cwd = isRoot ? rootDir : fileDir;
163
+ let normalized = isRoot ? raw.slice(1) : raw.replace(/^\.\//, '');
164
+ let keyPrefix = isRoot ? '/' : './';
165
+ while (normalized.startsWith('../')) {
166
+ cwd = dirname(cwd);
167
+ normalized = normalized.slice(3);
168
+ keyPrefix = isRoot ? `${keyPrefix}../` : keyPrefix === './' ? '../' : `${keyPrefix}../`;
169
+ }
170
+ // Narrow walk root to any static directory prefix before the first glob metacharacter.
171
+ const parts = normalized.split('/');
172
+ const staticParts = [];
173
+ while (parts.length > 1 && !/[*?{[\]]/.test(parts[0]))
174
+ staticParts.push(parts.shift());
175
+ let walkDir = staticParts.length ? resolve(cwd, ...staticParts) : cwd;
176
+ if (isRoot && !existsSync(walkDir)) {
177
+ const fallbackRoot = projectRootOf(filePath);
178
+ const alt = staticParts.length ? resolve(fallbackRoot, ...staticParts) : fallbackRoot;
179
+ if (existsSync(alt))
180
+ walkDir = alt;
181
+ }
182
+ const matcher = globToRegExp(parts.join('/'));
183
+ const out = [];
184
+ for (const rel of walkFiles(walkDir)) {
185
+ if (!matcher.test(rel))
186
+ continue;
187
+ const abs = resolve(walkDir, rel);
188
+ if (!existsSync(abs) || statSync(abs).isDirectory())
189
+ continue;
190
+ const fullRel = staticParts.length ? `${staticParts.join('/')}/${rel}` : rel;
191
+ out.push({ key: `${keyPrefix}${fullRel}`, abs });
192
+ }
193
+ return out;
194
+ };
195
+ for (const p of patterns) {
196
+ if (p.startsWith('!')) {
197
+ for (const ex of expandOne(p.slice(1)))
198
+ matched.delete(ex.abs);
199
+ }
200
+ else {
201
+ for (const inc of expandOne(p))
202
+ if (!matched.has(inc.abs))
203
+ matched.set(inc.abs, inc);
204
+ }
205
+ }
206
+ return [...matched.values()]
207
+ .sort((a, b) => a.key.localeCompare(b.key))
208
+ .map(({ key, abs }) => {
209
+ let spec = relative(fileDir, abs).split('\\').join('/');
210
+ if (!spec.startsWith('.') && !isAbsolute(spec))
211
+ spec = `./${spec}`;
212
+ return { key, abs, specifier: spec };
213
+ });
214
+ }
215
+ /**
216
+ * Expands static Vite `import.meta.glob(...)` / `import.meta.globEager(...)` calls in `code` into hoisted static
217
+ * ES imports plus a plain object literal mapping matched keys to modules (eager) or `() => Promise.resolve(mod)` (lazy).
218
+ */
219
+ export function expandImportMetaGlob(code, filePath, appRoot = null) {
220
+ if (!code.includes('import.meta.glob'))
221
+ return code;
222
+ const sf = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
223
+ const specs = findGlobCalls(sf);
224
+ if (!specs.length)
225
+ return code;
226
+ const imports = [];
227
+ const edits = [];
228
+ let counter = 0;
229
+ for (const spec of specs) {
230
+ const matches = resolvePatterns(spec.patterns, filePath, appRoot);
231
+ const entries = [];
232
+ for (const m of matches) {
233
+ const id = `__nsGlob_${counter++}`;
234
+ const importSpec = m.specifier + spec.query;
235
+ let val;
236
+ if (spec.importName === 'default' || (spec.query === '?raw' && !spec.importName)) {
237
+ imports.push(`import ${id} from ${JSON.stringify(importSpec)};`);
238
+ val = id;
239
+ }
240
+ else if (spec.importName && spec.importName !== '*') {
241
+ imports.push(`import { ${spec.importName} as ${id} } from ${JSON.stringify(importSpec)};`);
242
+ val = id;
243
+ }
244
+ else {
245
+ imports.push(`import * as ${id} from ${JSON.stringify(importSpec)};`);
246
+ val = `(${id} as any)`;
247
+ }
248
+ entries.push(`${JSON.stringify(m.key)}: ${spec.eager ? val : `() => Promise.resolve(${val})`}`);
249
+ }
250
+ const obj = `{ ${entries.join(', ')} }`;
251
+ const valType = spec.typeArg ?? (spec.query === '?raw' && !spec.importName ? 'string' : 'any');
252
+ const entryType = spec.eager ? valType : `() => Promise<${valType}>`;
253
+ const wrapped = `((__m: Record<string, ${entryType}>): Record<string, ${entryType}> => __m)(${obj})`;
254
+ edits.push({ start: spec.call.getStart(sf), end: spec.call.getEnd(), text: wrapped });
255
+ }
256
+ let out = code;
257
+ for (const e of edits.sort((a, b) => b.start - a.start))
258
+ out = out.slice(0, e.start) + e.text + out.slice(e.end);
259
+ return imports.length ? `${out}\n${imports.join('\n')}\n` : out;
260
+ }
261
+ /** Returns absolute file paths matched by static `import.meta.glob(...)` calls in `code` (for app reachability). */
262
+ export function globMatchedFiles(code, filePath, appRoot = null) {
263
+ if (!code.includes('import.meta.glob'))
264
+ return [];
265
+ const sf = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
266
+ const out = [];
267
+ for (const spec of findGlobCalls(sf)) {
268
+ if (spec.query === '?raw' || spec.query === '?url')
269
+ continue;
270
+ for (const m of resolvePatterns(spec.patterns, filePath, appRoot))
271
+ out.push(m.abs);
272
+ }
273
+ return out;
274
+ }
@@ -11,7 +11,7 @@ import { dirname, join, matchesGlob, posix } from 'node:path';
11
11
  export function foldPlatform(text, fileName, platform, modulesDir, defines = []) {
12
12
  text = applyDefines(text, fileName, defines);
13
13
  // A defined string compared with a literal (`'nativescript' === 'css-tree'`) folds as well.
14
- if (!/\b(isIOS|isAndroid|__IOS__|__ANDROID__|__APPLE__|__VISIONOS__|__DEV__)\b|\bApplication\.(android|ios)\b|import\.meta\.hot|(['"])[^'"\n]*\2\)?\s*[!=]==?\s*\(?['"]/.test(text))
14
+ if (!/\b(isIOS|isAndroid|__IOS__|__ANDROID__|__APPLE__|__VISIONOS__|__CATALYST__|__WINDOWS__|__LINUX__|__DEV__)\b|\bApplication\.(android|ios)\b|import\.meta\.hot|(['"])[^'"\n]*\2\)?\s*[!=]==?\s*\(?['"]/.test(text))
15
15
  return text;
16
16
  // Core's `Application.android` and `Application.ios`, the platform's object or undefined: where the file imports core's Application.
17
17
  const application = /import\s*\{[^}]*\bApplication\b[^}]*\}\s*from\s*['"]@nativescript\/core['"]/.test(text);
@@ -23,6 +23,9 @@ export function foldPlatform(text, fileName, platform, modulesDir, defines = [])
23
23
  isAndroid: platform === 'android',
24
24
  __ANDROID__: platform === 'android',
25
25
  __VISIONOS__: false,
26
+ __CATALYST__: false,
27
+ __WINDOWS__: false,
28
+ __LINUX__: false,
26
29
  __DEV__: false,
27
30
  };
28
31
  const kind = fileName.endsWith('x') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
@@ -84,8 +87,33 @@ function dropUnreferenced(text, fileName, kind, modulesDir) {
84
87
  const d = st.declarationList.declarations[0];
85
88
  return ts.isIdentifier(d.name) && (!d.initializer || inert(d.initializer)) && unused(d.name, st);
86
89
  });
87
- if (!dead)
88
- return text;
90
+ if (!dead) {
91
+ // Also drop individual unused non-type named specifiers from a live import (e.g. an Android-only function
92
+ // guarded by `if (__ANDROID__)` that shares an import declaration with cross-platform symbols).
93
+ let specEdit = null;
94
+ for (const st of sf.statements) {
95
+ if (!ts.isImportDeclaration(st) || !st.importClause || st.importClause.isTypeOnly)
96
+ continue;
97
+ const nb = st.importClause.namedBindings;
98
+ if (!nb || !ts.isNamedImports(nb) || nb.elements.length <= 1)
99
+ continue;
100
+ const usedCount = nb.elements.filter((e) => e.isTypeOnly || !unused(e.name, st)).length;
101
+ if (usedCount === 0 || usedCount === nb.elements.length)
102
+ continue;
103
+ const deadEl = nb.elements.find((e) => !e.isTypeOnly && unused(e.name, st));
104
+ if (deadEl) {
105
+ const idx = nb.elements.indexOf(deadEl);
106
+ const start = idx > 0 ? nb.elements[idx - 1].getEnd() : deadEl.getStart(sf);
107
+ const end = idx > 0 ? deadEl.getEnd() : nb.elements[idx + 1].getStart(sf);
108
+ specEdit = { start, end };
109
+ break;
110
+ }
111
+ }
112
+ if (!specEdit)
113
+ return text;
114
+ text = apply(text, { span: [specEdit.start, specEdit.end], keep: null });
115
+ continue;
116
+ }
89
117
  text = apply(text, { span: [dead.getStart(sf), dead.getEnd()], keep: null });
90
118
  }
91
119
  }
@@ -348,7 +376,7 @@ function declaredAround(id) {
348
376
  if (!(ts.isBlock(scope) || ts.isSourceFile(scope) || ts.isModuleBlock(scope)))
349
377
  continue;
350
378
  for (const st of scope.statements) {
351
- if (ts.isVariableStatement(st) && st.declarationList.declarations.some((d) => binds(d.name)))
379
+ if (ts.isVariableStatement(st) && !st.modifiers?.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword) && st.declarationList.declarations.some((d) => binds(d.name)))
352
380
  return true;
353
381
  if ((ts.isFunctionDeclaration(st) || ts.isClassDeclaration(st)) && st.name?.text === name)
354
382
  return true;