@nstudio/nativescript-compiler 9.2.0-alpha.12 → 9.2.0-alpha.13

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.
@@ -1,7 +1,7 @@
1
1
  // A call's arguments as Kotlin: the slot each parameter takes, spreads, rest and packed arguments, and function values passed.
2
2
  import ts from 'typescript';
3
3
  import { branch, functionTypeParts, isCompared, isFunctionType, isNullable, isThisParameter, nullishType, optionalType, scriptPrimitive, splitTopLevel, RT, adaptOf } from "./syntax.js";
4
- import { argumentSlot, place, storeSlot } from "../semantics/placement.js";
4
+ import { argumentSlot, place } from "../semantics/placement.js";
5
5
  import { isLibDeclaration, implementationOf } from "../semantics/ast.js";
6
6
  import { keepsIdentity } from "../semantics/conversion.js";
7
7
  import { constructorOf } from "../semantics/classes.js";
@@ -356,25 +356,6 @@ export const argumentsMethods = {
356
356
  return `, *${this.packed(args, 'JSArray<Any?>', slot)}.storage.toTypedArray()`;
357
357
  return args.map((a) => `, ${place(this.placement, a, slot(a))}`).join('');
358
358
  },
359
- /** An argument of `call` with no declared parameter's cell, as `element`: a built-in's (`Math.max`) or one an untyped callee takes. */
360
- restArgument(call, a, element) {
361
- return place(this.placement, a, this.restSlot(call, element)(a));
362
- },
363
- /** The slot of each value `at` stores as a container's element (`elementStoreOf`), held as `element`. */
364
- elementSlot(at, element) {
365
- return (a) => storeSlot(this.placement, element, at, a);
366
- },
367
- /** A value `call` stores as an element of its receiver (`push`'s, `add`'s), held as `element`. */
368
- elementArgument(call, a, element) {
369
- return place(this.placement, a, this.elementSlot(call, element)(a));
370
- },
371
- /** The slot of each argument `call` gives a rest parameter (`decl`), or an untyped callee: one `element` each, placed with no declared parameter's cell. */
372
- restSlot(call, element, decl) {
373
- return (a) => {
374
- const k = call.arguments?.indexOf(a) ?? -1;
375
- return argumentSlot(this.placement, element, decl, { call, k, a: k < 0 ? undefined : a }, { rest: true });
376
- };
377
- },
378
359
  /** Arguments (spreads included) as one `JSArray` of `arrayType`; `slot` places each element where they are a call's. */
379
360
  packed(items, arrayType, slot) {
380
361
  const el = arrayType.replace(/^JSArray<(.*)>$/, '$1');
@@ -4,7 +4,6 @@ import { BUILTIN_CLASSES } from "./library.js";
4
4
  import { ERRORS } from "../semantics/globals.js";
5
5
  import { branch, ident, isFunctionType, isNullable, optionalType, RT } from "./syntax.js";
6
6
  import { asOperation, assignedValues } from "../semantics/lang.js";
7
- import { located } from "../semantics/refusals.js";
8
7
  import { notedField } from "../semantics/shapes.js";
9
8
  import { isKit, isUntyped, spelledType } from "../semantics/types.js";
10
9
  import { assertedFrom, emptyComparison, scriptComparison } from "../semantics/placement.js";
@@ -438,15 +437,4 @@ export const operatorsMethods = {
438
437
  signalAlias(m) {
439
438
  return !this.library && !!m.initializer && (ts.isIdentifier(m.initializer) || ts.isPropertyAccessExpression(m.initializer)) && this.framework.signalKind(this.symbolName(m.initializer)) === 'computed';
440
439
  },
441
- /** An error the translation of `n` failed with, at `n` unless it says where already (semantics/refusals.ts). */
442
- located(e, n) {
443
- return located(e, n, (at, what, id) => this.error(at, what, id));
444
- },
445
- error(n, what, id = 'unhandled') {
446
- if (!n)
447
- return this.config.refusals.refusal(`${what} is not supported in a release build yet`, id);
448
- const sf = n.getSourceFile();
449
- const { line, character } = sf.getLineAndCharacterOfPosition(n.getStart());
450
- return this.config.refusals.refusedAt(sf.fileName, line + 1, character + 1, what, n.getText().slice(0, 80), id);
451
- },
452
440
  };
@@ -1,7 +1,7 @@
1
1
  // Statements as Kotlin: declarations, bindings, patterns, loops and returns.
2
2
  import ts from 'typescript';
3
3
  import { atLossSite, HELD_LOSS } from "../semantics/losses.js";
4
- import { place, resultSlot, returnCell, storeSlot } from "../semantics/placement.js";
4
+ import { place, returnCell } from "../semantics/placement.js";
5
5
  import { TYPED_ARRAYS } from "../semantics/globals.js";
6
6
  import { assignsTo, breaksOut, ident, RT } from "./syntax.js";
7
7
  import { containsJump } from "../semantics/ast.js";
@@ -374,21 +374,6 @@ export const statementsMethods = {
374
374
  tryPrefix(_e) {
375
375
  return '';
376
376
  },
377
- /** An expression where Kotlin needs a value of `target`. */
378
- coerce(e, target) {
379
- return place(this.placement, e, target);
380
- },
381
- /** `e` stored by `at` (a declaration, an object literal's field, an assignment's target) where Kotlin holds `target`; `checks` as `storeSlot` has it. */
382
- stored(e, at, target, checks = true) {
383
- return place(this.placement, e, this.storeSlot(e, target, at, checks));
384
- },
385
- storeSlot(e, target, at, checks = true) {
386
- return storeSlot(this.placement, target, at, e, checks);
387
- },
388
- /** The result slot of the function being translated, where `at` (a `return`, an expression body) gives its value. */
389
- resultSlot(at) {
390
- return resultSlot(this.asyncCtx ? this.asyncCtx.result : this.returnType, ts.findAncestor(at.parent, ts.isFunctionLike), !!this.asyncCtx);
391
- },
392
377
  /** A `return` statement's cell, as Kotlin writes it. */
393
378
  returned(cell, slot) {
394
379
  const i = this.indent, a = this.asyncCtx;
@@ -819,12 +819,6 @@ export class Translator {
819
819
  heldSignalVisits = new Set();
820
820
  untypedJavaFieldSet = null;
821
821
  thisValueSets = null;
822
- /** A declared limit of release builds: refused with why and how to write it instead. */
823
- limit(n, id, what) {
824
- const sf = n.getSourceFile();
825
- const { line, character } = sf.getLineAndCharacterOfPosition(n.getStart());
826
- return this.config.refusals.limitAt(sf.fileName, line + 1, character + 1, what, n.getText().slice(0, 80), id);
827
- }
828
822
  }
829
823
  for (const methods of mixins)
830
824
  Object.defineProperties(Translator.prototype, Object.getOwnPropertyDescriptors(methods));
@@ -409,10 +409,36 @@ export function parseIncludeGradle(text) {
409
409
  }
410
410
  if (blockOf('packagingOptions') || blockOf('packaging')) {
411
411
  i++;
412
+ const addPackagingItem = (p) => {
413
+ if (is(p, 'id', 'exclude') || is(p, 'id', 'pickFirst')) {
414
+ const list = p.text === 'exclude' ? out.packaging.excludes : out.packaging.pickFirsts;
415
+ i++;
416
+ list.push(stringArgument());
417
+ return;
418
+ }
419
+ if (is(p, 'id', 'excludes') || is(p, 'id', 'pickFirsts')) {
420
+ const list = p.text === 'excludes' ? out.packaging.excludes : out.packaging.pickFirsts;
421
+ i++;
422
+ if (is(peek(), 'punct', '+') && is(peek(1), 'punct', '=')) {
423
+ i += 2;
424
+ list.push(stringArgument());
425
+ return;
426
+ }
427
+ if (is(peek(), 'punct', '.') && is(peek(1), 'id', 'add')) {
428
+ i += 2;
429
+ list.push(stringArgument());
430
+ return;
431
+ }
432
+ }
433
+ unsupported(p);
434
+ };
412
435
  statements((p) => {
413
- const list = is(p, 'id', 'exclude') ? out.packaging.excludes : is(p, 'id', 'pickFirst') ? out.packaging.pickFirsts : unsupported(p);
414
- i++;
415
- list.push(stringArgument());
436
+ if (blockOf('resources') || blockOf('jniLibs')) {
437
+ i++;
438
+ statements(addPackagingItem);
439
+ return;
440
+ }
441
+ addPackagingItem(p);
416
442
  });
417
443
  return;
418
444
  }
@@ -443,6 +469,86 @@ export function parseIncludeGradle(text) {
443
469
  });
444
470
  return;
445
471
  }
472
+ if (blockOf('kotlinOptions')) {
473
+ i++;
474
+ statements((k) => {
475
+ if (!is(k, 'id', 'jvmTarget') && !is(k, 'id', 'freeCompilerArgs'))
476
+ unsupported(k);
477
+ i++;
478
+ if (is(peek(), 'punct', '=') || (is(peek(), 'punct', '+') && is(peek(1), 'punct', '='))) {
479
+ i += is(peek(), 'punct', '+') ? 2 : 1;
480
+ }
481
+ if (is(peek(), 'punct', '[')) {
482
+ i++;
483
+ while (!is(peek(), 'punct', ']') && !is(peek(), 'end'))
484
+ i++;
485
+ expect('punct', ']');
486
+ return;
487
+ }
488
+ if (is(peek(), 'str') || is(peek(), 'num')) {
489
+ i++;
490
+ return;
491
+ }
492
+ unsupported(peek());
493
+ });
494
+ return;
495
+ }
496
+ if (blockOf('buildFeatures')) {
497
+ i++;
498
+ statements((b) => {
499
+ if (!is(b, 'id') || !['viewBinding', 'buildConfig', 'dataBinding', 'compose', 'aidl', 'resValues'].includes(b.text))
500
+ unsupported(b);
501
+ i++;
502
+ if (is(peek(), 'punct', '='))
503
+ i++;
504
+ if (!is(peek(), 'id', 'true') && !is(peek(), 'id', 'false'))
505
+ unsupported(peek());
506
+ i++;
507
+ });
508
+ return;
509
+ }
510
+ if (blockOf('aaptOptions') || blockOf('androidResources')) {
511
+ i++;
512
+ statements((a) => {
513
+ if (!is(a, 'id', 'noCompress'))
514
+ unsupported(a);
515
+ i++;
516
+ if (is(peek(), 'punct', '='))
517
+ i++;
518
+ if (is(peek(), 'punct', '[')) {
519
+ i++;
520
+ while (!is(peek(), 'punct', ']') && !is(peek(), 'end'))
521
+ i++;
522
+ expect('punct', ']');
523
+ return;
524
+ }
525
+ stringArgument();
526
+ while (is(peek(), 'punct', ',')) {
527
+ i++;
528
+ stringArgument();
529
+ }
530
+ });
531
+ return;
532
+ }
533
+ if (is(s, 'id', 'flavorDimensions')) {
534
+ i++;
535
+ stringArgument();
536
+ while (is(peek(), 'punct', ',')) {
537
+ i++;
538
+ stringArgument();
539
+ }
540
+ return;
541
+ }
542
+ if (is(s, 'id', 'compileSdk') || is(s, 'id', 'compileSdkVersion')) {
543
+ i++;
544
+ if (is(peek(), 'punct', '='))
545
+ i++;
546
+ if (is(peek(), 'num') || is(peek(), 'str')) {
547
+ i++;
548
+ return;
549
+ }
550
+ unsupported(peek());
551
+ }
446
552
  if (!is(s, 'id', 'defaultConfig'))
447
553
  unsupported(s);
448
554
  i++;
@@ -455,6 +561,41 @@ export function parseIncludeGradle(text) {
455
561
  expect('id', 'true');
456
562
  return;
457
563
  }
564
+ if (is(d, 'id', 'targetSdkVersion') || is(d, 'id', 'targetSdk') || is(d, 'id', 'compileSdkVersion') || is(d, 'id', 'compileSdk')) {
565
+ i++;
566
+ if (is(peek(), 'punct', '='))
567
+ i++;
568
+ const paren = is(peek(), 'punct', '(');
569
+ if (paren)
570
+ i++;
571
+ expect('num');
572
+ if (paren)
573
+ expect('punct', ')');
574
+ return;
575
+ }
576
+ if (blockOf('vectorDrawables')) {
577
+ i++;
578
+ statements((v) => {
579
+ if (!is(v, 'id', 'useSupportLibrary'))
580
+ unsupported(v);
581
+ i++;
582
+ if (is(peek(), 'punct', '='))
583
+ i++;
584
+ if (!is(peek(), 'id', 'true') && !is(peek(), 'id', 'false'))
585
+ unsupported(peek());
586
+ i++;
587
+ });
588
+ return;
589
+ }
590
+ if (is(d, 'id', 'vectorDrawables') && is(peek(1), 'punct', '.') && is(peek(2), 'id', 'useSupportLibrary')) {
591
+ i += 3;
592
+ if (is(peek(), 'punct', '='))
593
+ i++;
594
+ if (!is(peek(), 'id', 'true') && !is(peek(), 'id', 'false'))
595
+ unsupported(peek());
596
+ i++;
597
+ return;
598
+ }
458
599
  if (!is(d, 'id', 'minSdkVersion') && !is(d, 'id', 'minSdk'))
459
600
  unsupported(d);
460
601
  i++;
@@ -1,3 +1,8 @@
1
+ // The async lowering's state and identical placement/refusal forwarding methods both translators keep alike, installed on
2
+ // each prototype as `frontMethods` are. Not traced: they answer nothing.
3
+ import ts from 'typescript';
4
+ import { argumentSlot, place, resultSlot, storeSlot } from "./placement.js";
5
+ import { located } from "./refusals.js";
1
6
  export const loweringMethods = {
2
7
  /** Runs `body` inside a lowered async region: its breaks and continues are the region's, not a native loop's. */
3
8
  withAsync(ctx, body) {
@@ -39,4 +44,55 @@ export const loweringMethods = {
39
44
  this.asyncCtx = saved;
40
45
  }
41
46
  },
47
+ /** An expression placed where the backend needs a value of `target`. */
48
+ coerce(e, target) {
49
+ return place(this.placement, e, target);
50
+ },
51
+ /** `e` stored by `at` (a declaration, an object literal's field, an assignment's target) where the backend holds `target`. */
52
+ stored(e, at, target, checks = true) {
53
+ return place(this.placement, e, this.storeSlot(e, target, at, checks));
54
+ },
55
+ storeSlot(e, target, at, checks = true) {
56
+ return storeSlot(this.placement, target, at, e, checks);
57
+ },
58
+ /** The result slot of the function being translated, where `at` (a `return`, an expression body) gives its value. */
59
+ resultSlot(at) {
60
+ return resultSlot(this.asyncCtx ? this.asyncCtx.result : this.returnType, ts.findAncestor(at.parent, ts.isFunctionLike), !!this.asyncCtx);
61
+ },
62
+ /** An argument of `call` with no declared parameter's cell, as `element`: a built-in's (`Math.max`) or one an untyped callee takes. */
63
+ restArgument(call, a, element) {
64
+ return place(this.placement, a, this.restSlot(call, element)(a));
65
+ },
66
+ /** The slot of each value `at` stores as a container's element (`elementStoreOf`), held as `element`. */
67
+ elementSlot(at, element) {
68
+ return (a) => storeSlot(this.placement, element, at, a);
69
+ },
70
+ /** A value `call` stores as an element of its receiver (`push`'s, `add`'s), held as `element`. */
71
+ elementArgument(call, a, element) {
72
+ return place(this.placement, a, this.elementSlot(call, element)(a));
73
+ },
74
+ /** The slot of each argument `call` gives a rest parameter (`decl`), or an untyped callee: one `element` each, placed with no declared parameter's cell. */
75
+ restSlot(call, element, decl) {
76
+ return (a) => {
77
+ const k = call.arguments?.indexOf(a) ?? -1;
78
+ return argumentSlot(this.placement, element, decl, { call, k, a: k < 0 ? undefined : a }, { rest: true });
79
+ };
80
+ },
81
+ /** An error the translation of `n` failed with, at `n` unless it says where already (semantics/refusals.ts). */
82
+ located(e, n) {
83
+ return located(e, n, (at, what, id) => this.error(at, what, id));
84
+ },
85
+ error(n, what, id = 'unhandled') {
86
+ if (!n)
87
+ return this.config.refusals.refusal(`${what} is not supported in a release build yet`, id);
88
+ const sf = n.getSourceFile();
89
+ const { line, character } = sf.getLineAndCharacterOfPosition(n.getStart());
90
+ return this.config.refusals.refusedAt(sf.fileName, line + 1, character + 1, what, n.getText().slice(0, 80), id);
91
+ },
92
+ /** A declared limit of release builds: refused with why and how to write it instead. */
93
+ limit(n, id, what) {
94
+ const sf = n.getSourceFile();
95
+ const { line, character } = sf.getLineAndCharacterOfPosition(n.getStart());
96
+ return this.config.refusals.limitAt(sf.fileName, line + 1, character + 1, what, n.getText().slice(0, 80), id);
97
+ },
42
98
  };
@@ -1,7 +1,7 @@
1
1
  // A call's arguments as Swift: the slot each parameter takes, missing and spread arguments, rest and packed arguments.
2
2
  import ts from 'typescript';
3
3
  import { functionParts, heldType, isOptional, nullishType, optionalType, RT } from "./syntax.js";
4
- import { argumentSlot, place, storeSlot } from "../semantics/placement.js";
4
+ import { argumentSlot, place } from "../semantics/placement.js";
5
5
  import { implementationOf } from "../semantics/ast.js";
6
6
  import { isStatic } from "../semantics/throws.js";
7
7
  import { isUntyped, spelledType } from "../semantics/types.js";
@@ -199,25 +199,6 @@ export const argumentsMethods = {
199
199
  return `, spread: ${this.packed(args, 'JSArray<Any?>', slot)}.storage`;
200
200
  return args.map((a) => `, ${place(this.placement, a, slot(a))}`).join('');
201
201
  },
202
- /** An argument of `call` with no declared parameter's cell, as `element`: a built-in's (`Math.max`) or one an untyped callee takes. */
203
- restArgument(call, a, element) {
204
- return place(this.placement, a, this.restSlot(call, element)(a));
205
- },
206
- /** The slot of each value `at` stores as a container's element (`elementStoreOf`), held as `element`. */
207
- elementSlot(at, element) {
208
- return (a) => storeSlot(this.placement, element, at, a);
209
- },
210
- /** A value `call` stores as an element of its receiver (`push`'s, `add`'s), held as `element`. */
211
- elementArgument(call, a, element) {
212
- return place(this.placement, a, this.elementSlot(call, element)(a));
213
- },
214
- /** The slot of each argument `call` gives a rest parameter (`decl`), or an untyped callee: one `element` each, placed with no declared parameter's cell. */
215
- restSlot(call, element, decl) {
216
- return (a) => {
217
- const k = call.arguments?.indexOf(a) ?? -1;
218
- return argumentSlot(this.placement, element, decl, { call, k, a: k < 0 ? undefined : a }, { rest: true });
219
- };
220
- },
221
202
  /** Arguments (spreads included) as one `JSArray` of `arrayType`; `slot` places each element where they are a call's. */
222
203
  packed(items, arrayType, slot) {
223
204
  const el = arrayType.replace(/^JSArray<(.*)>$/, '$1');
@@ -2,7 +2,7 @@
2
2
  import ts from 'typescript';
3
3
  import { atLossSite, HELD_LOSS } from "../semantics/losses.js";
4
4
  import { assignsTo, balanced, heldType, ident, isOptional, swiftString, withoutAvailableBlocks, RT } from "./syntax.js";
5
- import { place, resultSlot, returnCell, storeSlot } from "../semantics/placement.js";
5
+ import { place, returnCell } from "../semantics/placement.js";
6
6
  import { deadZoneBinding, leadingNeverRead } from "../semantics/lang.js";
7
7
  import { isAsync, isStatic } from "../semantics/throws.js";
8
8
  import { readEarly } from "../semantics/classes.js";
@@ -473,21 +473,6 @@ export const statementsMethods = {
473
473
  tryPrefix(e) {
474
474
  return this.throwsInfo.expr(e) ? 'try ' : '';
475
475
  },
476
- /** An expression where Swift needs a value of `target`. */
477
- coerce(e, target) {
478
- return place(this.placement, e, target);
479
- },
480
- /** `e` stored by `at` (a declaration, an object literal's field, an assignment's target) where Swift holds `target`; `checks` as `storeSlot` has it. */
481
- stored(e, at, target, checks = true) {
482
- return place(this.placement, e, this.storeSlot(e, target, at, checks));
483
- },
484
- storeSlot(e, target, at, checks = true) {
485
- return storeSlot(this.placement, target, at, e, checks);
486
- },
487
- /** The result slot of the function being translated, where `at` (a `return`, an expression body) gives its value. */
488
- resultSlot(at) {
489
- return resultSlot(this.asyncCtx ? this.asyncCtx.result : this.returnType, ts.findAncestor(at.parent, ts.isFunctionLike), !!this.asyncCtx);
490
- },
491
476
  /** A `return` statement's cell, as Swift writes it. */
492
477
  returned(cell, slot) {
493
478
  const i = this.indent, a = this.asyncCtx;
@@ -11,7 +11,7 @@ import { CoreAPI } from "./core-api.js";
11
11
  import { Framework } from "../adapters/hooks.js";
12
12
  import { NativeAPI } from "./native/api.js";
13
13
  import { recognizePatterns } from "../program/patterns.js";
14
- import { located, rethrowUnlessRefused } from "../semantics/refusals.js";
14
+ import { rethrowUnlessRefused } from "../semantics/refusals.js";
15
15
  import { ShapeMap } from "../semantics/shapes.js";
16
16
  import { Throws, isStatic } from "../semantics/throws.js";
17
17
  import { assertedOperand, implementedInterfaces, substitutedExpr, uncheckedMatch } from "../semantics/lang.js";
@@ -867,24 +867,6 @@ export class Translator {
867
867
  throw this.limit(n, 'lone-surrogate', 'a string with a lone surrogate');
868
868
  return text;
869
869
  }
870
- /** `return value` in an async generator: the value awaited first. */
871
- /** An error the translation of `n` failed with, at `n` unless it says where already (semantics/refusals.ts). */
872
- located(e, n) {
873
- return located(e, n, (at, what, id) => this.error(at, what, id));
874
- }
875
- error(n, what, id = 'unhandled') {
876
- if (!n)
877
- return this.config.refusals.refusal(`${what} is not supported in a release build yet`, id);
878
- const sf = n.getSourceFile();
879
- const { line, character } = sf.getLineAndCharacterOfPosition(n.getStart());
880
- return this.config.refusals.refusedAt(sf.fileName, line + 1, character + 1, what, n.getText().slice(0, 80), id);
881
- }
882
- /** A declared limit of release builds: refused with why and how to write it instead. */
883
- limit(n, id, what) {
884
- const sf = n.getSourceFile();
885
- const { line, character } = sf.getLineAndCharacterOfPosition(n.getStart());
886
- return this.config.refusals.limitAt(sf.fileName, line + 1, character + 1, what, n.getText().slice(0, 80), id);
887
- }
888
870
  }
889
871
  for (const methods of mixins)
890
872
  Object.defineProperties(Translator.prototype, Object.getOwnPropertyDescriptors(methods));
@@ -28,3 +28,7 @@ General | `$ ns compile ios [--for-device] [--team-id <Team>] [--provision <Prof
28
28
  * `--allow-untested-frameworks` - Warns instead of stopping when framework versions are outside the adapter range.
29
29
  * `--skip-toolchain-check` - Skips Xcode version validation.
30
30
  * `--whole-kit` - Compiles every file of NativeScriptKit instead of closed-world tree-shaking.
31
+
32
+ ### Platform Notes
33
+
34
+ * `new Worker(...)` background threads are currently supported in compiled Android builds (`ns compile android`) and refused at compile time on iOS (`worker` refusal); guard worker usage behind `if (__ANDROID__)` or use async/Promise concurrency for cross-platform builds.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstudio/nativescript-compiler",
3
- "version": "9.2.0-alpha.12",
3
+ "version": "9.2.0-alpha.13",
4
4
  "description": "NativeScript CLI plugin (`ns compile`) and compiler turning a NativeScript app into native Swift (iOS) or Kotlin (Android) with no JavaScript runtime; framework adapters (`@nstudio/nativescript-compiler-<framework>`) compile each framework.",
5
5
  "type": "module",
6
6
  "keywords": [